"Please specify a user-name and passward for the given host:%s", options.host) exit(1) host_name = options.host user = options.user if options.user else "root" passwd = str(options.passwd).replace('\\', '') if options.passwd else "" if not options.list_vif and not options.list_pif and not options.list_sr and not options.list_network and \ not options.list_bridge and \ (not options.vif_index and not options.del_index and not options.add_index and not options.disk_size and not options.cpu_cores and not options.max_cores and not options.memory_size and not options.min_memory and not options.max_memory): parser.print_help() exit(1) virthost = VirtHostDomain(host_name, user, passwd) if not virthost: log.fail( "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed." ) exit(1) vnet_driver = virthost.vnet_driver virt_driver = virthost.virt_driver if options.list_pif: pif_list = vnet_driver.get_all_devices() if pif_list: virthost.print_all_interface() else: log.info("No device found on the host.")
if not xml_utils.validate(schema_file, filename): log.fail("XML file '%s' did not validate with the schema.xsd!", filename) exit(1) # start to create via xml parsed_xml = xml_utils.parse_xml(filename) # [{'passwd': '123456', 'host': '192.168.1.10', 'user': '******', 'vms': []}] # 1. validate xml items iplist = [] for server in parsed_xml: hostname, user, passwd = server['host'], server['user'], server[ 'passwd'] log.info("Start to validate VMs in server: %s", hostname) virthost = VirtHostDomain(hostname, user, passwd) if not virthost: log.fail( "Can not connect to host [%s] or DB driver, initial VirtHostDomain failed.", hostname) exit(1) vnet_driver = virthost.vnet_driver virt_driver = virthost.virt_driver # {'cpucores': '2', 'vmname': 'createViaXml', 'maxMemory': '4', 'disks': [{'storage': 'Local storage', 'size': '2'}], # 'ips': [{'vifIndex': '0', 'netmask': None, 'network': 'xenbr1', 'ip': '192.168.1.240'}], # 'cpumax': '4', 'memory': '2', 'minMemory': None} default_sr = virthost.get_max_free_size_storage() all_sr_info = virthost.get_host_all_storage_info() free_memory = virt_driver.get_host_mem_info()['size_free'] total_memory = 0
help="Delete an unused VM in server, the disk will not be deleted") (options, args) = parser.parse_args() log.debug("options:%s, args:%s", str(options), str(args)) if options.host is not None and (options.user is None or options.passwd is None): log.fail( "Please specify a user-name and passward for the given host:%s", options.host) exit(1) host_name = options.host user = options.user if options.user else "root" passwd = str(options.passwd).replace('\\', '') if options.passwd else "" virthost = VirtHostDomain(host_name, user, passwd) if not virthost: log.fail( "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed." ) exit(1) virt_driver = virthost.virt_driver if options.vm: vm_name = options.vm if not virt_driver.is_instance_exists(vm_name): log.fail("No VM named %s.", vm_name) exit(1) # need user to confirm the input # answer = input("Are you sure to delete those VMs: %s ?(Yes/No)" % args)
(options, args) = parser.parse_args() log.debug("options:%s, args:%s", str(options), str(args)) if options.host is not None and (options.user is None or options.passwd is None): log.fail( "Please specify a user-name and passward for the given host:%s", options.host) exit(1) host_name = options.host user = options.user if options.user else "root" passwd = str(options.passwd).replace('\\', '') if options.passwd else "" virthost = VirtHostDomain(host_name, user, passwd) if not virthost: log.fail( "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed." ) exit(1) vnet_driver = virthost.vnet_driver virt_driver = virthost.virt_driver if options.list_vm: all_vms = virthost.get_vm_list() if all_vms: log.info(str(sorted(all_vms))) else: log.info("No VMs.")
if options.host is not None and (options.user is None or options.passwd is None): log.fail( "Please specify a user-name and passward for the given host:%s", options.host) exit(1) host_name = options.host user = options.user if options.user else "root" passwd = str(options.passwd).replace('\\', '') if options.passwd else "" if not args: log.fail("Please specify a VM name to config.") parser.print_help() exit(1) virthost = VirtHostDomain(host_name, user, passwd) if not virthost: log.fail( "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed." ) exit(1) vnet_driver = virthost.vnet_driver virt_driver = virthost.virt_driver vm_name = args[0] if not virt_driver.is_instance_exists(vm_name): log.fail("No VM named [%s].", vm_name) exit(1) if options.list:
help="Power off all VMs in server") (options, args) = parser.parse_args() log.debug("options:%s, args:%s", str(options), str(args)) if options.host is not None and (options.user is None or options.passwd is None): log.fail( "Please specify a user-name and passward for the given host:%s", options.host) exit(1) host_name = options.host user = options.user if options.user else "root" passwd = str(options.passwd).replace('\\', '') if options.passwd else "" virthost = VirtHostDomain(host_name, user, passwd) if not virthost: log.fail( "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed." ) exit(1) virt_driver = virthost.virt_driver if options.all: log.info("Start power off all VMs in server [%s].", host_name) all_vms_names = virt_driver.get_vm_list() for vm_name in all_vms_names: virthost.power_off_vm(vm_name) time.sleep(0.5) exit(0)
(options, args) = parser.parse_args() log.debug("options:%s, args:%s", str(options), str(args)) if options.host is not None and (options.user is None or options.passwd is None): log.fail( "Please specify a user-name and passward for the given host:%s", options.host) exit(1) host_name = options.host user = options.user if options.user else "root" passwd = str(options.passwd).replace('\\', '') if options.passwd else "" virthost = VirtHostDomain(host_name, user, passwd) if not virthost: log.fail( "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed." ) exit(1) virt_driver = virthost.virt_driver if options.all: log.info("Start reset all VMs in server.") all_vms_names = virt_driver.get_vm_list() for vm_name in all_vms_names: virthost.reset_vm(vm_name) time.sleep(1) exit(0)
(options, args) = parser.parse_args() log.debug("options: %s, args: %s", options, args) if options.host is not None and (options.user is None or options.passwd is None): log.fail( "Please specify a user-name and passward for the given host:%s", options.host) exit(1) host_name = options.host user = options.user if options.user else "root" passwd = str(options.passwd).replace('\\', '') if options.passwd else "" if options.vm_name: virt_host = VirtHostDomain(host_name, user, passwd) if not virt_host: log.fail( "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed." ) exit(1) if not virt_host.virt_driver.is_instance_exists(options.vm_name): log.fail("VM [%s] doesn't exist. Exiting...", options.vm_name) exit(1) if virt_host.update_database_info(inst_name=options.vm_name): log.success("Sync VM [%s] information successfully.", options.vm_name) exit(0) else: log.fail("Sync VM [%s] information failed.", options.vm_name) exit(1)
if options.host is not None and (options.user is None or options.passwd is None): log.fail("Please specify a user-name and passward for the given host:%s", options.host) exit(1) host_name = options.host user = options.user if options.user else "root" passwd = str(options.passwd).replace('\\', '') if options.passwd else "" if not options.list_vif and not options.list_pif and not options.list_sr and not options.list_network and\ (not options.vif_index and not options.del_index and not options.add_index and not options.disk_size and not options.cpu_cores and not options.max_cores and not options.memory_size and not options.min_memory and not options.max_memory): parser.print_help() exit(1) virthost = VirtHostDomain(host_name, user, passwd) if not virthost: log.fail("Can not connect to virtual driver or DB driver, initial VirtHostDomain failed.") exit(1) vnet_driver = virthost.vnet_driver virt_driver = virthost.virt_driver if options.list_pif: pif_list = vnet_driver.get_all_devices() if pif_list: virthost.print_all_interface() else: log.info("No device found on the host.") exit(0)
help="Remove disks when vm is deleted") (options, args) = parser.parse_args() log.debug("options:%s, args:%s", str(options), str(args)) if options.host is not None and (options.user is None or options.passwd is None): log.fail( "Please specify a user-name and passward for the given host:%s", options.host) exit(1) host_name = options.host user = options.user if options.user else "root" passwd = str(options.passwd).replace('\\', '') if options.passwd else "" virthost = VirtHostDomain(host_name, user, passwd) if not virthost: log.fail( "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed." ) exit(1) virt_driver = virthost.virt_driver if options.vm: vm_name = options.vm if not virt_driver.is_instance_exists(vm_name): log.fail("No VM named %s.", vm_name) exit(1) # need user to confirm the input # answer = input("Are you sure to delete those VMs: %s ?(Yes/No)" % args)
# when no input, find default server and default vmname and IP host_name, new_vm_name, vm_ip = None, None, None host_name, new_vm_name, vm_ip = get_available_vm_info( role_name, cluster_name, config_dict) if host_name is None or vm_ip is None: log.fail("Can not scheduale new vm to a server, exiting...") exit(1) log.info(">>") log.info( "Get schedualed VM with: host_ip=%s, new_vm_name=%s, vm_ip=%s", host_name, new_vm_name, vm_ip) log.info(">>") virthost = VirtHostDomain(host_name, Libvirtd_User, Libvirtd_Pass) if not virthost: log.fail( "Can not connect to virtual driver or DB driver, initial VirtHostDomain failed." ) exit(1) else: # use command "schedule_node.py --role=rolename --name=new_vm_name --host=hostip --ip=vm_ip" if options.hostip is None or options.new_vm_name is None or options.vm_ip is None: log.fail( "'--name=new_vm_name --host=hostip --ip=vm_ip' is required when with no '--cluster'." ) exit(1) host_name = str.strip(options.hostip)