Exemple #1
0
    def __init__(self, plugins=None):
        """User preference for each service.

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

        Create a new :class:`~ecl.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(compute_service.ComputeService(version="v2"))
        self._add_service(
            connectivity_service.ConnectivityService(version="v1"))
        self._add_service(identity_service.IdentityService(version="v3"))
        self._add_service(image_service.ImageService(version="v2"))
        self._add_service(network_service.NetworkService(version="v2"))
        self._add_service(sss_service.SssService(version="v1"))
        self._add_service(
            orchestration_service.OrchestrationService(version="v1"))
        self._add_service(
            provider_connectivity_service.ProviderConnectivityService(
                version="v2"))
        self._add_service(telemetry_service.TelemetryService(version="v2"))
        self._add_service(block_store_service.BlockStoreService(version="v2"))
        self._add_service(storage_service.StorageService(version="v1"))
        self._add_service(
            security_order_service.SecurityOrderService(version="v2"))
        self._add_service(
            security_portal_service.SecurityPortalService(version="v2"))
        ## This section will be deleted if MSS v1 API is not available
        self._add_service(
            security_order_service_v1.SecurityOrderService(version="v1"))
        self._add_service(
            security_portal_service_v1.SecurityPortalService(version="v1"))
        ## end of the section
        self._add_service(rca_service.RcaService(version="v1"))
        self._add_service(baremetal_service.BaremetalService(version="v2"))
        self._add_service(
            dedicated_hypervisor_service.DedicatedHypervisorService(
                version="v1"))
        self._add_service(dns_service.DnsService(version="v2"))
        self._add_service(
            virtual_network_appliance_service.VirtualNetworkApplianceService(
                version="v1"))
        self._add_service(mvna_service.MVNAService(version="v1"))

        # NOTE: The Metric service is not added here as it currently
        # only retrieves the /capabilities API.

        if plugins:
            for plugin in plugins:
                self._load_plugin(plugin)
        self.service_keys = sorted(self._services.keys())
Exemple #2
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 #3
0
class Zone(resource2.Resource):
    resource_key = None
    resources_key = "zones"
    base_path = '/v2/zones'
    service = dns_service.DnsService()

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

    # Properties
    #: ID for the resource
    id = resource2.Body('id')
    #: ID for the pool hosting this zone. This parameter is not currently supported. It always returns an empty string.
    pool_id = resource2.Body('pool_id')
    #: ID for the project(tenant) that owns the resource.
    project_id = resource2.Body('project_id')
    #: DNS Name for the zone
    name = resource2.Body('name')
    #: e-mail for the zone. Used in SOA records for the zone. This parameter is not currently supported.
    #: It always returns an empty string.
    email = resource2.Body('email')
    #: TTL (Time to Live) for the zone. This parameter is not currently supported. it always return zero.
    ttl = resource2.Body('ttl')
    #: current serial number for the zone. This parameter is not currently supported. it always return zero.
    serial = resource2.Body('serial')
    #: status of the resource.
    status = resource2.Body('status')
    #: Description for this zone.
    description = resource2.Body('description')
    #: For secondary zones. The servers to slave from to get DNS information. This parameter is not currently supported.
    #: It always returns an empty string.
    masters = resource2.Body('masters')
    #: Type of zone. PRIMARY is controlled by ECL2.0 DNS, SECONDARY zones are slaved from another DNS Server.
    #: Defaults to PRIMARY. This parameter is not currently supported. It always returns an empty string.
    type = resource2.Body('type')
    #: For secondary zones. The last time an update was retrieved from the master servers.
    #: This parameter is not currently supported. it always return null.
    transferred_at = resource2.Body('transferred_at')
    #: Version of the resource. This parameter is not currently supported. it always return 1.
    version = resource2.Body('version')
    #: Date / Time when resource was created.
    created_at = resource2.Body('created_at')
    #: Date / Time when resource last updated.
    updated_at = resource2.Body('updated_at')
    #: 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')


    @classmethod
    def find(cls, session, name_or_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 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 = cls.list(session, **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 #4
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))