当前位置: 首页>>代码示例>>Python>>正文


Python Http.post方法代码示例

本文整理汇总了Python中pyvcloud.Http.post方法的典型用法代码示例。如果您正苦于以下问题:Python Http.post方法的具体用法?Python Http.post怎么用?Python Http.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyvcloud.Http的用法示例。


在下文中一共展示了Http.post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_syslog_conf

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
 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
开发者ID:h-medjahed,项目名称:pyvcloud,代码行数:31,代码来源:gateway.py

示例2: create_vapp

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [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
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:57,代码来源:vcloudair.py

示例3: customize_on_next_poweron

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
    def customize_on_next_poweron(self):
        vm = self._get_vms()[0]
        link = filter(lambda link: link.get_rel() == "customizeAtNextPowerOn",
                      vm.get_Link())
        if link:
            self.response = Http.post(link[0].get_href(), data=None,
                                      headers=self.headers, logger=self.logger)
            if self.response.status_code == requests.codes.no_content:
                return True

        Log.error(self.logger, "link not found")
        return False
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:14,代码来源:vapp.py

示例4: save_services_configuration

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
 def save_services_configuration(self):
     edgeGatewayServiceConfiguration = self.me.get_Configuration().get_EdgeGatewayServiceConfiguration()
     body = '<?xml version="1.0" encoding="UTF-8"?>' + \
            CommonUtils.convertPythonObjToStr(self.me.get_Configuration().get_EdgeGatewayServiceConfiguration(),
                                              name='EdgeGatewayServiceConfiguration',
                                              namespacedef='xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ')
     content_type = "application/vnd.vmware.admin.edgeGatewayServiceConfiguration+xml"
     link = filter(lambda link: link.get_type() == content_type, self.me.get_Link())
     self.response = Http.post(link[0].get_href(), data=body, headers=self.headers, logger=self.logger)
     if self.response.status_code == requests.codes.accepted:
         task = taskType.parseString(self.response.content, True)
         return task
开发者ID:h-medjahed,项目名称:pyvcloud,代码行数:14,代码来源:gateway.py

示例5: _post

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
 def _post(self, href, body, content_type):
     headers = self._session.vca.vcloud_session.get_vcloud_headers()
     headers['Content-type'] = content_type
     response = Http.post(
         href,
         data=body,
         headers=headers,
         verify=CONF.vcloud.verify)
     print response.content
     if response.status_code == requests.codes.accepted:
         return taskType.parseString(response.content, True)
     return None
开发者ID:lionelz,项目名称:hybridcloud,代码行数:14,代码来源:vcloud_client.py

示例6: create_catalog

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
 def create_catalog(self, catalog_name, description):
     refs = filter(lambda ref: ref.rel == 'add' and ref.type_ == 'application/vnd.vmware.admin.catalog+xml',
                          self.vcloud_session.organization.Link)
     if len(refs) == 1:
         data = """<?xml version="1.0" encoding="UTF-8"?>
         <AdminCatalog xmlns="http://www.vmware.com/vcloud/v1.5" name="%s">
         <Description>%s</Description>
         </AdminCatalog>
         """ % (catalog_name, description)
         self.response = Http.post(refs[0].href, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, data=data, logger=self.logger)
         if self.response.status_code == requests.codes.created:
             task = vCloudEntities.parseString(self.response.content, True)
             return task.get_Tasks().get_Task()[0]
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:15,代码来源:vcloudair.py

示例7: add_disk

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
 def add_disk(self, vdc_name, name, size):
     data = """
             <vcloud:DiskCreateParams xmlns:vcloud="http://www.vmware.com/vcloud/v1.5">
                 <vcloud:Disk name="%s" size="%s"/>
             </vcloud:DiskCreateParams>
         """ % (name, size)        
     vdc = self.get_vdc(vdc_name)
     content_type = "application/vnd.vmware.vcloud.diskCreateParams+xml"
     link = filter(lambda link: link.get_type() == content_type, vdc.get_Link())
     self.response = Http.post(link[0].get_href(), data=data, headers=self.vcloud_session.get_vcloud_headers(), verify=self.verify, logger=self.logger)
     if self.response.status_code == requests.codes.created:
         disk = self._parse_disk(self.response.content)
         return(True, disk)
     else:
         return(False, self.response.content)
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:17,代码来源:vcloudair.py

示例8: start

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
 def start(self, deployment_id, workflow_id, parameters=None,
           allow_custom_parameters=False, force=False):
     assert deployment_id
     assert workflow_id
     data = {
         'deployment_id': deployment_id,
         'workflow_id': workflow_id,
         'parameters': parameters,
         'allow_custom_parameters': str(allow_custom_parameters).lower(),
         'force': str(force).lower()
     }
     headers = self.score.get_headers()
     headers['Content-type'] = 'application/json'
     self.score.response = Http.post(self.score.url + '/executions', headers=headers, data=json.dumps(data),  verify=self.score.verify, logger=self.logger)
     if self.score.response.status_code == requests.codes.ok:
         return json.loads(self.score.response.content)
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:18,代码来源:score.py

示例9: cancel

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
 def cancel(self, execution_id, force=False):
     data = {
         'execution_id': execution_id,
         'force': force
     }
     headers = self.score.get_headers()
     headers['Content-type'] = 'application/json'
     self.score.response = Http.post(
         self.score.url + '/executions/' + execution_id,
         headers=headers, data=json.dumps(data),
         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)
开发者ID:digideskio,项目名称:pyvcloud,代码行数:18,代码来源:score.py

示例10: start

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
 def start(self, deployment_id, workflow_id, parameters=None,
           allow_custom_parameters=False, force=False):
     data = {
         'deployment_id': deployment_id,
         'workflow_id': workflow_id,
         'parameters': parameters,
         'allow_custom_parameters': allow_custom_parameters,
         'force': force,
     }
     headers = self.score.get_headers()
     headers['Content-type'] = 'application/json'
     self.score.response = Http.post(self.score.url + '/executions',
                                     headers=headers,
                                     data=json.dumps(data),
                                     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)
开发者ID:digideskio,项目名称:pyvcloud,代码行数:21,代码来源:score.py

示例11: login_to_org

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
 def login_to_org(self, service, org_name):
     vdcReference = self.get_vdc_reference(service, org_name)
     if vdcReference:
         link = filter(lambda link: link.get_type() == "application/xml;class=vnd.vmware.vchs.vcloudsession", vdcReference.get_Link())[0]
         self.response = Http.post(link.get_href(), headers=self._get_vcloud_headers(), verify=self.verify, logger=self.logger)
         if self.response.status_code == requests.codes.created:
             vchs = vchsType.parseString(self.response.content, True)
             vdcLink = vchs.get_VdcLink()
             headers = {}
             headers[vdcLink.authorizationHeader] = vdcLink.authorizationToken
             headers["Accept"] = "application/*+xml;version=" + self.version
             self.response = Http.get(vdcLink.href, headers=headers, verify=self.verify, logger=self.logger)
             if self.response.status_code == requests.codes.ok:
                 self.vdc = vdcType.parseString(self.response.content, True)
                 self.org = self.vdc.name
                 org_url = filter(lambda link: link.get_type() == "application/vnd.vmware.vcloud.org+xml", self.vdc.get_Link())[0].href
                 vcloud_session = VCS(org_url, self.username, self.org, None, org_url, org_url, version=self.version, verify=self.verify, log=self.log)
                 if vcloud_session.login(password=None, token=vdcLink.authorizationToken):
                     self.vcloud_session = vcloud_session
                     return True
     return False
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:23,代码来源:vcloudair.py

示例12: customize_on_next_poweron

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
    def customize_on_next_poweron(self):
        """
        Force the guest OS customization script to be run for the first VM in the vApp.
        A customization script must have been previously associated with the VM
        using the pyvcloud customize_guest_os method or using the vCD console
        The VMware tools must be installed in the Guest OS.
       
        :return: (bool) True if the request was accepted, False otherwise. If False an error level log message is generated.

        """
        vm = self._get_vms()[0]
        link = filter(lambda link: link.get_rel() == "customizeAtNextPowerOn",
                      vm.get_Link())
        if link:
            self.response = Http.post(link[0].get_href(), data=None,
                                      headers=self.headers, logger=self.logger)
            if self.response.status_code == requests.codes.no_content:
                return True

        Log.error(self.logger, "link not found")
        return False
开发者ID:piraz,项目名称:pyvcloud,代码行数:23,代码来源:vapp.py

示例13: create_vdc_network

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
    def create_vdc_network(self, vdc_name, network_name, gateway_name, start_address,
                           end_address, gateway_ip, netmask,
                           dns1, dns2, dns_suffix):
        vdc = self.get_vdc(vdc_name)
        gateway = ReferenceType(href=self.get_gateway(vdc_name, gateway_name).me.href)
        gateway.original_tagname_ = "EdgeGateway"

        iprange = IpRangeType(StartAddress=start_address,
                              EndAddress=end_address)
        ipranges = IpRangesType(IpRange=[iprange])
        ipscope = IpScopeType(IsInherited=False,
                              Gateway=gateway_ip,
                              Netmask=netmask,
                              Dns1=dns1,
                              Dns2=dns2,
                              DnsSuffix=dns_suffix,
                              IpRanges=ipranges)
        ipscopes = IpScopesType(IpScope=[ipscope])

        configuration = NetworkConfigurationType(IpScopes=ipscopes,
                                                 FenceMode="natRouted")
        net = OrgVdcNetworkType(name=network_name, Description="Network created by pyvcloud",
                                EdgeGateway=gateway, Configuration=configuration,
                                IsShared=False)
        namespacedef = 'xmlns="http://www.vmware.com/vcloud/v1.5"'
        content_type = "application/vnd.vmware.vcloud.orgVdcNetwork+xml"
        body = '<?xml version="1.0" encoding="UTF-8"?>{0}'.format(
            CommonUtils.convertPythonObjToStr(net, name='OrgVdcNetwork',
                                              namespacedef=namespacedef))
        postlink = filter(lambda link: link.get_type() == content_type,
                          vdc.get_Link())[0].href
        headers = self.vcloud_session.get_vcloud_headers()
        headers["Content-Type"] = content_type
        self.response = Http.post(postlink, data=body, headers=headers, verify=self.verify, logger=self.logger)
        if self.response.status_code == requests.codes.created:
            network = networkType.parseString(self.response.content, True)
            task = network.get_Tasks().get_Task()[0]
            return (True, task)
        else:
            return (False, self.response.content)
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:42,代码来源:vcloudair.py

示例14: force_customization

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
 def force_customization(self, vm_name):
     children = self.me.get_Children()
     if children:
         vms = [vm for vm in children.get_Vm() if vm.name == vm_name]
         if len(vms) == 1:
             sections = vms[0].get_Section()
             links = filter(lambda link: link.rel== "deploy", vms[0].Link)
             if len(links) == 1:
                 forceCustomizationValue = 'true'
                 deployVAppParams = vcloudType.DeployVAppParamsType()
                 deployVAppParams.set_powerOn('true')
                 deployVAppParams.set_deploymentLeaseSeconds(0)
                 deployVAppParams.set_forceCustomization('true')
                 body = CommonUtils.convertPythonObjToStr(deployVAppParams, name = "DeployVAppParams",
                         namespacedef = 'xmlns="http://www.vmware.com/vcloud/v1.5"')
                 headers = self.headers
                 headers['Content-type'] = 'application/vnd.vmware.vcloud.deployVAppParams+xml'
                 self.response = Http.post(links[0].href, data=body, headers=headers, verify=self.verify, logger=self.logger)
                 if self.response.status_code == requests.codes.accepted:
                     return taskType.parseString(self.response.content, True)
                 else:
                     Log.debug(self.logger, "response status=%d, content=%s" % (self.response.status_code, self.response.text))
开发者ID:nmishkin,项目名称:pyvcloud,代码行数:24,代码来源:vapp.py

示例15: login

# 需要导入模块: from pyvcloud import Http [as 别名]
# 或者: from pyvcloud.Http import post [as 别名]
 def login(self, password=None, token=None):
     if token:
         headers = {}
         headers["x-vcloud-authorization"] = token
         headers["Accept"] = "application/*+xml;version=" + self.version
         self.response = Http.get(self.org_url, headers=headers, verify=self.verify, logger=self.logger)
         if self.response.status_code == requests.codes.ok:
             self.token = token
             self.organization = organizationType.parseString(self.response.content, True)
             return True
         else:
             return False
     else:
         headers = {}
         headers["Accept"] = "application/*+xml;version=" + self.version
         self.response = Http.post(self.url, headers=headers, auth=(self.username + "@" + self.org, password), verify=self.verify, logger=self.logger)
         if self.response.status_code == requests.codes.ok:
             self.token = self.response.headers["x-vcloud-authorization"]
             self.session = sessionType.parseString(self.response.content, True)
             self.org_url = filter(lambda link: link.type_ == 'application/vnd.vmware.vcloud.org+xml', self.session.Link)[0].href
             return True
         else:
             return False
开发者ID:kostya13,项目名称:pyvcloud,代码行数:25,代码来源:vcloudsession.py


注:本文中的pyvcloud.Http.post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。