Package: vconnector
vConnector - VMware vSphere Connector Module for PythonvConnector is a wrapper module aroundpyVmomi VMware vSphere bindings,
which provides methods for connecting and retrieving of
objects from a VMware vSphere server.The purpose of vConnector is to provide the basic primitives for
building complex applications. vConnector can also be used for
managing the user/pass/host credentials for your vSphere environment
using an SQLite database, which in turn can be shared between
multiple applications requiring access to your vSphere environment
through a common interface.RequirementsPython 2.7.x, 3.2.x or laterdocoptpyVmomitabulateContributionsvConnector is hosted onGithub. Please contribute
by reporting issues, suggesting features or by sending patches
using pull requests.InstallationThe easiest way to install vConnector is by usingpip:$pipinstallvconnectorIn order to install the latest version of vConnector from the
Github repository simply execute these commands instead:$gitclonehttps://github.com/dnaeon/py-vconnector.git$cdpy-vconnector$pythonsetup.pyinstallApplications using vConnector modulevPoller - Distributed vSphere API ProxyvEvents - VMware vSphere Events from the command-lineUsing the vconnector-cli toolUsing thevconnector-clitool you can manage the user/pass/host
credentials of your vSphere environment. Thevconnector-clitool
stores this information in an SQLite database file,
which also makes it easy to be shared between applications.First, initialize the vConnector database by executing the
command below:$vconnector-cliinitHere is how to add a new vSphere host to the vConnector database:$vconnector-cli-Hvc01.example.org-Uroot-Pp4ssw0rdaddHere is how to update an already existing vSphere host
from the vConnector database:$vconnector-cli-Hvc01.example.org-Uroot-Pnewp4ssw0rdupdateHere is how to remove a vSphere host using vconnector-cli:$vconnector-cli-Hvc01.example.orgremoveHere is how to enable a vSphere host using vconnector-cli:$vconnector-cli-Hvc01.example.orgenableHere this is how to disable a vSphere host:$vconnector-cli-Hvc01.example.orgdisableAnd here is how to get the currently registered vSphere hosts from
the vConnector database:$vconnector-cliget+---------------------------+---------------------+--------------+-----------+|Hostname|Username|Password|Enabled|+===========================+=====================+==============+===========+|vc01.example.org|root|p4ssw0rd|0|+---------------------------+---------------------+--------------+-----------+Using the vConnector APIHere are a few examples of using thevconnectormodule API.Connecting to a vSphere host:>>>fromvconnector.coreimportVConnector>>>client=VConnector(...user='root',...pwd='p4ssw0rd',...host='vc01.example.org'...)>>>client.connect()Disconnecting from a vSphere host:>>>client.disconnect()Re-connecting to a vSphere host:>>>client.reconnect()How to get aVMware vSphere Viewof allVirtualMachinemanaged objects:>>>from__future__importprint_function>>>fromvconnector.coreimportVConnector>>>client=VConnector(...user='root',...pwd='p4ssw0rd',...host='vc01.example.org'...)>>>client.connect()>>>vms=client.get_vm_view()>>>print(vms.view)(ManagedObject)['vim.VirtualMachine:vm-36','vim.VirtualMachine:vm-129','vim.VirtualMachine:vm-162','vim.VirtualMachine:vm-146','vim.VirtualMachine:vm-67','vim.VirtualMachine:vm-147','vim.VirtualMachine:vm-134','vim.VirtualMachine:vm-88']>>>client.disconnect()How to get aManaged Objectby a specific property, e.g. find the
Managed Object of an ESXi host which name isesxi01.example.org:>>>from__future__importprint_function>>>importpyVmomi>>>fromvconnector.coreimportVConnector>>>client=VConnector(...user='root',...pwd='p4ssw0rd',...host='vc01.example.org'...)>>>client.connect()>>>host=client.get_object_by_property(...property_name='name',...property_value='esxi01.example.org',...obj_type=pyVmomi.vim.HostSystem...)>>>print(host.name)'esxi01.example.org'>>>client.disconnect()How to collect properties forvSphere Managed Objects, e.g. get
thenameandcapacityproperties for allDatastoremanaged objects:>>>from__future__importprint_function>>>importpyVmomi>>>fromvconnector.coreimportVConnector>>>client=VConnector(...user='root',...pwd='p4ssw0rd',...host='vc01.example.org'...)>>>client.connect()>>>datastores=client.get_datastore_view()>>>result=client.collect_properties(...view_ref=datastores,...obj_type=pyVmomi.vim.Datastore,...path_set=['name','summary.capacity']...)>>>print(result)[{u'summary.capacity':994821799936L,u'name':'datastore1'}]>>>client.disconnect()