Ejemplo n.º 1
0
class ESXI():
	def __init__(self, host, name, passwd):
		self.host = host 		# the host's ip
		self.name = name 		# the host's name
		self.passwd = passwd 	# the host's password
		self.esxiInst = None	# the esxi's handler 
		self.VMBuf = []  		# the all vms in the vcenter
		self.datastores = {}	# the host's datastores
		self.hosts = {}			# the host's host 
		self.esxiInst = VIServer() # get init the handles of the host
		self.esxiType = ""		# the type(esxi or vcneter) of the  host connected
		self.VGList = [] 		# the vms you get from the vm's buffer
		self.vm = None			# the handler of the vm you got

	# connect to ESXI
	def esxiConnect(self):
		if self.esxiInst == None:
			logging.fatal("ESXI connect failed...")
			return False
		try:
			if not self.esxiInst.is_connected():
				self.esxiInst.connect(self.host, self.name, self.passwd)
				self.esxiType = self.esxiInst.get_api_type() 
			else:
				logging.fatal("esxi already connected")
				return False
		except VIApiException, e:
			logging.fatal(str(e))
			return False
		except error, e:
			logging.fatal(str(e) + " " + "Host Unreachable...")
			return False
Ejemplo n.º 2
0
def vConnect(VIHost, VIUser, VIPassword):
    """Verbindungs Funktion zum Server
    Baut eine Verbindung mit VCS Server auf und speichert die Verbindungsinformationen in der VISerever variable des Typs "VIServer".
    """
    logger.info("Connecting to vSphere: " + VIHost)
    VirtualServerInstance = VIServer()
    VirtualServerInstance.connect(VIHost, VIUser, VIPassword)
    if VirtualServerInstance:
        logger.info("Connected to vSphere: " + VIHost)
        logger.info(VirtualServerInstance.get_api_type() + " API " + VirtualServerInstance.get_api_version())
        return VirtualServerInstance
    else:
        logger.error("Connection to the vSphere failed.")
        sys.exit(2)
Ejemplo n.º 3
0
def main():
    if len(sys.argv) <> 3:
        print ("Usage:")
        print (sys.argv[0], "<username> <password")

    username = sys.argv[1]
    password = sys.argv[2]

    vcenter = "ecnshmw1001.sh.cn.ao.ericsson.se"


    server = VIServer()
    server.connect( vcenter, username, password )
    print ("Login .....")
    type = server.get_api_type()
    version = server.get_api_version()

    print ("You are now connecting with {0} with API version {1}".format(type, version))


    select(server)
    server.disconnect()