示例#1
0
def openConnection(myvc, myadmin, mypwd):
    """ Opens a connection to a VC/ESXi 

	Args:
		myvc (str): vCenter/ESXi IP or FQDN 

	Raises:
		exception: [Timeout, Invalid Login, etc]

	Returns:
		[connection,vms]: Returns both the connection open as well as a list of VMs present on the VC/ESXi
	"""
    print("\n========== %s ==========" % myvc)
    #Open VC Connection
    try:
        client = VConnector(user=myadmin, pwd=mypwd, host=myvc)
        #print("Connecting to %s using account %s" % (myvc,myadmin))
        client.connect()
        vms = client.get_vm_view()  #Obtain VMs
        globals.hostReport += '-' + myvc + ' OK!\n'

        return client, vms

    except Exception as exception:
        print(exception.__class__.__name__)
        print("Unexpected error:", sys.exc_info()[0])
        print(
            "Please confirm\n1) The vCenter/ESXi is reachable\n2) If FQDN is used, that it is resolvable\n3) Credentials are correct\n"
        )
        raise exception

    print("Connected to VC %s" % myvc)
示例#2
0
def openConnection():
    print("========== %s ==========" % myvc)
    #Open VC Connection
    try:
        client = VConnector(user=myadmin, pwd=mypwd, host=myvc)
        client.connect()
        return client.get_vm_view()  #Obtain VMs

    except Exception as exception:
        print(exception.__class__.__name__)
        print("Unexpected error:", sys.exc_info()[0])
        print(
            "Please confirm\n1) The vCenter/ESXi is reachable\n2) If FQDN is used, that it is resolvable\n3) Credentials are correct\n"
        )
        hostReport += myvc + ' NOT OK!\n'
        raise exception

    print("Connected to VC %s" % myvc)
示例#3
0
#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      Shoblin
#
# Created:     27.03.2019
# Copyright:   (c) Shoblin 2019
# Licence:     <your licence>
#-------------------------------------------------------------------------------


from __future__ import print_function
from vconnector.core import VConnector


username = '******'
password = '******'
hostname = 'msk-vcenter1.office.finam.ru'

client = VConnector(  user=username, pwd=password, host=hostname)
client.connect()
vms = client.get_vm_view()
print(vms.view)
client.disconnect()