def create_network_map_from_config(config, pg_cache=False): """Creates physical network to dvs map from config""" connection = None while not connection: try: connection = api.VMwareAPISession( host=config.vsphere_hostname, port=config.host_port, server_username=config.vsphere_login, server_password=config.vsphere_password, api_retry_count=config.api_retry_count, task_poll_interval=config.task_poll_interval, scheme='https', create_session=True, cacert=config.ca_file, insecure=config.insecure, pool_size=config.connections_pool_size) except ConnectionError: LOG.error(_LE("No connection to vSphere. Retry in 10 sec...")) sleep(10) network_map = {} controller_class = DVSControllerWithCache if pg_cache else DVSController for pair in config.network_maps: network, dvs = pair.split(':') network_map[network] = controller_class(dvs, config.cluster_name, connection) return network_map
def __init__(self, name='', args=None, session=None): if args is None: args = self.empty_credentials() else: args['tenant_name'] = None super(VCenterDriver, self).__init__(name, args=args) datasource_driver.ExecutionDriver.__init__(self) try: self.max_VMs = int(args['max_vms']) except (KeyError, ValueError): LOG.warning("max_vms has not been configured, " " defaulting to 999.") self.max_VMs = 999 try: self.max_Hosts = int(args['max_hosts']) except (KeyError, ValueError): LOG.warning("max_hosts has not been configured, " "defaulting to 999.") self.max_Hosts = 999 self.hosts = None self.creds = args self.session = session if session is None: self.session = api.VMwareAPISession(self.creds['auth_url'], self.creds['username'], self.creds['password'], 10, 1, create_session=True) self._init_end_start_poll()
def reset_session(self): self.session = api.VMwareAPISession(self.server_host, self.server_username, self.server_password, self.api_retry_count, self.tpoll_interval) return self.session
def reset_session(self): self.session = api.VMwareAPISession( self.server_host, self.server_username, self.server_password, self.api_retry_count, self.tpoll_interval, cacert=self.ca_file, insecure=self.api_insecure) return self.session
def __init__(self, vsphere_url, username, password): """Get the instance of VSphereClient. :params vsphere_url: a string of vSphere connection url. :type: ``str`` e.g. 'https://127.0.0.1:443' :params username: a string of vSphere login username. :type: ``str`` :params password: a string of vSphere login password. :type: ``str`` """ vsphere_url = urlparse(vsphere_url) self.vsphere_ipaddr = vsphere_url.hostname self.vsphere_port = vsphere_url.port global _SESSION if _SESSION: self.session = _SESSION else: try: _SESSION = self.session = api.VMwareAPISession( host=self.vsphere_ipaddr, server_username=username, server_password=password, api_retry_count=API_RETRY_COUNT, task_poll_interval=TASK_POLL_INTERVAL, port=self.vsphere_port) except vexc.VimFaultException: raise except Exception: raise
def _get_api_session(self): api_session = api.VMwareAPISession( self.vcenter_ip, self.user, self.password, 3, # retry count 0.5, # task_poll_interval scheme="https") return api_session
def get_api_session(): api_session = api.VMwareAPISession(cfg.CONF.vmware.host_ip, cfg.CONF.vmware.host_username, cfg.CONF.vmware.host_password, cfg.CONF.vmware.api_retry_count, cfg.CONF.vmware.task_poll_interval, wsdl_loc=cfg.CONF.vmware.wsdl_location, port=cfg.CONF.vmware.host_port) return api_session
def dvs_create_session(): return api.VMwareAPISession(CONF.dvs.host_ip, CONF.dvs.host_username, CONF.dvs.host_password, CONF.dvs.api_retry_count, CONF.dvs.task_poll_interval, port=CONF.dvs.host_port, cacert=CONF.dvs.ca_file, insecure=CONF.dvs.insecure)
def _create_session(self): return api.VMwareAPISession(self._ip, self._username, self._password, self._api_retry_count, self._task_poll_interval, port=self._port, cacert=self._ca_file, insecure=self._insecure)
def setUp(self): super(TestVsphereInspection, self).setUp() conf = service.prepare_service([], []) api_session = api.VMwareAPISession("test_server", "test_user", "test_password", 0, None, create_session=False, port=7443) vsphere_inspector.get_api_session = mock.Mock( return_value=api_session) self._inspector = vsphere_inspector.VsphereInspector(conf) self._inspector._ops = mock.MagicMock()
def connect_to_vcenter(self): self.session = api.VMwareAPISession(self.vcenter_ip, self.vcenter_user, self.vcenter_password, const.VIM_API_RETRY_COUNT, const.VIM_TASK_POLL_INTERVAL, port=self.vcenter_port, create_session=True ) self.cf = self.session.vim.client.factory
def get_api_session(self): api_session = api.VMwareAPISession( self.init_config.get("vcenter_ip", ""), self.init_config.get("vcenter_user", ""), self.init_config.get("vcenter_password", ""), self.init_config.get("retry_count", 3), # retry count self.init_config.get("poll_interval", 0.5), # task_poll_interval port=self.init_config.get("vcenter_port", 443), scheme="https") return api_session
def setUp(self): api_session = api.VMwareAPISession("test_server", "test_user", "test_password", 0, None, create_session=False) api_session._vim = mock.MagicMock() self._vsphere_ops = vsphere_operations.VsphereOperations( api_session, 1000) super(VsphereOperationsTest, self).setUp()
def get_api_session(conf): api_session = api.VMwareAPISession(conf.vmware.host_ip, conf.vmware.host_username, conf.vmware.host_password, conf.vmware.api_retry_count, conf.vmware.task_poll_interval, wsdl_loc=conf.vmware.wsdl_location, port=conf.vmware.host_port, cacert=conf.vmware.ca_file, insecure=conf.vmware.insecure) return api_session
def create_network_map_from_config(config): """Creates physical network to dvs map from config""" connection = api.VMwareAPISession( config.vsphere_hostname, config.vsphere_login, config.vsphere_password, config.api_retry_count, config.task_poll_interval) network_map = {} for pair in config.network_maps: network, dvs = pair.split(':') network_map[network] = DVSController(dvs, connection) return network_map
def setUp(self): super(TestVsphereInspection, self).setUp() self.CONF = self.useFixture(fixture_config.Config()).conf api_session = api.VMwareAPISession("test_server", "test_user", "test_password", 0, None, create_session=False, port=7443) vsphere_inspector.get_api_session = mock.Mock(return_value=api_session) self._inspector = vsphere_inspector.VsphereInspector(self.CONF) self._inspector._ops = mock.MagicMock()
def _create_api_session(self, _create_session, retry_count=10, task_poll_interval=1): return api.VMwareAPISession(VMwareAPISessionTest.SERVER_IP, VMwareAPISessionTest.USERNAME, VMwareAPISessionTest.PASSWORD, retry_count, task_poll_interval, 'https', _create_session, port=VMwareAPISessionTest.PORT, cacert=self.cert_mock, insecure=False)
def _create_session(self): """Create Vcenter Session for API Calling.""" host_ip = CONF.ml2_vmware.host_ip host_username = CONF.ml2_vmware.host_username host_password = CONF.ml2_vmware.host_password wsdl_location = CONF.ml2_vmware.wsdl_location task_poll_interval = CONF.ml2_vmware.task_poll_interval api_retry_count = CONF.ml2_vmware.api_retry_count self._session = vmwareapi.VMwareAPISession( host_ip, host_username, host_password, api_retry_count, task_poll_interval, create_session=True, wsdl_loc=wsdl_location)
def _create_session(self): """Create Vcenter Session for API Calling.""" try: host_ip = CONF.ml2_vmware.host_ip host_username = CONF.ml2_vmware.host_username host_password = CONF.ml2_vmware.host_password wsdl_location = CONF.ml2_vmware.wsdl_location task_poll_interval = CONF.ml2_vmware.task_poll_interval api_retry_count = CONF.ml2_vmware.api_retry_count self._session = vmwareapi.VMwareAPISession(host_ip, host_username, host_password, api_retry_count, task_poll_interval, create_session=True, wsdl_loc=wsdl_location) except exceptions.VimConnectionException: LOG.error(_("Connection to vcenter %s failed"), host_ip)
def connect(config, **kwds): connection = None while not connection: try: connection = api.VMwareAPISession( config.vsphere_hostname, config.vsphere_login, config.vsphere_password, config.api_retry_count, config.task_poll_interval, cacert=config.ca_certs, insecure=False if config.ca_certs else True, pool_size=config.connections_pool_size, **kwds) except ConnectionError: LOG.error(_LE("No connection to vSphere")) sleep(10) return connection
def create_network_map_from_config(config, pg_cache=False): """Creates physical network to dvs map from config""" connection = None while not connection: try: connection = api.VMwareAPISession( config.vsphere_hostname, config.vsphere_login, config.vsphere_password, config.api_retry_count, config.task_poll_interval, pool_size=config.connections_pool_size) except ConnectionError: LOG.error(_LE("No connection to vSphere")) sleep(10) network_map = {} controller_class = DVSControllerWithCache if pg_cache else DVSController for pair in config.network_maps: network, dvs = pair.split(':') network_map[network] = controller_class(dvs, connection) return network_map
from oslo_vmware import api from oslo_vmware import vim_util # Get a handle to a vSphere API session session = api.VMwareAPISession( '192.168.103.110', # vSphere host endpoint 'root', # vSphere username 'root123', # vSphere password 10, # Number of retries for connection failures in tasks 0.1 # Poll interval for async tasks (in seconds) ) # Example call to get all the managed objects of type "HostSystem" # on the server. # result = session.invoke_api( # vim_util, # Handle to VIM utility module # 'get_objects', # API method name to invoke HostSystem # session.vim, 'VirtualMachine',1, ["config"],all_properties=False) # Params to API method (*args) def _get_token(results): """Get the token from the property results.""" return getattr(results, 'token', None) result = session.invoke_api(vim_util, "get_objects", session.vim, "VirtualMachine",10, ['config.extraConfig["RemoteDisplay.vnc.port"]']) print result vnc_ports = set() while result:
#!/usr/bin/env python __author__ = 'igis_gzy' from oslo_vmware import api from oslo_vmware import vim_util # Get a handle to a vSphere API session session = api.VMwareAPISession( '192.168.126.2', # vCenter_IP 'root', # vCenter_username 'vmware', # vCenter_password 1, 0.1) # Get MO of type "HostSystem" result1 = session.invoke_api(vim_util, 'get_objects', session.vim, 'HostSystem', 100) print "=" * 50 print result1 print "=" * 50 # Get information by properties of MO object rep2 = session.invoke_api(vim_util, 'get_object_properties_dict', session.vim, result1.objects[0].obj, 'vm') print "*" * 50 print rep2 print "*" * 50 rep3 = session.invoke_api(vim_util, 'get_object_properties_dict', session.vim, rep2['vm'].ManagedObjectReference[0], 'summary') print "=" * 50
from oslo_vmware import api from oslo_vmware import vim_util # Get a handle to a vSphere API session session = api.VMwareAPISession( '192.168.103.200', # vSphere host endpoint '*****@*****.**', # vSphere username '!@#4qwerFDSA', # vSphere password 10, # Number of retries for connection failures in tasks 0.1 # Poll interval for async tasks (in seconds) ) # Example call to get all the managed objects of type "HostSystem" # on the server. # result = session.invoke_api( # vim_util, # Handle to VIM utility module # 'get_objects', # API method name to invoke HostSystem # session.vim, 'VirtualMachine',1, ["config"],all_properties=False) # Params to API method (*args) result = session.invoke_api(vim_util, "get_objects", session.vim, "VirtualMachine", 10) print result