#!/usr/bin/env python # -*- coding: utf-8 -*- from pyVmomi import vim from pyVim.connect import SmartConnect, Disconnect, SmartConnectNoSSL import sys import atexit class Exsi(object): # 获取vcenter的相关参数 # def __init__(self, host='xx.xx.xx.xx', port=2020, user='xxxx', password='xxxxxxxx'): #esxi def __init__(self, host='xx.xx.xx.xx', port=2020, user='xxxx', password='xxxxxxxx'): #vcenter self._host = host self._port = port self._user = user self._password = password def get_obj(self,content, vimtype, name=None): ''' 列表返回,name 可以指定匹配的对象 ''' container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True) obj = [view for view in container.view] return obj def get_conn(self): # 连接vcenter si = SmartConnectNoSSL(
python 通过连接center或esxi,关闭esxi服务器
最新推荐文章于 2024-06-27 15:53:03 发布
该Python脚本展示了如何通过pyVmomi库连接到vCenter或ESXi服务器,并执行关闭ESXi主机的任务。首先,它定义了连接参数,然后使用SmartConnectNoSSL建立连接。之后,获取ESXi主机对象并调用ShutdownHost_Task方法来关闭主机。
摘要由CSDN通过智能技术生成