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


Python connect.Disconnect方法代码示例

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


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

示例1: setup

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def setup(context=None):
    global vm_name, client, service_instance, cleardata
    if context:
        # Run sample suite via setup script
        client = context.client
        vm_name = testbed.config['VM_NAME_DEFAULT']
        service_instance = context.service_instance
    else:
        # Run sample in standalone mode
        server, username, password, cleardata, skip_verification, vm_name = \
            parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
        session = get_unverified_session() if skip_verification else None
        client = create_vsphere_client(server=server,
                                       username=username,
                                       password=password,
                                       session=session)

        context = None
        if skip_verification:
            context = get_unverified_context()
        service_instance = SmartConnect(host=server,
                                        user=username,
                                        pwd=password,
                                        sslContext=context)
        atexit.register(Disconnect, service_instance) 
开发者ID:vmware,项目名称:vsphere-automation-sdk-python,代码行数:27,代码来源:parallel.py

示例2: close

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def close(self):
        """ Closes and disconnects from a hypervisor
        """
        # self._channels[self._current_name]['connection'].Disconnect()
        channel = self._channels[self._current_name]
        Disconnect(channel['connection'])
        channel['ssh'].switch_connection(self._current_name+'_ssh')
        channel['ssh'].close_connection()
        channel['ssh_logger'].flush()
        channel['ssh_logger'].close()
        del(self._channels[self._current_name])

        # choose another active channel
        if len(self._channels) == 0:
            self._current_name = ''
            self._current_id = 0
            self._max_id = 0
        else:
            first = list(self._channels.keys())[0]
            self._current_name = self._channels[first]['name']
            self._current_id = self._channel[first]['id']

        return self._current_name 
开发者ID:bachng2017,项目名称:RENAT,代码行数:25,代码来源:Hypervisor.py

示例3: main

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def main():
    try:
        si = None
        try:
            print "Trying to connect to VCENTER SERVER . . ."
            si = connect.Connect(inputs['vcenter_ip'], 443, inputs['vcenter_user'], inputs['vcenter_password'])
        except IOError, e:
            pass
            atexit.register(Disconnect, si)

        print "Connected to VCENTER SERVER !"
        
        content = si.RetrieveContent()
        datacenter = get_obj(content, [vim.Datacenter], inputs['datacenter'])
	cluster = get_obj(content, [vim.ClusterComputeResource], inputs['cluster'])
	network_folder = datacenter.networkFolder
	#Create DV Switch
	dv_switch = create_dvSwitch(si, content, network_folder, cluster)
	#Add port group to this switch
	add_dvPort_group(si, dv_switch) 
开发者ID:reubenur-rahman,项目名称:vmware-pyvmomi-examples,代码行数:22,代码来源:create_dvs_and_dvport_group.py

示例4: connect_vsphere

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def connect_vsphere(username, password, hostname, port, use_ssl):
    """ Connects to a ESXi host or vCenter server. """
    server = None
    try:
        if use_ssl:  # Connect to server using SSL certificate verification
            server = connect.SmartConnect(host=hostname, user=username,
                                          pwd=password, port=port)
        else:
            server = connect.SmartConnectNoSSL(host=hostname, user=username,
                                               pwd=password, port=port)
    except vim.fault.InvalidLogin:
        print("ERROR: Invalid login credentials for user '%s'" % username)
        exit(1)
    except vim.fault as message:
        print("Error connecting to vSphere: %s" % str(message))
        exit(1)

    # Ensures clean disconnect upon program termination
    atexit.register(connect.Disconnect, server)

    return server 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:23,代码来源:upgrade_vm.py

示例5: main

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def main():
    args = get_args()

    # connect to vc
    si = SmartConnect(
        host=args.host,
        user=args.user,
        pwd=args.password,
        port=args.port)
    # disconnect vc
    atexit.register(Disconnect, si)

    content = si.RetrieveContent()
    print 'Searching for VM {}'.format(args.vmname)
    vm_obj = get_obj(content, [vim.VirtualMachine], args.vmname)

    if vm_obj:
        update_virtual_cd_backend_by_obj(si, vm_obj, args.unitnumber, args.iso)
        device_change = args.iso if args.iso else 'Client Device'
        print 'VM CD/DVD {} successfully' \
              ' state changed to {}'.format(args.unitnumber, device_change)
    else:
        print "VM not found"

# start 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:27,代码来源:change_vm_cd_backend.py

示例6: main

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def main():
    args = get_args()

    # connect to vc
    si = SmartConnect(
        host=args.host,
        user=args.user,
        pwd=args.password,
        port=args.port)
    # disconnect vc
    atexit.register(Disconnect, si)

    content = si.RetrieveContent()
    # Get list of ds mo
    ds_obj_list = get_obj(content, [vim.Datastore], args.name)
    for ds in ds_obj_list:
        print_datastore_info(ds)

# start 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:21,代码来源:list_dc_datastore_info.py

示例7: main

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def main():
    args = get_args()

    # connect to vc
    si = SmartConnect(
        host=args.host,
        user=args.user,
        pwd=args.password,
        port=args.port)
    # disconnect vc
    atexit.register(Disconnect, si)

    content = si.RetrieveContent()
    print 'Searching for VM {}'.format(args.vmname)
    vm_obj = get_obj(content, [vim.VirtualMachine], args.vmname)

    if vm_obj:
        update_virtual_nic_state(si, vm_obj, args.unitnumber, args.state)
        print 'VM NIC {} successfully' \
              ' state changed to {}'.format(args.unitnumber, args.state)
    else:
        print "VM not found"

# start 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:26,代码来源:change_vm_nic_state.py

