本文整理汇总了Python中pyvcloud.Http类的典型用法代码示例。如果您正苦于以下问题:Python Http类的具体用法?Python Http怎么用?Python Http使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Http类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_catalog
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
示例2: get_instances
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
示例3: get_plans
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
示例4: create_vapp
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
示例5: get_media
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: get_gateways
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
示例7: block_until_completed
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
示例8: get_vapp
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
示例9: get_vdc_references
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()
示例10: get_disks
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: set_syslog_conf
def set_syslog_conf(self, syslog_server_ip):
headers = self.headers
headers['Accept'] = 'application/*+xml;version=5.11'
headers['Content-Type'] = 'application/vnd.vmware.vcloud.SyslogSettings+xml;version=5.11'
# content_type = "application/vnd.vmware.vcloud.SyslogSettings+xml"
body = ''
if '' == syslog_server_ip:
body = """
<SyslogServerSettings xmlns="http://www.vmware.com/vcloud/v1.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.160.99.94/api/v1.5/schema/master.xsd">
<TenantSyslogServerSettings>
</TenantSyslogServerSettings>
</SyslogServerSettings>
"""
else:
body = """
<SyslogServerSettings xmlns="http://www.vmware.com/vcloud/v1.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.160.99.94/api/v1.5/schema/master.xsd">
<TenantSyslogServerSettings>
<SyslogServerIp>%s</SyslogServerIp>
</TenantSyslogServerSettings>
</SyslogServerSettings>
""" % syslog_server_ip
# '<SyslogServerSettings><TenantSyslogServerSettings><SyslogServerIp>%s</SyslogServerIp></TenantSyslogServerSettings></SyslogServerSettings>' % syslog_server_ip
# link = filter(lambda link: link.get_type() == content_type, self.me.get_Link())
self.response = Http.post(self.me.href+'/action/configureSyslogServerSettings', data=body, headers=headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
task = taskType.parseString(self.response.content, True)
return task
示例12: connect_to_network
def connect_to_network(self, network_name, network_href, fence_mode='bridged'):
"""
Connect the vApp to an existing virtual network in the VDC.
:param network_name: (str): The name of the virtual network.
:param network_href: (str): A uri that points to the network resource.
:param fence_mode: (str, optional):
:return: (TaskType) a :class:`pyvcloud.schema.vcd.v1_5.schemas.admin.vCloudEntities.TaskType` object that can be used to monitor the request.
"""
vApp_NetworkConfigSection = [section for section in self.me.get_Section() if section.__class__.__name__ == "NetworkConfigSectionType"][0]
link = [link for link in vApp_NetworkConfigSection.get_Link() if link.get_type() == "application/vnd.vmware.vcloud.networkConfigSection+xml"][0]
for networkConfig in vApp_NetworkConfigSection.get_NetworkConfig():
if networkConfig.get_networkName() == network_name:
task = TaskType()
task.set_status("success")
task.set_Progress("100")
return task
networkConfigSection = VAPP.create_networkConfigSection(network_name, network_href, fence_mode, vApp_NetworkConfigSection)
output = StringIO()
networkConfigSection.export(output,
0,
name_ = 'NetworkConfigSection',
namespacedef_ = 'xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"',
pretty_print = True)
body = output.getvalue().\
replace('Info msgid=""', "ovf:Info").replace("Info", "ovf:Info").replace(":vmw", "").replace("vmw:","")\
.replace("RetainNetovf", "ovf").replace("ovf:InfoAcrossDeployments","RetainNetInfoAcrossDeployments")
self.response = Http.put(link.get_href(), data=body, headers=self.headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
return taskType.parseString(self.response.content, True)
示例13: connect_vms
def connect_vms(self, network_name, connection_index,
connections_primary_index=None, ip_allocation_mode='DHCP',
mac_address=None, ip_address=None):
children = self.me.get_Children()
if children:
vms = children.get_Vm()
for vm in vms:
new_connection = self._create_networkConnection(
network_name, connection_index, ip_allocation_mode,
mac_address, ip_address)
networkConnectionSection = [section for section in vm.get_Section() if isinstance(section, NetworkConnectionSectionType)][0]
self._modify_networkConnectionSection(
networkConnectionSection,
new_connection,
connections_primary_index)
output = StringIO()
networkConnectionSection.export(output,
0,
name_ = 'NetworkConnectionSection',
namespacedef_ = 'xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:vmw="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"',
pretty_print = False)
body=output.getvalue().replace("vmw:Info", "ovf:Info")
self.response = Http.put(vm.get_href() + "/networkConnectionSection/", data=body, headers=self.headers, verify=self.verify, logger=self.logger)
if self.response.status_code == requests.codes.accepted:
return taskType.parseString(self.response.content, True)
示例14: _upload
def _upload(self, tar_file_obj,
blueprint_id,
application_file_name=None):
query_params = {}
if application_file_name is not None:
query_params['application_file_name'] = \
urllib.quote(application_file_name)
def file_gen():
buffer_size = 8192
while True:
read_bytes = tar_file_obj.read(buffer_size)
yield read_bytes
if len(read_bytes) < buffer_size:
return
uri = '/blueprints/{0}'.format(blueprint_id)
url = '{0}{1}'.format(self.score.url, uri)
headers = self.score.get_headers()
self.score.response = Http.put(url, headers=headers, params=query_params, data=file_gen(), verify=self.score.verify, logger=self.logger)
if self.score.response.status_code != 201:
raise Exception(self.score.response.status_code)
return self.score.response.json()
示例15: _get_services
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)