skywalker-nick / handle-esxi-hosts-vcenter-python

Some Python modules to handle ESXi Host on a vCenter - using pyVmomi (VMware vSphere API Python)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

handle-esxi-hosts

Some Python modules used to handle ESXi Hosts:

  • Add a standalone ESXi Host to a Cluster with vSAN enabled or not
  • Move an ESXi Host from a cluster to another
  • Remove an ESXi Host from the vCenter inventory

Bonus: Print out the vCenter inventory

Those moduels use pyVmomi (VMware vSphere API Python)

import vcenter_helper
import handle_esxi_host
import sys

vc_details = {
    'host': '10.162.54.10',
    'user': 'administrator@vsphere.local',
    'pwd': '****',
}


def main(argv):
    # Establish connection with vCenter
    vc_si = vcenter_helper.create_connection_to_endpoint(
                                    ip_address=vc_details['host'],
                                    username=vc_details['user'],
                                    password=vc_details['pwd'])


    # Print vC Inventory
    vcenter_helper.print_vc_inventory(vc_serviceInstance=vc_si)


    # Add a standalone ESXi Host to a Cluster with vSAN enabled
    cluster = handle_esxi_host.get_cluster_object_from_vc(
                                 vc_serviceInstance=vc_si,
                                 target_cluster_name='cls')
    handle_esxi_host.add_standalone_esxi_host(
                                vc_serviceInstance=vc_si,
                                host_ip='10.160.178.123',
                                hostUserName='root',
                                hostPassword='',
                                dest_cluster=cluster,
                                cluster_vsan_enabled=True)


    # Move an ESXi Host from a cluster to another
    ## Get Cluster object (assuming a second cluster named 'cluster-test' got created)
    second_cluster = handle_esxi_host.get_cluster_object_from_vc(
                                 vc_serviceInstance=vc_si,
                                 target_cluster_name='cluster-test')
    ## Get Host object
    host = handle_esxi_host.get_host_object_from_vc(
                                vc_serviceInstance=vc_si,
                                target_host_name='10.145.6.172')
    ## Move the ESXi Host from its original cluster to the other cluster
    handle_esxi_host.move_host_to_another_cluster(
                                 host=host,
                                 dest_cluster=second_cluster)


    # Remove an ESXi Host from the vCenter Inventory
    handle_esxi_host.remove_host_from_vc_inventory(host)


if __name__ == "__main__":
    main(sys.argv)

About

Some Python modules to handle ESXi Host on a vCenter - using pyVmomi (VMware vSphere API Python)


Languages

Language:Python 100.0%