Пример #1
0
class Route(resource.Resource):
    resource_key = 'route'
    resources_key = 'routes'
    base_path = '/vpc/routes'
    service = vpc_service.VpcService()

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

    _query_mapping = resource.QueryParameters(
        'id',
        'vpc_id',
        'destination',
        'type',
        project_id='tenant_id',
    )

    # Properties
    #: The route ID.
    id = resource.Body('id')
    #: The destination IP address or CIDR block.
    destination = resource.Body('destination')
    #: The next hop. If the route type is peering,
    #: enter the VPC peering connection ID.
    nexthop = resource.Body('nexthop')
    #: The route type.
    type = resource.Body('type')
    #: The VPC for which a route is to be added.
    vpc_id = resource.Body('vpc_id')
    #: The project ID.
    project_id = resource.Body('tenant_id')
Пример #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())
class Peering(resource.Resource):
    resource_key = 'peering'
    resources_key = 'peerings'
    base_path = '/vpc/peerings'
    service = vpc_service.VpcService()

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

    _query_mapping = resource.QueryParameters(
        'id',
        'name',
        'status',
        'vpc_id',
        project_id='tenant_id',
    )

    # Properties
    #: The VPC peering connection ID.
    id = resource.Body('id')
    #: The name of the VPC peering connection. The value can contain 1 to 64 characters.
    name = resource.Body('name')
    #: The VPC peering connection status.
    #: The value can be PENDING_ACCEPTANCE, REJECTED, EXPIRED, DELETED, or ACTIVE.
    status = resource.Body('status')
    #: The information about the local VPC.
    request_vpc_info = resource.Body('request_vpc_info', type=dict)
    #: The information about the peer VPC.
    accept_vpc_info = resource.Body('accept_vpc_info', type=dict)
Пример #4
0
class RemoveIpFromBandwidth(resource2.Resource):
    service = vpc_service.VpcService()

    base_path = '/bandwidths/%(bandwidth_id)s/remove'
    resource_key = 'bandwidth'

    # Allowed operations on this resource.
    allow_create = True

    # Resource key.
    bandwidth = resource2.Body('bandwidth', type=dict)
    # Id of bandwidth.
    bandwidth_id = resource2.URI('bandwidth_id')
    # Flexible public network IP information corresponding to bandwidth.
    publicip_info = resource2.Body('publicip_info', type=list)
    # Unique identifier of the flexible public network IP.
    publicip_id = resource2.Body('publicip_id')
    # Charge mode as bandwidth or traffic default is bandwidth.
    charge_mode = resource2.Body('charge_mode')
    # Size of bandwidth.
    size = resource2.Body('size', type=int)

    def create(self, session, prepend_key=True, has_body=False):
        """Create a remote resource based on this instance.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param prepend_key: A boolean indicating whether the resource_key
                            should be prepended in a resource creation
                            request. Default to True.
        :param bool has_body: should mapping response body to resource.

        :return: This :class:`Resource` instance.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_create` is not set to ``True``.
        """
        if not self.allow_create:
            raise exceptions.MethodNotSupported(self, "create")

        endpoint_override = self.service.get_endpoint_override()
        if self.put_create:
            request = self._prepare_request(requires_id=True,
                                            prepend_key=prepend_key)
            response = session.put(request.uri,
                                   endpoint_filter=self.service,
                                   endpoint_override=endpoint_override,
                                   json=request.body,
                                   headers=request.headers)
        else:
            request = self._prepare_request(requires_id=False,
                                            prepend_key=prepend_key)
            response = session.post(request.uri,
                                    endpoint_filter=self.service,
                                    endpoint_override=endpoint_override,
                                    json=request.body,
                                    headers=request.headers)

        self._translate_response(response, has_body=has_body)
        return self
Пример #5
0
 def test_service(self):
     sot = vpc_service.VpcService()
     self.assertEqual('vpcv2.0', sot.service_type)
     self.assertEqual('public', sot.interface)
     self.assertIsNone(sot.region)
     self.assertIsNone(sot.service_name)
     self.assertEqual('v2', sot.valid_versions[0].module)
     self.assertEqual('v2', sot.valid_versions[0].path)
