Exemple #1
0
class CIC(resource2.Resource):

    resource_key = None
    resources_key = None
    base_path = '/mCICs/%(mcic_id)s/CICs'
    service = connectivity_service.ConnectivityService()

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

    _query_mapping = resource2.QueryParameters("sort_key", "sort_dir")

    cic_id = resource2.Body("cic_id", alternate_id=True)
    cic_name = resource2.Body("cic_name")
    cic_status = resource2.Body("cic_status")
    network_id = resource2.Body("network_id")
    network_name = resource2.Body("network_name")
    destination_vlan = resource2.Body("destination_vlan", type=int)
    colo_vlan = resource2.Body("colo_vlan", type=int)
    bandwidth = resource2.Body("bandwidth", type=int)
    mcic_id = resource2.URI("mcic_id")

    def update(self, session, mcic_id, cic_id, has_body=True, **attrs):
        uri = self.base_path % ({'mcic_id': mcic_id})
        uri = utils.urljoin(uri, cic_id)
        args = {'json': attrs}
        resp = session.put(uri, endpoint_filter=self.service, **args)
        self._translate_response(resp, has_body=False)
        return self
Exemple #2
0
class Database(resource2.Resource):
    resource_key = "database"
    resources_key = "databases"
    base_path = '/instances/%(instance_id)s/databases'
    service = database_service.DatabaseService()

    # Capabilities
    allow_create = True
    allow_delete = True
    allow_list = True

    allow_update = False
    allow_get = False

    # Properties
    #: Name of Database.
    name = resource2.Body('name', alternate_id=True)
    #: Character set of Database.
    character_set = resource2.Body('character_set')
    #: Collate of Database.
    collate = resource2.Body('collate')
    #: ID of instance associated with this database
    instance_id = resource2.URI('instance_id')

    def create(self, session, instance_id, **attrs):
        base = self.base_path % {"instance_id": instance_id}
        body = {"databases": [attrs]}
        resp = session.post(base, endpoint_filter=self.service, json=body,
                            headers={"Accept": "application/json"})
        self._translate_response(resp, has_body=False)
        return self
Exemple #3
0
class DefaultQuota(resource2.Resource):
    resource_key = "quota_set"
    resources_key = "quota_sets"
    base_path = '/os-quota-sets/%(tenant_id)s/defaults'
    service = compute_service.ComputeService()

    allow_get = True

    tenant_id = resource2.URI("tenant_id")
    cores = resource2.Body("cores", int)
    fixed_ips = resource2.Body("fixed_ips", int)
    id = resource2.Body("id")
    injected_file_content_bytes = resource2.Body("injected_file_content_bytes",
                                                 int)
    injected_file_path_bytes = resource2.Body("injected_file_path_bytes", int)
    injected_files = resource2.Body("injected_files", int)
    instances = resource2.Body("instances", int)
    key_pairs = resource2.Body("key_pairs", int)
    metadata_items = resource2.Body("metadata_items", int)
    ram = resource2.Body("ram", int)
    security_group_rules = resource2.Body("security_group_rules", int)
    security_groups = resource2.Body("security_groups", int)
    server_group_members = resource2.Body("server_group_members", int)
    server_groups = resource2.Body("server_groups", int)

    def get(self, session, requires_id=False):
        return super(DefaultQuota, self).get(session, False)
Exemple #4
0
class ServerInterface(resource2.Resource):
    resource_key = 'interfaceAttachment'
    resources_key = 'interfaceAttachments'
    base_path = '/servers/%(server_id)s/os-interface'
    service = compute_service.ComputeService()

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

    #: Fixed IP addresses with subnet IDs.
    fixed_ips = resource2.Body('fixed_ips')
    #: The MAC address.
    mac_addr = resource2.Body('mac_addr')
    #: The network ID.
    net_id = resource2.Body('net_id')
    #: The ID of the port for which you want to create an interface.
    port_id = resource2.Body('port_id', alternate_id=True)
    #: The port state.
    port_state = resource2.Body('port_state')
    #: The ID for the server.
    server_id = resource2.URI('server_id')
