psphere logo

Table Of Contents

Previous topic

HostSystem examples

This Page

API Documentation

This page documents the psphere API.

psphere.client - A client for communicating with a vSphere server

The main module for accessing a vSphere server.

Module author: Jonathan Kinred <jonathan.kinred@gmail.com>

class psphere.client.Client(server=None, username=None, password=None, wsdl_location='local', timeout=30)

A client for communicating with a VirtualCenter/ESX/ESXi server

>>> from psphere.client import Client
>>> Client = Client(server="esx.foo.com", username="me", password="pass")
Parameters:
  • server (str) – The server of the server. e.g. https://esx.foo.com/sdk
  • username (str) – The username to connect with
  • password (str) – The password to connect with
  • wsdl_location (The string “local” (default) or “remote”) – Whether to use the provided WSDL or load the server WSDL
  • timeout (int (default=30)) – The timeout to use when connecting to the server

Methods

add_prefix
clone
create
dict
find_entity_view
find_entity_views
get_search_filter_spec
get_view
get_views
invoke
invoke_task
items
last_received
last_sent
login
logout
metadata
set_options
create(type_, **kwargs)

Create a SOAP object of the requested type.

>>> client.create('VirtualE1000')
Parameters:
  • type (str) – The type of SOAP object to create.
  • kwargs (TODO) – TODO
find_entity_view(view_type, begin_entity=None, filter={}, properties=None)

Find a ManagedEntity of the requested type.

Traverses the MOB looking for an entity matching the filter.

Parameters:
  • view_type (str) – The type of ManagedEntity to find.
  • begin_entity (ManagedObjectReference or None) – The MOR to start searching for the entity. The default is to start the search at the root folder.
  • filter (dict) – Key/value pairs to filter the results. The key is a valid parameter of the ManagedEntity type. The value is what that parameter should match.
Returns:

If an entity is found, a ManagedEntity matching the search.

Return type:

ManagedEntity

find_entity_views(view_type, begin_entity=None, properties=None)

Find all ManagedEntity’s of the requested type.

Parameters:
  • view_type (str) – The type of ManagedEntity’s to find.
  • begin_entity (ManagedObjectReference or None) – The MOR to start searching for the entity. The default is to start the search at the root folder.
Returns:

A list of ManagedEntity’s

Return type:

list

get_search_filter_spec(begin_entity, property_spec)

Build a PropertyFilterSpec capable of full inventory traversal.

By specifying all valid traversal specs we are creating a PFS that can recursively select any object under the given entity.

Parameters:
  • begin_entity (ManagedEntity) – The place in the MOB to start the search.
  • property_spec (TODO) – TODO
Returns:

A PropertyFilterSpec, suitable for recursively searching under the given ManagedEntity.

Return type:

PropertyFilterSpec

get_view(mo_ref, properties=None)

Get a view of a vSphere managed object.

Parameters:
  • mo_ref (ManagedObjectReference) – The MOR to get a view of
  • properties (list) – A list of properties to retrieve from the server
Returns:

A view representing the ManagedObjectReference.

Return type:

ManagedObject

get_views(mo_refs, properties=None)

Get a list of local view’s for multiple managed objects.

Parameters:
  • mo_refs (ManagedObjectReference) – The list of ManagedObjectReference’s that views are to be created for.
  • properties (list) – The properties to retrieve in the views.
Returns:

A list of local instances representing the server-side managed objects.

Return type:

list of ManagedObject’s

invoke(method, _this, **kwargs)

Invoke a method on the server.

>>> client.invoke('CurrentTime', client.si)
Parameters:
  • method (str) – The method to invoke, as found in the SDK.
  • _this (ManagedObject) – The managed object reference against which to invoke the method.
  • kwargs (TODO) – The arguments to pass to the method, as found in the SDK.
invoke_task(method, **kwargs)

Execute a *_Task method and wait for it to complete.

Parameters:
  • method (str) – The *_Task method to invoke.
  • kwargs (TODO) – The arguments to pass to the method.
login(username=None, password=None)

Login to a vSphere server.

>>> client.login(username='Administrator', password='strongpass')
Parameters:
  • username (str) – The username to authenticate as.
  • password (str) – The password to authenticate with.
logout()
Logout of a vSphere server.