1
0
mirror of https://github.com/vmware/vsphere-automation-sdk-python.git synced 2024-11-24 10:19:59 -05:00
vsphere-automation-sdk-python/samples/vsphere/common/service_manager.py

68 lines
2.4 KiB
Python
Raw Normal View History

2016-10-26 19:08:23 -04:00
"""
* *******************************************************
* Copyright VMware, Inc. 2013, 2016. All Rights Reserved.
* SPDX-License-Identifier: MIT
2016-10-26 19:08:23 -04:00
* *******************************************************
*
* DISCLAIMER. THIS PROGRAM IS PROVIDED TO YOU "AS IS" WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, WHETHER ORAL OR WRITTEN,
* EXPRESS OR IMPLIED. THE AUTHOR SPECIFICALLY DISCLAIMS ANY IMPLIED
* WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY,
* NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE.
"""
__author__ = 'VMware, Inc.'
__copyright__ = 'Copyright 2013, 2016 VMware, Inc. All rights reserved.'
from pyVim.connect import SmartConnect, Disconnect
from samples.vsphere.common import vapiconnect
from samples.vsphere.common.ssl_helper import get_unverified_context
class ServiceManager(object):
"""
Manages Vim and vAPI services on a management node.
"""
def __init__(self, server, username, password, skip_verification):
self.server_url = server
self.username = username
self.password = password
self.skip_verification = skip_verification
self.vapi_url = None
self.vim_url = None
self.session = None
self.session_id = None
self.stub_config = None
self.si = None
self.content = None
self.vim_uuid = None
def connect(self):
# Connect to vAPI Endpoint on vCenter Server system
self.stub_config = vapiconnect.connect(host=self.server_url,
user=self.username,
pwd=self.password,
skip_verification=self.skip_verification)
# Connect to VIM API Endpoint on vCenter Server system
context = None
if self.skip_verification:
context = get_unverified_context()
self.si = SmartConnect(host=self.server_url,
user=self.username,
pwd=self.password,
sslContext=context)
assert self.si is not None
# Retrieve the service content
self.content = self.si.RetrieveContent()
assert self.content is not None
self.vim_uuid = self.content.about.instanceUuid
def disconnect(self):
print('disconnecting the session')
vapiconnect.logout(self.stub_config)
Disconnect(self.si)