本文整理汇总了Python中pyvcloud.Http.get方法的典型用法代码示例。如果您正苦于以下问题:Python Http.get方法的具体用法?Python Http.get怎么用?Python Http.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyvcloud.Http
的用法示例。
在下文中一共展示了Http.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_instances
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def get_instances(self):
self.response = Http.get(self.host + "/api/sc/instances", headers=self._get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.history and self.response.history[-1]:
self.response = Http.get(self.response.history[-1].headers['location'], headers=self._get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
return json.loads(self.response.content)['instances']
else:
return None
示例2: get_plans
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def get_plans(self):
headers = self._get_vcloud_headers()
headers['Accept'] = "application/json;version=%s;class=com.vmware.vchs.sc.restapi.model.planlisttype" % self.version
self.response = Http.get(self.host + "/api/sc/plans", headers=headers, verify=self.verify, logger=self.logger)
if self.response.history and self.response.history[-1]:
self.response = Http.get(self.response.history[-1].headers['location'], headers=headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
return json.loads(self.response.content)['plans']
else:
return None
示例3: create_vapp
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def create_vapp(self, vdc_name, vapp_name, template_name, catalog_name,
network_name=None, network_mode='bridged', vm_name=None,
vm_cpus=None, vm_memory=None, deploy='false',
poweron='false'):
self.vdc = self.get_vdc(vdc_name)
if not self.vcloud_session or not self.vcloud_session.organization or not self.vdc:
#"Select an organization and datacenter first"
return False
if '' == vm_name: vm_name = None
catalogs = filter(lambda link: catalog_name == link.get_name() and link.get_type() == "application/vnd.vmware.vcloud.catalog+xml",
self.vcloud_session.organization.get_Link())
if len(catalogs) == 1:
self.response = Http.get(catalogs[0].get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
catalog = catalogType.parseString(self.response.content, True)
catalog_items = filter(lambda catalogItemRef: catalogItemRef.get_name() == template_name, catalog.get_CatalogItems().get_CatalogItem())
if len(catalog_items) == 1:
self.response = Http.get(catalog_items[0].get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
# use ElementTree instead because none of the types inside resources (not even catalogItemType) is able to parse the response correctly
catalogItem = ET.fromstring(self.response.content)
entity = [child for child in catalogItem if child.get("type") == "application/vnd.vmware.vcloud.vAppTemplate+xml"][0]
vm_href = None
if vm_name:
self.response = Http.get(entity.get('href'), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
vAppTemplate = ET.fromstring(self.response.content)
for vm in vAppTemplate.iter('{http://www.vmware.com/vcloud/v1.5}Vm'):
vm_href = vm.get('href')
template_params = self._create_instantiateVAppTemplateParams(
vapp_name, entity.get("href"), vm_name=vm_name,
vm_href=vm_href, vm_cpus=vm_cpus, vm_memory=vm_memory,
deploy=deploy, power=poweron)
if network_name:
pass
output = StringIO()
template_params.export(output,
0,
name_ = 'InstantiateVAppTemplateParams',
namespacedef_ = '''xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"''',
pretty_print = False)
body = '<?xml version="1.0" encoding="UTF-8"?>' + \
output.getvalue().replace('class:', 'rasd:')\
.replace(' xmlns:vmw="http://www.vmware.com/vcloud/v1.5"', '')\
.replace('vmw:', 'rasd:')\
.replace('Info>', "ovf:Info>")
content_type = "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml"
link = filter(lambda link: link.get_type() == content_type, self.vdc.get_Link())
self.response = Http.post(link[0].get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, data=body, logger=self.logger)
if self.response.status_code == requests.codes.created:
vApp = vAppType.parseString(self.response.content, True)
task = vApp.get_Tasks().get_Task()[0]
return task
return False
示例4: get_gateways
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def get_gateways(self, vdc_name):
gateways = []
vdc = self.get_vdc(vdc_name)
if not vdc: return gateways
link = filter(lambda link: link.get_rel() == "edgeGateways", vdc.get_Link())
self.response = Http.get(link[0].get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
queryResultRecords = queryRecordViewType.parseString(self.response.content, True)
if queryResultRecords.get_Record():
for edgeGatewayRecord in queryResultRecords.get_Record():
self.response = Http.get(edgeGatewayRecord.get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
gateway = Gateway(networkType.parseString(self.response.content, True), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, log=self.log)
gateways.append(gateway)
return gateways
示例5: get_media
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def get_media(self, catalog_name, media_name):
refs = filter(lambda ref: ref.name == catalog_name and ref.type_ == 'application/vnd.vmware.vcloud.catalog+xml', self.vcloud_session.organization.Link)
if len(refs) == 1:
self.response = Http.get(refs[0].get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
catalog = catalogType.parseString(self.response.content, True)
catalog_items = filter(lambda catalogItemRef: catalogItemRef.get_name() == media_name, catalog.get_CatalogItems().get_CatalogItem())
if len(catalog_items) == 1:
self.response = Http.get(catalog_items[0].get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
# print self.response.content
if self.response.status_code == requests.codes.ok:
doc = self.parsexml_(self.response.content)
for element in doc._children:
if element.tag == '{http://www.vmware.com/vcloud/v1.5}Entity':
return element.attrib
示例6: block_until_completed
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def block_until_completed(self, task):
progress = task.get_Progress()
status = task.get_status()
rnd = 0
while status != "success":
if status == "error":
error = task.get_Error()
Log.error(self.logger, "task error, major=%s, minor=%s, message=%s" % (error.get_majorErrorCode(), error.get_minorErrorCode(), error.get_message()))
return False
else:
# some task doesn't not report progress
if progress:
pass
else:
rnd += 1
time.sleep(1)
self.response = Http.get(task.get_href(), headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
task = taskType.parseString(self.response.content, True)
progress = task.get_Progress()
status = task.get_status()
else:
Log.error(self.logger, "can't get task")
return False
return True
示例7: get_vapp
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def get_vapp(self, vdc, vapp_name):
refs = filter(lambda ref: ref.name == vapp_name and ref.type_ == 'application/vnd.vmware.vcloud.vApp+xml', vdc.ResourceEntities.ResourceEntity)
if len(refs) == 1:
self.response = Http.get(refs[0].href, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
vapp = VAPP(vAppType.parseString(self.response.content, True), self.vcloud_session.get_vcloud_headers(), self.verify, self.log)
return vapp
示例8: get_vdc_references
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def get_vdc_references(self, serviceId):
serviceReferences = filter(lambda serviceReference: serviceReference.get_serviceId() == serviceId, self.services.get_Service())
if len(serviceReferences) == 0:
return []
self.response = Http.get(serviceReferences[0].get_href(), headers=self._get_vcloud_headers(), verify=self.verify, logger=self.logger)
vdcs = vchsType.parseString(self.response.content, True)
return vdcs.get_VdcRef()
示例9: delete_catalog
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def delete_catalog(self, catalog_name):
admin_url = None
if not self.vcloud_session or not self.vcloud_session.organization: return False
if 'ondemand' == self.service_type:
refs = filter(lambda ref: ref.type_ == 'application/vnd.vmware.admin.organization+xml',
self.vcloud_session.organization.Link)
if len(refs) == 1:
admin_url = refs[0].href
else:
refs = filter(lambda ref: ref.type_ == 'application/vnd.vmware.admin.catalog+xml',
self.vcloud_session.organization.Link)
if len(refs) == 1:
admin_url = refs[0].href[:refs[0].href.rindex('/')]
if admin_url:
self.response = Http.get(admin_url, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
adminOrg = vCloudEntities.parseString(self.response.content, True)
if adminOrg and adminOrg.Catalogs and adminOrg.Catalogs.CatalogReference:
catRefs = filter(lambda ref: ref.name == catalog_name and ref.type_ == 'application/vnd.vmware.admin.catalog+xml',
adminOrg.Catalogs.CatalogReference)
if len(catRefs) == 1:
self.response = Http.delete(catRefs[0].href, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.no_content:
return True
return False
示例10: get_disks
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def get_disks(self, vdc_name):
vdc = self.get_vdc(vdc_name)
links = self.get_diskRefs(vdc)
disks = []
for link in links:
response = Http.get(link.get_href(), headers = self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
disk = self._parse_disk(response.content)
vms = []
content_type = "application/vnd.vmware.vcloud.vms+xml"
response = Http.get(link.get_href()+'/attachedVms', headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
# print response.content
listofvms = vmsType.parseString(response.content, True)
for vmReference in listofvms.get_VmReference():
vms.append(vmReference)
disks.append([disk, vms])
return disks
示例11: _get_services
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def _get_services(self):
headers = {}
headers["x-vchs-authorization"] = self.token
headers["Accept"] = "application/xml;version=" + self.version
response = Http.get(self.host + "/api/vchs/services", headers=headers, verify=self.verify, logger=self.logger)
if response.status_code == requests.codes.ok:
return serviceType.parseString(response.content, True)
示例12: get_status
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def get_status(self):
self.response = Http.get(self.url + '/status',
headers=self.get_headers(),
verify=self.verify, logger=self.logger)
Log.debug(self.logger, self.response.status_code)
Log.debug(self.logger, self.response.content)
return self.response.content
示例13: list
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def list(self, deployment_id):
params = {'deployment_id': deployment_id}
self.score.response = Http.get(self.score.url + '/executions', headers=self.score.get_headers(), params=params, verify=self.score.verify, logger=self.logger)
if self.score.response.status_code == requests.codes.ok:
return json.loads(self.score.response.content)
else:
Log.error(self.logger, 'list executions returned %s' % self.score.response.status_code)
示例14: get_vdc
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def get_vdc(self, vdc_name):
if self.vcloud_session and self.vcloud_session.organization:
refs = filter(lambda ref: ref.name == vdc_name and ref.type_ == 'application/vnd.vmware.vcloud.vdc+xml', self.vcloud_session.organization.Link)
if len(refs) == 1:
self.response = Http.get(refs[0].href, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.ok:
# print self.response.content
return vdcType.parseString(self.response.content, True)
示例15: list
# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import get [as 别名]
def list(self):
self.score.response = Http.get(self.score.url + '/blueprints',
headers=self.score.get_headers(),
verify=self.score.verify,
logger=self.logger)
if self.score.response.status_code != requests.codes.ok:
raise exceptions.from_response(self.score.response)
return json.loads(self.score.response.content)