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


Python retry_http.http_retriable_request函数代码示例

本文整理汇总了Python中sm.retry_http.http_retriable_request函数的典型用法代码示例。如果您正苦于以下问题:Python http_retriable_request函数的具体用法?Python http_retriable_request怎么用?Python http_retriable_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: __init_so

    def __init_so(self):
        url = HTTP + self.host + '/orchestrator/default'
        heads = {
            'Category': 'orchestrator; scheme="http://schemas.mobile-cloud-networking.eu/occi/service#"',
            'Content-Type': 'text/occi',
            'X-Auth-Token': self.extras['token'],
            'X-Tenant-Name': self.extras['tenant_name'],
            'X-OCCI-Attribute': 'occi.mcn.app.url="' + HTTP + self.host + '/orchestrator/default"'
        }

        occi_attrs = self.extras['srv_prms'].service_parameters(self.state)
        if len(occi_attrs) > 0:
            LOG.info('Adding service-specific parameters to call... X-OCCI-Attribute: ' + occi_attrs)
            heads['X-OCCI-Attribute'] = occi_attrs

        LOG.debug('Initialising SO with: ' + url)
        LOG.info('Sending headers: ' + heads.__repr__())
        http_retriable_request('PUT', url, headers=heads)
        elapsed_time = time.time() - self.start_time
        infoDict = {
                    'so_id': self.entity.attributes['occi.core.id'],
                    'sm_name': self.entity.kind.term,
                    'so_phase': 'activate',
                    'phase_event': 'done',
                    'response_time': elapsed_time,
                    'tenant': self.extras['tenant_name']
                    }
        tmpJSON = json.dumps(infoDict)
        LOG.debug(tmpJSON)
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:29,代码来源:so_manager.py

示例2: run

    def run(self):
        # take parameters from EEU and send them down to the SO instance
        # Trigger update on SO + service instance:
        #
        # $ curl -v -X POST http://localhost:8051/orchestrator/default \
        #       -H 'Content-Type: text/occi' \
        #       -H 'X-Auth-Token: '$KID \
        #       -H 'X-Tenant-Name: '$TENANT \
        #       -H 'X-OCCI-Attribute: occi.epc.attr_1="foo"'
        url = HTTP + self.host + '/orchestrator/default'
        heads = {
            'Content-Type': 'text/occi',
            'X-Auth-Token': self.extras['token'],
            'X-Tenant-Name': self.extras['tenant_name']}

        occi_attrs = self.extras['srv_prms'].service_parameters(self.state)

        if len(occi_attrs) > 0:
            LOG.info('Adding service-specific parameters to call... X-OCCI-Attribute:' + occi_attrs)
            heads['X-OCCI-Attribute'] = occi_attrs

        if len(self.new.attributes) > 0:
            LOG.info('Adding updated parameters... X-OCCI-Attribute: ' + self.new.attributes.__repr__())
            for k, v in self.new.attributes.items():
                occi_attrs = occi_attrs + ', ' + k + '=' + v
                self.entity.attributes[k] = v
            heads['X-OCCI-Attribute'] = occi_attrs

        LOG.debug('Updating (Provisioning) SO with: ' + url)
        LOG.info('Sending headers: ' + heads.__repr__())

        http_retriable_request('POST', url, headers=heads)

        self.entity.attributes['mcn.service.state'] = 'update'
        return self.entity, self.extras
开发者ID:MobileCloudNetworking,项目名称:dssaas,代码行数:35,代码来源:so_manager.py

