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()
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()
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()
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()