NSXT instance migration: support file logging

Add the option to log the output of the instance migration into a
file.

Change-Id: Ia8c0723c487f0b8bf635149dafd9d7226c51caa8
(cherry picked from commit 0a25301596)
This commit is contained in:
Kobi Samoray 2017-07-11 16:04:37 +03:00 committed by garyk
parent ec75ff9581
commit 300d8dc15d
1 changed files with 10 additions and 0 deletions

View File

@ -37,6 +37,7 @@ def usage():
"[--project-domain-id=<project domain>] "
"[--user-domain-id=<user domain>] "
"[--machine-type=<migrated machine type] "
"[--logfile=<log file>] "
"[--nsx-bridge=<NSX managed vSwitch>]\n\n"
"Convert libvirt interface definitions on a KVM host, to NSX "
"managed vSwitch definitions\n\n"
@ -46,6 +47,7 @@ def usage():
" project domain: Keystone project domain\n"
" user domain: Keystone user domain\n"
" migrated machine type: Overwrites libvirt's machine type\n"
" log file: Output log of the command execution\n"
" NSX managed vSwitch: vSwitch on host, managed by NSX\n\n")
sys.exit()
@ -64,6 +66,7 @@ def get_opts():
'user-domain-id=',
'auth-url=',
'machine-type=',
'logfile=',
'nsx-bridge='])
except getopt.GetoptError as err:
LOG.debug(err)
@ -188,6 +191,13 @@ def instance_migrate(libvirt_conn, neutron, instance, machine_type,
def main():
opts = get_opts()
if opts.get('logfile'):
f_handler = logging.FileHandler(opts.get('logfile'))
f_formatter = logging.Formatter(
'%(asctime)s %(levelname)s %(message)s')
f_handler.setFormatter(f_formatter)
LOG.addHandler(f_handler)
conn = libvirt.open('qemu:///system')
if conn is None:
LOG.debug('Failed to connect to libvirt')