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


Python VIServer.connect方法代码示例

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


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

示例1: connectToHost

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def connectToHost(host,host_user,host_pw):
    #create server object
    s=VIServer()
    #connect to the host
    try:
        s.connect(host,host_user,host_pw)
        return s
开发者ID:prwitt,项目名称:python,代码行数:9,代码来源:vm_include.py

示例2: esx_connect

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def esx_connect(host, user, password):
    esx = VIServer()
    try:
        esx.connect(host, user, password)
    except VIApiException, e:
        print("There was an error while connecting to esx: %s" % e)
        return 1
开发者ID:bartekrutkowski,项目名称:egniter,代码行数:9,代码来源:egniter.py

示例3: viConnect

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def viConnect(vCenter,username,password,vmname):
	server = VIServer()
	server.connect(vCenter,username,password)
	#print "vCenter: {} User: {} Pass: {}".format(vCenter,username,password)
	#return server
	#print viConnect("192.168.219.129","root","vmware")
	return getVm(server,vmname)
开发者ID:cjohannsen81,项目名称:pySphereClient,代码行数:9,代码来源:pySphereClient.py

示例4: main

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def main(argv=None):

    if argv is None:
    argv=sys.argv

    server = VIServer()
    try:
        server.connect(sys.argv[1], sys.argv[2], sys.argv[3])

    hosts = server.get_hosts()
        for h_mor, h_name in hosts.items():
            props = VIProperty(server, h_mor)
        try:
            f = open("/tmp/esxi_hosts_" + sys.argv[1] + ".txt", "w")
            try:
            f.write("memorySize=" + str(props.hardware.memorySize) + "\n")
            f.write("overallCpuUsage=" + str(props.summary.quickStats.overallCpuUsage) + "\n")
                    f.write("overallMemoryUsage=" + str(props.summary.quickStats.overallMemoryUsage) + "\n")
            f.write("uptime=" + str(props.summary.quickStats.uptime) + "\n")
                # $CPUTotalMhz = $_.Summary.hardware.CPUMhz * $_.Summary.Hardware.NumCpuCores
                # $row."CpuUsage%" = [math]::round( ($row.CpuUsageMhz / $CPUTotalMhz), 2) * 100
                f.write("cpuMhz=" + str(props.summary.hardware.cpuMhz) + "\n")
                f.write("numCpuCores=" + str(props.summary.hardware.numCpuCores) + "\n")
            finally:
                f.close()
        except IOError:
            print "0"
            sys.exit(0)	
开发者ID:karabatov,项目名称:linscripts,代码行数:30,代码来源:check_esxi_hosts.py

示例5: main

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def main():
    vm = None

    module = AnsibleModule(
        argument_spec=dict(
            vcenter_hostname=dict(required=True, type='str'),
            vcenter_username=dict(required=True, type='str'),
            vcenter_password=dict(required=True, type='str'),
            datacenter_name=dict(required=True, type='str'),
            folder_structure=dict(required=True, type='list'),
            guest_list=dict(required=True, type='list'),
        ),
        supports_check_mode=False,
    )

    if not HAS_PYSPHERE:
        module.fail_json(msg='pysphere module required')

    vcenter_hostname = module.params['vcenter_hostname']
    vcenter_username = module.params['vcenter_username']
    vcenter_password = module.params['vcenter_password']
    guest_list = module.params['guest_list']
    folder_structure = module.params['folder_structure']
    base_datacenter = module.params['datacenter_name']

    # CONNECT TO THE SERVER
    viserver = VIServer()
    try:
        viserver.connect(vcenter_hostname, vcenter_username, vcenter_password)
    except VIApiException, err:
        module.fail_json(msg="Cannot connect to %s: %s" %
                         (vcenter_hostname, err))
开发者ID:zarlant,项目名称:ansible-modules,代码行数:34,代码来源:vsphere_folder_relocate.py

示例6: _connect_server

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def _connect_server(bot):
    try:
        server = VIServer()
        server.connect(bot.config.pysphere.server, bot.config.pysphere.login, bot.config.pysphere.password)        
    except Exception, e:
        bot.say("No connection to the server")
        return False
开发者ID:perheld,项目名称:willie-pysphere,代码行数:9,代码来源:willie-pysphere.py

示例7: connect_VI

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def connect_VI(vcenter_hostname, user, password):
    # Create the connection to vCenter Server
    server = VIServer()
    try:
        server.connect(vcenter_hostname, user, password)
    except VIApiException, err:
        module.fail_json(msg="Cannot connect to %s: %s" % (vcenter_hostname, err))
开发者ID:mikecali,项目名称:BAU_plays,代码行数:9,代码来源:vm_snapshot.py

示例8: main

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def main():
    u"""Main method

    Create session.
    Excute subcommand.
    """
    # Import
    import socket
    import getpass
    import sys
    from pysphere import VIApiException, VIServer
    import argument

    # Get argument
    args = argument.args()
    s = VIServer()

    # Set information
    host = args.host if args.host else raw_input('Host> ')
    user = args.user if args.user else raw_input('User> ')
    passwd = args.passwd if args.passwd else getpass.getpass('Password> ')
    try:
        print 'Connecting...'
        s.connect(host, user, passwd)

        # Execute function
        args.func(args, s)
    except socket.error:
        print >> sys.stderr, "Cannot connected."
    except VIApiException:
        print >> sys.stderr, "Incorrect user name or password."
    except Exception, e:
        print >> sys.stderr, e.message
