Пример #1
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())
Пример #2
0
class SubscriptionMin(_smnresource.Resource):

    resources_key = 'subscriptions'
    service = smn_service.SMNService()

    _query_mapping = resource.QueryParameters('offset', 'limit')

    # capabilities
    allow_list = True

    # Properties
    #: endpoint publish protocol
    protocol = resource.Body('protocol')
    #: subscription urn
    subscription_urn = resource.Body('subscription_urn', alternate_id=True)
    #: Topic creator id
    owner = resource.Body('owner')
    #: Message endpoint
    endpoint = resource.Body('endpoint')
    #: Remark
    remark = resource.Body('remark')
    #: Status: 0, 1, 3.
    #: *Type: int*
    status = resource.Body('status', type=int)
    #: Request id
    request_id = resource.Body('request_id')
Пример #3
0
class TopicAttr(_smnresource.Resource):

    base_path = '/notifications/topics/%(topic_urn)s/attributes'

    service = smn_service.SMNService()
    _query_mapping = resource.QueryParameters('name')

    # Properties
    #: topic urn
    topic_urn = resource.URI('topic_urn')
    #: attribute name
    attributes_name = resource.Body('attributes_name', alternate_id=True)
    #: attribute value are string
    attr_value = resource.Body('value')
    #: attributes
    #: *Type: dict*
    attributes = resource.Body('attributes', type=dict)
    #: request_id
    request_id = resource.Body('request_id')

    # capabilities
    allow_update = True
    allow_delete = True

    @classmethod
    def list(cls, session, paginated=False, **params):
        query_params = cls._query_mapping._transpose(params)
        uri = cls.base_path % params

        endpoint_override = cls.service.get_endpoint_override()
        resp = session.get(uri,
                           endpoint_filter=cls.service,
                           endpoint_override=endpoint_override,
                           headers={
                               "Accept": "application/json",
                               "Content-type": "application/json"
                           },
                           params=query_params)
        resp = resp.json()
        # Notes, smn doesn't returen topic_urn, it's from URI
        resp.update({"topic_urn": params['topic_urn']})

        return cls.existing(**resp)

    @classmethod
    def delete_all(cls, session, **params):
        uri = cls.base_path % params

        endpoint_override = cls.service.get_endpoint_override()
        session.delete(uri,
                       endpoint_filter=cls.service,
                       endpoint_override=endpoint_override,
                       headers={
                           "Accept": "",
                           "Content-type": "application/json"
                       })
 def test_service(self):
     sot = smn_service.SMNService()
     self.assertEqual('smn', 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('v2', sot.valid_versions[0].module)
     self.assertEqual('v2', sot.valid_versions[0].path)
     self.assertTrue(sot.requires_project_id)
Пример #5
0
class MessageTemplate(_smnresource.Resource):

    base_path = '/notifications/message_template'
    resources_key = 'message_templates'
    service = smn_service.SMNService()

    _query_mapping = resource.QueryParameters('offset', 'limit'
                                              'message_template_name'
                                              'protocol',
                                              'locale')

    # capabilities
    allow_create = True
    allow_delete = True
    allow_get = True
    allow_update = True
    allow_list = True

    # Properties
    #: Template ID
    message_template_id = resource.Body('message_template_id',
                                        alternate_id=True)
    #: Template name
    message_template_name = resource.Body('message_template_name')
    #: Template language. e.g: zh-cn, en-us, de-de, pt-br
    locale = resource.Body('locale')
    #: Template tag list
    #: *Type: list*
    tag_names = resource.Body('tag_names', type=list)
    #: Created time
    create_time = resource.Body('create_time')
    #: Update time
    update_time = resource.Body('update_time')
    #: Template content
    content = resource.Body('content')
    #: Protocol
    protocol = resource.Body('protocol')
Пример #6
0
class Topic(_smnresource.Resource):

    resources_key = 'topics'
    base_path = '/notifications/topics'
    service = smn_service.SMNService()

    _query_mapping = resource.QueryParameters('offset', 'limit')

    # capabilities
    allow_create = True
    allow_delete = True
    allow_update = True
    allow_get = True
    allow_list = True

    # Properties
    #: topic urn
    topic_urn = resource.Body('topic_urn', alternate_id=True)
    #: Topic name
    name = resource.Body('name')
    #: Topic display name
    display_name = resource.Body('display_name')
    #: Request id of topic
    request_id = resource.Body('request_id')
    #: upate time
    update_time = resource.Body('update_time')
    #: create time
    create_time = resource.Body('create_time')
    #: push policy
    #: *Type: int*
    push_policy = resource.Body('push_policy', type=int)

    def _dict_to_str(self, dt):
        # dict to json string
        ret = json.dumps(dt)
        return ret

    def publish(self, session, **kwargs):
        url = utils.urljoin(self.base_path, self._get_id(self), 'publish')

        headers = {
            "Accept": "application/json",
            "Content-type": "application/json",
            "Content-Length": str(len(str(kwargs)))
        }

        endpoint_override = self.service.get_endpoint_override()

        if 'message_structure' in kwargs:
            kwargs['message_structure'] = (self._dict_to_str(
                kwargs['message_structure']))

        resp = session.post(url,
                            endpoint_filter=self.service,
                            endpoint_override=endpoint_override,
                            json=kwargs,
                            headers=headers)

        return resp.json()

    @classmethod
    def direct_publish(cls, session, **kwargs):
        url = '/notifications/sms'
        endpoint_override = cls.service.get_endpoint_override()

        headers = {
            "Accept": "application/json",
            "Content-type": "application/json",
            "Content-Length": str(len(str(kwargs)))
        }

        resp = session.post(url,
                            endpoint_filter=cls.service,
                            endpoint_override=endpoint_override,
                            json=kwargs,
                            headers=headers)
        return resp.json()