示例3: run

    def run(self):
        # take parameters from EEU and send them down to the SO instance
        # Trigger update on SO + service instance:
        #
        # $ curl -v -X POST http://localhost:8051/orchestrator/default \
        #       -H 'Content-Type: text/occi' \
        #       -H 'X-Auth-Token: '$KID \
        #       -H 'X-Tenant-Name: '$TENANT \
        #       -H 'X-OCCI-Attribute: occi.epc.attr_1="foo"'

        self.start_time = time.time()
        infoDict = {
                    'so_id': self.entity.attributes['occi.core.id'],
                    'sm_name': self.entity.kind.term,
                    'so_phase': 'update',
                    'phase_event': 'start',
                    'response_time': 0,
                    'tenant': self.extras['tenant_name']
                    }
        tmpJSON = json.dumps(infoDict)
        LOG.debug(tmpJSON)

        url = HTTP + self.host + '/orchestrator/default'
        heads = {
            'Content-Type': 'text/occi',
            'X-Auth-Token': self.extras['token'],
            'X-Tenant-Name': self.extras['tenant_name']}

        occi_attrs = self.extras['srv_prms'].service_parameters(self.state)

        if len(occi_attrs) > 0:
            LOG.info('Adding service-specific parameters to call... X-OCCI-Attribute:' + occi_attrs)
            heads['X-OCCI-Attribute'] = occi_attrs

        if len(self.new.attributes) > 0:
            LOG.info('Adding updated parameters... X-OCCI-Attribute: ' + self.new.attributes.__repr__())
            for k, v in self.new.attributes.items():
                occi_attrs = occi_attrs + ', ' + k + '=' + v
                self.entity.attributes[k] = v
            heads['X-OCCI-Attribute'] = occi_attrs

        LOG.debug('Updating (Provisioning) SO with: ' + url)
        LOG.info('Sending headers: ' + heads.__repr__())

        http_retriable_request('POST', url, headers=heads)

        self.entity.attributes['mcn.service.state'] = 'update'

        #start thread here
        thread = Thread(target = deploy_complete, args = (url, self.start_time, self.extras, self.entity ))
        thread.start()

        return self.entity, self.extras
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:53,代码来源:so_manager.py

示例4: __is_complete

    def __is_complete(self, url):
        # XXX copy/paste code - merge the two places!
        heads = {
                'Content-type': 'text/occi',
                'Accept': 'application/occi+json',
                'X-Auth-Token': self.extras['token'],
                'X-Tenant-Name': self.extras['tenant_name'],
            }

        LOG.info('Checking app state at: ' + url)
        LOG.info('Sending headers: ' + heads.__repr__())

        r = http_retriable_request('GET', url, headers=heads, authenticate=True)
        attrs = json.loads(r.content)

        if len(attrs['attributes']) > 0:
            attr_hash = attrs['attributes']
            app_state = ''
            try:
                app_state = attr_hash['occi.app.state']
            except KeyError:
                pass

            LOG.info('Current service state: ' + str(app_state))
            if app_state == 'active':
                # check if it returns something valid instead of 503
                try:
                    tmpUrl = 'http://' + attr_hash['occi.app.url']
                except KeyError:
                    LOG.info(('App is not ready. app url is not yet set.'))
                    return False
                r = http_retriable_request('GET', tmpUrl, headers=heads, authenticate=True)
                if r.status_code == 200:
                    LOG.info('App is ready')
                    elapsed_time = time.time() - self.extras['occi.init.starttime']
                    del self.extras['occi.init.starttime']

                    infoDict = {
                                'so_id': self.entity.attributes['occi.core.id'],
                                'sm_name': self.entity.kind.term,
                                'so_phase': 'init',
                                'phase_event': 'done',
                                'response_time': elapsed_time,
                                'tenant': self.extras['tenant_name']
                                }
                    tmpJSON = json.dumps(infoDict)
                    LOG.debug(tmpJSON)
                    return True
                else:
                    LOG.info('App is not ready. app url returned: ' + r.status_code)
            else:
                LOG.info('App is not ready. Current state state: ' + app_state)
                return False
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:53,代码来源:so_manager.py

