Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.vhost_threads = re.findall("\w+\s+(\d+)\s.*\[vhost-%s\]" %
self.get_pid(), o)
# Establish a session with the serial console -- requires a version
# of netcat that supports -U
self.serial_console = aexpect.ShellSession(
"nc -U %s" % self.get_serial_console_filename(),
auto_close=False,
output_func=utils_misc.log_line,
output_params=("serial-%s.log" % name,),
prompt=self.params.get("shell_prompt", "[\#\$]"))
for key, value in self.logs.items():
outfile = "%s-%s.log" % (key, name)
logging.info("add log: %s" % outfile)
self.logsessions[key] = aexpect.Tail(
"nc -U %s" % value,
auto_close=False,
output_func=utils_misc.log_line,
output_params=(outfile,))
# start guest
if self.monitor.verify_status("paused"):
try:
self.monitor.cmd("cont")
except kvm_monitor.QMPCmdError, e:
if ((e.data['class'] == "MigrationExpected") and
(migration_mode is not None)):
logging.debug("Migration did not start yet...")
else:
raise e
def start(self, arg_str='', wait_for_working=True):
"""
Start libvirtd session.
:param arg_str: Argument passing to the session
:param wait_for_working: Whether wait for libvirtd finish loading
"""
if self.gdb:
self.gdb.run(arg_str=arg_str)
self.pid = self.gdb.pid
else:
self.tail = aexpect.Tail(
"%s %s" % (LIBVIRTD, arg_str),
output_func=self._output_handler,
termination_func=self._termination_handler,
)
self.running = True
if wait_for_working:
self.wait_for_working()
tmp_serial = self.serial_ports[0]
except IndexError:
raise virt_vm.VMConfigMissingError(name, "isa_serial")
self.serial_console = aexpect.ShellSession(
"nc -U %s" % self.get_serial_console_filename(tmp_serial),
auto_close=False,
output_func=utils_misc.log_line,
output_params=("serial-%s-%s.log" % (tmp_serial, name),),
prompt=self.params.get("shell_prompt", "[\#\$]"))
del tmp_serial
for key, value in self.logs.items():
outfile = "%s-%s.log" % (key, name)
logging.debug("Add log: %s" % outfile)
self.logsessions[key] = aexpect.Tail(
"nc -U %s" % value,
auto_close=False,
output_func=utils_misc.log_line,
output_params=(outfile,))
# start guest
if self.monitor.verify_status("paused"):
try:
self.monitor.cmd("cont")
except kvm_monitor.QMPCmdError, e:
if ((e.data['class'] == "MigrationExpected") and
(migration_mode is not None)):
logging.debug("Migration did not start yet...")
else:
raise e
try:
tmp_serial = self.serial_ports[0]
except IndexError:
raise virt_vm.VMConfigMissingError(name, "isa_serial")
self.serial_console = aexpect.ShellSession(
"nc -U %s" % self.get_serial_console_filename(tmp_serial),
auto_close=False,
output_func=utils_misc.log_line,
output_params=("serial-%s-%s.log" % (tmp_serial, name),),
prompt=self.params.get("shell_prompt", "[\#\$]"))
del tmp_serial
for key, value in self.logs.items():
outfile = "%s-%s.log" % (key, name)
self.logsessions[key] = aexpect.Tail(
"nc -U %s" % value,
auto_close=False,
output_func=utils_misc.log_line,
output_params=(outfile,))
self.logsessions[key].set_log_file(outfile)
if params.get("paused_after_start_vm") != "yes":
# start guest
if self.monitor.verify_status("paused"):
try:
self.monitor.cmd("cont")
except qemu_monitor.QMPCmdError, e:
if ((e.data['class'] == "MigrationExpected") and
(migration_mode is not None)):
logging.debug("Migration did not start yet...")
else:
if "tcpdump" not in env and params.get("run_tcpdump", "yes") == "yes":
cmd = "%s -npvi any 'dst port 68'" % utils_misc.find_command("tcpdump")
if params.get("remote_preprocess") == "yes":
logging.debug("Starting tcpdump '%s' on remote host", cmd)
login_cmd = ("ssh -o UserKnownHostsFile=/dev/null -o \
PreferredAuthentications=password -p %s %s@%s" %
(port, username, address))
env["tcpdump"] = aexpect.ShellSession(
login_cmd,
output_func=_update_address_cache,
output_params=(env["address_cache"],))
remote._remote_login(env["tcpdump"], username, password, prompt)
env["tcpdump"].sendline(cmd)
else:
logging.debug("Starting tcpdump '%s' on local host", cmd)
env["tcpdump"] = aexpect.Tail(
command=cmd,
output_func=_update_address_cache,
output_params=(env["address_cache"],))
if utils_misc.wait_for(lambda: not env["tcpdump"].is_alive(),
0.1, 0.1, 1.0):
logging.warn("Could not start tcpdump")
logging.warn("Status: %s" % env["tcpdump"].get_status())
logging.warn("Output:" + utils_misc.format_str_for_message(
env["tcpdump"].get_output()))
# Destroy and remove VMs that are no longer needed in the environment
requested_vms = params.objects("vms")
for key in env.keys():
vm = env[key]
if not utils_misc.is_vm(vm):