if options.vif_ip is not None: if not virthost.is_IP_available( options.vif_ip, options.vif_netmask, device_name, network, bridge): log.fail("IP check failed.") exit(1) if options.add_index: vif_index = options.add_index if vnet_driver.is_vif_exist(inst_name, vif_index): log.fail("Virtual interface with index %s already exist.", vif_index) exit(1) if virthost.create_new_vif(inst_name, vif_index, device_name, network, bridge, options.vif_ip): log.success( "New virtual interface device created successfully.") exit(0) else: log.fail( "New virtual interface device created or attached failed.") exit(1) elif options.vif_index: vif_index = options.vif_index if virthost.config_vif(inst_name, vif_index, device_name, network, bridge, options.vif_ip): log.success( "New virtual interface device configured successfully.") exit(0) else: log.fail("New virtual interface device configured failed.") exit(1)
"Total memory %s exceed the limit of free memory %s in server %s", total_memory, free_memory, virthost.server_name) log.fail("Validate memory failed in xml file %s.", filename) exit(1) for storage_key, storage_value in disk_size.iteritems(): if storage_value > all_sr_info[storage_key][1] - 1: # log.error( "There is only %sGB in storage: %s, but all VMs disk need: %sGB on '%s'.", all_sr_info[storage_key][1], storage_key, storage_value, storage_key) log.fail("Disk validate failed in xml: %s", filename) exit(1) if not create: log.success("All resource validate successfully.") exit(0) else: log.info("All resource validate successfully.") # 2. create vms in xml for server in parsed_xml: hostname, user, passwd = server['host'], server['user'], server[ 'passwd'] virthost = VirtHostDomain(hostname, user, passwd) vnet_driver = virthost.vnet_driver virt_driver = virthost.virt_driver log.info("Start to create VMs in server: %s", hostname) for vm in server['vms']: vmname = vm['vmname'] log.info("Start to create vm [%s]!", vmname)
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) prompt = "Are you sure to delete those VMs: %s? (Yes/No)\n" % vm_name answer = timeout_func(raw_input, 5, None, prompt) if answer != "Yes": log.info("Your input is not 'Yes'. Exiting...") exit(0) else: log.info("You input 'Yes' to confirm the deletion.") ret = virthost.delete_vm(vm_name) if not ret: log.fail("VM [%s] deleted failed.", vm_name) exit(1) else: log.success("VM [%s] has been deleted successfully.", vm_name) exit(0) else: parser.print_help() exit(0)
else: log.info( "Successfully configured the virtual interface device [%s] to VM [%s].", options.vif_index, new_vm_name) # 4. config VM disk if options.disk_size is not None: ret = virthost.add_vm_disk(new_vm_name, storage_name=options.storage_name, size=size) if ret: log.info( "Successfully add a new disk with size [%s]GB to VM [%s].", size, new_vm_name) else: log.warn( "Failed to add a new disk with size [%s]GB to VM [%s].", size, new_vm_name) # 5. power on VM ret = virthost.power_on_vm(new_vm_name) if ret: log.success("Create VM [%s] and power on successfully.", new_vm_name) exit(0) else: log.fail("VM [%s] created, but power on failed.", new_vm_name) exit(1) else: parser.print_help() exit(1)
exit(0) elif args: virt_driver = VirtFactory.get_virt_driver(host_name, user, passwd) res_dict = {} for vm_name in args: if not virt_driver.is_instance_exists(vm_name): log.warn("No VM exists with name [%s].", vm_name) # if vmname doesn't exist, set it as power off failed res_dict[vm_name] = 1 continue res_dict.setdefault(vm_name, 0) ret = virthost.power_off_vm(vm_name) if not ret: log.error("VM [%s] power on failed.", vm_name) res_dict[vm_name] = 1 time.sleep(0.5) failed_vm_list = [ item[0] for item in filter(lambda x: x[1] == 1, res_dict.items()) ] if failed_vm_list: log.fail("VMs %s power on failed.", str(failed_vm_list)) exit(1) else: log.success("All VMs %s power off successfully.", args) else: parser.print_help() exit(0)
for vm_name in all_vms_names: virthost.power_on_vm(vm_name) time.sleep(0.5) exit(0) elif args: res_dict = {} for vm_name in args: if not virt_driver.is_instance_exists(vm_name): log.warn("No VM exists with name [%s].", vm_name) continue res_dict.setdefault(vm_name, 0) ret = virthost.power_on_vm(vm_name) if not ret: log.error("VM [%s] power on failed.", vm_name) res_dict[vm_name] = 1 time.sleep(0.5) failed_vm_list = [ item[0] for item in filter(lambda x: x[1] == 1, res_dict.items()) ] if failed_vm_list: log.fail("VMs %s power on failed.", str(failed_vm_list)) exit(1) else: log.success("All VMs in %s power on successfully.", args) exit(0) else: parser.print_help() exit(0)
"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) elif options.vm is not None: vm_name = options.vm if not virt_driver.is_instance_exists(vm_name): log.fail("No VM named %s.", vm_name) exit(1) ret = virthost.reset_vm(vm_name) if ret: log.success("VM [%s] reset successfully.", vm_name) exit(0) else: log.fail("VM [%s] reset failed.", vm_name) exit(1) else: parser.print_help() exit(0)
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) elif options.update: server = ServerDomain(host_name, user, passwd) if not server: log.fail( "Can not connect to virtual driver or DB driver, initial HostDomain failed." ) exit(1) server.update_database_info() virt_host = VirtHostDomain(host_name, user, passwd) for vm_name in virt_host.virt_driver.get_vm_list(): virt_host.update_database_info(inst_name=vm_name)
thread_log.exception("thread_log test log for exception") log.info("nohup_orig_log") nohup_orig_log.debug("test log for debug.") nohup_orig_log.info("test log for info") nohup_orig_log.warning("test log for warning") nohup_orig_log.error("test log for error") nohup_orig_log.exception("test log for exception") log.info("nohup log") nohup_log.debug("nohup test log for debug.") nohup_log.info("nohup test log for info") nohup_log.warning("nohup test log for warning") nohup_log.error("nohup test log for error") nohup_log.exception("nohup test log for exception") log.info("rotate_log") rotate_log.debug("test log for debug.") rotate_log.info("test log for info") rotate_log.warning("test log for warning") rotate_log.error("test log for error") rotate_log.exception("test log for exception") log.info("virt console") log.debug("test log for debug.") log.info("test log for info") log.warning("test log for warning") log.error("test log for error") log.exception("test log for exception") log.success("test log for success") log.fail("test log for fail")