1
0
mirror of https://github.com/vmware/vsphere-automation-sdk-python.git synced 2024-11-23 01:49:59 -05:00

use atexit intead of try catch in main

This commit is contained in:
Tianhao He 2017-02-17 15:03:22 -08:00
parent 288f81d686
commit 4e88ae783d
14 changed files with 104 additions and 125 deletions

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware.boot_client import Device as BootDevice
from com.vmware.vcenter.vm.hardware_client import (
Disk, Ethernet)
@ -62,6 +64,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
@ -154,15 +157,11 @@ def cleanup():
def main():
try:
setup()
cleanup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm_client import Power
from com.vmware.vcenter_client import VM
from samples.vsphere.common import vapiconnect
@ -56,6 +58,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
@ -113,16 +116,11 @@ def cleanup():
def main():
try:
setup()
cleanup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':
main()

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware.boot_client import Device as BootDevice
from com.vmware.vcenter.vm.hardware_client import (
Cpu, Memory, Disk, Ethernet, Cdrom, Serial, Parallel, Floppy, Boot)
@ -66,6 +68,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
@ -242,16 +245,11 @@ def cleanup():
def main():
try:
setup()
cleanup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':
main()

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware.adapter_client import Sata
from samples.vsphere.common import vapiconnect
from samples.vsphere.common.sample_util import pp, \
@ -53,6 +55,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
global vm
@ -123,14 +126,10 @@ def cleanup():
def main():
try:
setup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware.adapter_client import Scsi
from samples.vsphere.common import vapiconnect
from samples.vsphere.common.sample_util import pp, \
@ -53,6 +55,8 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
global vm
@ -133,15 +137,10 @@ def cleanup():
'Final SCSI adapters info does not match original')
def main():
try:
setup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':
main()

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware_client import Boot
from samples.vsphere.common import vapiconnect
from samples.vsphere.common.sample_util import parse_cli_args_vm
@ -53,6 +55,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
@ -125,14 +128,10 @@ def cleanup():
def main():
try:
setup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':

View File

@ -16,13 +16,14 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware.boot_client import Device as BootDevice
from com.vmware.vcenter.vm.hardware_client import (Disk, Ethernet)
from samples.vsphere.common import vapiconnect
from samples.vsphere.common.sample_util import parse_cli_args_vm
from samples.vsphere.common.sample_util import pp
from samples.vsphere.vcenter.setup import testbed
from samples.vsphere.vcenter.helper.vm_helper import get_vm
"""
@ -59,6 +60,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
@ -126,14 +128,10 @@ def cleanup():
def main():
try:
setup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware.adapter_client import Sata
from com.vmware.vcenter.vm.hardware_client import (Cdrom,
IdeAddressSpec,
@ -61,6 +63,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
@ -278,14 +281,10 @@ def cleanup():
def main():
try:
setup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware_client import Cpu
from samples.vsphere.common import vapiconnect
from samples.vsphere.common.sample_util import parse_cli_args_vm
@ -53,6 +55,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
@ -113,14 +116,10 @@ def cleanup():
def main():
try:
setup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware_client import Ethernet
from com.vmware.vcenter.vm_client import Power
from samples.vsphere.common import vapiconnect
@ -23,7 +25,6 @@ from samples.vsphere.common.sample_util import parse_cli_args_vm
from samples.vsphere.common.sample_util import pp
from samples.vsphere.vcenter.helper import network_helper
from samples.vsphere.vcenter.setup import testbed
from samples.vsphere.vcenter.helper.vm_helper import get_vm
"""
@ -56,6 +57,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
@ -247,14 +249,10 @@ def cleanup():
def main():
try:
setup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware_client import Floppy
from com.vmware.vcenter.vm_client import Power
from samples.vsphere.common import vapiconnect
@ -53,6 +55,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
# * Floppy images must be pre-existing. This API does not expose
@ -182,14 +185,10 @@ def cleanup():
def main():
try:
setup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware_client import Memory
from samples.vsphere.common import vapiconnect
from samples.vsphere.common.sample_util import parse_cli_args_vm
@ -53,6 +55,8 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
def run():
global vm
@ -111,14 +115,10 @@ def cleanup():
def main():
try:
setup()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if __name__ == '__main__':
main()

View File

@ -16,6 +16,8 @@ __author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
__vcenter_version__ = '6.5+'
import atexit
from com.vmware.vcenter.vm.hardware_client import Parallel
from com.vmware.vcenter.vm_client import Power
from pyVim.connect import SmartConnect, Disconnect
@ -60,6 +62,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
context = None
if skip_verification:
@ -68,6 +71,7 @@ def setup(context=None):
user=username,
pwd=password,
sslContext=context)
atexit.register(Disconnect, service_instance)
def run():
@ -211,17 +215,11 @@ def cleanup_backends():
def main():
try:
setup()
cleanup_backends()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if service_instance:
Disconnect(service_instance)
if __name__ == '__main__':

View File

@ -15,6 +15,8 @@
__author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2016 VMware, Inc. All rights reserved.'
import atexit
from com.vmware.vcenter.vm.hardware_client import Serial
from com.vmware.vcenter.vm_client import Power
from pyVim.connect import SmartConnect, Disconnect
@ -59,6 +61,7 @@ def setup(context=None):
username,
password,
skip_verification)
atexit.register(vapiconnect.logout, stub_config)
context = None
if skip_verification:
@ -67,6 +70,7 @@ def setup(context=None):
user=username,
pwd=password,
sslContext=context)
atexit.register(Disconnect, service_instance)
def run():
@ -231,20 +235,12 @@ def cleanup_backends():
datacenter_name,
datastore_path)
def main():
try:
setup()
cleanup_backends()
run()
if cleardata:
cleanup()
finally:
if stub_config:
vapiconnect.logout(stub_config)
if service_instance:
Disconnect(service_instance)
if __name__ == '__main__':
main()