示例5: __is_complete

    def __is_complete(self, url):
        # XXX copy/paste code - merge the two places!
        heads = {
                'Content-type': 'text/occi',
                'Accept': 'application/occi+json',
                'X-Auth-Token': self.extras['token'],
                'X-Tenant-Name': self.extras['tenant_name'],
            }

        LOG.info('Checking app state at: ' + url)
        LOG.info('Sending headers: ' + heads.__repr__())

        r = http_retriable_request('GET', url, headers=heads, authenticate=True)
        attrs = json.loads(r.content)

        if len(attrs['attributes']) > 0:
            attr_hash = attrs['attributes']
            app_state = ''
            try:
                app_state = attr_hash['occi.app.state']
            except KeyError:
                pass

            LOG.info('Current service state: ' + str(app_state))
            if app_state == 'active':
                LOG.info('App is ready')
                return True
            else:
                LOG.info('App is not ready. Current state state: ' + app_state)
                return False
开发者ID:MobileCloudNetworking,项目名称:dssaas,代码行数:30,代码来源:so_manager.py

示例6: __create_app

    def __create_app(self):
        # name must be A-Za-z0-9 and <=32 chars
        app_name = self.entity.kind.term[0:4] + 'srvinst' + ''.join(random.choice('0123456789ABCDEF') for i in range(16))
        heads = {
            'Content-Type': 'text/occi',
            'Category': 'app; scheme="http://schemas.ogf.org/occi/platform#", '
            'python-2.7; scheme="http://schemas.openshift.com/template/app#", '
            'small; scheme="http://schemas.openshift.com/template/app#"',
            'X-OCCI-Attribute': 'occi.app.name=' + app_name
            }

        url = self.nburl + '/app/'
        LOG.debug('Requesting container to execute SO Bundle: ' + url)
        LOG.info('Sending headers: ' + heads.__repr__())
        r = http_retriable_request('POST', url, headers=heads, authenticate=True)

        loc = r.headers.get('Location', '')
        if loc == '':
            raise AttributeError("No OCCI Location attribute found in request")

        app_uri_path = urlparse(loc).path
        LOG.debug('SO container created: ' + app_uri_path)

        LOG.debug('Updating OCCI entity.identifier from: ' + self.entity.identifier + ' to: '
                  + app_uri_path.replace('/app/', self.entity.kind.location))
        self.entity.identifier = app_uri_path.replace('/app/', self.entity.kind.location)

        LOG.debug('Setting occi.core.id to: ' + app_uri_path.replace('/app/', ''))
        self.entity.attributes['occi.core.id'] = app_uri_path.replace('/app/', '')

        # get git uri. this is where our bundle is pushed to
        return self.__git_uri(app_uri_path)
开发者ID:MobileCloudNetworking,项目名称:mobaas,代码行数:32,代码来源:so_manager.py

示例7: deploy_complete

    def deploy_complete(self, url):
        # XXX fugly - code copied from Resolver
        heads = {
            'Content-type': 'text/occi',
            'Accept': 'application/occi+json',
            'X-Auth-Token': self.extras['token'],
            'X-Tenant-Name': self.extras['tenant_name'],
        }

        LOG.info('checking service state at: ' + url)
        LOG.info('sending headers: ' + heads.__repr__())

        r = http_retriable_request('GET', url, headers=heads)
        attrs = json.loads(r.content)

        if len(attrs['attributes']) > 0:
            attr_hash = attrs['attributes']
            stack_state = ''
            try:
                stack_state = attr_hash['occi.mcn.stack.state']
            except KeyError:
                pass

            LOG.info('Current service state: ' + str(stack_state))
            if stack_state == 'CREATE_COMPLETE' or stack_state == 'UPDATE_COMPLETE':
                LOG.info('Stack is ready')
                return True
            elif stack_state == 'CREATE_FAILED':
                raise RuntimeError('Heat stack creation failed.')
            else:
                LOG.info('Stack is not ready. Current state state: ' + stack_state)
                return False
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:32,代码来源:so_manager.py

