本文整理汇总了Python中pyVim.connect.SmartConnectNoSSL方法的典型用法代码示例。如果您正苦于以下问题:Python connect.SmartConnectNoSSL方法的具体用法?Python connect.SmartConnectNoSSL怎么用?Python connect.SmartConnectNoSSL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyVim.connect
的用法示例。
在下文中一共展示了connect.SmartConnectNoSSL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [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))
示例2: connect_vsphere
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [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
示例3: main
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [as 别名]
def main():
args = setup_args()
si = SmartConnectNoSSL(host=args.host,
user=args.user,
pwd=args.password,
port=args.port)
# Start with all the VMs from container, which is easier to write than
# PropertyCollector to retrieve them.
vms = get_obj(si, si.content.rootFolder, [vim.VirtualMachine])
pc = si.content.propertyCollector
filter_spec = create_filter_spec(pc, vms, args.property)
options = vmodl.query.PropertyCollector.RetrieveOptions()
result = pc.RetrievePropertiesEx([filter_spec], options)
vms = filter_results(result, args.value)
print("VMs with %s = %s" % (args.property, args.value))
for vm in vms:
print(vm.name)
Disconnect(si)
示例4: main
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [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
示例5: connect
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [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()
示例6: apply_terraform
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [as 别名]
def apply_terraform(self, cluster, hosts_dict):
vars = cluster.plan.mixed_vars
st = connect.SmartConnectNoSSL(host=vars['vc_host'], user=vars['vc_username'],
pwd=vars['vc_password'], port=vars['vc_port'])
content = st.RetrieveContent()
container = content.rootFolder
dc = get_obj(content, [vim.Datacenter], container, vars['region'])
folder = get_obj(content, [vim.Folder], container, 'kubeoperator')
if not folder:
dc.vmFolder.CreateFolder('kubeoperator')
return super().apply_terraform(cluster, hosts_dict)
示例7: get_service_instance
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [as 别名]
def get_service_instance(kwargs):
host = kwargs.get('host')
username = kwargs.get('username')
password = kwargs.get('password')
port = kwargs.get('port')
service_instance = connect.SmartConnectNoSSL(host=host, user=username, pwd=password, port=port)
if not service_instance:
logger.error(msg='Could not connect to the specified host using specified username and password',
exc_info=True)
raise Exception('Could not connect to the specified host using specified username and password')
return service_instance
示例8: hello_vcenter
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [as 别名]
def hello_vcenter(vchost,username,password,port):
try:
si = SmartConnectNoSSL(
host=vchost,
user=username,
pwd=password,
port=port)
atexit.register(Disconnect, si)
return True, "ok"
except vmodl.MethodFault as error:
return False, error.msg
except Exception as e:
return False, str(e)
示例9: __init__
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [as 别名]
def __init__(self, VMWARE_SERVER, VMWARE_USERNAME, VMWARE_PASSWD):
self.server = VMWARE_SERVER
self.service_instance = connect.SmartConnectNoSSL(
host=VMWARE_SERVER,
user=VMWARE_USERNAME,
pwd=VMWARE_PASSWD,
port=443
)
atexit.register(connect.Disconnect, self.service_instance)
示例10: esx_connect
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [as 别名]
def esx_connect(host, user, pwd, port, ssl):
"""Establish connection with host/vcenter."""
si = None
# connect depending on SSL_VERIFY setting
if ssl is False:
si = SmartConnectNoSSL(host=host, user=user, pwd=pwd, port=port)
current_session = si.content.sessionManager.currentSession.key
_LOGGER.debug("Logged in - session %s", current_session)
else:
si = SmartConnect(host=host, user=user, pwd=pwd, port=port)
current_session = si.content.sessionManager.currentSession.key
_LOGGER.debug("Logged in - session %s", current_session)
return si
示例11: __init__
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [as 别名]
def __init__(self, host, user, pwd):
session = SmartConnectNoSSL(host=host, user=user, pwd=pwd)
self.session = session
示例12: main
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [as 别名]
def main():
args = get_args()
try:
if args.disable_ssl_verification:
service_instance = SmartConnectNoSSL(host=args.host,
user=args.user,
pwd=args.password,
port=args.port)
else:
service_instance = SmartConnect(host=args.host,
user=args.user,
pwd=args.password,
port=args.port)
atexit.register(Disconnect, service_instance)
content = service_instance.RetrieveContent()
# Assigning destination datastores
datastore_dest = args.datastore_dest
# Target compute resource
host_dest = args.target_esx_host
relocate_vm(args.vm_name,
content=content,
host_dest=host_dest,
datastore_dest=datastore_dest)
except vmodl.MethodFault as error:
print("Caught vmodl fault : " + error.msg)
return -1
return 0
# Start program
示例13: main
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [as 别名]
def main():
args = get_args()
# connect this thing
serviceInstance = None
if args.no_ssl:
serviceInstance = SmartConnectNoSSL(
host=args.host,
user=args.user,
pwd=args.password,
port=args.port)
else:
serviceInstance = SmartConnect(
host=args.host,
user=args.user,
pwd=args.password,
port=args.port)
# disconnect this thing
atexit.register(Disconnect, serviceInstance)
vm = None
if args.uuid:
search_index = serviceInstance.content.searchIndex
vm = search_index.FindByUuid(None, args.uuid, True)
elif args.vm_name:
content = serviceInstance.RetrieveContent()
vm = get_obj(content, [vim.VirtualMachine], args.vm_name)
if vm:
add_nic(serviceInstance, vm, args.port_group)
else:
print("VM not found")
# start this thing
示例14: main
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [as 别名]
def main():
"""
Simple command-line program for listing all snapshots of a fcd
"""
args = get_args()
try:
if args.disable_ssl_verification:
service_instance = connect.SmartConnectNoSSL(host=args.host,
user=args.user,
pwd=args.password,
port=int(args.port))
else:
service_instance = connect.SmartConnect(host=args.host,
user=args.user,
pwd=args.password,
port=int(args.port))
atexit.register(connect.Disconnect, service_instance)
content = service_instance.RetrieveContent()
# Retrieve Datastore Object
datastore = disk.get_obj(content, [vim.Datastore], args.datastore)
# Retrieve FCD Object
vdisk = disk.retrieve_fcd(content, datastore, args.vdisk)
# Retrieve all Snapshots
list_fcd_snapshots(content, vdisk)
except vmodl.MethodFault as error:
print("Caught vmodl fault : " + error.msg)
return -1
return 0
# Start program
示例15: main
# 需要导入模块: from pyVim import connect [as 别名]
# 或者: from pyVim.connect import SmartConnectNoSSL [as 别名]
def main():
args = setup_args()
si = SmartConnectNoSSL(host=args.host,
user=args.user,
pwd=args.password,
port=args.port)
if args.datacenter:
dc = get_dc(si, args.datacenter)
else:
dc = si.content.rootFolder.childEntity[0]
vm = si.content.searchIndex.FindChild(dc.vmFolder, args.name)
if vm is None:
raise Exception('Failed to find VM %s in datacenter %s' %
(dc.name, args.name))
byEntity = vim.event.EventFilterSpec.ByEntity(entity=vm, recursion="self")
ids = ['VmRelocatedEvent', 'DrsVmMigratedEvent', 'VmMigratedEvent']
filterSpec = vim.event.EventFilterSpec(entity=byEntity, eventTypeId=ids)
# Optionally filter by users
userList = []
if args.filterUsers:
userList = re.split('.*,.*', args.filterUsers)
if len(userList) > 0 or args.filterSystemUser:
byUser = vim.event.EventFilterSpec.ByUsername(userList=userList)
byUser.systemUser = args.filterSystemUser
filterSpec.userName = byUser
eventManager = si.content.eventManager
events = eventManager.QueryEvent(filterSpec)
for event in events:
print("%s" % event._wsdlName)
print("VM: %s" % event.vm.name)
print("User: %s" % event.userName)
print("Host: %s -> %s" % (event.sourceHost.name, event.host.name))
print("Datacenter: %s -> %s" % (event.sourceDatacenter.name,
event.datacenter.name))
print("Datastore: %s -> %s" % (event.sourceDatastore.name,
event.ds.name))
print("%s" % events)