Exemple #5
0
class AddressAssignment(resource2.Resource):
    resources_key = "address_assignments"
    resource_key = "address_assignment"

    service = provider_connectivity_service.ProviderConnectivityService("v2.0")
    base_path = '/' + service.version + \
                '/tenant_connection_requests/' \
                '%(tenant_connection_request_id)s/address_assignment'

    # capabilities
    allow_list = True

    #: tenant_connection_request unique ID.
    tenant_connection_request_id = resource2.URI(
        "tenant_connection_request_id")

    #: tenant_connection unique ID.
    tenant_connection_id = resource2.Body("tenant_connection_id")

    #: Network unique ID
    network_id = resource2.Body("network_id")

    #: mac address assigned with port
    mac_address = resource2.Body("mac_address")

    #: List of fixes IP addresses assign to port.
    fixed_ips = resource2.Body("fixed_ips")

    #: Allowed address pairs
    allowed_address_pairs = resource2.Body("allowed_address_pairs")

    @staticmethod
    def _get_id(value):
        if isinstance(value, resource2.Resource):
            # Don't check _alternate_id unless we need to. It's an uncommon
            # case and it involves looping through the class' dict.
            id = value.id or getattr(
                value, value._alternate_id(),
                hashlib.new('md5', str(value)).hexdigest())
            return id
        else:
            return value

    def __getattribute__(self, name):
        """Return an attribute on this instance

        This is mostly a pass-through except for a specialization on
        the 'id' name, as this can exist under a different name via the
        `alternate_id` argument to resource.Body.
        """
        if name == "id":
            if name in self._body:
                return self._body[name]
            elif self._alternate_id():
                return self._body[self._alternate_id()]
            else:
                return hashlib.new('md5', str(self)).hexdigest()
        else:
            return object.__getattribute__(self, name)
Exemple #6
0
class User(resource2.Resource):
    resource_key = "user"
    resources_key = "users"
    base_path = '/instances/%(instance_id)s/users'
    service = database_service.DatabaseService()

    # _query_mapping = resource2.QueryParameters()

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

    # Properties
    #: User's name of Database instance.
    name = resource2.Body('name', alternate_id=True)

    #: Allowed access host of user.
    host = resource2.Body('host')

    #: Relevant database of this user.
    databases = resource2.Body('databases', type=list)

    #: User's password of Database instance.
    #: This parameter is only used in instance creation.
    password = resource2.Body('password')

    #: ID of instance associated with this user
    instance_id = resource2.URI('instance_id')

    def create(self, session, instance_id, **attrs):
        base = self.base_path % {"instance_id": instance_id}
        body = {"users": [attrs]}
        resp = session.post(base, endpoint_filter=self.service, json=body,
                            headers={"Accept": "application/json"})
        self._translate_response(resp, has_body=False)
        return self

    def grant(self, session, instance_id, user, databases):
        base = self.base_path % {"instance_id": instance_id}
        uri = "%s/%s/databases" % (base, user)
        resp = session.put(uri, endpoint_filter=self.service,
                           json={"databases": databases})
        self._translate_response(resp, has_body=False)
        return self

    def revoke(self, session, instance_id, user, database):
        base = self.base_path % {"instance_id": instance_id}
        uri = uri = "%s/%s/databases/%s" % (base, user, database)
        resp = session.delete(uri, endpoint_filter=self.service)
        self._translate_response(resp, has_body=False)
        return self
Exemple #7
0
class NameServer(resource2.Resource):
    resource_key = None
    resources_key = "nameservers"
    base_path = '/v2/zones/%(zone_id)s/nameservers'
    service = dns_service.DnsService()

    # Capabilities
    allow_list = True

    # Properties
    #: ID for the zone.
    zone_id = resource2.URI('zone_id')
    #: The hostname of the nameserver that the zone should be delegated to.
    hostname = resource2.Body('hostname', alternate_id=True)
    #: The priority of the nameserver. This is used to determine the order of the the nameserver listings,
    #: and which server is used in the SOA record for the zone. This parameter is not currently supported.
    priority = resource2.Body('priority')
