Esempio n. 1
0
class Log(cdn_resource.Resource):
    base_path = '/cdn/logs'
    resource_key = 'log'
    resources_key = 'logs'
    service = cdn_service.CDNService()

    allow_create = False
    allow_get = False
    allow_delete = False
    allow_list = True

    _query_mapping = cdn_resource.QueryParameters('query_date', 'domain_name')

    #: The queried domain name.
    domain_name = resource.Body('domain_name')
    #: The start time of a query, which is expressed as milliseconds
    #: since 1970-01-01 00:00:00 UTC.
    start_time = resource.Body('start_time')
    #: The end time of a query, which is expressed as milliseconds
    #: since 1970-01-01 00:00:00 UTC.
    end_time = resource.Body('end_time')
    #: The name of a log file.
    name = resource.Body('name', alternate_id=True)
    #: The size (Byte) of a log file.
    size = resource.Body('size', type=int)
    #: The link to download.
    link = resource.Body('link')
Esempio n. 2
0
    def __init__(self, plugins=None):
        """User preference for each service.

        :param plugins: List of entry point namespaces to load.

        Create a new :class:`~openstack.profile.Profile`
        object with no preferences defined, but knowledge of the services.
        Services are identified by their service type, e.g.: 'identity',
        'compute', etc.
        """
        self._services = {}

        self._add_service(anti_ddos_service.AntiDDosService(version="v1"))
        self._add_service(block_store_service.BlockStoreService(version="v2"))
        self._add_service(compute_service.ComputeService(version="v2"))
        self._add_service(cts_service.CTSService(version="v1"))
        self._add_service(dms_service.DMSService(version="v1"))
        self._add_service(identity_service.IdentityService(version="v3"))
        self._add_service(image_service.ImageService(version="v2"))
        self._add_service(kms_service.KMSService(version="v1"))
        self._add_service(maas_service.MaaSService(version="v1"))
        self._add_service(network_service.NetworkService(version="v2.0"))
        self._add_service(
            orchestration_service.OrchestrationService(version="v1"))
        self._add_service(smn_service.SMNService(version="v2"))
        # QianBiao.NG HuaWei Services
        self._add_service(dns_service.DNSService(version="v2"))
        self._add_service(cloud_eye_service.CloudEyeService(version="v1"))
        ass = auto_scaling_service.AutoScalingService(version="v1")
        self._add_service(ass)
        vbs_v2 = volume_backup_service.VolumeBackupService(version="v2")
        self._add_service(vbs_v2)
        self._add_service(map_reduce_service.MapReduceService(version="v1"))
        self._add_service(evs_service.EvsServiceV2_1(version='v2.1'))
        self._add_service(evs_service.EvsService(version='v2'))
        self._add_service(ecs_service.EcsService(version='v1'))
        self._add_service(ecs_service.EcsServiceV1_1(version='v1.1'))
        self._add_service(vpc_service.VpcService(version='v2.0'))
        self._add_service(bms_service.BmsService(version='v1'))
        self._add_service(lb_service.LoadBalancerService(version='v1'))
        # not support below service
        # self._add_service(message_service.MessageService(version="v1"))
        # self._add_service(cluster_service.ClusterService(version="v1"))
        # self._add_service(database_service.DatabaseService(version="v1"))
        # self._add_service(alarm_service.AlarmService(version="v2"))
        # self._add_service(bare_metal_service.BareMetalService(version="v1"))
        # self._add_service(key_manager_service.KeyManagerService(version="v1"))
        # self._add_service(
        # object_store_service.ObjectStoreService(version="v1"))

        self._add_service(rds_service.RDSService(version="v1"))
        self._add_service(cdn_service.CDNService(version='v1'))

        # self._add_service(rds_os_service.RDSService(version="v1"))
        # self._add_service(telemetry_service.TelemetryService(version="v2"))
        # self._add_service(workflow_service.WorkflowService(version="v2"))
        if plugins:
            for plugin in plugins:
                self._load_plugin(plugin)
        self.service_keys = sorted(self._services.keys())
