~devel-sumpfralle/virtualbrick/nitpicking

« back to all changes in this revision

Viewing changes to virtualbricks/console.py

  • Committer: Marco Giusti
  • Date: 2013-06-12 12:39:38 UTC
  • Revision ID: marco.giusti@gmail.com-20130612123938-n74j6uyuoqk7fyl9
Remove or disable remote management

Show diffs side-by-side

added added

removed removed

Lines of Context:
528
528
                    self.sendLine("\tlink: %s " % pl.sock.nickname)
529
529
    do_conn = do_connections
530
530
 
531
 
    def do_control(self, args):
532
 
        if len(args) == 2:
533
 
            host, password = args
534
 
            remote = self.factory.get_host_by_name(host)
535
 
            remote.password = password
536
 
            if remote.connect():
537
 
                self.sendLine("Connection OK")
538
 
            else:
539
 
                self.sendLine("Connection Failed.")
540
 
 
541
 
    def do_udp(self, args):
542
 
        self.sendLine("udp command does not work at the moment")
543
 
        return
544
 
        # if self.factory.TCP:
545
 
        #     if len(args) != 4:
546
 
        #         self.sendLine("FAIL udp arguments")
547
 
        #     for b in iter(self.factory.bricks):
548
 
        #         if b.name == args[2]:
549
 
        #             w = PyWire(self.factory, args[1])
550
 
        #             w.set_remoteport(args[3])
551
 
        #             w.connect(b.socks[0])
552
 
        #             w.poweron()
553
 
        #             break
554
 
        #         self.sendLine("FAIL Brick not found: %s" % args[2])
555
 
 
556
531
    # easter eggs
557
532
    def do_python(self, args):
558
533
        """Open a python interpreter. Use ^D (^Z on windows) to exit."""
575
550
class ImagesProtocol(Protocol):
576
551
 
577
552
    def do_list(self, parts):
578
 
        host = None
579
 
        if parts:
580
 
            host = self.factory.get_host_by_name(parts[0])
581
553
        for img in self.factory.disk_images:
582
 
            if len(parts) == 1 and img.host is None:
583
 
                self.sendLine("%s,%s" % (img.name, img.path))
584
 
            if (host is not None and img.host is not None
585
 
                and img.host.addr[0] == host.addr[0]):
586
 
                self.sendLine("%s,%s" % (img.name, img.path))
 
554
            self.sendLine("%s, %s" % (img.name, img.path))
587
555
 
588
556
    def do_files(self, parts):
589
 
        if parts:
590
 
            host = self.factory.get_host_by_name(parts[0])
591
 
            if host is not None and host.connected:
592
 
                self.sendLine("files not works for remote hosts.")
593
 
                return
594
 
                # XXX
595
 
                # files = host.get_files_list()
596
 
                # log.debug(files)
597
 
                # if files is None:
598
 
                #     self.sendLine("No files found.")
599
 
                # else:
600
 
                #     for f in files:
601
 
                #         self.sendLine(f)
602
 
            else:
603
 
                self.sendLine("Not connected to %s" % parts[0])
604
 
            return
605
557
        dirname = self.factory.settings.get("baseimages")
606
558
        for image_file in os.listdir(dirname):
607
559
            if os.path.isfile(dirname + "/" + image_file):
610
562
    def do_add(self, parts):
611
563
        if parts:
612
564
            basepath = self.factory.settings.get("baseimages")
613
 
            host = None
614
565
            name = parts[0].replace(".", "_")
615
566
            name = name.replace("/", "_")
616
 
            if len(parts) == 2:
617
 
                host = self.factory.get_host_by_name(parts[1])
618
 
                if host is not None:
619
 
                    basepath = host.baseimages
620
 
            if len(parts) == 2 and parts[1].find("/") > -1:
621
 
                img = self.factory.new_disk_image(name, parts[1])
622
 
            else:
623
 
                img = self.factory.new_disk_image(name, basepath + "/" + parts[0])
624
 
            if host is not None:
625
 
                img.host = host
626
 
                if host.connected is True:
627
 
                    host.send("i add " + parts[1])
628
 
                    host.expect_OK()
 
567
            img = self.factory.new_disk_image(name, basepath + "/" + parts[0])
629
568
 
630
569
    def do_del(self, parts):
631
570
        if parts:
632
571
            image = self.factory.get_image_by_name(parts[0])
633
572
            if image is not None:
634
 
                if len(parts) == 2:
635
 
                    host = self.factory.get_host_by_name(parts[1])
636
 
                    if host.connected is False:
637
 
                        host = None
638
 
                    if host is None:
639
 
                        return
640
 
                    if host is not None and image.host != host:
641
 
                        return
642
 
                    self.factory.remove_disk_image(image)
643
 
                    # self.disk_images.remove(image)
644
 
                    if host.connected is True:
645
 
                        host.send("i del " + parts[0])
646
 
                        host.expect_OK()
647
 
                if image.host is not None:
648
 
                    return
649
573
                self.factory.remove_disk_image(image)
650
 
                # self.disk_images.remove(image)
651
574
 
652
575
    def do_base(self, parts):
653
576
        if not parts or parts[0] == "show":
654
 
            self.sendLine("%s" % self.factory.settings.get("baseimages"))
 
577
            self.sendLine(self.factory.settings.get("baseimages"))
655
578
        elif parts[0] == "set" and len(parts) > 1:
656
 
            if len(parts) == 3:
657
 
                host = None
658
 
                host = self.factory.get_host_by_name(parts[2])
659
 
                if host is None:
660
 
                    return
661
 
                host.baseimages = str(parts[1])
662
 
            else:
663
 
                self.factory.settings.set("baseimages", parts[1])
 
579
            self.factory.settings.set("baseimages", parts[1])
664
580
 
665
581
 
666
582
class ConfigurationProtocol(Protocol):
676
592
        #     pass  # TODO: show all settings
677
593
 
678
594
    def do_set(self, args):
679
 
        if len(args) > 1:
680
 
            if self.factory.settings.has_option(args[0]):
681
 
                host = None
682
 
                if len(args) == 3:
683
 
                    host = self.factory.get_host_by_name(args[2])
684
 
                    if host is not None and host.connected is True:
685
 
                        host.send("cfg " + args[0] + " " + args[1])
686
 
                else:
687
 
                    self.factory.settings.set(args[0], args[1])
 
595
        if len(args) > 1 and self.factory.settings.has_option(args[0]):
 
596
            self.factory.settings.set(args[0], args[1])