Skip to content

Update sample template #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions samples/vsphere/common/sample_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
__author__ = 'VMware, Inc.'
__vcenter_version__ = '6.5+'

import atexit

from com.vmware.vcenter_client import VM
from samples.vsphere.common import vapiconnect
from samples.vsphere.common.sample_util import parse_cli_args
from samples.vsphere.common.service_manager_factory import ServiceManagerFactory


class Sample:
Expand All @@ -33,21 +31,36 @@ class Sample:

def __init__(self):
self.vm_service = None # Service used by the sample code.
self.stub_config = None
self.si = None
self.cleardata = None

def setup(self):
server, username, password, cleardata, skip_verification = \
parse_cli_args()
stub_config = vapiconnect.connect(server, username, password,
skip_verification)
self.vm_service = VM(stub_config)
self.cleardata = cleardata
atexit.register(vapiconnect.logout, stub_config)

# Connect to both Vim and vAPI services
service_manager = ServiceManagerFactory.get_service_manager(
server,
username,
password,
skip_verification)

# Get the vAPI stub
self.stub_config = service_manager.stub_config
self.vm_service = VM(self.stub_config)

# Get VIM service instance (pyVmomi)
self.si = service_manager.si

def run(self):
vms = self.vm_service.list()
print(vms)

current_time = self.si.CurrentTime()
print(current_time)

def cleanup(self):
if self.cleardata:
pass
Expand All @@ -60,6 +73,5 @@ def main():
sample.cleanup()


# Start program
if __name__ == '__main__':
main()