예제 #1
0
파일: machine.py 프로젝트: nacx/kahuna
    def delete(self, args):
        """ Remove a physical machine from abiquo """
        parser = OptionParser(usage="machine delete <options>")
        parser.add_option("-n", "--name",
                help="the name of the physical machine",
                action="store", dest="name")
        parser.add_option("-i", "--host",
                help="the ip of the physical machine",
                action="store", dest="host")
        (options, args) = parser.parse_args(args)
        name = options.name
        host = options.host

        if not name and not host:
            parser.print_help()
            return

        try:
            admin = self._context.getAdministrationService()
            if name:
                machine = admin.findMachine(MachinePredicates.name(name))
            else:
                machine = admin.findMachine(MachinePredicates.ip(host))
            if not machine:
                print "Machine not found"
                return
            name = machine.getName()
            machine.delete()
            log.debug("Machine %s deleted succesfully" % name)

        except (AbiquoException, AuthorizationException), ex:
            print "Error %s" % ex.getMessage()
예제 #2
0
    def checkMachines(self, args):
        """ Check state from physical machine. """
        parser = OptionParser(usage="machine check <options>")
        parser.add_option("-n","--name",help="the name of the physical machine",action="store",dest="name")
        parser.add_option("-i","--host",help="the ip of the physical machine",action="store",dest="host")
        parser.add_option("-a","--all",help="check all machines",action="store_true",dest="a")
        (options, args) = parser.parse_args(args)
        all_true = options.a
        name = options.name
        host = options.host

        if not name and not host and not all_true:
            parser.print_help()
            return

        context = ContextLoader().load()
        try:
            admin =  context.getAdministrationService()
            if all_true:
                machines = admin.listMachines()
                log.debug("%s machines found." % str(len(machines)))
                [self._checkMachine for machine in machines]
                pprint_machines(machines)
            else:
                if name:
                    machine = admin.findMachine(MachinePredicates.name(name))
                else:
                    machine = admin.findMachine(MachinePredicates.ip(host))
                self._checkMachine(machine)
                pprint_machines([machine]);
        except (AbiquoException, AuthorizationException), ex:
            print "Error %s" % ex.getMessage()
예제 #3
0
    def check(self, args):
        """ Check state from physical machine """
        parser = OptionParser(usage="machine check <options>")
        parser.add_option('-n',
                          '--name',
                          help='the name of the physical machine',
                          action='store',
                          dest='name')
        parser.add_option('-i',
                          '--host',
                          help='the ip of the physical machine',
                          action='store',
                          dest='host')
        parser.add_option('-a',
                          '--all',
                          help='check all machines',
                          action='store_true',
                          dest='a')
        (options, args) = parser.parse_args(args)
        all_true = options.a
        name = options.name
        host = options.host

        if not name and not host and not all_true:
            parser.print_help()
            return

        try:
            admin = self._context.getAdministrationService()
            if all_true:
                machines = admin.listMachines()
                log.debug("%s machines found." % str(len(machines)))
                [self._checkMachine for machine in machines]
                pprint_machines(machines)
            else:
                if name:
                    machine = admin.findMachine(MachinePredicates.name(name))
                else:
                    machine = admin.findMachine(MachinePredicates.ip(host))
                self._checkMachine(machine)
                pprint_machines([machine])
        except (AbiquoException, AuthorizationException), ex:
            print "Error %s" % ex.getMessage()
예제 #4
0
파일: machine.py 프로젝트: nacx/kahuna
    def check(self, args):
        """ Check state from physical machine """
        parser = OptionParser(usage="machine check <options>")
        parser.add_option('-n', '--name',
                help='the name of the physical machine',
                action='store', dest='name')
        parser.add_option('-i', '--host',
                help='the ip of the physical machine',
                action='store', dest='host')
        parser.add_option('-a', '--all', help='check all machines',
                action='store_true', dest='a')
        (options, args) = parser.parse_args(args)
        all_true = options.a
        name = options.name
        host = options.host

        if not name and not host and not all_true:
            parser.print_help()
            return

        try:
            admin = self._context.getAdministrationService()
            if all_true:
                machines = admin.listMachines()
                log.debug("%s machines found." % str(len(machines)))
                [self._checkMachine for machine in machines]
                pprint_machines(machines)
            else:
                if name:
                    machine = admin.findMachine(MachinePredicates.name(name))
                else:
                    machine = admin.findMachine(MachinePredicates.ip(host))
                self._checkMachine(machine)
                pprint_machines([machine])
        except (AbiquoException, AuthorizationException), ex:
            print "Error %s" % ex.getMessage()
예제 #5
0
    def delete(self, args):
        """ Remove a physical machine from abiquo """
        parser = OptionParser(usage="machine delete <options>")
        parser.add_option("-n",
                          "--name",
                          help="the name of the physical machine",
                          action="store",
                          dest="name")
        parser.add_option("-i",
                          "--host",
                          help="the ip of the physical machine",
                          action="store",
                          dest="host")
        (options, args) = parser.parse_args(args)
        name = options.name
        host = options.host

        if not name and not host:
            parser.print_help()
            return

        try:
            admin = self._context.getAdministrationService()
            if name:
                machine = admin.findMachine(MachinePredicates.name(name))
            else:
                machine = admin.findMachine(MachinePredicates.ip(host))
            if not machine:
                print "Machine not found"
                return
            name = machine.getName()
            machine.delete()
            log.debug("Machine %s deleted succesfully" % name)

        except (AbiquoException, AuthorizationException), ex:
            print "Error %s" % ex.getMessage()
예제 #6
0
파일: vm.py 프로젝트: fmontserrat/kahuna
    def find(self, args):
        """ Find a virtual machine given its name. """
        # Parse user input to get the name of the virtual machine
        parser = OptionParser(usage="vm find <options>")
        parser.add_option("-n", "--name", help="The name of the virtual machine to find",
                action="store", dest="name")
        parser.add_option("-v", "--verbose", help="Show virtual machine extended information",
                action="store_true", dest="verbose")
        (options, args) = parser.parse_args(args)
        name = options.name
        if not name:
            parser.print_help()
            return

        # Once user input has been read, find the virtual machine
        context = ContextLoader().load_context()
        try:
            cloud = context.getCloudService()
            vm = cloud.findVirtualMachine(VirtualMachinePredicates.name(name))
            if vm:
                pprint_vms([vm])
                if options.verbose:
                    print "Found virtual machine in: "
                    print "  %s" % vm.getVirtualAppliance()
                    print "  %s" % vm.getVirtualDatacenter()
                    print "  %s" % vm.getEnterprise()
                    if vm.getState().existsInHypervisor():
                        admin = context.getAdministrationService()
                        machine = admin.findMachine(MachinePredicates.ip(vm.getVncAddress()))
                        print "  %s" % machine
                    else:
                        print "  Machine [None (VM not deployed)]"
            else:
                print "No virtual machine found with name: %s" % name
        except (AbiquoException, AuthorizationException), ex:
            print "Error: %s" % ex.getMessage()