开发者ID:corrupt952,项目名称:pyxenter,代码行数:35,代码来源:esxi.py

示例9: get_connection

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def get_connection(host_ip, username, password):
    server = VIServer()
    if host_ip is not None and username is not None and password is not None:
        server.connect(host_ip, username, password)
    else:
        return None
    return server
开发者ID:wuhongyang,项目名称:iass-web,代码行数:9,代码来源:vmwarecli.py

示例10: host_connect

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def host_connect(host):
    """ Connect to a host. """
    server = VIServer()
    server.connect(host, CREDS.get('Host', 'user'),
                   CREDS.get('Host', 'pass'))

    return server
开发者ID:gcavalcante8808,项目名称:vunit,代码行数:9,代码来源:vmwtest.py

示例11: main

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def main(argv=None):

    if argv is None:
    argv = sys.argv

    server = VIServer()
    server.connect(sys.argv[1], sys.argv[2], sys.argv[3])

    print "{"
    print "\t\"data\":[\n"
    first = 1

    for ds_mor, name in server.get_datastores().items():
        props = VIProperty(server, ds_mor)
    if not first:
        sys.stdout.write(",")
    first = 0

    pfree = float(props.summary.freeSpace) / float(props.summary.capacity) * 100

    print "\n\t{"
        print "\t\t\"{#DSNAME}\":\"%s\"," % name
        print "\t\t\"{#DSACCESS}\":\"%d\"," % props.summary.accessible
        print "\t\t\"{#DSCAP}\":\"%s\"," % props.summary.capacity
        print "\t\t\"{#DSFREE}\":\"%s\"," % props.summary.freeSpace
        print "\t\t\"{#DSPFREE}\":\"%s\"" % pfree
        sys.stdout.write("\t}") 

    print "\n\t]"
    print "}"

    server.disconnect()
开发者ID:karabatov,项目名称:linscripts,代码行数:34,代码来源:check_esxi_datastores.py

示例12: vmwareplugin_datastores

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def vmwareplugin_datastores(request):
    from pysphere import VIServer
    data = {
        'error': False,
    }
    if request.POST.get('oid'):
        vmware = models.VMWarePlugin.objects.get(id=request.POST.get('oid'))
    else:
        vmware = None
    try:
        if request.POST.get('password'):
            password = request.POST.get('password')
        elif not request.POST.get('password') and vmware:
            password = vmware.get_password()
        else:
            password = ''
        server = VIServer()
        server.connect(
            request.POST.get('hostname'),
            request.POST.get('username'),
            password,
            sock_timeout=7,
        )
        data['value'] = server.get_datastores().values()
        server.disconnect()
    except Exception, e:
        data['error'] = True
        data['errmsg'] = unicode(e).encode('utf8')
开发者ID:Arcko,项目名称:freenas,代码行数:30,代码来源:views.py

示例13: vcenter_connect

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
def vcenter_connect():
    """ Connect to the vcenter. """
    server = VIServer()
    server.connect(CREDS.get('Vcenter', 'server'),
                   CREDS.get('Vcenter', 'user'),
                   CREDS.get('Vcenter', 'pass'))

    return server
开发者ID:gcavalcante8808,项目名称:vunit,代码行数:10,代码来源:vmwtest.py

示例14: __init__

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
 def __init__(self, vcip, vcuser, vcpassword, dc, clu):
     self.vcip = vcip
     self.translation = {'POWERED OFF':'down', 'POWERED ON':'up'}
     s = VIServer()
     s.connect(vcip, vcuser, vcpassword)
     self.s = s
     self.clu = clu
     self.dc = dc
开发者ID:aiminickwong,项目名称:nuages,代码行数:10,代码来源:vsphereng.py

示例15: VSphereConnection

# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import connect [as 别名]
class VSphereConnection(ConnectionUserAndKey):
    def __init__(self, user_id, key, secure=True,
                 host=None, port=None, url=None, timeout=None, **kwargs):
        if host and url:
            raise ValueError('host and url arguments are mutually exclusive')

        if host:
            host_or_url = host
        elif url:
            host_or_url = url
        else:
            raise ValueError('Either "host" or "url" argument must be '
                             'provided')

        self.host_or_url = host_or_url
        self.client = None
        super(VSphereConnection, self).__init__(user_id=user_id,
                                                key=key, secure=secure,
                                                host=host, port=port,
                                                url=url, timeout=timeout,
                                                **kwargs)

    def connect(self):
        self.client = VIServer()

        trace_file = os.environ.get('LIBCLOUD_DEBUG', None)

        try:
            self.client.connect(host=self.host_or_url, user=self.user_id,
                                password=self.key,
                                sock_timeout=DEFAULT_CONNECTION_TIMEOUT,
                                trace_file=trace_file)
        except Exception:
            e = sys.exc_info()[1]
            message = e.message
            if hasattr(e, 'strerror'):
                message = e.strerror
            fault = getattr(e, 'fault', None)

            if fault == 'InvalidLoginFault':
                raise InvalidCredsError(message)
            raise LibcloudError(value=message, driver=self.driver)

        atexit.register(self.disconnect)

    def disconnect(self):
        if not self.client:
            return

        try:
            self.client.disconnect()
        except Exception:
            # Ignore all the disconnect errors
            pass

    def run_client_method(self, method_name, **method_kwargs):
        method = getattr(self.client, method_name, None)
        return method(**method_kwargs)
开发者ID:SecurityCompass,项目名称:libcloud,代码行数:60,代码来源:vsphere.py


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