本文整理汇总了Python中pyVim.connect.SmartConnect方法的典型用法代码示例。如果您正苦于以下问题:Python connect.SmartConnect方法的具体用法?Python connect.SmartConnect怎么用?Python connect.SmartConnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyVim.connect
的用法示例。
在下文中一共展示了connect.SmartConnect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: attach_volumes
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [as 别名]
def attach_volumes(self, conn, node, vm):
"""
Attach a the required volumes (in the RADL) to the launched instance
Arguments:
- conn(:py:class:`vim.connect.SmartConnect` ): Connection object.
- node(:py:class:`vim.VirtualMachine` ): VM to add the disk.
- vm(:py:class:`IM.VirtualMachine`): VM information.
"""
try:
if node.summary.runtime.powerState == "poweredOn" and "volumes" not in vm.__dict__.keys():
# Flag to set that this VM has created (or is creating) the
# volumes
vm.volumes = True
cont = 1
while vm.info.systems[0].getValue("disk." + str(cont) + ".size"):
disk_size = vm.info.systems[0].getFeature("disk." + str(cont) + ".size").getValue('G')
# disk_device = vm.info.systems[0].getValue("disk." + str(cont) + ".device")
self.log_info("Creating a %d GB volume for the disk %d" % (int(disk_size), cont))
self.add_disk(node, conn, disk_size)
cont += 1
except Exception:
self.log_exception("Error creating or attaching the volume to the instance")
示例2: connect
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [as 别名]
def connect(self):
"""
Initialize the service instance to the VSphere server
"""
# Check if an valid connection has already been establised.
# If yes, just refresh the connection to keep it alive.
# If not, close the old connection and establise a new one.
if self.is_conn_dead():
self.close()
else:
self.keep_alive()
return
kwargs = self.kwargs
if self.insecure:
self.service_instance = SmartConnectNoSSL(**kwargs)
else:
self.service_instance = SmartConnect(**kwargs)
if self.service_instance:
logging.debug(
'New vsphere connection established: %s (%s)',
self.service_instance, id(self.service_instance))
示例3: connect
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [as 别名]
def connect(self):
# Connect to vAPI Endpoint on vCenter Server system
self.stub_config = vapiconnect.connect(host=self.server_url,
user=self.username,
pwd=self.password,
skip_verification=self.skip_verification)
# Connect to VIM API Endpoint on vCenter Server system
context = None
if self.skip_verification:
context = get_unverified_context()
self.si = SmartConnect(host=self.server_url,
user=self.username,
pwd=self.password,
sslContext=context)
assert self.si is not None
# Retrieve the service content
self.content = self.si.RetrieveContent()
assert self.content is not None
self.vim_uuid = self.content.about.instanceUuid
示例4: setup
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [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)
示例5: __init__
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [as 别名]
def __init__(self, host, user, password, datacenter, cluster, debug=False, filtervms=False, filteruser=False,
filtertag=None):
# 4-1-CONNECT
si = connect.SmartConnect(host=host, port=443, user=user, pwd=password, sslContext=_create_unverified_context())
self.conn = si
self.si = si
self.vcip = host
self.url = "https://%s:%s@%s/sdk" % (user, password, host)
self.rootFolder = si.content.rootFolder
self.dc = find(si, self.rootFolder, vim.Datacenter, datacenter)
self.macaddr = []
self.clu = cluster
self.distributed = False
self.filtervms = filtervms
self.filtervms = filtervms
self.filteruser = filteruser
self.filtertag = filtertag
self.debug = debug
return
示例6: __connect
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [as 别名]
def __connect(self):
"""This function establishes a connection to the hypervisor."""
global SESSION
context = None
#skip SSL verification for now
if hasattr(ssl, '_create_unverified_context'):
context = ssl._create_unverified_context()
#try to connect
try:
self.SESSION = SmartConnect(
host=self.HOSTNAME,
user=self.USERNAME, pwd=self.PASSWORD,
port=self.PORT, sslContext=context
)
except vim.fault.InvalidLogin:
raise InvalidCredentialsException("Invalid credentials")
示例7: connect_vsphere
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [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
示例8: main
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [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
示例9: main
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [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
示例10: main
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [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
示例11: main
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [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
示例12: main
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [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
示例13: connect_to_vcenter
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [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))
示例14: connection
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [as 别名]
def connection(self):
"""
Connect to Vcenter and get connection
"""
context = None
if self.ignore_ssl:
context = ssl._create_unverified_context()
try:
vmware_connect = yield threads.deferToThread(
connect.SmartConnect,
host=self.host,
user=self.username,
pwd=self.password,
sslContext=context,
)
return vmware_connect
except vmodl.MethodFault as error:
logging.error("Caught vmodl fault: {error}".format(error=error.msg))
return None
示例15: connect
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnect [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()