Пример #1
0
    def get_nuage_plugin_stats(self):
        stats = {}
        if nuage_config.is_enabled(plugin_constants.DEBUG_API_STATS):
            stats['api_count'] = self.restproxy.api_count
        if nuage_config.is_enabled(plugin_constants.DEBUG_TIMING_STATS):
            stats['time_spent_in_nuage'] = TimeTracker.get_time_tracked()
            stats['time_spent_in_core'] = TimeTracker.get_time_not_tracked()
            stats["total_time_spent"] = TimeTracker.get_time_tracked() + \
                TimeTracker.get_time_not_tracked()

        return stats
Пример #2
0
 def __init__(self,
              server,
              base_uri,
              serverssl,
              verify_cert,
              serverauth,
              auth_resource,
              organization,
              servertimeout=30,
              max_retries=5):
     self.scheme = "https" if serverssl else "http"
     self.server = server
     self.base_uri = base_uri
     if verify_cert.lower() == 'true':
         self.verify_cert = True
     elif verify_cert.lower() == 'false':
         self.verify_cert = False
     else:
         self.verify_cert = verify_cert
     self.serverauth = serverauth
     self.auth_resource = auth_resource
     self.organization = organization
     self.timeout = servertimeout
     self.max_retries = max_retries
     self.api_stats_enabled = nuage_config.is_enabled(
         plugin_constants.DEBUG_API_STATS)
     self.api_count = 0
Пример #3
0
    def _rest_call(self,
                   action,
                   resource,
                   data,
                   extra_headers=None,
                   ignore_marked_for_deletion=False):
        if nuage_config.is_enabled(plugin_constants.DEBUG_API_STATS):
            self.api_count += 1
        uri = self.base_uri + resource
        body = json.dumps(data)
        headers = {
            'Content-type': 'application/json',
            'X-Nuage-Organization': self.organization
        }
        if self.auth:
            headers['Authorization'] = self.auth
        if extra_headers:
            headers.update(extra_headers)

        if "X-Nuage-Filter" in headers:
            hdr = '[' + headers['X-Nuage-Filter'] + ']'
            LOG.debug('VSD_API REQ %s %s %s %s', action, uri, hdr, body)
        else:
            LOG.debug('VSD_API REQ %s %s %s', action, uri, body)

        ret = None
        for attempt in range(self.max_retries):
            try:
                conn = self._create_connection()
                conn.request(action, uri, body, headers)
                response = conn.getresponse()
                respstr = response.read()
                respdata = respstr

                LOG.debug('VSD_API RSP %s %s %s', response.status,
                          response.reason, respdata)
                if response.status in self.success_codes:
                    try:
                        respdata = json.loads(respstr)
                    except ValueError:
                        # response was not JSON, ignore the exception
                        pass
                    if (action.upper() == 'GET'
                            and not ignore_marked_for_deletion):
                        if (LIST_L2DOMAINS.match(resource) is not None
                                or LIST_SUBNETS.match(resource) is not None):
                            respdata = [
                                d for d in respdata if not self.is_marked(d)
                            ]
                        else:
                            match = GET_L2DOMAIN.match(resource)
                            if match is not None and respdata and \
                                    self.is_marked(respdata[0]):
                                return self._l2domain_not_found(match.group(1))
                            match = GET_SUBNET.match(resource)
                            if match is not None and respdata and \
                                    self.is_marked(respdata[0]):
                                return self._subnet_not_found(match.group(1))
                ret = (response.status, response.reason, respstr, respdata)
            except (socket.timeout, socket.error) as e:
                LOG.error(_('ServerProxy: %(action)s failure, %(e)r'),
                          locals())
            else:
                conn.close()
                if response.status != REST_SERV_UNAVAILABLE_CODE:
                    return ret
            time.sleep(1)
            LOG.debug("Attempt %s of %s" % (attempt + 1, self.max_retries))
        LOG.debug('After %d retries VSD did not respond properly.' %
                  self.max_retries)
        return ret or 0, None, None, None
Пример #4
0
 def get_nuage_plugin_stats(self):
     stats = {}
     if nuage_config.is_enabled(plugin_constants.DEBUG_API_STATS):
         stats['api_count'] = self.restproxy.api_count
     return stats