Giter Club home page Giter Club logo

py-vconnector's Introduction

vConnector - VMware vSphere Connector Module for Python

Latest Version Downloads

vConnector is a wrapper module around pyVmomi 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.

Requirements

Contributions

vConnector is hosted on Github. Please contribute by reporting issues, suggesting features or by sending patches using pull requests.

Installation

The easiest way to install vConnector is by using pip:

$ pip install vconnector

In order to install the latest version of vConnector from the Github repository simply execute these commands instead:

$ git clone https://github.com/dnaeon/py-vconnector.git
$ cd py-vconnector
$ python setup.py install

Applications using vConnector module

Using the vconnector-cli tool

Using the vconnector-cli tool you can manage the user/pass/host credentials of your vSphere environment. The vconnector-cli tool 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-cli init

Here is how to add a new vSphere host to the vConnector database:

$ vconnector-cli -H vc01.example.org -U root -P p4ssw0rd add

Here is how to update an already existing vSphere host from the vConnector database:

$ vconnector-cli -H vc01.example.org -U root -P newp4ssw0rd update

Here is how to remove a vSphere host using vconnector-cli:

$ vconnector-cli -H vc01.example.org remove

Here is how to enable a vSphere host using vconnector-cli:

$ vconnector-cli -H vc01.example.org enable

Here this is how to disable a vSphere host:

$ vconnector-cli -H vc01.example.org disable

And here is how to get the currently registered vSphere hosts from the vConnector database:

$ vconnector-cli get
+---------------------------+---------------------+--------------+-----------+
| Hostname                  | Username            | Password     |   Enabled |
+===========================+=====================+==============+===========+
| vc01.example.org          | root                | p4ssw0rd     |         0 |
+---------------------------+---------------------+--------------+-----------+

Using the vConnector API

Here are a few examples of using the vconnector module API.

Connecting to a vSphere host:

>>> from vconnector.core import VConnector
>>> 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 a VMware vSphere View of all VirtualMachine managed objects:

>>> from __future__ import print_function
>>> from vconnector.core import VConnector
>>> 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 a Managed Object by a specific property, e.g. find the Managed Object of an ESXi host which name is esxi01.example.org:

>>> from __future__ import print_function
>>> import pyVmomi
>>> from vconnector.core import VConnector
>>> 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 for vSphere Managed Objects, e.g. get the name and capacity properties for all Datastore managed objects:

>>> from __future__ import print_function
>>> import pyVmomi
>>> from vconnector.core import VConnector
>>> 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()

py-vconnector's People

Contributors

dnaeon avatar andrew-regan avatar dreslan avatar depa77 avatar lucadepaoli avatar movermeyer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.