From 0a25301596a727b7c493825c90d8b59d4c0f0f5f Mon Sep 17 00:00:00 2001 From: Kobi Samoray Date: Tue, 11 Jul 2017 16:04:37 +0300 Subject: [PATCH] NSXT instance migration: support file logging Add the option to log the output of the instance migration into a file. Change-Id: Ia8c0723c487f0b8bf635149dafd9d7226c51caa8 --- vmware_nsx/shell/nsx_instance_if_migrate.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vmware_nsx/shell/nsx_instance_if_migrate.py b/vmware_nsx/shell/nsx_instance_if_migrate.py index 053a9637b7..d8536a5bd6 100644 --- a/vmware_nsx/shell/nsx_instance_if_migrate.py +++ b/vmware_nsx/shell/nsx_instance_if_migrate.py @@ -37,6 +37,7 @@ def usage(): "[--project-domain-id=] " "[--user-domain-id=] " "[--machine-type=] " "[--nsx-bridge=]\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.error(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.error('Failed to connect to libvirt')