Example #1
0
    def __init__(self, controller, health_map):
        super(HealthModel, self).__init__()

        health_dns = collections.OrderedDict()
        if health_map['dns']['is_alive']:
            health_dns['online'] = 'true'
        else:
            health_dns['online'] = 'false'

        health_dns['links'] = link.Model(
            u'{0}/health/dns/{1}'.format(controller.base_url,
                                         health_map['dns']['dns_name']),
            'self')

        self['dns'] = {health_map['dns']['dns_name']: health_dns}

        health_storage = collections.OrderedDict()
        if health_map['storage']['is_alive']:
            health_storage['online'] = 'true'
        else:
            health_storage['online'] = 'false'

        health_storage['links'] = link.Model(
            u'{0}/health/storage/{1}'.format(
                controller.base_url, health_map['storage']['storage_name']),
            'self')

        self['storage'] = {
            health_map['storage']['storage_name']: health_storage
        }

        self['providers'] = {}
        for provider in health_map['providers']:
            health_provider = collections.OrderedDict()
            if provider['is_alive']:
                health_provider['online'] = 'true'
            else:
                health_provider['online'] = 'false'

            health_provider['links'] = link.Model(
                u'{0}/health/provider/{1}'.format(controller.base_url,
                                                  provider['provider_name']),
                'self')

            self['providers'][provider['provider_name']] = health_provider
Example #2
0
    def __init__(self, flavor, controller):
        super(Model, self).__init__()

        self['id'] = flavor.flavor_id
        self['providers'] = []

        for x in flavor.providers:
            provider = collections.OrderedDict()
            provider['provider'] = x.provider_id
            provider['links'] = []
            provider['links'].append(link.Model(x.provider_url,
                                                'provider_url'))

            self['providers'].append(provider)

        self['links'] = []
        self['links'].append(
            link.Model(
                u'{0}/flavors/{1}'.format(controller.base_url,
                                          flavor.flavor_id), 'self'))
Example #3
0
    def get_all(self):
        marker = pecan.request.GET.get('marker', None)
        limit = pecan.request.GET.get('limit', 10)
        try:
            limit = int(limit)
            if limit <= 0:
                pecan.abort(400, detail=u'Limit should be greater than 0')
            if limit > self.max_services_per_page:
                error = u'Limit should be less than or equal to {0}'.format(
                    self.max_services_per_page)
                pecan.abort(400, detail=error)
        except ValueError:
            error = (u'Limit should be an integer greater than 0 and less'
                     u' or equal to {0}'.format(self.max_services_per_page))
            pecan.abort(400, detail=error)

        try:
            if marker is not None:
                marker = str(uuid.UUID(marker))
        except ValueError:
            pecan.abort(400, detail="Marker must be a valid UUID")

        services_controller = self._driver.manager.services_controller
        service_resultset = services_controller.list(self.project_id, marker,
                                                     limit)
        results = [
            resp_service_model.Model(s, self) for s in service_resultset
        ]

        links = []
        if len(results) >= limit:
            links.append(
                link.Model(
                    u'{0}/services?marker={1}&limit={2}'.format(
                        self.base_url, results[-1]['id'], limit), 'next'))

        return {'links': links, 'services': results}
Example #4
0
    def __init__(self, service_obj, controller):
        super(Model, self).__init__()
        self["name"] = util.help_escape(service_obj.name)
        self["id"] = str(service_obj.service_id)
        self["project_id"] = str(service_obj.project_id)
        self["domains"] = [domain.Model(d) for d in service_obj.domains]

        # default other type of certificate domains to create_in_progress
        # Note(tonytan4ever): with out this piece of code
        # there will be a short period of time domain without certificate
        # status
        for domain_d in self["domains"]:
            if domain_d.get("protocol", "http") == "https":
                if domain_d.get("certificate") == "shared":
                    domain_d["certificate_status"] = 'deployed'
                else:
                    domain_d["certificate_status"] = 'create_in_progress'

        self["origins"] = [origin.Model(o) for o in service_obj.origins]
        self["restrictions"] = [
            restriction.Model(r) for r in service_obj.restrictions
        ]
        self["caching"] = [cachingrules.Model(c) for c in service_obj.caching]
        self["flavor_id"] = service_obj.flavor_id
        self["log_delivery"] = log_delivery.Model(service_obj.log_delivery)
        self["status"] = service_obj.status
        if service_obj.operator_status == "disabled":
            self["status"] = service_obj.operator_status

        self["errors"] = []

        self["links"] = [
            link.Model(
                str(
                    uri.encode(u'{0}/services/{1}'.format(
                        controller.base_url, service_obj.service_id))),
                'self'),
            link.Model(
                str(
                    uri.encode(u'{0}/flavors/{1}'.format(
                        controller.base_url, service_obj.flavor_id))),
                'flavor')
        ]

        for provider_name in service_obj.provider_details:
            provider_detail = service_obj.provider_details[provider_name]

            # add any certificate_status for non shared ssl domains
            # Note(tonytan4ever): for right now we only consider one provider,
            # in case of multiple providers we really should consider all
            # provider's domain certificate status
            for domain_d in self["domains"]:
                if domain_d.get("protocol", "http") == "https":
                    if domain_d.get("certificate") != "shared":
                        domain_d["certificate_status"] = (
                            provider_detail.domains_certificate_status.
                            get_domain_certificate_status(domain_d['domain']))

            # add the access urls
            access_urls = provider_detail.access_urls
            for access_url in access_urls:
                if ('operator_url' in access_url
                        and access_url['operator_url'] is not None):
                    self['links'].append(
                        link.Model(access_url['operator_url'], 'access_url'))
                elif 'log_delivery' in access_url:
                    self['links'].append(
                        link.Model(access_url['log_delivery'][0]['publicURL'],
                                   'log_delivery'))

            # add any errors
            error_message = provider_detail.error_message
            if error_message:
                self["errors"].append({"message": error_message})