Esempio n. 3
0
 def test_service(self):
     sot = cdn_service.CDNService()
     self.assertEqual('cdn', sot.service_type)
     self.assertEqual('public', sot.interface)
     self.assertIsNone(sot.region)
     self.assertIsNone(sot.service_name)
     self.assertEqual(1, len(sot.valid_versions))
     self.assertEqual('v1', sot.valid_versions[0].module)
     self.assertEqual('v1.0', sot.valid_versions[0].path)
Esempio n. 4
0
class Version(resource.Resource):
    resource_key = 'version'
    resources_key = 'versions'
    base_path = '/'
    service = cdn_service.CDNService(
        version=cdn_service.CDNService.UNVERSIONED)

    # capabilities
    allow_list = True

    # Properties
    links = resource.Body('links')
    status = resource.Body('status')
    updated = resource.Body('updated')
Esempio n. 5
0
class Statistic(cdn_resource.Resource):
    base_path = None
    resource_key = None
    resources_key = None
    service = cdn_service.CDNService()

    allow_create = False
    allow_get = False
    allow_update = False
    allow_delete = False
    allow_list = False

    _query_mapping = cdn_resource.StatisticParameters()

    #: The timestamp marking the start of the query, which is expressed as
    #: milliseconds since 1970-01-01 00:00:00 UTC.
    start_time = resource.Body('start_time')
    #: The timestamp marking the end of the query, which is expressed as
    #: milliseconds since 1970-01-01 00:00:00 UTC.
    end_time = resource.Body('end_time')
    #: The value matching the query.
    value = resource.Body('value')

    def query(self, session, **query):
        """Queries the total network traffic

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param \*\*query: The query parameters. Available parameters include:

            * start_time: The timestamp marking the start of the query.
            * end_time: The timestamp marking the end of the query.
            * domain_name: A domain name list. Use commas (,) to separate
                domain names from each other.
                For example, 'www.test1.com,www.test2.com'.
                The value 'ALL' indicates that all domain names under
                a tenant are queried.

        :returns: The total network traffic matching the query
        :rtype: subclass of :class:`~openstack.cdn.v1.statistic.Statistic`
        """
        endpoint_override = self.service.get_endpoint_override()
        resp = session.get(self.base_path,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override,
                           params=query)
        self._translate_response(resp)
        return self
Esempio n. 6
0
class StatisticDetail(cdn_resource.Resource):
    base_path = None
    resource_key = None
    resources_key = None
    service = cdn_service.CDNService()

    allow_create = False
    allow_get = False
    allow_update = False
    allow_delete = False
    allow_list = False

    _query_mapping = cdn_resource.StatisticParameters('interval')

    #: The timestamp marking the start of the query, which is expressed as
    #: milliseconds since 1970-01-01 00:00:00 UTC.
    start_time = resource.Body('start_time')
    #: The timestamp marking the end of the query, which is expressed as
    #: milliseconds since 1970-01-01 00:00:00 UTC.
    end_time = resource.Body('end_time')
    #: The granularity of a time span during which the data is monitored.
    #: It is measured by seconds.
    interval = resource.Body('interval', type=int)
    #: The values matching the query.
    values = resource.Body('values', type=list)

    def query(self, session, **query):
        """Queries the detail of the statistic

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param \*\*query: The query parameters. Available parameters include:

        :returns: The statistic data matching the query
        :rtype: subclasses of
                :class:`~openstack.cdn.v1.statistic.StatisticDetail`
        """
        endpoint_override = self.service.get_endpoint_override()
        resp = session.get(self.base_path,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override,
                           params=query)
        self._translate_response(resp)
        return self
