PyVmomi package¶
pyVim.connect module¶
Connect to a VMOMI ServiceInstance.
Detailed description (for [e]pydoc goes here).
-
pyVim.connect.
Connect
(host='localhost', port=443, user='root', pwd='', service='hostd', adapter='SOAP', namespace=None, path='/sdk', connectionPoolTimeout=900, version=None, keyFile=None, certFile=None, thumbprint=None, sslContext=None, b64token=None, mechanism='userpass')[source]¶ Connect to the specified server, login and return the service instance object.
Throws any exception back to caller. The service instance object is also saved in the library for easy access.
Clients should modify the service parameter only when connecting to a VMOMI server other than hostd/vpxd. For both of the latter, the default value is fine.
@param host: Which host to connect to. @type host: string @param port: Port @type port: int @param user: User @type user: string @param pwd: Password @type pwd: string @param service: Service @type service: string @param adapter: Adapter @type adapter: string @param namespace: Namespace * Deprecated: Use version instead * @type namespace: string @param path: Path @type path: string @param connectionPoolTimeout: Timeout in secs for idle connections to close, specify negative numbers for never
closing the connections
@type connectionPoolTimeout: int @param version: Version @type version: string @param keyFile: ssl key file path @type keyFile: string @param certFile: ssl cert file path @type certFile: string @param thumbprint: host cert thumbprint @type thumbprint: string @param sslContext: SSL Context describing the various SSL options. It is only
supported in Python 2.7.9 or higher.
@type sslContext: SSL.Context @param b64token: base64 encoded token @type b64token: string @param mechanism: authentication mechanism: userpass or sspi @type mechanism: string
-
pyVim.connect.
ConnectNoSSL
(host='localhost', port=443, user='root', pwd='', service='hostd', adapter='SOAP', namespace=None, path='/sdk', version=None, keyFile=None, certFile=None, thumbprint=None, b64token=None, mechanism='userpass')[source]¶ Provides a standard method for connecting to a specified server without SSL verification. Useful when connecting to servers with self-signed certificates or when you wish to ignore SSL altogether. Will attempt to create an unverified SSL context and then connect via the Connect method.
-
pyVim.connect.
Disconnect
(si)[source]¶ Disconnect (logout) service instance @param si: Service instance (returned from Connect)
-
pyVim.connect.
OpenPathWithStub
(path, stub, verify=True)[source]¶ Open the specified path using HTTP, using the host/port/protocol associated with the specified stub. If the stub has a session cookie, it is included with the HTTP request. Returns the response as a file-like object.
-
pyVim.connect.
OpenUrlWithBasicAuth
(url, user='root', pwd='', verify=True)[source]¶ Open the specified URL, using HTTP basic authentication to provide the specified credentials to the server as part of the request. Returns the response as a file-like object.
-
pyVim.connect.
SmartConnect
(protocol='https', host='localhost', port=443, user='root', pwd='', service='hostd', path='/sdk', connectionPoolTimeout=900, preferredApiVersions=None, keyFile=None, certFile=None, thumbprint=None, sslContext=None, b64token=None, mechanism='userpass')[source]¶ Determine the most preferred API version supported by the specified server, then connect to the specified server using that API version, login and return the service instance object.
Throws any exception back to caller. The service instance object is also saved in the library for easy access.
Clients should modify the service parameter only when connecting to a VMOMI server other than hostd/vpxd. For both of the latter, the default value is fine.
@param protocol: What protocol to use for the connection (e.g. https or http). @type protocol: string @param host: Which host to connect to. @type host: string @param port: Port @type port: int @param user: User @type user: string @param pwd: Password @type pwd: string @param service: Service @type service: string @param path: Path @type path: string @param connectionPoolTimeout: Timeout in secs for idle connections to close, specify negative numbers for never
closing the connections
@type connectionPoolTimeout: int @param preferredApiVersions: Acceptable API version(s) (e.g. vim.version.version3)
If a list of versions is specified the versions should be ordered from most to least preferred. If None is specified, the list of versions support by pyVmomi will be used.
@type preferredApiVersions: string or string list @param keyFile: ssl key file path @type keyFile: string @param certFile: ssl cert file path @type certFile: string @param thumbprint: host cert thumbprint @type thumbprint: string @param sslContext: SSL Context describing the various SSL options. It is only
supported in Python 2.7.9 or higher.
@type sslContext: SSL.Context
-
pyVim.connect.
SmartConnectNoSSL
(protocol='https', host='localhost', port=443, user='root', pwd='', service='hostd', path='/sdk', connectionPoolTimeout=900, preferredApiVersions=None, keyFile=None, certFile=None, thumbprint=None, b64token=None, mechanism='userpass')[source]¶ Provides a standard method for connecting to a specified server without SSL verification. Useful when connecting to servers with self-signed certificates or when you wish to ignore SSL altogether. Will attempt to create an unverified SSL context and then connect via the SmartConnect method.
-
pyVim.connect.
SmartStubAdapter
(host='localhost', port=443, path='/sdk', url=None, sock=None, poolSize=5, certFile=None, certKeyFile=None, httpProxyHost=None, httpProxyPort=80, sslProxyPath=None, thumbprint=None, cacertsFile=None, preferredApiVersions=None, acceptCompressedResponses=True, connectionPoolTimeout=900, samlToken=None, sslContext=None)[source]¶ Determine the most preferred API version supported by the specified server, then create a soap stub adapter using that version
The parameters are the same as for pyVmomi.SoapStubAdapter except for version which is renamed to prefferedApiVersions
- @param preferredApiVersions: Acceptable API version(s) (e.g. vim.version.version3)
If a list of versions is specified the versions should be ordered from most to least preferred. If None is specified, the list of versions support by pyVmomi will be used.
@type preferredApiVersions: string or string list
-
class
pyVim.connect.
VimSessionOrientedStub
(soapStub, loginMethod, retryDelay=0.1, retryCount=4)[source]¶ Bases:
pyVmomi.SoapAdapter.SessionOrientedStub
A vim-specific SessionOrientedStub. See the SessionOrientedStub class in pyVmomi/SoapAdapter.py for more information.
-
SESSION_EXCEPTIONS
= (<class 'pyVmomi.VmomiSupport.vim.fault.NotAuthenticated'>,)¶
-
static
makeCertHokTokenLoginMethod
(stsUrl, stsCert=None)[source]¶ Return a function that will call the vim.SessionManager.LoginByToken() after obtaining a HoK SAML token from the STS. The result of this function can be passed as the “loginMethod” to a SessionOrientedStub constructor.
@param stsUrl: URL of the SAML Token issuing service. (i.e. SSO server). @param stsCert: public key of the STS service.
-
static
makeCredBearerTokenLoginMethod
(username, password, stsUrl, stsCert=None)[source]¶ Return a function that will call the vim.SessionManager.LoginByToken() after obtaining a Bearer token from the STS. The result of this function can be passed as the “loginMethod” to a SessionOrientedStub constructor.
@param username: username of the user/service registered with STS. @param password: password of the user/service registered with STS. @param stsUrl: URL of the SAML Token issueing service. (i.e. SSO server). @param stsCert: public key of the STS service.
-
pyVmomi.VmomiSupport module¶
-
pyVmomi.VmomiSupport.
CreateAndLoadManagedType
(vmodlName, wsdlName, parent, version, props, methods)[source]¶
-
pyVmomi.VmomiSupport.
CreateManagedType
(vmodlName, wsdlName, parent, version, props, methods)[source]¶
-
pyVmomi.VmomiSupport.
FormatObject
(val, info=<pyVmomi.VmomiSupport.Object object>, indent=0)[source]¶
-
pyVmomi.VmomiSupport.
GetServiceVersions
(namespace)[source]¶ Get all the versions for the service with specified namespace (partially) ordered by compatibility (i.e. any version in the list that is compatible with some version v in the list will preceed v)
-
pyVmomi.VmomiSupport.
GetVersionProps
(version)[source]¶ Get version properties
This function is a fixed version of GetVersion().
-
class
pyVmomi.VmomiSupport.
LazyObject
(**kwargs)[source]¶ Bases:
pyVmomi.VmomiSupport.Object
-
class
pyVmomi.VmomiSupport.
ManagedMethod
(info)[source]¶ Bases:
pyVmomi.VmomiSupport.Curry
-
class
pyVmomi.VmomiSupport.
ManagedObject
(moId, stub=None, serverGuid=None)[source]¶ Bases:
object
-
Array
¶ alias of
ManagedObject[]
-
-
pyVmomi.VmomiSupport.
SetAttr
()¶ Implement setattr(self, name, value).
-
class
pyVmomi.VmomiSupport.
StringDict
(*args, **kwargs)[source]¶ Bases:
dict
String only dictionary: same as dict, except it only accept string as value
dict in python is kind of strange. U cannot just override __setitem__, as __init__, update, and setdefault all bypass __setitem__. When override, we have to override all three together
-
class
pyVmomi.VmomiSupport.
VmomiJSONEncoder
(*args, **kwargs)[source]¶ Bases:
json.encoder.JSONEncoder
Custom JSON encoder to encode vSphere objects.
- When a ManagedObject is encoded, it gains three properties:
_vimid is the _moId (ex: ‘vm-42’) _vimref is the moRef (ex: ‘vim.VirtualMachine:vm-42’) _vimtype is the class name (ex: ‘vim.VirtualMachine’)
- When a DataObject is encoded, it gains one property:
_vimtype is the class name (ex: ‘vim.VirtualMachineQuestionInfo’)
- If the dynamicProperty and dynamicType are empty, they are optionally
omitted from the results of DataObjects and ManagedObjects
- @example “Explode only the object passed in”
data = json.dumps(vm, cls=VmomiJSONEncoder)
- @example “Explode specific objects”
- data = json.dumps(vm, cls=VmomiJSONEncoder,
explode=[vm, vm.network[0]])
- @example “Explode all virtual machines in a list and their snapshots”
- data = json.dumps([vm1, vm2], cls=VmomiJSONEncoder,
- explode=[templateOf(‘VirtualMachine’),
templateOf(‘VirtualMachineSnapshot’)])
-
default
(obj)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
pyVmomi.VmomiSupport.
arrayType
¶ alias of
pyVmomi.VmomiSupport.PropertyPath[]