Пример #6
0
class EIP(resource2.Resource):
    base_path = "/publicips"

    service = vpc_service.VpcService()

    allow_create = True
    # object of public ip
    publicip = resource2.Body('publicip', type=dict)
    # object of bandwidth
    bandwidth = resource2.Body('bandwidth', type=dict)
    # object of extend params
    extendParam = resource2.Body('extendParam', type=dict)
    # public ip type such as telcom union bgp or sbgp
    type = resource2.Body('type')
    # public ip name
    name = resource2.Body('name')
    # public ip size
    size = resource2.Body('size')
    # public ip id
    id = resource2.Body('id')
    # public ip share type such as PRE or WHOLE
    share_type = resource2.Body('share_type')
    # charge mode as bandwidth or traffic default is bandwidth
    charge_mode = resource2.Body('charge_mode')

    # project id
    project_id = resource2.Body('tenant_id')

    chargingMode = resource2.Body('chargingMode')
    # period of public ip like year or month
    periodType = resource2.Body('periodType')
    # period count
    periodNum = resource2.Body('count', type=int)
    # optional whether public ip auto pay order
    isAutoPay = resource2.Body('isAutoPay')
    # optional whether public ip auto renew
    isAutoRenew = resource2.Body('isAutoRenew')

    # order id
    order_id = resource2.Body('order_id')
    message = resource2.Body('message')
    code = resource2.Body('code')
    # status of public ip
    status = resource2.Body('status')
    # public ip address
    public_ip_address = resource2.Body('public_ip_address')
    # create time
    create_time = resource2.Body('create_time')
    # bandwidth size
    bandwidth_size = resource2.Body('bandwidth_size')
    # tenant id
    tenant_id = resource2.Body('tenant_id')
    #publicip id
    publicip_id = resource2.Body("publicip_id")