Exemple #8
0
class Member(resource2.Resource):
    resources_key = 'members'
    service = image_service.ImageService()
    base_path = '/' + service.version + '/images/%(image_id)s/members'

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

    # Properties

    # See https://bugs.launchpad.net/glance/+bug/1526991 for member/member_id
    # 'member' is documented incorrectly as being deprecated but it's the
    # only thing that works. 'member_id' is not accepted.

    #: The ID of the image member. An image member is a tenant
    #: with whom the image is shared.
    member_id = resource2.Body('member_id')
    #: The date and time when the member was created.
    created_at = resource2.Body('created_at')
    #: Image ID stored through the image API. Typically a UUID.
    image_id = resource2.URI('image_id')
    #: The status of the image.
    status = resource2.Body('status')
    #: The URL for schema of the member.
    schema = resource2.Body('schema')
    #: The date and time when the member was updated.
    updated_at = resource2.Body('updated_at')
    #: Member_id used to create a member
    member = resource2.Body('member', alternate_id=True)

    def update(self, session, image_id, member_id, status):
        """Update the member of an image."""

        uri = self.base_path + '/%(member_id)s'
        uri = uri % {"image_id": image_id, "member_id": member_id}
        resp = session.put(uri,
                           json={"status": status},
                           headers={"Accept": "application/json"},
                           endpoint_filter=self.service)
        self._translate_response(resp, has_body=True)
        return self
Exemple #9
0
class ICCSubnet(subnet.Subnet):

    service = provider_connectivity_service.ProviderConnectivityService("v2.0")
    base_path = '/' + service.version + \
                '/tenant_connection_requests/' \
                '%(tenant_connection_request_id)s/subnets'

    id = resource2.Body("id")
    tenant_connection_request_id = resource2.URI(
        "tenant_connection_request_id")

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

    dhcp_server_address = resource2.Body('dhcp_server_address')
Exemple #10
0
class ServerVolume(resource2.Resource):
    resource_key = 'volumeAttachment'
    resources_key = 'volumeAttachments'
    base_path = '/servers/%(serverId)s/os-volume_attachments'
    service = compute_service.ComputeService()

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

    #: Device name
    device = resource2.Body('device')
    #: Attachment ID
    id = resource2.Body('id')
    #: The ID of the server
    serverId = resource2.URI('serverId')
    #: The ID of the volume
    volumeId = resource2.Body('volumeId')
