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.23-py2.py3-none-any.whl (23.6 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: vlab_inf_common-2020.11.23-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.6 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.23-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 26da7aad347a0684c643951b33a785834a165daaf2e97d8af7a58e44a313bf81
MD5 eed6b8e4e281965a8d43d814cafbe73a
BLAKE2b-256 892afd15dc92dcbc5f134e722be77d07e542380d579b0fcf978b7663498fb129

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