class NetworkIPAvailability(resource.Resource):
    resource_key = 'network_ip_availability'
    resources_key = None
    base_path = '/network-ip-availabilities'
    service = vpc_service.VpcService()

    # capabilities
    allow_get = True

    # Properties
    #: The network ID.
    network_id = resource.Body('network_id')
    #: The network name.
    network_name = resource.Body('network_name')
    #: The project ID.
    project_id = resource.Body('tenant_id')
    #: The total number of IP addresses on a network.
    total_ips = resource.Body('total_ips', type=int)
    #: The number of in-use IP addresses on a network.
    used_ips = resource.Body('used_ips', type=int)
    #: The subnet IP address usage object.
    subnet_ip_availability = resource.Body('subnet_ip_availability', type=list)

    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.
        :return: This :class:`Resource` instance.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_get` is not set to ``True``.
        """
        if not self.allow_get:
            raise exceptions.MethodNotSupported(self, "get")

        request = self._prepare_request(requires_id=requires_id)
        endpoint_override = self.service.get_endpoint_override() if self.service.get_endpoint_override() \
            else self.get_endpoint_override(session)
        service = self.get_service_filter(self, session)
        response = session.get(request.uri,
                               endpoint_filter=self.service,
                               microversion=service.microversion,
                               endpoint_override=endpoint_override)
        self._translate_response(response)
        return self

    def get_endpoint_override(self, session):
        endpoint = session.get_endpoint(interface=self.service.interface,
                                        service_type=self.service.service_type)
        endpoint_override = endpoint[0:endpoint.rindex('/')]
        return endpoint_override
Пример #8
0
class Version(resource.Resource):
    resource_key = 'version'
    resources_key = 'versions'
    base_path = '/'
    service = vpc_service.VpcService(
        version=vpc_service.VpcService.UNVERSIONED)

    # capabilities
    allow_list = True

    # Properties
    links = resource.Body('links')
    status = resource.Body('status')
Пример #9
0
class BatchShareBandwidth(resource2.Resource):
    service = vpc_service.VpcService()

    base_path = '/batch-bandwidths'
    resource_key = 'bandwidth'
    resources_key = 'bandwidths'

    # Allowed operations on this resource.
    allow_create = True

    # Resource key.
    bandwidth = resource2.Body('bandwidth', type=dict)
    # Resources key.
    bandwidths = resource2.Body('bandwidths', type=list)
    # Name of bandwidth.
    name = resource2.Body('name')
    # Size of bandwidth.
    size = resource2.Body('size', type=int)
    # Count of bandwidth.
    count = resource2.Body('count', type=int)
    # Id of bandwidth.
    id = resource2.Body('id')
    # Share type of bandwidth.
    share_type = resource2.Body('share_type')
    # Flexible public network IP information corresponding to bandwidth.
    publicip_info = resource2.Body('publicip_info', type=list)
    # Unique identifier of the flexible public network IP.
    publicip_id = resource2.Body('publicip_id')
    # The address of the flexible public network IP.
    publicip_address = resource2.Body('publicip_address')
    # Type of flexible public network IP.
    publicip_type = resource2.Body('publicip_type')
    # Id of tenant.
    tenant_id = resource2.Body('tenant_id')
    # Type of bandwidth.
    bandwidth_type = resource2.Body('bandwidth_type')
    # Charge mode as bandwidth or traffic default is bandwidth.
    charge_mode = resource2.Body('charge_mode')
    # Infomation of billing.
    billing_info = resource2.Body('billing_info')
class NetworkIPAvailability(resource.Resource):
    resource_key = 'network_ip_availability'
    resources_key = None
    base_path = '/network-ip-availabilities'
    service = vpc_service.VpcService()

    # capabilities
    allow_get = True

    # Properties
    #: The network ID.
    network_id = resource.Body('network_id')
    #: The network name.
    network_name = resource.Body('network_name')
    #: The project ID.
    project_id = resource.Body('tenant_id')
    #: The total number of IP addresses on a network.
    total_ips = resource.Body('total_ips', type=int)
    #: The number of in-use IP addresses on a network.
    used_ips = resource.Body('used_ips', type=int)
    #: The subnet IP address usage object.
    subnet_ip_availability = resource.Body('subnet_ip_availability', type=list)
Пример #11
0
class Route(resource.Resource):
    resource_key = 'route'
    resources_key = 'routes'
    base_path = '/vpc/routes'
    service = vpc_service.VpcService()

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

    _query_mapping = resource.QueryParameters(
        'id',
        'vpc_id',
        'destination',
        'type',
        project_id='tenant_id',
    )

    # Properties
    #: The route ID.
    id = resource.Body('id')
    #: The destination IP address or CIDR block.
    destination = resource.Body('destination')
    #: The next hop. If the route type is peering,
    #: enter the VPC peering connection ID.
    nexthop = resource.Body('nexthop')
    #: The route type.
    type = resource.Body('type')
    #: The VPC for which a route is to be added.
    vpc_id = resource.Body('vpc_id')
    #: The project ID.
    project_id = resource.Body('tenant_id')

    def create(self, session, prepend_key=True):
        """Create a remote resource based on this instance.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param prepend_key: A boolean indicating whether the resource_key
                            should be prepended in a resource creation
                            request. Default to True.

        :return: This :class:`Resource` instance.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_create` is not set to ``True``.
        """
        if not self.allow_create:
            raise exceptions.MethodNotSupported(self, "create")

        endpoint_override = self.service.get_endpoint_override() if self.service.get_endpoint_override() \
            else self.get_endpoint_override(session)
        service = self.get_service_filter(self, session)
        if self.put_create:
            request = self._prepare_request(requires_id=True,
                                            prepend_key=prepend_key)
            response = session.put(request.uri,
                                   endpoint_filter=self.service,
                                   endpoint_override=endpoint_override,
                                   json=request.body,
                                   headers=request.headers,
                                   microversion=service.microversion)
        else:
            request = self._prepare_request(requires_id=False,
                                            prepend_key=prepend_key)
            response = session.post(request.uri,
                                    endpoint_filter=self.service,
                                    endpoint_override=endpoint_override,
                                    json=request.body,
                                    headers=request.headers,
                                    microversion=service.microversion)

        self._translate_response(response)
        return self

    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.
        :return: This :class:`Resource` instance.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_get` is not set to ``True``.
        """
        if not self.allow_get:
            raise exceptions.MethodNotSupported(self, "get")

        request = self._prepare_request(requires_id=requires_id)
        endpoint_override = self.service.get_endpoint_override() if self.service.get_endpoint_override() \
            else self.get_endpoint_override(session)
        service = self.get_service_filter(self, session)
        response = session.get(request.uri,
                               endpoint_filter=self.service,
                               microversion=service.microversion,
                               endpoint_override=endpoint_override)
        self._translate_response(response)
        return self

    def delete(self, session, params=None, has_body=False):
        """Delete the remote resource based on this instance.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param params: http params to be sent
        :param bool has_body: should mapping response body to resource

        :return: This :class:`Resource` instance.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_update` is not set to ``True``.
        """
        if not self.allow_delete:
            raise exceptions.MethodNotSupported(self, "delete")

        request = self._prepare_request()
        service = self.get_service_filter(self, session)
        endpoint_override = self.service.get_endpoint_override() if self.service.get_endpoint_override() \
            else self.get_endpoint_override(session)
        response = session.delete(request.uri,
                                  endpoint_filter=self.service,
                                  microversion=service.microversion,
                                  endpoint_override=endpoint_override,
                                  headers={"Accept": ""},
                                  params=params)

        self._translate_response(response, has_body=has_body)
        return self

    def list(self, session, paginated=False, **params):
        """This method is a generator which yields resource objects.

        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.

        :return: A generator of :class:`Resource` objects.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_list` is not set to ``True``.
        """
        if not self.allow_list:
            raise exceptions.MethodNotSupported(self, "list")

        more_data = True
        query_params = self._query_mapping._transpose(params)
        uri = self.get_list_uri(params)
        service = self.get_service_filter(self, session)
        while more_data:
            endpoint_override = self.service.get_endpoint_override() if self.service.get_endpoint_override() \
                else self.get_endpoint_override(session)
            resp = session.get(uri,
                               endpoint_filter=self.service,
                               microversion=service.microversion,
                               endpoint_override=endpoint_override,
                               headers={"Accept": "application/json"},
                               params=query_params)
            response_json = resp.json()
            if self.resources_key:
                resources = self.find_value_by_accessor(
                    response_json, self.resources_key)
            else:
                resources = response_json

            if not resources:
                more_data = False

            # Keep track of how many items we've yielded. If we yielded
            # less than our limit, we don't need to do an extra request
            # to get back an empty data set, which acts as a sentinel.
            yielded = 0
            new_marker = None
            for data in resources:
                # Do not allow keys called "self" through. Glance chose
                # to name a key "self", so we need to pop it out because
                # we can't send it through cls.existing and into the
                # Resource initializer. "self" is already the first
                # argument and is practically a reserved word.
                data.pop("self", None)

                value = self.existing(**data)
                new_marker = value.id
                yielded += 1
                yield value

            query_params = dict(query_params)
            # if `next marker path` is explicit specified, use it as marker
            next_marker = self.get_next_marker(response_json, yielded,
                                               query_params)
            if next_marker:
                new_marker = next_marker if next_marker != -1 else None

            # if cls.next_marker_path:
            #     if isinstance(cls.next_marker_path, six.string_types):
            #         new_marker = cls.find_value_by_accessor(response_json,
            #                                                 cls.next_marker_path)
            #     elif callable(cls.next_marker_path):
            #         new_marker = cls.next_marker_path(response_json, yielded)

            if not new_marker:
                return
            if not paginated:
                return
            if self.query_limit_key in query_params:
                if yielded < query_params["limit"]:
                    return
            query_params[self.query_limit_key] = yielded
            query_params[self.query_marker_key] = new_marker

    def get_endpoint_override(self, session):
        endpoint = session.get_endpoint(interface=self.service.interface,
                                        service_type=self.service.service_type)
        endpoint_override = endpoint[0:endpoint.rindex('/')]
        return endpoint_override
