当前位置: 首页>>代码示例>>Python>>正文


Python VIServer.is_connected方法代码示例

本文整理汇总了Python中pysphere.VIServer.is_connected方法的典型用法代码示例。如果您正苦于以下问题:Python VIServer.is_connected方法的具体用法?Python VIServer.is_connected怎么用?Python VIServer.is_connected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pysphere.VIServer的用法示例。


在下文中一共展示了VIServer.is_connected方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: descon

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import is_connected [as 别名]
try:
        from pysphere import VIServer
	def descon(vc):
		if server.is_connected() == True:
			print "Disconnecting from " + str(vc)
			server.disconnect()
		else:
			print "cannot to vc " + i
except ImportError:
        print "try to install pysphere module"
        sys.exit(1)

vcenters = [ ]

for i in vcenters:
        try:
                try:
                        server = VIServer()
                        server.connect(i, "SDA\user01", "password")
			if server.is_connected() == True:
                        	vm = server.get_vm_by_name(name.upper())
                        	if vm is not None:
                                	print "Found " + name.upper() + " on " + i
					#descon(i)
				#	break
                except:
			descon(i)
                        pass
        except:
                pass
开发者ID:c4m4,项目名称:python,代码行数:32,代码来源:vcenter.py

示例2: __init__

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import is_connected [as 别名]
class Creator:
    # todo; add comment
    """

    """

    def __init__(self, manager_address, manager_user, manager_password):
        """

        :param manager_address:
        :param manager_user:
        :param manager_password:
        """
        self.esx_server = VIServer()
        self.esx_address = manager_address
        self.esx_user = manager_user
        self.esx_password = manager_password

    def __del__(self):
        self._disconnect_from_esx()

    # todo; add comment
    def _connect_to_esx(self):
        """


        :raise:
        """
        if not self.esx_server.is_connected():
            try:
                self.esx_server.connect(self.esx_address, self.esx_user, self.esx_password)
            except Exception as inst:
                raise CreatorException(str(inst))

    def _disconnect_from_esx(self):
        # todo; add comment
        """

        """
        if self.esx_server.is_connected():
            self.esx_server.disconnect()

    def create_resource_pool(
        self,
        name,
        parent_rp="/",
        esx_hostname=None,
        cpu_resources=("normal", 4000, 0, True, -1),
        memory_resources=("normal", 163840, 0, True, -1),
    ):

        """
        Creates a resource pool on esx server
        name - name for new resource pool
        parent_pr - parent resource pool
        esx_hostname - host name of esx server when resource pool will be created
        cpu_resources and memory_resources: tuple
        0:share level - 'low' 'normal' 'high' 'custom'
        1:share value - 'custom' share value, int
        2:reservation - reserved CPU/Memory, int
        3:expandable reservation - bool
        4:limit - -1 - unlimited, another value - limit value, int

        :raise: CreatorException
        """
        self._connect_to_esx()

        if parent_rp == "/":
            parent_rpmor = None
            try:
                rp_mor_temp = [k for k, v in self.esx_server.get_resource_pools().items() if v == "/Resources"]
            except IndexError:
                raise CreatorException("Couldn't find parent resource pool")
            if len(rp_mor_temp) == 0:
                raise CreatorException("Couldn't find parent resource pool")

            if esx_hostname:
                for rp in rp_mor_temp:
                    prop = VIProperty(self.esx_server, rp)
                    if prop.parent.name == esx_hostname:
                        parent_rpmor = rp
                        break
                if not parent_rpmor:
                    raise CreatorException("Couldn't find host")
            else:
                parent_rpmor = rp_mor_temp[0]
        else:
            parent_rp = "/Resources" + parent_rp
            parent_rpmor = None
            try:
                parent_rp_temp = [k for k, v in self.esx_server.get_resource_pools().items() if v == parent_rp]
            except IndexError:
                raise CreatorException("Couldn't find parent a resource pool")
            if len(parent_rp_temp) == 0:
                raise CreatorException("Couldn't find parent a resource pool")
                ##222
            if len(parent_rp_temp) == 1:
                parent_rpmor = parent_rp_temp[0]
            elif esx_hostname:
                for rp in parent_rp_temp:
