From ca53102df499fdf26dc582c0fc045976ae327dac Mon Sep 17 00:00:00 2001 From: Tianhao He Date: Fri, 24 Mar 2017 20:02:40 -0700 Subject: [PATCH] Remove the output file before creating the parallel port Need to make the same fix as the one in #13 for parallel port. Also move the cleanup_backends to the main sample run to make sure the output file is always deleted. Signed-off-by: Tianhao He --- samples/vsphere/vcenter/vm/hardware/parallel.py | 8 ++++++-- samples/vsphere/vcenter/vm/hardware/serial.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/samples/vsphere/vcenter/vm/hardware/parallel.py b/samples/vsphere/vcenter/vm/hardware/parallel.py index de528920..b7764e7a 100644 --- a/samples/vsphere/vcenter/vm/hardware/parallel.py +++ b/samples/vsphere/vcenter/vm/hardware/parallel.py @@ -103,6 +103,9 @@ def run(): print('vm.hardware.Parallel.get({}, {}) -> {}'.format(vm, parallel, pp( parallel_info))) + # Make sure output file doesn't exist already + cleanup_backends() + print('\n# Example: Create Parallel port with defaults') parallel_create_spec = Parallel.CreateSpec() parallel = parallel_svc.create(vm, parallel_create_spec) @@ -180,6 +183,9 @@ def run(): print('vm.hardware.Parallel.list({}) -> {}'. format(vm, parallel_summaries)) + # Always cleanup output file so the VM can be powered on next time + cleanup_backends() + def cleanup(): print('\n# Cleanup: Delete VM Parallel ports that were added') @@ -193,8 +199,6 @@ def cleanup(): print('vm.hardware.Parallel WARNING: ' 'Final Parallel ports info does not match original') - cleanup_backends() - def cleanup_backends(): """ diff --git a/samples/vsphere/vcenter/vm/hardware/serial.py b/samples/vsphere/vcenter/vm/hardware/serial.py index 1f282b8e..3e9d9286 100644 --- a/samples/vsphere/vcenter/vm/hardware/serial.py +++ b/samples/vsphere/vcenter/vm/hardware/serial.py @@ -214,6 +214,9 @@ def run(): serial_summaries = serial_svc.list(vm=vm) print('vm.hardware.Serial.list({}) -> {}'.format(vm, serial_summaries)) + # Always cleanup output file so the VM can be powered on next time + cleanup_backends() + def cleanup(): print('\n# Delete VM Serial ports that were added') @@ -227,8 +230,6 @@ def cleanup(): print('vm.hardware.Serial WARNING: ' 'Final Serial ports info does not match original') - cleanup_backends() - def cleanup_backends(): """