Пример #12
0
class Bandwidths(resource2.Resource):
    base_path = "/bandwidths/%(bandwidth_id)s"

    service = vpc_service.VpcService()
    allow_create = True
    put_create = True

    # bandwidth id
    bandwidth_id = resource2.URI('bandwidth_id')
    bandwidth = resource2.Body('bandwidth', type=dict)
    # extend param to apply bandwidth
    extendParam = resource2.Body('extendParam', type=dict)

    # string type bandwidth name
    name = resource2.Body('name')
    # string type bandwidth size
    size = resource2.Body('size')
    # optional whether auto pay order
    isAutoPay = resource2.Body('isAutoPay')
    # order id
    order_id = resource2.Body('order_id')
    message = resource2.Body('message')
    code = resource2.Body('code')
    id = resource2.Body('id')
    # share type PER or WHOLE
    share_type = resource2.Body('share_type')
    # bandwidth type
    bandwidth_type = resource2.Body('bandwidth_type')
    tenant_id = resource2.Body('tenant_id')
    # charge mode as bandwidth or traffic default is bandwidth
    charge_mode = resource2.Body('charge_mode')
    # public ip info
    publicip_info = resource2.Body('publicip_info')
    # public ip id
    publicip_id = resource2.Body('publicip_id')
    # public ip address
    publicip_address = resource2.Body('publicip_address')
    # public ip type
    publicip_type = resource2.Body('publicip_type')

    # project id
    project_id = resource2.Body('tenant_id')

    def create(self, session, prepend_key=True):
        """Create a remote resource based on this instance.

        :param session: The session to use for making this request.
        :type session: :class:`~openstack.session.Session`
        :param prepend_key: A boolean indicating whether the resource_key
                            should be prepended in a resource creation
                            request. Default to True.

        :return: This :class:`Resource` instance.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_create` is not set to ``True``.
        """
        if not self.allow_create:
            raise exceptions.MethodNotSupported(self, "create")

        if not self.put_create:
            raise exceptions.MethodNotSupported(self, "put create")

        endpoint_override = self.service.get_endpoint_override()

        request = self._prepare_request(requires_id=False,
                                        prepend_key=prepend_key)
        response = session.put(request.uri,
                               endpoint_filter=self.service,
                               endpoint_override=endpoint_override,
                               json=request.body,
                               headers=request.headers)

        self._translate_response(response)
        return self