def ssh_process_autostart(vm_name): logger.info('%s(): caller: %s()', log_utils.get_fname(1), log_utils.get_fname(2)) # If a KVM VM has been created by an earlier script run, its IP address # is not known if not conf.vm[vm_name].ssh_ip: vm.node_to_ip(vm_name) logger.info("Waiting for ssh server in VM %s to respond at %s:%s.", vm_name, conf.vm[vm_name].ssh_ip, conf.vm[vm_name].ssh_port) ssh.wait_for_ssh(vm_name) logger.info(" Connected to ssh server.") sys.stdout.flush() if conf.vm[vm_name].updated: ssh.vm_ssh(vm_name, "rm -rf autostart") else: logging.debug("Updating config, lib, scripts directories for VM %s.", vm_name) ssh.vm_ssh(vm_name, "rm -rf autostart config lib scripts") ssh.vm_scp_to_vm(vm_name, conf.config_dir, conf.lib_dir, conf.scripts_dir) for script_path in sorted(glob(join(conf.autostart_dir, "*.sh"))): ssh_exec_script(vm_name, script_path) os.remove(script_path) open(join(conf.status_dir, "done"), 'a').close()
def ssh_exec_script(vm_name, script_path): ssh.vm_scp_to_vm(vm_name, script_path) remote_path = hf.strip_top_dir(conf.top_dir, script_path) logger.info("Start %s", remote_path) script_name = os.path.splitext(os.path.basename(script_path))[0] prefix = host.get_next_prefix(conf.log_dir, "auto") log_name = "{}_{}.auto".format(prefix, script_name) log_path = os.path.join(conf.log_dir, log_name) try: ssh.vm_ssh(vm_name, "bash {} && rm -vf {}".format(remote_path, remote_path), log_file=log_path) except EnvironmentError: logger.error("Script failure: %s", script_name) sys.exit(1) logger.info(" done")
def ssh_process_autostart(vm_name): # If a KVM VM has been created by an earlier script run, its IP address # is not known if not conf.vm[vm_name].ssh_ip: vm.node_to_ip(vm_name) logger.info("Waiting for ssh server in VM %s to respond at %s:%s.", vm_name, conf.vm[vm_name].ssh_ip, conf.vm[vm_name].ssh_port) ssh.wait_for_ssh(vm_name) logger.info(" Connected to ssh server.") sys.stdout.flush() ssh.vm_ssh(vm_name, "rm -rf osbash lib config autostart") ssh.vm_scp_to_vm(vm_name, conf.lib_dir, conf.config_dir) for script_path in sorted(glob(join(conf.autostart_dir, "*.sh"))): ssh_exec_script(vm_name, script_path) os.remove(script_path) open(join(conf.status_dir, "done"), 'a').close()