Esempio n. 7
0
class Domain(cdn_resource.Resource):
    base_path = '/cdn/domains'
    resource_key = 'domain'
    resources_key = 'domains'
    service = cdn_service.CDNService()

    allow_create = True
    allow_get = True
    allow_delete = True
    allow_list = True

    _query_mapping = cdn_resource.QueryParameters('domain_name',
                                                  'business_type',
                                                  'domain_status',
                                                  'enterprise_project_id')

    #: The acceleration domain name.
    domain_name = resource.Body('domain_name')
    #: The business type. Values include:
    #: 'web' (the acceleration for static contents);
    #: 'download' (the acceleration for downloads);
    #: 'video' (the acceleration for media streaming).
    business_type = resource.Body('business_type')

    enterprise_project_id = resource.Body('enterprise_project_id')
    #enterprise_project_id = resource.URI('enterprise_project_id')
    #: The domain ID of the domain name's owner.
    user_domain_id = resource.Body('user_domain_id')
    #: The status of the acceleration domain name. Values include
    #: 'online': CDN is enabled;
    #: 'offline': CDN is disabled;
    #: 'configuring': CDN is being configured;
    #: 'configure_failed': the configuration failed;
    #: 'checking': the configuration is being audited;
    #: 'check_failed': the audit failed;
    #: 'deleting': the acceleration domain name is being deleted.
    domain_status = resource.Body('domain_status')
    #: The CNAME of the acceleration domain name.
    cname = resource.Body('cname')
    #: The domain name or the IP address of the origin server.
    sources = resource.Body('sources', type=list)
    #: The configuration information of the retrieval host.
    domain_origin_host = resource.Body('domain_origin_host', type=dict)
    #: HTTPS status for the acceleration.
    #: 0: disabled,
    #: 1: enable HTTPS for acceleration and following the origin.
    #: 2: enable HTTPS only for acceleration.
    https_status = resource.Body('https_status')
    #: The time when the domain name is modified.
    created_at = resource.Body('create_time')
    #: The time when the domain name is modified.
    modified_at = resource.Body('modify_time')
    #: Whether the acceleration domain name is disabled.
    is_disabled = resource.Body('disabled', type=format.BoolInt)
    #: Whether the status is locked.
    is_locked = resource.Body('locked', type=format.BoolInt)

    def get(self, session, requires_id=True):
        """Get a remote resource based on this instance.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param boolean requires_id: A boolean indicating whether resource ID
                                    should be part of the requested URI.

        :returns: This :class:`Domain` instance.
        :rtype: :class:`~openstack.cdn.v1.domain.Domain`
        """

        request = self._prepare_request(requires_id=requires_id)
        # NOTE(samsong8610): The URL for GET is not standard.
        request.uri = utils.urljoin(
            request.uri, 'detail') + "?enterprise_project_id=" + requires_id
        endpoint_override = self.service.get_endpoint_override()
        response = session.get(request.uri,
                               endpoint_filter=self.service,
                               endpoint_override=endpoint_override)

        self._translate_response(response)
        return self

    def set_sources(self, session, *sources):
        """Update information about the origin server

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param \*sources: A list of dict which specifies the domain name
            or the IP address of the origin server.
            Available keys for each source dict include:

            * ip_or_domain: The IP address or domain name of the origin server
                            Mandatory.
            * origin_type: The origin type. The value can be 'ipaddr' or
                           'domain'. Mandatory.
            * active_standby: Whether the source is active. 1: active,
                              0: standby. Mandatory.

        :returns: This :class:`Domain` instance.
        :rtype: :class:`Domain`
        """
        body = {'origin': {'sources': list(sources)}}
        url = utils.urljoin(self.base_path, self.id, 'origin')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.put(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override,
                           json=body)
        resp_json = resp.json()
        self.check_error(resp_json)
        self.sources = resp_json['origin']['sources']
        return self

    def enable(self, session):
        """Enables an acceleration domain name

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`

        :returns: This :class:`Domain` instance.
        :rtype: :class:`Domain`
        """
        url = utils.urljoin(self.base_path, self.id, 'enable')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.put(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override)
        self._translate_response(resp)
        return self

    def disable(self, session):
        """Disable an acceleration domain name

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`

        :returns: This :class:`Domain` instance.
        :rtype: :class:`Domain`
        """
        url = utils.urljoin(self.base_path, self.id, 'disable')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.put(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override)
        self._translate_response(resp)
        return self

    def set_origin_host(self, session, **attrs):
        """Modifies the configuration of the retrieval host

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param dict attrs: Keyword arguments which contains origin host
            configuration for :class:`~openstack.cdn.v1.domain.Domain`.
            Available attributes include:

            * origin_host_type: The type of the retrieval host.
                'accelerate': the acceleration domain name is used as
                the retrieval host address;
                'customize': A custom domain name is used as the retrieval
                host address;
                'source': The origin domain name is used as the retrieval
                host address.
            * customize_domain: The custom domain name of the retrieval host.

        :returns: This :class:`Domain` instance.
        :rtype: :class:`Domain`
        """
        body = {'origin_host': attrs}
        url = utils.urljoin(self.base_path, self.id, 'originhost')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.put(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override,
                           json=body)
        resp_json = resp.json()
        self.check_error(resp_json)
        self.domain_origin_host = resp_json['origin_host']
        return self

    def get_origin_host(self, session):
        """Queries the configuration of the retrieval host

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`

        :returns: The retrieval host configuration of this domain name
        :rtype: dict
        """
        url = utils.urljoin(self.base_path, self.id, 'originhost')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.get(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override)
        resp_json = resp.json()
        self.check_error(resp_json)
        return resp_json['origin_host']

    def set_referer(self, session, **attrs):
        """Configures a referrer list

        Self-define referrer whitelists and blacklists identify and filter
        user identities, controlling access.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param dict attrs: Keyword arguments which contains origin host
            configuration for :class:`~openstack.cdn.v1.domain.Domain`.
            Available attributes include:

            * referer_type: The referer type. The values include:
            0: referer filter not set; 1: blacklist; 2: whitelist.
            * referer_list: A list of domain names that are separated from
            each other by semicolon (;).
            * include_empty: Whether blank referrers are included.
            A referrer blacklist including blank referrers indicates that
            requests without any referrers are not allowed to access.
            A referrer whitelist including blank referrers indicates that
            requests without any referrers are allowed to access.

        :returns: This :class:`Domain` instance.
        :rtype: :class:`Domain`
        """
        body = {'referer': attrs}
        url = utils.urljoin(self.base_path, self.id, 'referer')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.put(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override,
                           json=body)
        resp_json = resp.json()
        self.check_error(resp_json)
        return self

    def get_referer(self, session):
        """Queries the referer list of the domain name

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`

        :returns: The referer list of this domain name
        :rtype: dict
        """
        url = utils.urljoin(self.base_path, self.id, 'referer')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.get(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override)
        resp_json = resp.json()
        self.check_error(resp_json)
        return resp_json['referer']

    def set_cache_rules(self, session, **attrs):
        """Configures a cache policy for resources on CDN nodes

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param dict attrs: Keyword arguments which contains cache policies
            for :class:`~openstack.cdn.v1.domain.Domain`.
            Available attributes include:

            * ignore_url_parameter: Whether to ignore URL parameters
            * rules: A list of the cache rules, which overwrite the previous
            rule configurations. Blank rules are reset to default rules.
            Each cache rule contains 'rule_type','content','ttl','ttl_type' and
            'priority' properties.

        :returns: This :class:`Domain` instance.
        :rtype: :class:`Domain`
        """
        body = {'cache_config': attrs}
        url = utils.urljoin(self.base_path, self.id, 'cache')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.put(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override,
                           json=body)
        resp_json = resp.json()
        self.check_error(resp_json)
        return self

    def get_cache_rules(self, session):
        """Queries the cache rules of the domain name

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`

        :returns: The cache rules of this domain name
        :rtype: dict
        """
        url = utils.urljoin(self.base_path, self.id, 'cache')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.get(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override)
        resp_json = resp.json()
        self.check_error(resp_json)
        return resp_json['cache_config']

    def set_https(self, session, **attrs):
        """Configures the HTTPS of the acceleration domain name

        This method sets HTTPS by configuring the certificate of a domain name,
        and deploy the HTTPS configuration on all CDN nodes to implement
        secure acceleration.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param dict attrs: Keyword arguments which contains cache policies
            for :class:`~openstack.cdn.v1.domain.Domain`.
            Available attributes include:

            * cert_name: The certificate name.
            * https_status: The HTTPS certificate is enabled.
            * certificate: The certificate used by HTTPS.
            * private_key: The private key used by HTTPS.
            * force_redirect_https: Whether to force the client request to be
            redirected.
            * http2: Whether to use HTTP 2.0.

        :returns: This :class:`Domain` instance.
        :rtype: :class:`Domain`
        """
        body = {'https': attrs}
        url = utils.urljoin(self.base_path, self.id, 'https-info')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.put(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override,
                           json=body)
        resp_json = resp.json()
        self.check_error(resp_json)
        return self

    def get_https(self, session):
        """Obtains the certificate for the acceleration domain name

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`

        :returns: The HTTPS certificate of this domain name
        :rtype: dict
        """
        url = utils.urljoin(self.base_path, self.id, 'https-info')
        endpoint_override = self.service.get_endpoint_override()
        resp = session.get(url,
                           endpoint_filter=self.service,
                           endpoint_override=endpoint_override)
        resp_json = resp.json()
        self.check_error(resp_json)
        return resp_json['https']