示例8: __git_uri

    def __git_uri(self, app_uri_path):
        url = self.nburl + app_uri_path
        headers = {'Accept': 'text/occi'}
        LOG.debug('Requesting container\'s URL ' + url)
        LOG.info('Sending headers: ' + headers.__repr__())
        r = http_retriable_request('GET', url, headers=headers, authenticate=True)

        attrs = r.headers.get('X-OCCI-Attribute', '')
        if attrs == '':
            raise AttributeError("No occi attributes found in request")

        repo_uri = ''
        for attr in attrs.split(', '):
            if attr.find('occi.app.repo') != -1:
                repo_uri = attr.split('=')[1][1:-1]  # scrubs trailing wrapped quotes
                break
            elif attr.find('occi.app.url') != -1:
                repo_uri = attr.split('=')[1][1:-1]  # scrubs trailing wrapped quotes
                break
        if repo_uri == '':
            raise AttributeError("No occi.app.repo or occi.app.url attribute found in request")

        LOG.debug('SO container URL: ' + repo_uri)

        return repo_uri
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:25,代码来源:so_manager.py

示例9: __init_so

    def __init_so(self):
        url = HTTP + self.host + '/orchestrator/default'
        heads = {
            'Category': 'orchestrator; scheme="http://schemas.mobile-cloud-networking.eu/occi/service#"',
            'Content-Type': 'text/occi',
            'X-Auth-Token': self.extras['token'],
            'X-Tenant-Name': self.extras['tenant_name'],
        }

        occi_attrs = self.extras['srv_prms'].service_parameters(self.state)
        if len(occi_attrs) > 0:
            LOG.info('Adding service-specific parameters to call... X-OCCI-Attribute: ' + occi_attrs)
            heads['X-OCCI-Attribute'] = occi_attrs

        LOG.debug('Initialising SO with: ' + url)
        LOG.info('Sending headers: ' + heads.__repr__())
        http_retriable_request('PUT', url, headers=heads)
开发者ID:MobileCloudNetworking,项目名称:dssaas,代码行数:17,代码来源:so_manager.py

示例10: __ensure_ssh_key

    def __ensure_ssh_key(self):
        url = self.nburl + '/public_key/'
        heads = {'Accept': 'text/occi'}
        resp = http_retriable_request('GET', url, headers=heads, authenticate=True)
        locs = resp.headers.get('x-occi-location', '')
        # Split on spaces, test if there is at least one key registered
        if len(locs.split()) < 1:
            LOG.debug('No SM SSH registered. Registering default SM SSH key.')
            occi_key_name, occi_key_content = self.__extract_public_key()

            create_key_headers = {'Content-Type': 'text/occi',
                                  'Category': 'public_key; scheme="http://schemas.ogf.org/occi/security/credentials#"',
                                  'X-OCCI-Attribute': 'occi.key.name="' + occi_key_name + '", occi.key.content="' +
                                                      occi_key_content + '"'
                                  }
            http_retriable_request('POST', url, headers=create_key_headers, authenticate=True)
        else:
            LOG.debug('Valid SM SSH is registered with OpenShift.')
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:18,代码来源:so_manager.py

示例11: run

    def run(self):
        url = HTTP + self.host + '/orchestrator/default'
        params = {'action': 'provision'}
        heads = {
            'Category': 'provision; scheme="http://schemas.mobile-cloud-networking.eu/occi/service#"',
            'Content-Type': 'text/occi',
            'X-Auth-Token': self.extras['token'],
            'X-Tenant-Name': self.extras['tenant_name']}
        occi_attrs = self.extras['srv_prms'].service_parameters(self.state)
        if len(occi_attrs) > 0:
            LOG.info('Adding service-specific parameters to call... X-OCCI-Attribute: ' + occi_attrs)
            heads['X-OCCI-Attribute'] = occi_attrs
        LOG.debug('Provisioning SO with: ' + url)
        LOG.info('Sending headers: ' + heads.__repr__())
        http_retriable_request('POST', url, headers=heads, params=params)

        self.entity.attributes['mcn.service.state'] = 'provision'
        return self.entity, self.extras
