Skip to main content

vLab common logic for working with virtual infrastructure

Project description

This library centralizes logic for working with virtual infrastructure providers.

VMware

Builds upon the pyVmomi API bindings for vSphere to create more human friendly objects like:

vCenter

It’s called vCenter because that’s the host you’ll connect to. This object focuses more on interacting with Virtual Machines, than configuring the system.

Here’s an example of what using the vCenter object is like:

from vlab_inf_common.vmware import vCenter, vim
vc = vCenter(user='Alice', password='iLoveDogs', host='some-vcenter-server.corp')
vc.networks
{'front-end': 'vim.Network:network-14'}    # mapping of name -> object
vc.create_vm_folder(path='/some/new/path') # recursively creates the whole path
vms = vc.get_by_type(vim.VirtualMachine)
vms
(ManagedObject) [
'vim.VirtualMachine:vm-15'
]

Ova

This object abstracts use of an OVA file when creating new Virtual Machines. It handles both local paths and URLs for the OVA file location. Deploying the OVA is a single method call (once you’ve obtained a spec and lease).

Here’s an example of using the Ova object:

from vlab_inf_common.vmware import Ova
ova = Ova('https://some-server/myMachine.ova')
ova.networks
['eth0']
ova.vmdks
['disk-1.vmdk', 'disk-2.vmdk']
hasattr(ova, 'ovf') # b/c the ovf XML is too long to put in an example
True

Here’s an example using Ova and vCenter to deploy a new Virtual Machine It’s a bit long, but pyVmomi doesn’t make it easy…

import time
from vlab_inf_common.vmware import Ova, vCenter, vim
vc = vCenter(user='Alice', password='iLoveDogs', host='some-vsphere-server.corp')
ova = Ova('/some/path/myMachine.ova')
my_folder = vc.get_vm_folder('/users/alice')
network_map = vim.OvfManager.NetworkMapping()
network_map.name = ova.networks[0]
network_map.network = vc.networks['front-end'] # assuming you have a network named 'frond-end'
resouce_pool = vc.resource_pool['users']       # assuming your pool name is 'users'
datastore = vc.datastores['general']           # another assumption!
host = list(vc.host_systems.values())[0]       # if you don't care which host you upload to
spec_params = vim.OvfManager.CreateImportSpecParams(entityName='myNewVM', networkMapping=[network_map])
spec = vc.ovf_manager.CreateImportSpec(ovfDescriptor=ova.ovf,
         resourcePool=resouce_pool, datastore=datastore, cisp=spec_params)
lease = resource_pool.ImportVApp(spec.importSpec, folder=my_folder, host=host)
for _ in range(30):
  if lease.state != 'ready':
    time.sleep(1)
  else:
    break
print('starting deploy')
ova.deploy(spec, lease, host.name)
print('Upload complete')
ova.close()

FAQ

How do I deal with self-signed TLS certs in vCenter?

Set the environment variable INF_VCENTER_VERIFY_CERT to anything, and we’ll use the default context created by the Python ssl lib. By default, we’ll ignore self-signed certs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vlab_inf_common-2020.11.24-py2.py3-none-any.whl (23.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file vlab_inf_common-2020.11.24-py2.py3-none-any.whl.

File metadata

  • Download URL: vlab_inf_common-2020.11.24-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.5

File hashes

Hashes for vlab_inf_common-2020.11.24-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3623989a893fce37a490ea4f46a0be76750828777e6a3e9daf74059bc29457fd
MD5 35d433ca38b57363e4ee4e033e2a260a
BLAKE2b-256 02d588c2cd4ea58b10f2eb1ed795fd89a599624f749da59dbaa20241ea8c92d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page