Esempio n. 8
0
class Task(cdn_resource.Resource):
    base_path = '/cdn/historytasks'
    resource_key = 'task'
    resources_key = 'tasks'
    service = cdn_service.CDNService()

    allow_create = False
    allow_get = True
    allow_delete = False
    allow_list = True

    _query_mapping = cdn_resource.QueryParameters('status', 'start_date',
                                                  'end_date', 'order_field',
                                                  'order_type',
                                                  'user_domain_id',
                                                  'enterprise_project_id')

    #: The type of a task. The value is either 'refresh' or 'preheating'.
    task_type = resource.Body('task_type')
    #: The status of a task after refreshing.
    #: 'task_done' indicates the refreshing task is completed successfully.
    #: 'task_inprocess' indicates that the refreshing task is being processed.
    status = resource.Body('status')
    #: The number of URLs being processing.
    processing = resource.Body('processing', type=int)
    #: The number of URLs processed successfully.
    succeeded = resource.Body('succeed', type=int)
    #: The number of URLs that failed to be processed.
    failed = resource.Body('failed', type=int)
    #: The total number of tasks.
    total = resource.Body('total', type=int)
    #: The time when the task is created.
    created_at = resource.Body('create_time')
    #: The URLs that need to be refreshed or preheated.
    urls = resource.Body('urls')

    @classmethod
    def list(cls, session, paginated=False, **params):
        """Override to mapping query parameters

        In order to be PEP8 compatible, we rename some attributes.
        When the query parameter 'order_field' is set to one of these
        attributes, we need map it back to the name on server side.

        This resource object list generator handles pagination and takes query
        params for response filtering.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param bool paginated: ``True`` if a GET to this resource returns
                               a paginated series of responses, or ``False``
                               if a GET returns only one page of data.
                               **When paginated is False only one
                               page of data will be returned regardless
                               of the API's support of pagination.**
        :param dict params: These keyword arguments are passed through the
            :meth:`~openstack.resource2.QueryParamter._transpose` method
            to find if any of them match expected query parameters to be
            sent in the *params* argument to
            :meth:`~openstack.session.Session.get`. They are additionally
            checked against the
            :data:`~openstack.resource2.Resource.base_path` format string
            to see if any path fragments need to be filled in by the contents
            of this argument.

        :returns: A generator of :class:`Resource` objects.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_list` is not set to ``True``.
        """
        mapping = {
            'processing': 'process',
            'created_at': 'create_time',
            'succeeded': 'succeed'
        }
        if 'order_field' in params and params['order_field'] in mapping:
            params['order_field'] = mapping[params['order_field']]
        return super(Task, cls).list(session, paginated=paginated, **params)

    def get(self, session, requires_id=True, **params):
        """Get a remote resource based on this instance.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param boolean requires_id: A boolean indicating whether resource ID
                                    should be part of the requested URI.

        :returns: This :class:`Task` instance.
        :rtype: :class:`~openstack.cdn.v1.task.Task`
        """
        request = self._prepare_request(requires_id=requires_id)
        request.uri = utils.urljoin(request.uri, 'detail')
        endpoint_override = self.service.get_endpoint_override()
        response = session.get(request.uri,
                               endpoint_filter=self.service,
                               endpoint_override=endpoint_override,
                               params=params)

        self._translate_response(response)
        return self