开发者ID:MobileCloudNetworking,项目名称:mobaas,代码行数:18,代码来源:so_manager.py

示例12: __detect_ops_version

 def __detect_ops_version(self):
     # make a call to the cloud controller and based on the app kind, heuristically select version
     version = 'v2'
     heads = {
         'Content-Type': 'text/occi',
         'Accept': 'text/occi'
         }
     url = self.nburl + '/-/'
     LOG.debug('Requesting CC Query Interface: ' + url)
     LOG.info('Sending headers: ' + heads.__repr__())
     r = http_retriable_request('GET', url, headers=heads, authenticate=True)
     if r.headers['category'].find('occi.app.image') > -1 and r.headers['category'].find('occi.app.env') > -1:
         LOG.info('Found occi.app.image and occi.app.env - this is OpenShift V3')
         version = 'v3'
     else:
         LOG.info('This is OpenShift V2')
     return version
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:17,代码来源:so_manager.py

示例13: __create_app

    def __create_app(self):

        # will generate an appname 24 chars long - compatible with v2 and v3
        # e.g. soandycd009b39c28790f3
        app_name = 'so' + self.entity.kind.term[0:4] + \
                   ''.join(random.choice('0123456789abcdef') for _ in range(16))
        heads = {'Content-Type': 'text/occi'}

        url = self.nburl + '/app/'

        if self.entity.extras['ops_version'] == 'v2':
            heads['category'] = 'app; scheme="http://schemas.ogf.org/occi/platform#", ' \
                                'python-2.7; scheme="http://schemas.openshift.com/template/app#", ' \
                                'small; scheme="http://schemas.openshift.com/template/app#"'
            heads['X-OCCI-Attribute'] = str('occi.app.name=' + app_name)
            LOG.debug('Ensuring SM SSH Key...')
            self.__ensure_ssh_key()
        elif self.entity.extras['ops_version'] == 'v3':

            # for OpSv3 bundle location is the repo id of the container image
            bundle_loc = CONFIG.get('service_manager', 'bundle_location', '')
            if bundle_loc == '':
                LOG.error('No bundle_location parameter supplied in sm.cfg')
                raise Exception('No bundle_location parameter supplied in sm.cfg')
            if bundle_loc.startswith('/'):
                LOG.warn('Bundle location does not look like an image reference!')
            LOG.debug('Bundle to execute: ' + bundle_loc)

            design_uri = CONFIG.get('service_manager', 'design_uri', '')
            if design_uri == '':
                raise Exception('No design_uri parameter supplied in sm.cfg')
            LOG.debug('Design URI: ' + design_uri)

            heads['category'] = 'app; scheme="http://schemas.ogf.org/occi/platform#"'
            # TODO provide a means to provide additional docker env params
            attrs = 'occi.app.name="' + app_name + '", ' + \
                    'occi.app.image="' + bundle_loc + '", ' + \
                    'occi.app.env="DESIGN_URI=' + design_uri + '"'
            heads['X-OCCI-Attribute'] = str(attrs)
        else:
            LOG.error('Unknown OpenShift version. ops_version: ' + self.entity.extras['ops_version'])
            raise Exception('Unknown OpenShift version. ops_version: ' + self.entity.extras['ops_version'])

        LOG.debug('Requesting container to execute SO Bundle: ' + url)
        LOG.info('Sending headers: ' + heads.__repr__())
        r = http_retriable_request('POST', url, headers=heads, authenticate=True)

        loc = r.headers.get('Location', '')
        if loc == '':
            LOG.error("No OCCI Location attribute found in request")
            raise AttributeError("No OCCI Location attribute found in request")

        self.entity.attributes['occi.so.url'] = loc

        app_uri_path = urlparse(loc).path
        LOG.debug('SO container created: ' + app_uri_path)

        LOG.debug('Updating OCCI entity.identifier from: ' + self.entity.identifier + ' to: ' +
                  app_uri_path.replace('/app/', self.entity.kind.location))
        self.entity.identifier = app_uri_path.replace('/app/', self.entity.kind.location)

        LOG.debug('Setting occi.core.id to: ' + app_uri_path.replace('/app/', ''))
        self.entity.attributes['occi.core.id'] = app_uri_path.replace('/app/', '')

        # its a bit wrong to put this here, but we do not have the required information before.
        # this keeps things consistent as the timing is done right
        infoDict = {
                    'so_id': self.entity.attributes['occi.core.id'].split('/'),
                    'sm_name': self.entity.kind.term,
                    'so_phase': 'init',
                    'phase_event': 'start',
                    'response_time': 0,
                    'tenant': self.extras['tenant_name']
                    }
        tmpJSON = json.dumps(infoDict)
        LOG.debug(tmpJSON)

        # OpSv2 only: get git uri. this is where our bundle is pushed to
        # XXX this is fugly
        # TODO use the same name for the app URI
        if self.entity.extras['ops_version'] == 'v2':
            self.entity.extras['repo_uri'] = self.__git_uri(app_uri_path)
        elif self.entity.extras['ops_version'] == 'v3':
            self.entity.extras['loc'] = self.__git_uri(app_uri_path)