Exemple #11
0
class RecordSet(resource2.Resource):
    resource_key = None
    resources_key = "recordsets"
    base_path = '/v2/zones/%(zone_id)s/recordsets'
    service = dns_service.DnsService()

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

    _query_mapping = resource2.QueryParameters("limit", "marker")

    # Properties
    #: ID for the resource
    id = resource2.Body('id')
    #: DNS Name for the recordset.
    name = resource2.Body('name')
    #: Description for this recordset.
    description = resource2.Body('description')
    #: ID for the zone that contains this recordset.
    zone_id = resource2.URI('zone_id')
    #: Date / Time when resource was created.
    created_at = resource2.Body('created_at')
    #: Date / Time when resource last updated.
    updated_at = resource2.Body('updated_at')
    #: Version of the resource. This parameter is not currently supported. it always return 1.
    version = resource2.Body('version')
    #: They RRTYPE of the recordset.
    type = resource2.Body('type')
    #: status of the resource.
    status = resource2.Body('status')
    #: TTL (Time to Live) for the recordset. This parameter is not currently supported. it always return zero.
    ttl = resource2.Body('ttl')
    #: Links to the resource, and other related resources. When a response has been broken into pages,
    #: we will include a next link that should be followed to retrive all results.
    links = resource2.Body('links')
    #: Links to the resource, and other related resources. When a response has been broken into pages,
    #: we will include a next link that should be followed to retrive all results.
    records = resource2.Body('records')

    def _translate_recordsets(self, response, has_body=True):
        """
        In order to handle the response.
        Response example:
        {"recordsets":
        [
            {"id":"fcb86eb9-8f8d-4cfd-8309-9052236d75df",
                "zone_id":"d4f0ea0e-edb6-4bbb-aefd-2944457be234",
                "records":["203.0.143.22"],
                "ttl":3600,"name":"ns3.base.co.jp.",
                "description":null,"type":"A","version":1,
                "created_at":"","updated_at":null,
                "links":{"self":"https://dns-lab3ec-ecl.lab.api.ntt.com/v2/zones/d4f0ea0e-edb6-4bbb-aefd-2944457be234/recordsets/fcb86eb9-8f8d-4cfd-8309-9052236d75df"}},
            {"id":"b0590460-11b3-413d-ad95-5cd3f4b01c27",
                "zone_id":"d4f0ea0e-edb6-4bbb-aefd-2944457be234",
                "records":["203.0.143.23"],"ttl":3600,
                "name":"ns3.base.co.jp.",
                "description":null,"type":"A",
                "version":1,"created_at":"",
                "updated_at":null,
                "links":{"self":"https://dns-lab3ec-ecl.lab.api.ntt.com/v2/zones/d4f0ea0e-edb6-4bbb-aefd-2944457be234/recordsets/b0590460-11b3-413d-ad95-5cd3f4b01c27"}}
        ],
        "links":{"self":"https://dns-lab3ec-ecl.lab.api.ntt.com/v2/zones/d4f0ea0e-edb6-4bbb-aefd-2944457be234/recordsets"},
        "metadata":{"total_count":2}}
        """

        if has_body:
            body = response.json()
            body = body[self.resources_key]

            for data in body:
                value = self.existing(**data)
                yield value

    def create(self, session, prepend_key=True):
        """
        Recordset allow creating several records once.
        Thus return a list.
        """
        if not self.allow_create:
            raise exceptions.MethodNotSupported(self, "create")

        if self.put_create:
            request = self._prepare_request(requires_id=True,
                                            prepend_key=prepend_key)
            response = session.put(request.uri,
                                   endpoint_filter=self.service,
                                   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,
                                    json=request.body,
                                    headers=request.headers)

        return list(self._translate_recordsets(response, has_body=True))

    @classmethod
    def multi_delete(cls, session, zone_id, recordset_ids):
        """
        Delete multiple Recordsets
        """
        uri = cls.base_path % {"zone_id": zone_id}
        body = {"id": recordset_ids}
        session.delete(uri, endpoint_filter=cls.service, json=body)

    @classmethod
    def find(cls,
             session,
             name_or_id,
             zone_id,
             ignore_missing=False,
             **params):
        """Find a resource by its name or id.

        :param session: The session to use for making this request.
        :type session: :class:`~ecl.session.Session`
        :param name_or_id: This resource's identifier, if needed by
                           the request. The default is ``None``.
        :param zone_id: ID for the zone
        :param bool ignore_missing: When set to ``False``
                    :class:`~ecl.exceptions.ResourceNotFound` will be
                    raised when the resource does not exist.
                    When set to ``True``, None will be returned when
                    attempting to find a nonexistent resource.
        :param dict params: Any additional parameters to be passed into
                            underlying methods, such as to
                            :meth:`~ecl.resource2.Resource.existing`
                            in order to pass on URI parameters.

        :return: The :class:`Resource` object matching the given name or id
                 or None if nothing matches.
        :raises: :class:`ecl.exceptions.DuplicateResource` if more
                 than one resource is found for this request.
        :raises: :class:`ecl.exceptions.ResourceNotFound` if nothing
                 is found and ignore_missing is ``False``.
        """
        # Try to short-circuit by looking directly for a matching ID.

        data = list(cls.list(session, zone_id=zone_id, **params))

        result = cls._get_one_match(name_or_id, data)
        if result is not None:
            return result

        if ignore_missing:
            return None
        raise exceptions.ResourceNotFound("No %s found for %s" %
                                          (cls.__name__, name_or_id))
Exemple #12
0
 class Test(resource2.Resource):
     x = resource2.URI("x")
     y = resource2.URI("y")
     z = resource2.URI("z")
Exemple #13
0
 class Example(resource2.Resource):
     x = resource2.Body("x")
     y = resource2.Header("y")
     z = resource2.URI("z")
Exemple #14
0
 class Test(self.test_class):
     _query_mapping = resource2.QueryParameters(query_param=qp_name)
     base_path = "/%(something)s/blah"
     something = resource2.URI("something")