本文整理汇总了Python中pyvcloud.vcloudair.VCA.login_to_org方法的典型用法代码示例。如果您正苦于以下问题:Python VCA.login_to_org方法的具体用法?Python VCA.login_to_org怎么用?Python VCA.login_to_org使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvcloud.vcloudair.VCA
的用法示例。
在下文中一共展示了VCA.login_to_org方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: login_to_vcloud
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
def login_to_vcloud(username, password, host, version, org, service_type, instance):
vca = VCA(host=host, username=username, service_type=service_type, version=version, verify=True, log=True)
assert vca
if VCA.VCA_SERVICE_TYPE_STANDALONE == service_type:
result = vca.login(password=password, org=org)
assert result, "Wrong password or Org?"
result = vca.login(token=vca.token, org=org, org_url=vca.vcloud_session.org_url)
assert result
elif VCA.VCA_SERVICE_TYPE_VCHS == service_type:
result = vca.login(password=password)
assert result, "Wrong Password?"
result = vca.login(token=vca.token)
assert result
result = vca.login_to_org(instance, org) # service now called instance
assert result, "Wrong service/aka instance or org?"
elif VCA.VCA_SERVICE_TYPE_VCA == service_type:
result = vca.login(password=password)
assert result
result = vca.login_to_instance(password=password, instance=instance, token=None, org_url=None)
assert result
print "token " + vca.vcloud_session.token
result = vca.login_to_instance(password=None, instance=instance, token=vca.vcloud_session.token, org_url=vca.vcloud_session.org_url)
assert result
return vca
示例2: _login_user_to_service
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
def _login_user_to_service(self, user, host, password, service_type,
service_version, service, org_name):
vca = VCA(host, user, service_type, service_version)
result = vca.login(password=password)
if result:
if service_type == 'subscription':
if not service:
if org_name:
service = org_name
else:
services = vca.services.get_Service()
if not services:
return None
service = services[0].serviceId
if not org_name:
org_name = vca.get_vdc_references(service)[0].name
result = vca.login_to_org(service, org_name)
if result:
return vca
return
示例3: VCA
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
vapp = 'cts'
#sample login sequence on vCloud Air Subscription
vca = VCA(host=host, username=username, service_type='subscription', version='5.6', verify=True)
#first login, with password
result = vca.login(password=password)
print_vca(vca)
#next login, with token, no password
#this tests the vca token
result = vca.login(token=vca.token)
print_vca(vca)
#uses vca.token to generate vca.vcloud_session.token
vca.login_to_org(service, org)
print_vca(vca)
#this tests the vcloud session token
test_vcloud_session(vca, vdc, vapp)
##############################
### On Demand
##############################
host='iam.vchs.vmware.com'
username = os.environ['VCAUSER']
password = os.environ['PASSWORD']
instance = '28149a83-0d23-4f03-85e1-eb8be013e4ff'
示例4: __init__
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
class TestCatalog:
def __init__(self):
self.vca = None
self.login_to_vcloud()
def login_to_vcloud(self):
"""Login to vCloud"""
username = config['vcloud']['username']
password = config['vcloud']['password']
service_type = config['vcloud']['service_type']
host = config['vcloud']['host']
version = config['vcloud']['version']
org = config['vcloud']['org']
service = config['vcloud']['service']
instance = config['vcloud']['instance']
self.vca = VCA(host=host, username=username, service_type=service_type, version=version, verify=True, log=True)
assert self.vca
if vcloudair.VCA_SERVICE_TYPE_STANDALONE == service_type:
result = self.vca.login(password=password, org=org)
assert result
result = self.vca.login(token=self.vca.token, org=org, org_url=self.vca.vcloud_session.org_url)
assert result
elif vcloudair.VCA_SERVICE_TYPE_SUBSCRIPTION == service_type:
result = self.vca.login(password=password)
assert result
result = self.vca.login(token=self.vca.token)
assert result
result = self.vca.login_to_org(service, org)
assert result
elif vcloudair.VCA_SERVICE_TYPE_ONDEMAND == service_type:
result = self.vca.login(password=password)
assert result
result = self.vca.login_to_instance(password=password, instance=instance, token=None, org_url=None)
assert result
result = self.vca.login_to_instance(password=None, instance=instance, token=self.vca.vcloud_session.token, org_url=self.vca.vcloud_session.org_url)
assert result
def logout_from_vcloud(self):
"""Logout from vCloud"""
print 'logout'
selfl.vca.logout()
self.vca = None
assert self.vca is None
def catalog_exists(self, catalog_name, catalogs):
for catalog in catalogs:
if catalog.name == catalog_name:
return True
return False
def test_0001(self):
"""Loggin in to vCloud"""
assert self.vca.token
def test_0002(self):
"""Get VDC"""
vdc_name = config['vcloud']['vdc']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
def test_0009(self):
"""Validate that catalog doesn't exist"""
vdc_name = config['vcloud']['vdc']
vapp_name = config['vcloud']['vapp']
vm_name = config['vcloud']['vm']
custom_catalog = config['vcloud']['custom_catalog']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
catalogs = self.vca.get_catalogs()
assert not self.catalog_exists(custom_catalog, catalogs)
def test_0010(self):
"""Create Catalog"""
vdc_name = config['vcloud']['vdc']
vapp_name = config['vcloud']['vapp']
vm_name = config['vcloud']['vm']
custom_catalog = config['vcloud']['custom_catalog']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
task = self.vca.create_catalog(custom_catalog, custom_catalog)
assert task
result = self.vca.block_until_completed(task)
assert result
catalogs = self.vca.get_catalogs()
assert self.catalog_exists(custom_catalog, catalogs)
def test_0011(self):
#.........这里部分代码省略.........
示例5: vca_login
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
def vca_login(module=None):
service_type = module.params.get('service_type')
username = module.params.get('username')
password = module.params.get('password')
instance = module.params.get('instance_id')
org = module.params.get('org')
service = module.params.get('service_id')
vdc_name = module.params.get('vdc_name')
version = module.params.get('api_version')
verify = module.params.get('verify_certs')
if not vdc_name:
if service_type == 'vchs':
vdc_name = module.params.get('service_id')
if not org:
if service_type == 'vchs':
if vdc_name:
org = vdc_name
else:
org = service
if service_type == 'vcd':
host = module.params.get('host')
else:
host = LOGIN_HOST[service_type]
if not username:
if 'VCA_USER' in os.environ:
username = os.environ['VCA_USER']
if not password:
if 'VCA_PASS' in os.environ:
password = os.environ['VCA_PASS']
if not username or not password:
module.fail_json(msg = "Either the username or password is not set, please check")
if service_type == 'vchs':
version = '5.6'
if service_type == 'vcd':
if not version:
version == '5.6'
vca = VCA(host=host, username=username, service_type=SERVICE_MAP[service_type], version=version, verify=verify)
if service_type == 'vca':
if not vca.login(password=password):
module.fail_json(msg = "Login Failed: Please check username or password", error=vca.response.content)
if not vca.login_to_instance(password=password, instance=instance, token=None, org_url=None):
s_json = serialize_instances(vca.instances)
module.fail_json(msg = "Login to Instance failed: Seems like instance_id provided is wrong .. Please check",\
valid_instances=s_json)
if not vca.login_to_instance(instance=instance, password=None, token=vca.vcloud_session.token,
org_url=vca.vcloud_session.org_url):
module.fail_json(msg = "Error logging into org for the instance", error=vca.response.content)
return vca
if service_type == 'vchs':
if not vca.login(password=password):
module.fail_json(msg = "Login Failed: Please check username or password", error=vca.response.content)
if not vca.login(token=vca.token):
module.fail_json(msg = "Failed to get the token", error=vca.response.content)
if not vca.login_to_org(service, org):
module.fail_json(msg = "Failed to login to org, Please check the orgname", error=vca.response.content)
return vca
if service_type == 'vcd':
if not vca.login(password=password, org=org):
module.fail_json(msg = "Login Failed: Please check username or password or host parameters")
if not vca.login(password=password, org=org):
module.fail_json(msg = "Failed to get the token", error=vca.response.content)
if not vca.login(token=vca.token, org=org, org_url=vca.vcloud_session.org_url):
module.fail_json(msg = "Failed to login to org", error=vca.response.content)
return vca
示例6: __init__
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
class TestVCloud:
def __init__(self):
self.vca = None
self.login_to_vcloud()
def login_to_vcloud(self):
"""Login to vCloud"""
username = config['vcloud']['username']
password = config['vcloud']['password']
service_type = config['vcloud']['service_type']
host = config['vcloud']['host']
version = config['vcloud']['version']
org = config['vcloud']['org']
service = config['vcloud']['service']
instance = config['vcloud']['instance']
self.vca = VCA(host=host, username=username, service_type=service_type, version=version, verify=True, log=True)
assert self.vca
if vcloudair.VCA_SERVICE_TYPE_STANDALONE == service_type:
result = self.vca.login(password=password, org=org)
assert result
result = self.vca.login(token=self.vca.token, org=org, org_url=self.vca.vcloud_session.org_url)
assert result
elif vcloudair.VCA_SERVICE_TYPE_SUBSCRIPTION == service_type:
result = self.vca.login(password=password)
assert result
result = self.vca.login(token=self.vca.token)
assert result
result = self.vca.login_to_org(service, org)
assert result
elif vcloudair.VCA_SERVICE_TYPE_ONDEMAND == service_type:
result = self.vca.login(password=password)
assert result
result = self.vca.login_to_instance(password=password, instance=instance, token=None, org_url=None)
assert result
result = self.vca.login_to_instance(password=None, instance=instance, token=self.vca.vcloud_session.token, org_url=self.vca.vcloud_session.org_url)
assert result
def logout_from_vcloud(self):
"""Logout from vCloud"""
print 'logout'
selfl.vca.logout()
self.vca = None
assert self.vca is None
def test_0001(self):
"""Loggin in to vCloud"""
assert self.vca.token
def test_0002(self):
"""Get VDC"""
vdc_name = config['vcloud']['vdc']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
def test_0003(self):
"""Create vApp"""
vdc_name = config['vcloud']['vdc']
vapp_name = config['vcloud']['vapp']
vm_name = config['vcloud']['vm']
catalog = config['vcloud']['catalog']
template = config['vcloud']['template']
network = config['vcloud']['network']
mode = config['vcloud']['mode']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
task = self.vca.create_vapp(vdc_name, vapp_name, template, catalog, vm_name=vm_name)
assert task
result = self.vca.block_until_completed(task)
assert result
the_vdc = self.vca.get_vdc(vdc_name)
the_vapp = self.vca.get_vapp(the_vdc, vapp_name)
assert the_vapp
assert the_vapp.name == vapp_name
def test_0004(self):
"""Disconnect vApp from pre-defined networks"""
vdc_name = config['vcloud']['vdc']
vapp_name = config['vcloud']['vapp']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
the_vapp = self.vca.get_vapp(the_vdc, vapp_name)
assert the_vapp
assert the_vapp.name == vapp_name
task = the_vapp.disconnect_from_networks()
assert task
result = self.vca.block_until_completed(task)
assert result
def test_0005(self):
"""Connect vApp to network"""
vdc_name = config['vcloud']['vdc']
vapp_name = config['vcloud']['vapp']
vm_name = config['vcloud']['vm']
network = config['vcloud']['network']
mode = config['vcloud']['mode']
the_vdc = self.vca.get_vdc(vdc_name)
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
class TestVApp:
def __init__(self):
self.vca = None
self.login_to_vcloud()
def login_to_vcloud(self):
"""Login to vCloud"""
username = config['vcloud']['username']
password = config['vcloud']['password']
service_type = config['vcloud']['service_type']
host = config['vcloud']['host']
version = config['vcloud']['version']
org = config['vcloud']['org']
service = config['vcloud']['service']
instance = config['vcloud']['instance']
self.vca = VCA(host=host, username=username, service_type=service_type, version=version, verify=True, log=True)
assert self.vca
if VCA.VCA_SERVICE_TYPE_STANDALONE == service_type:
result = self.vca.login(password=password, org=org)
assert result
result = self.vca.login(token=self.vca.token, org=org, org_url=self.vca.vcloud_session.org_url)
assert result
elif VCA.VCA_SERVICE_TYPE_VCHS == service_type:
result = self.vca.login(password=password)
assert result
result = self.vca.login(token=self.vca.token)
assert result
result = self.vca.login_to_org(service, org)
assert result
elif VCA.VCA_SERVICE_TYPE_VCA == service_type:
result = self.vca.login(password=password)
assert result
result = self.vca.login_to_instance(password=password, instance=instance, token=None, org_url=None)
assert result
result = self.vca.login_to_instance(password=None, instance=instance, token=self.vca.vcloud_session.token, org_url=self.vca.vcloud_session.org_url)
assert result
def logout_from_vcloud(self):
"""Logout from vCloud"""
print 'logout'
selfl.vca.logout()
self.vca = None
assert self.vca is None
def test_0001(self):
"""Loggin in to vCloud"""
assert self.vca.token
def test_0002(self):
"""Get VDC"""
vdc_name = config['vcloud']['vdc']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
def test_0003(self):
"""Create vApp"""
vdc_name = config['vcloud']['vdc']
vapp_name = config['vcloud']['vapp']
vm_name = config['vcloud']['vm']
catalog = config['vcloud']['catalog']
template = config['vcloud']['template']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
task = self.vca.create_vapp(vdc_name, vapp_name, template, catalog, vm_name=vm_name)
assert task
result = self.vca.block_until_completed(task)
assert result
the_vdc = self.vca.get_vdc(vdc_name)
the_vapp = self.vca.get_vapp(the_vdc, vapp_name)
assert the_vapp
assert the_vapp.name == vapp_name
def test_0004(self):
"""Validate vApp State is powered off (8)"""
vdc_name = config['vcloud']['vdc']
vapp_name = config['vcloud']['vapp']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
the_vapp = self.vca.get_vapp(the_vdc, vapp_name)
assert the_vapp
assert the_vapp.me.get_status() == 8
def test_0009(self):
"""Disconnect VM from pre-defined networks"""
vdc_name = config['vcloud']['vdc']
vapp_name = config['vcloud']['vapp']
vm_name = config['vcloud']['vm']
the_vdc = self.vca.get_vdc(vdc_name)
#.........这里部分代码省略.........
示例8: VCAInventory
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
#.........这里部分代码省略.........
for j in vdcs:
actual_vdc = j.name
j.name = self.to_safe(j.name)
self.results[j.name] = dict(children=[])
org_children.append(j.name)
vapps = self.get_vapps(self.vca, j.name)
for k in vapps:
k['vapp_name'] = self.to_safe(k['vapp_name'])
self.results[j.name]['children'].append(k['vapp_name'])
self.results[k['vapp_name']] = k['vms']
self.results[self.org] = dict(children=org_children)
self.results['_meta'] = self.meta
cache_name = '__inventory_all__' + self.service_type
self._put_cache(cache_name, self.results)
return self.results
def get_inventory_vca(self):
if not self.vca.login(password=self.password):
sys.stdout.write("Login Failed: Please check username or password")
sys.exit(1)
instances_dict = self.vca.get_instances()
for i in instances_dict:
instance = i['id']
# region = i['id']
region = i['region']
region = self.to_safe(region.split('.')[0])
region_children = []
if len(instance) != 36:
continue
if not self.vca.login_to_instance(password=self.password, instance=instance, token=None, org_url=None):
sys.stdout.write( "Login to Instance failed: Seems like instance provided is wrong .. Please check")
sys.exit(1)
if not self.vca.login_to_instance(instance=instance, password=None, token=self.vca.vcloud_session.token,
org_url=self.vca.vcloud_session.org_url):
sys.stdout.write("Error logging into org for the instance %s" %instance)
vdcs = self.get_vdcs(self.vca)
for j in vdcs:
j.name = self.to_safe(j.name)
self.results[region + '_' + j.name] = dict(children=[])
region_children.append(region + '_' + j.name)
vapps = self.get_vapps(self.vca, j.name)
for k in vapps:
k['vapp_name'] = self.to_safe(k['vapp_name'])
self.results[region + '_' + j.name]['children'].append(region + '_' + j.name + '_' + k['vapp_name'])
self.results[region + '_' + j.name + '_' + k['vapp_name']] = k['vms']
self.results[region] = dict(children=region_children)
self.results['_meta'] = self.meta
cache_name = '__inventory_all__' + self.service_type
self._put_cache(cache_name, self.results)
return self.results
def get_inventory_vchs(self):
if not self.vca.login(password=self.password):
sys.stdout.write("Login Failed: Please check username or password, errors: %s" %(self.vca.response))
sys.exit(1)
if not self.vca.login(token=self.vca.token):
sys.stdout.write("Failed to get the token")
sys.exit(1)
if self.vca.services:
table = []
for s in self.vca.services.get_Service():
for vdc in self.vca.get_vdc_references(s.serviceId):
table.append(dict(service=s.serviceId, service_type=s.serviceType, region=s.region,\
vdc=vdc.name, status=vdc.status))
for i in table:
if i['service'] != i['vdc']:
self.results[i['service']] = dict(children=[i['vdc']])
region = i['vdc']
region = self.to_safe(region)
self.results[region] = dict(children=[])
if not self.vca.login_to_org(i['service'], i['vdc']):
sys.stdout.write("Failed to login to org, Please check the orgname")
vapps = self.get_vapps(self.vca, i['vdc'])
for k in vapps:
k['vapp_name'] = self.to_safe(k['vapp_name'])
self.results[region]['children'].append(region + '_' + k['vapp_name'])
self.results[region + '_' + k['vapp_name']] = k['vms']
self.results['_meta'] = self.meta
cache_name = '__inventory_all__' + self.service_type
self._put_cache(cache_name, self.results)
return self.results
def get_inventory(self):
cache_name = '__inventory_all__' + self.service_type
inv = self._get_cache(cache_name, None)
if inv is not None:
return inv
if self.service_type == 'ondemand':
return self.get_inventory_vca()
if self.service_type == 'subscription':
return self.get_inventory_vchs()
if self.service_type == 'vcd':
return self.get_inventory_vcd()
示例9: __init__
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
#.........这里部分代码省略.........
self.error_message = 'Org can\'t be null'
return False
result = self.vca.login(password=password, org=org)
if result:
Log.debug(self.logger, 'logged in, org=%s' % self.vca.org)
if VCA.VCA_SERVICE_TYPE_STANDALONE == service_type:
result = self.vca.vcloud_session.login(token=self.vca.
vcloud_session.token)
assert result
if save_password:
self.password = password
self.save_config(self.profile, self.profile_file)
return result
def re_login_vcloud_session(self):
Log.debug(self.logger, 'about to re-login vcloud_session vca=%s' %
self.vca)
if self.vca.vcloud_session is not None:
Log.debug(self.logger, 'about to re-login vcloud_session=%s' %
self.vca.vcloud_session)
if self.vca.vcloud_session.token is not None:
Log.debug(self.logger,
'about to re-login vcloud_session token=%s' %
self.vca.vcloud_session.token)
if self.vca.vcloud_session is not None and \
self.vca.vcloud_session.token is not None:
result = self.vca.vcloud_session.login(
token=self.vca.vcloud_session.token)
if not result:
Log.debug(self.logger,
'vcloud session invalid, getting a new one')
if self.vca.service_type in [VCA.VCA_SERVICE_TYPE_VCHS,
'subscription']:
result = self.vca.login_to_org(self.instance, self.vca.org)
elif self.vca.service_type in [VCA.VCA_SERVICE_TYPE_VCA,
'ondemand']:
result = self.vca.login_to_instance_sso(self.instance)
if result:
Log.debug(self.logger,
'successfully retrieved a new vcloud session')
else:
raise Exception("Couldn't retrieve a new vcloud session")
else:
Log.debug(self.logger, 'vcloud session is valid')
def re_login(self):
if self.vca is None or \
(self.vca.token is None and self.password is None):
return False
result = False
try:
Log.debug(self.logger,
'about to re-login with ' +
'host=%s type=%s token=%s org=%s' %
(self.vca.host, self.vca.service_type,
self.vca.token, self.vca.org))
org_url = None if self.vca.vcloud_session is None else \
self.vca.vcloud_session.org_url
result = self.vca.login(token=self.vca.token,
org=self.vca.org,
org_url=org_url)
if result:
Log.debug(self.logger, 'vca.login with token successful')
self.re_login_vcloud_session()
else:
Log.debug(self.logger, 'vca.login with token failed %s' %
示例10: __init__
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
class TestVApp:
def __init__(self):
self.vca = None
self.login_to_vcloud()
def login_to_vcloud(self):
"""Login to vCloud"""
username = config['vcloud']['username']
password = config['vcloud']['password']
service_type = config['vcloud']['service_type']
host = config['vcloud']['host']
version = config['vcloud']['version']
org = config['vcloud']['org']
service = config['vcloud']['service']
instance = config['vcloud']['instance']
self.vca = VCA(host=host, username=username, service_type=service_type, version=version, verify=True, log=True)
assert self.vca
if VCA.VCA_SERVICE_TYPE_STANDALONE == service_type:
result = self.vca.login(password=password, org=org)
assert result
result = self.vca.login(token=self.vca.token, org=org, org_url=self.vca.vcloud_session.org_url)
assert result
elif VCA.VCA_SERVICE_TYPE_VCHS == service_type:
result = self.vca.login(password=password)
assert result
result = self.vca.login(token=self.vca.token)
assert result
result = self.vca.login_to_org(service, org)
assert result
elif VCA.VCA_SERVICE_TYPE_VCA == service_type:
result = self.vca.login(password=password)
assert result
result = self.vca.login_to_instance(password=password, instance=instance, token=None, org_url=None)
assert result
result = self.vca.login_to_instance(password=None, instance=instance, token=self.vca.vcloud_session.token, org_url=self.vca.vcloud_session.org_url)
assert result
def logout_from_vcloud(self):
"""Logout from vCloud"""
print 'logout'
selfl.vca.logout()
self.vca = None
assert self.vca is None
def test_0001(self):
"""Loggin in to vCloud"""
assert self.vca.token
def test_0002(self):
"""Get VDC"""
vdc_name = config['vcloud']['vdc']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
def test_0003(self):
"""Create vApp"""
vdc_name = config['vcloud']['vdc']
vapp_name = config['vcloud']['vapp']
vm_name = config['vcloud']['vm']
catalog = config['vcloud']['catalog']
template = config['vcloud']['template']
cpu = config['vcloud']['cpus_new']
memory = config['vcloud']['memory_new']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
task = self.vca.create_vapp(vdc_name, vapp_name, template, catalog,
vm_name=vm_name,
vm_cpus=cpu,
vm_memory=memory)
assert task
result = self.vca.block_until_completed(task)
assert result
the_vdc = self.vca.get_vdc(vdc_name)
the_vapp = self.vca.get_vapp(the_vdc, vapp_name)
assert the_vapp
assert the_vapp.name == vapp_name
def test_0004(self):
"""Validate vApp State is powered off (8)"""
vdc_name = config['vcloud']['vdc']
vapp_name = config['vcloud']['vapp']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
the_vapp = self.vca.get_vapp(the_vdc, vapp_name)
assert the_vapp
assert the_vapp.me.get_status() == 8
def test_0031(self):
#.........这里部分代码省略.........
示例11: __init__
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
class TestNet:
def __init__(self):
self.vca = None
self.login_to_vcloud()
def login_to_vcloud(self):
"""Login to vCloud"""
username = config['vcloud']['username']
password = config['vcloud']['password']
service_type = config['vcloud']['service_type']
host = config['vcloud']['host']
version = config['vcloud']['version']
org = config['vcloud']['org']
service = config['vcloud']['service']
instance = config['vcloud']['instance']
self.vca = VCA(host=host, username=username, service_type=service_type, version=version, verify=True, log=True)
assert self.vca
if VCA.VCA_SERVICE_TYPE_STANDALONE == service_type:
result = self.vca.login(password=password, org=org)
assert result
result = self.vca.login(token=self.vca.token, org=org, org_url=self.vca.vcloud_session.org_url)
assert result
elif VCA.VCA_SERVICE_TYPE_VCHS == service_type:
result = self.vca.login(password=password)
assert result
result = self.vca.login(token=self.vca.token)
assert result
result = self.vca.login_to_org(service, org)
assert result
elif VCA.VCA_SERVICE_TYPE_VCA == service_type:
result = self.vca.login(password=password)
assert result
result = self.vca.login_to_instance(password=password, instance=instance, token=None, org_url=None)
assert result
result = self.vca.login_to_instance(password=None, instance=instance, token=self.vca.vcloud_session.token, org_url=self.vca.vcloud_session.org_url)
assert result
def logout_from_vcloud(self):
"""Logout from vCloud"""
print 'logout'
selfl.vca.logout()
self.vca = None
assert self.vca is None
def test_0001(self):
"""Loggin in to vCloud"""
assert self.vca.token
def test_0003(self):
"""Get Networks"""
print('')
vdc_name = config['vcloud']['vdc']
networks = self.vca.get_networks(vdc_name)
for network in networks:
print(network)
def test_0004(self):
""" Connect to Networks"""
print('')
vdc_name = config['vcloud']['vdc']
vapp_name = config['vcloud']['vapp']
vm_name = config['vcloud']['vm']
network_name = config['vcloud']['network']
network_name2 = config['vcloud']['network2']
network_name3 = config['vcloud']['network3']
the_vdc = self.vca.get_vdc(vdc_name)
assert the_vdc
assert the_vdc.get_name() == vdc_name
the_vapp = self.vca.get_vapp(the_vdc, vapp_name)
assert the_vapp
assert the_vapp.name == vapp_name
print('disconnect vms')
task = the_vapp.disconnect_vms()
assert task
result = self.vca.block_until_completed(task)
assert result
print('disconnect vapp')
task = the_vapp.disconnect_from_networks()
assert task
result = self.vca.block_until_completed(task)
assert result
index = 0
the_vapp = self.vca.get_vapp(the_vdc, vapp_name)
nets = filter(lambda n: n.name == network_name,
self.vca.get_networks(vdc_name))
mode = 'POOL'
if len(nets) == 1:
print("connecting vApp to network"
" '%s' with mode '%s'" %
(network_name, mode))
task = the_vapp.connect_to_network(
#.........这里部分代码省略.........
示例12: __init__
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
class TestSQLAir:
def __init__(self):
self.vca = None
self.login_to_vcloud()
def login_to_vcloud(self):
"""Login to vCloud"""
username = config['vcloud']['username']
password = config['vcloud']['password']
service_type = config['vcloud']['service_type']
host = config['vcloud']['host']
version = config['vcloud']['version']
org = config['vcloud']['org']
service = config['vcloud']['service']
instance = config['vcloud']['instance']
self.vca = VCA(host=host, username=username, service_type=service_type, version=version, verify=True, log=True)
assert self.vca
if vcloudair.VCA_SERVICE_TYPE_STANDALONE == service_type:
result = self.vca.login(password=password, org=org)
assert result
result = self.vca.login(token=self.vca.token, org=org, org_url=self.vca.vcloud_session.org_url)
assert result
elif vcloudair.VCA_SERVICE_TYPE_SUBSCRIPTION == service_type:
result = self.vca.login(password=password)
assert result
result = self.vca.login(token=self.vca.token)
assert result
result = self.vca.login_to_org(service, org)
assert result
elif vcloudair.VCA_SERVICE_TYPE_ONDEMAND == service_type:
result = self.vca.login(password=password)
assert result
# result = self.vca.login_to_instance(password=password, instance=instance, token=None, org_url=None)
# assert result
# result = self.vca.login_to_instance(password=None, instance=instance, token=self.vca.vcloud_session.token, org_url=self.vca.vcloud_session.org_url)
assert result
def logout_from_vcloud(self):
"""Logout from vCloud"""
print 'logout'
selfl.vca.logout()
self.vca = None
assert self.vca is None
def test_0001(self):
"""Loggin in to vCloud"""
assert self.vca.token
def test_0002(self):
"""Check SQLAir access"""
# vdc_name = config['vcloud']['vdc']
# the_vdc = self.vca.get_vdc(vdc_name)
# assert the_vdc
# assert the_vdc.get_name() == vdc_name
sql_air = SQLAir(token=self.vca.token, version='5.7', verify=True, log=True)
response_code = sql_air.ping()
assert response_code == 200
def test_0003(self):
"""Get MSSQL Service Info"""
sql_air = SQLAir(token=self.vca.token, version='5.7', verify=True, log=True)
service_code = 'mssql'
service_mssql = sql_air.get_service(service_code)
assert service_mssql
assert service_mssql['serviceCode'] == service_code
def test_0003(self):
"""Get DB Instances"""
sql_air = SQLAir(token=self.vca.token, version='5.7', verify=True, log=True)
service_code = 'mssql'
instances = sql_air.get_instances(service_code)
assert instances
assert instances['total'] >= 0
示例13: vca_login
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
def vca_login(module=None):
service_type = module.params.get("service_type")
username = module.params.get("username")
password = module.params.get("password")
instance = module.params.get("instance_id")
org = module.params.get("org")
service = module.params.get("service_id")
vdc_name = module.params.get("vdc_name")
version = module.params.get("api_version")
verify = module.params.get("verify_certs")
if not vdc_name:
if service_type == "vchs":
vdc_name = module.params.get("service_id")
if not org:
if service_type == "vchs":
if vdc_name:
org = vdc_name
else:
org = service
if service_type == "vcd":
host = module.params.get("host")
else:
host = LOGIN_HOST[service_type]
if not username:
if "VCA_USER" in os.environ:
username = os.environ["VCA_USER"]
if not password:
if "VCA_PASS" in os.environ:
password = os.environ["VCA_PASS"]
if not username or not password:
module.fail_json(msg="Either the username or password is not set, please check")
if service_type == "vchs":
version = "5.6"
if service_type == "vcd":
if not version:
version == "5.6"
vca = VCA(host=host, username=username, service_type=SERVICE_MAP[service_type], version=version, verify=verify)
if service_type == "vca":
if not vca.login(password=password):
module.fail_json(msg="Login Failed: Please check username or password", error=vca.response.content)
if not vca.login_to_instance(password=password, instance=instance, token=None, org_url=None):
s_json = serialize_instances(vca.instances)
module.fail_json(
msg="Login to Instance failed: Seems like instance_id provided is wrong .. Please check",
valid_instances=s_json,
)
if not vca.login_to_instance(
instance=instance, password=None, token=vca.vcloud_session.token, org_url=vca.vcloud_session.org_url
):
module.fail_json(msg="Error logging into org for the instance", error=vca.response.content)
return vca
if service_type == "vchs":
if not vca.login(password=password):
module.fail_json(msg="Login Failed: Please check username or password", error=vca.response.content)
if not vca.login(token=vca.token):
module.fail_json(msg="Failed to get the token", error=vca.response.content)
if not vca.login_to_org(service, org):
module.fail_json(msg="Failed to login to org, Please check the orgname", error=vca.response.content)
return vca
if service_type == "vcd":
if not vca.login(password=password, org=org):
module.fail_json(msg="Login Failed: Please check username or password or host parameters")
if not vca.login(password=password, org=org):
module.fail_json(msg="Failed to get the token", error=vca.response.content)
if not vca.login(token=vca.token, org=org, org_url=vca.vcloud_session.org_url):
module.fail_json(msg="Failed to login to org", error=vca.response.content)
return vca
示例14: VCA
# 需要导入模块: from pyvcloud.vcloudair import VCA [as 别名]
# 或者: from pyvcloud.vcloudair.VCA import login_to_org [as 别名]
import os
from pyvcloud import vcloudair
from pyvcloud.vcloudair import VCA
username = os.environ['VCAUSER']
password = os.environ['VCAPASS']
service_type = VCA.VCA_SERVICE_TYPE_VCHS
host = 'vchs.vmware.com'
version = '5.6'
vca = VCA(host=host, username=username, service_type=service_type,
version=version, verify=True, log=True)
assert vca
result = vca.login(password=password)
assert result
assert vca.token
service = 'M684216431-4470'
org = 'M684216431-4470'
result = vca.login_to_org(service, org)
assert result
vdc = 'M684216431-4470'
the_vdc = vca.get_vdc(vdc)
assert the_vdc
print 'vdc name: ' + the_vdc.get_name()
print 'catalogs: '
for catalog in vca.get_catalogs():
print ' - ' + catalog.get_name()