示例8: main

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def main():
    args = get_args()

    si = SmartConnect(host=args.host,
                      user=args.user,
                      pwd=args.password,
                      port=int(args.port))
    atexit.register(Disconnect, si)

    content = si.RetrieveContent()
    print 'Searching for VM {}'.format(args.vmname)
    vm_obj = get_obj(content, [vim.VirtualMachine], args.vmname)

    if vm_obj:
        change_disk_mode(si, vm_obj, args.disk_number, args.mode)
        print 'VM Disk {} successfully ' \
              'changed to mode {}.'.format(args.disk_number,
                                           args.mode)
    else:
        print "VM not found."

# start 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:24,代码来源:change_disk_mode.py

示例9: main

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def main():
    global content, hosts, hostPgDict
    host, user, password = GetArgs()
    serviceInstance = SmartConnect(host=host,
                                   user=user,
                                   pwd=password,
                                   port=443)
    atexit.register(Disconnect, serviceInstance)
    content = serviceInstance.RetrieveContent()
    hosts = GetVMHosts(content)
    hostPgDict = GetHostsPortgroups(hosts)
    vms = GetVMs(content)
    for vm in vms:
        PrintVmInfo(vm)

# Main section 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:18,代码来源:getvnicinfo.py

示例10: main

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def main():
    args = get_args()
    serviceInstance = SmartConnect(host=args.host,
                                   user=args.user,
                                   pwd=args.password,
                                   port=443)
    atexit.register(Disconnect, serviceInstance)
    content = serviceInstance.RetrieveContent()

    hosts = GetVMHosts(content)
    hostSwitchesDict = GetHostsSwitches(hosts)

    for host, vswithes in hostSwitchesDict.items():
        for v in vswithes:
            print(v.name)


# Main section 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:20,代码来源:get_hosts_vswitch.py

示例11: main

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def main():
    args = get_args()
    if args.skip_verification:
        serviceInstance = SmartConnectNoSSL(host=args.host,
                                            user=args.user,
                                            pwd=args.password,
                                            port=443)
    else:
        serviceInstance = SmartConnect(host=args.host,
                                       user=args.user,
                                       pwd=args.password,
                                       port=443)
    atexit.register(Disconnect, serviceInstance)
    content = serviceInstance.RetrieveContent()

    hosts = GetVMHosts(content, args.regex_esxi)
    AddHostsPortgroup(hosts, args.vswitch, args.portgroup, args.vlanid)


# Main section 
开发者ID:vmware,项目名称:pyvmomi-community-samples,代码行数:22,代码来源:add_portgroup_to_vswitch.py

示例12: connect_to_vcenter

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def connect_to_vcenter(module, disconnect_atexit=True):
    hostname = module.params['host']
    username = module.params['login']
    password = module.params['password']
    port = module.params['port']

    try:
        service_instance = connect.SmartConnect(
            host=hostname,
            user=username,
            pwd=password,
            port=port
        )

        if disconnect_atexit:
            atexit.register(connect.Disconnect, service_instance)

        return service_instance.RetrieveContent()
    except vim.fault.InvalidLogin, invalid_login:
        module.fail_json(msg=invalid_login.msg, apierror=str(invalid_login)) 
开发者ID:vmware-archive,项目名称:ansible-module-chaperone,代码行数:22,代码来源:vcenter_addvmk.py

示例13: connect

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def connect(self):
        """Connect to vCenter server"""
        try:
            context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
            if self.config['no_ssl_verify']:
                requests.packages.urllib3.disable_warnings()
                context.verify_mode = ssl.CERT_NONE
                self.si = SmartConnectNoSSL(
                    host=self.config['server'],
                    user=self.config['username'],
                    pwd=self.config['password'],
                    port=int(self.config['port']),
                    certFile=None,
                    keyFile=None,
                )
            else:
                self.si = SmartConnect(
                    host=self.config['server'],
                    user=self.config['username'],
                    pwd=self.config['password'],
                    port=int(self.config['port']),
                    sslContext=context,
                    certFile=None,
                    keyFile=None,
                )
        except Exception as e:
            print('Unable to connect to vsphere server.')
            print(e)
            sys.exit(1)

        # add a clean up routine
        atexit.register(Disconnect, self.si)

        self.content = self.si.RetrieveContent() 
开发者ID:snobear,项目名称:ezmomi,代码行数:36,代码来源:ezmomi.py

示例14: disconnect

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def disconnect(self):
        return Disconnect(self.si) 
开发者ID:conjure-up,项目名称:conjure-up,代码行数:4,代码来源:vsphere.py

示例15: setup

# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import Disconnect [as 别名]
def setup(context=None):
    global vm_name, client, service_instance, cleardata
    if context:
        # Run sample suite via setup script
        client = context.client
        vm_name = testbed.config['VM_NAME_DEFAULT']
        service_instance = context.service_instance
    else:
        # Run sample in standalone mode
        server, username, password, cleardata, skip_verification, vm_name = \
            parse_cli_args_vm(testbed.config['VM_NAME_DEFAULT'])
        session = get_unverified_session() if skip_verification else None

        # Connect to vSphere client
        client = create_vsphere_client(server=server,
                                       username=username,
                                       password=password,
                                       session=session)

        context = None
        if skip_verification:
            context = get_unverified_context()
        service_instance = SmartConnect(host=server,
                                        user=username,
                                        pwd=password,
                                        sslContext=context)
        atexit.register(Disconnect, service_instance) 
开发者ID:vmware,项目名称:vsphere-automation-sdk-python,代码行数:29,代码来源:serial.py


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