Skip to content

multi-cloud-explorer/mce-lib-vsphere

Repository files navigation

Multi-Cloud-Explorer - VMware (Vsphere)

Inventory library for VMware (Vsphere Release)

License: GPL v3 Build Status Coverage Status codecov Code Health Requirements Status Documentation Status

Inventory library for VMware (Vsphere Release)

Features

  • List all Datacenter
  • List all Cluster
  • List all Datastores
  • List all Virtual Machines
  • Command line client

Demo with Terraform and Vcenter Simulator

Open demo-terraform directory

Installation

Requires:

  • Python 3.7+
  • Admin access to Vcenter
pip install git+https://github.com/multi-cloud-explorer/mce-lib-vpshere.git

Usage

Connect with URL:

export MCE_VCENTER_URL=https://user1:pass@127.0.0.1:8989/sdk?timeout=120
with Client() as cli:
    vm = cli.get_vm_by_name("DC0_H0_VM0")
    print(vm.name)

Connect with host/port:

with Client(host="127.0.0.1", port=8989, username="user1", password="pass") as cli:
    vm = cli.get_vm_by_name("DC0_H0_VM0")
    print(vm.name)

Display Vcenter Infos:

from pprint import pprint
from mce_lib_vsphere.core import Client

client = Client('https://user1:pass@127.0.0.1:8989/sdk')
client.connect()

si, content = client.connect()

pprint(client.vcenter_infos())
{
    'apiType': 'VirtualCenter',
    'apiVersion': '6.5',
    'build': '5973321',
    'licenseProductName': 'VMware VirtualCenter Server',
    'licenseProductVersion': '6.0',
    'osType': 'linux-amd64',
    'version': '6.5.0'
}

client.disconnect()

Pytest plugin

# conftest.py
pytest_plugins = ['mce_lib_vsphere.pytest.plugin']

# test_yourtest.py

import pytest

from pyVmomi import vim

from mce_lib_vsphere import core

def test_get_all_vms(vsphere_server, vcsim_settings):
    url = vsphere_server

    with core.Client(host=url) as client:
        client.connect()
        objects = client.get_all_vms()

TODO

  • Publish to Pypi repository
  • Sphinx doc
  • Terraform templates ou Pulumi code for IAC
  • Contrib doc

Similar Python Projects

About

Inventory library for VMware (Vsphere Release)

Resources

License

Stars

Watchers

Forks

Packages

No packages published