#.........这里部分代码省略.........
开发者ID:rkhozinov,项目名称:deployment_system,代码行数:103,代码来源:hatchery.py

示例3: __init__

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import is_connected [as 别名]
class ESXi_Server:
    server_ip    = ''
    user_name    = ''
    password     = ''
    connect_flag = False
    server       = None
    #vm_list      = []

    #def __init__(self):

    #Use the given args to connect the esxi server you want
    #@ip[string]: ESXi server's IP address
    #@name[string]: the username used to login the ESXi server
    #@pwd[string]: the password used to login the ESXi server
    def connect_server(self, ip, name, pwd):
        self.server_ip = ip
        self.user_name = name
        self.password  = pwd
        self.server = VIServer()
        self.server.connect(self.server_ip, self.user_name, self.password)
        self.connect_flag = self.server.is_connected()
        if self.connect_flag:
            return True
        return False

    #To get all the definition registered vms from the connected server
    #@param[string]: can be set as ALL, POWER_ON, POWER_OFF, SUSPENDED
    #According to the param, returns a list of VM Paths. You might also filter by datacenter,
    #cluster, or resource pool by providing their name or MORs.
    #if  cluster is set, datacenter is ignored, and if resource pool is set
    #both, datacenter and cluster are ignored.
    def get_registered_vms(self, param, status=None, datacenter=None, cluster=None,
                           resource_pool=None):
        if param not in ['ALL', 'POWER_ON', 'POWER_OFF', 'SUSPENDED']:
            print "Get VMs error: param can only be set as ALL, POWER_ON, POWER_OFF, or SUSPENDED."
            return None
        if self.connect_flag == False:
            print "Get VMs error: Server not connected."
            return None
        if param == 'ALL':
            return self.server.get_registered_vms(datacenter, cluster, resource_pool)
        elif param == 'POWER_ON':
            return self.server.get_registered_vms(datacenter, cluster, resource_pool, status='poweredOn')
        elif param == 'POWER_OFF':
            return self.server.get_registered_vms(datacenter, cluster, resource_pool, status='poweredOff')
        elif param == 'SUSPENDED':
            return self.server.get_registered_vms(datacenter, cluster, resource_pool, status='suspended')
        else:
            return None

    #Disconnect to the Server
    def disconnect(self):
        if self.connect_flag == True:
            self.server = self.server.disconnect()
            self.connect_flag == False

    #To keep session alive
    def keep_session_alive(self):
        assert self.server.keep_session_alive()

    #To get the server type
    def get_server_type(self):
        return self.server.get_server_type()

    #To get performance manager
    def get_performance_manager(self):
        return self.server.get_performance_manager()

    #To get the all the server's hosts
    def get_all_hosts(self):
        """
        Returns a dictionary of the existing hosts keys are their names
        and values their ManagedObjectReference object.
        """
        return self.server.get_hosts()

    #To get all datastores
    def get_all_datastores(self):
        """
        Returns a dictionary of the existing datastores. Keys are
        ManagedObjectReference and values datastore names.
        """
        return self.server.get_datastores()

    #To get all clusters
    def get_all_clusters(self):
        """
        Returns a dictionary of the existing clusters. Keys are their
        ManagedObjectReference objects and values their names.
        """
        return self.server.get_clusters()

    #To get all datacenters
    def get_all_datacenters(self):
        """
        Returns a dictionary of the existing datacenters. keys are their
        ManagedObjectReference objects and values their names.
        """
        return self.server.get_datacenters()

#.........这里部分代码省略.........
开发者ID:cloudtrends,项目名称:scaffold-shell,代码行数:103,代码来源:esxitools.py

示例4: connect_to_server

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import is_connected [as 别名]
def connect_to_server(ip,user,pw):
	server=VIServer()
	server.connect(ip,user,pw)
	try:
		server.is_connected()
开发者ID:idlevy,项目名称:python1,代码行数:7,代码来源:python_vmware_try.py


注:本文中的pysphere.VIServer.is_connected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。