开发者ID:AleDanish,项目名称:sm-0.4,代码行数:84,代码来源:so_manager.py

示例14: run

    def run(self):
        LOG.debug("running destroy")
        self.start_time = time.time()
        infoDict = {
                    'sm_name': self.entity.kind.term,
                    'phase': 'destroy',
                    'phase_event': 'start',
                    'response_time': 0,
                    }
        LOG.debug(json.dumps(infoDict))
        self.entity.attributes['mcn.service.state'] = 'destroy'

        # Do destroy work here

        # first, the SO has to be notified that it should destroy the computing
        # cluster...
        token = self.extras['token']
        heads = {
            'X-Auth-Token':token,
            'X-Tenant-Name':CONFIG.get('openstackso','tenantname'),
             'Content-Type':'text/occi',
             'Accept':'text/occi'
        }

        # this happens with the delete command
        self.sofloatingip = self.entity.attributes['sofloatingip']
        http_retriable_request('DELETE', "http://"+self.sofloatingip+':8080/orchestrator/default', headers=heads)

        # this time, we don't have to wait anymore until the SO's VM is
        # destroyed because it's OpenStack's duty to worry about that...so
        # let's destroy the SO's VM straight away
        global soStackId

        # design_uri contains the keystone endpoint
        design_uri = CONFIG.get('openstackso', 'heat_endpoint', '')
        if design_uri == '':
            LOG.fatal('No design_uri parameter supplied in sm.cfg')
            raise Exception('No design_uri parameter supplied in sm.cfg')

        # get the connection handle to keytone
        heatClient = client.Client(HEAT_VERSION, design_uri, token=token)

        # get the floating IP of the SO's VM
        try:
            self.sofloatingip = self.entity.attributes['sofloatingip']
        except:
            raise Exception("argument sofloatingip not given")

        try:
            from novaclient import client as novaclient

            # the following doesn't work, but maybe with nova.servers.remove_floating_ip(server,ip)
            # heatClient.v2.floating_ips.delete(self.sofloatingip)
            heatClient.stacks.delete(soStackId[self.sofloatingip])
        except:
            LOG.debug("either openstack_so_manager::heatClient or openstack_so_manager::soStackId wasn't defined")

        # at this point, the computing cluster as well as the SO's VM have been
        # deleted on OpenStack

        elapsed_time = time.time() - self.start_time
        infoDict = {
                    'sm_name': self.entity.kind.term,
                    'phase': 'destroy',
                    'phase_event': 'done',
                    'response_time': elapsed_time,
                    }
        LOG.debug(json.dumps(infoDict))
        return self.entity, self.extras
开发者ID:zioproto,项目名称:sm_openstack,代码行数:69,代码来源:openstack_so_manager.py


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