Ejemplo n.º 1
0
 def test_service(self):
     sot = storage_service.StorageService()
     self.assertEqual('storage', 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)
Ejemplo n.º 2
0
class Storage(resource2.Resource):
    resource_key = 'virtual_storage'
    resources_key = 'virtual_storages'
    base_path = '/virtual_storages'

    service = storage_service.StorageService()

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

    # Properties
    #: id of storage(UUID)
    id = resource2.Body('id')
    #: Network id(UUID) of storage
    network_id = resource2.Body('network_id')
    #: Subnet id(UUID) of storage
    subnet_id = resource2.Body('subnet_id')
    #: The pool of IP addresses for storage
    ip_addr_pool = resource2.Body('ip_addr_pool', type=dict)
    #: static routes settings of storage
    host_routes = resource2.Body('host_routes', type=list)
    #: volume type id(UUID) of storage
    volume_type_id = resource2.Body('volume_type_id')
    #: name of storage
    name = resource2.Body('name')
    #: description of storage
    description = resource2.Body('description')
    #: status of storage
    status = resource2.Body('status')
    #: creation timestamp of storage
    created_at = resource2.Body('created_at')
    #: update timestamp of storage
    updated_at = resource2.Body('updated_at')
    #: error description of storage
    error_message = resource2.Body('error_message')

    def create(self, session, **attrs):
        body = {"virtual_storage": attrs}
        resp = session.post(self.base_path,
                            endpoint_filter=self.service,
                            json=body,
                            headers={"Accept": "application/json"})
        self._translate_response(resp, has_body=True)
        return self

    def update(self, session, storage_id, has_body=True, **attrs):
        uri = utils.urljoin(self.base_path, storage_id)
        body = {"virtual_storage": attrs}
        args = {'json': body}
        resp = session.put(uri, endpoint_filter=self.service, **args)
        self._translate_response(resp, has_body)
        return self
Ejemplo n.º 3
0
class VolumeType(resource2.Resource):
    resource_key = 'volume_type'
    resources_key = 'volume_types'
    base_path = '/volume_types'

    service = storage_service.StorageService()

    # capabilities
    allow_list = True
    allow_get = True

    # Properties
    #: id of volume type
    id = resource2.Body('id')
    #: name of volume type
    name = resource2.Body('name')
    #: state of volume type
    extra_specs = resource2.Body('extra_specs', type=dict)

    @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))
Ejemplo n.º 4
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())
Ejemplo n.º 5
0
class Version(resource2.Resource):
    resource_key = 'version'
    resources_key = 'versions'
    base_path = '/'
    service = storage_service.StorageService(
        version=storage_service.StorageService.UNVERSIONED)

    # capabilities
    allow_list = True
    allow_get = True

    # Properties
    #: Version identifier included in API URL.
    id = resource2.Body('id', alternate_id=True)
    #: media-type object
    media_types = resource2.Body('media-types', type=dict)
    #: Created time of the version, although the name is "updated"
    updated = resource2.Body('updated')
    #: Version support status. Valid values are CURRENT or SUPPORTED.
    #: CURRENT is newest stable version. SUPPORTED is old supported version.
    status = resource2.Body('status')

    def list_version(self, session):
        uri = self.base_path
        resp = session.get(uri,
                           headers={"Accept": "application/json"},
                           endpoint_filter=self.service)
        resp = resp.json()[self.resources_key]

        for data in resp:
            version = self.existing(**data)
            yield version

    def get_version(self, session):
        url = self.base_path + 'v1.0'
        resp = session.get(url,
                           headers={"Accept": "application/json"},
                           endpoint_filter=self.service)
        self._translate_response(resp, has_body=True)
        return self
Ejemplo n.º 6
0
class Volume(resource2.Resource):
    resource_key = 'volume'
    resources_key = 'volumes'
    base_path = '/volumes'

    service = storage_service.StorageService()

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

    # Properties
    #: id of volume(UUID)
    id = resource2.Body('id')
    #: status of volume
    status = resource2.Body('status')
    #: name of volume
    name = resource2.Body('name')
    #: description of volume
    description = resource2.Body('description')
    #: The size of volume in gigabyte
    size = resource2.Body('size', type=int)
    #: The provisioned IOPS/GB for volume
    iops_per_gb = resource2.Body('iops_per_gb', type=int)
    #: Array of initiator IQN who can access to this volume
    initiator_iqns = resource2.Body('initiator_iqns', type=list)
    #: Initiator's secret (password) for CHAP auth of iSCSI
    initiator_secret = resource2.Body('initiator_secret')
    #: Target's secret (password) for CHAP auth of iSCSI
    target_secret = resource2.Body('target_secret')
    #: Array of Snapshot IDs taken from this volume
    snapshot_ids = resource2.Body('snapshot_ids', type=list)
    #: Array of IPv4 addresses of the volume.
    target_ips = resource2.Body('target_ips', type=list)
    #: One or more metadata key and value pairs to associate with the volume.
    metadata = resource2.Body('metadata', type=dict)
    #: storage ID (UUID) volume belongs to
    virtual_storage_id = resource2.Body('virtual_storage_id')
    #: An availability_zone in which the volume belongs to
    availability_zone = resource2.Body('availability_zone')
    #: Creation timestamp of volume
    created_at = resource2.Body('created_at')
    #: update timestamp of volume
    updated_at = resource2.Body('updated_at')
    #: error description of volume
    error_message = resource2.Body('error_message')
    #: The provisioned throughput for volume in MB/s
    throughput = resource2.Body('throughput', type=int)
    #: Array of IPv4 CIDRc who can access to this volume
    export_rules = resource2.Body('export_rules', type=list)
    #: Percentage of Used Snapshots
    percentage_snapshot_reserve_used = \
        resource2.Body('percentage_snapshot_reserve_used', type=int)

    def create(self, session, **attrs):
        body = {"volume": attrs}
        resp = session.post(self.base_path,
                            endpoint_filter=self.service,
                            json=body,
                            headers={"Accept": "application/json"})
        self._translate_response(resp, has_body=True)
        return self

    def update(self, session, volume_id, has_body=True, **attrs):
        uri = utils.urljoin(self.base_path, volume_id)
        body = {"volume": attrs}
        args = {'json': body}
        resp = session.put(uri, endpoint_filter=self.service, **args)
        self._translate_response(resp, has_body)
        return self
Ejemplo n.º 7
0
class Snapshot(resource2.Resource):
    resource_key = 'snapshot'
    resources_key = 'snapshots'
    base_path = '/snapshots'

    service = storage_service.StorageService()

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

    # query mappings
    _query_mapping = resource2.QueryParameters('volume_id', )

    # Properties
    #: id of snapshot(UUID)
    id = resource2.Body('id')
    #: status of volume
    status = resource2.Body('status')
    #: Name of volume
    name = resource2.Body('name')
    #: Description of snapshot
    description = resource2.Body('description')
    #: Usage of snapshot
    usage = resource2.Body('usage', type=int)
    #: ID (UUID) of parent volume
    volume_id = resource2.Body('volume_id')
    #: ID (UUID) of snapshot type
    snapshot_type_id = resource2.Body('snapshot_type_id')
    #: Creation timestamp of snapshot
    created_at = resource2.Body('created_at')
    #: Update timestamp of snapshot
    updated_at = resource2.Body('updated_at')
    #: Delete timestamp of snapshot
    deleted_at = resource2.Body('deleted_at')
    #: Error message for snapshot
    error_message = resource2.Body('error_message')
    #: Reason of automatic deletion
    delete_reason = resource2.Body('delete_reason')

    def _action(self, session, body):
        """Preform server actions given the message body."""
        # NOTE: This is using Server.base_path instead of self.base_path
        # as both Server and ServerDetail instances can be acted on, but
        # the URL used is sans any additional /detail/ part.
        url = utils.urljoin(Snapshot.base_path, self.id, 'action')
        headers = {'Accept': ''}
        return session.post(url,
                            endpoint_filter=self.service,
                            json=body,
                            headers=headers)

    def create(self, session, **attrs):
        body = {"snapshot": attrs}
        resp = session.post(self.base_path,
                            endpoint_filter=self.service,
                            json=body,
                            headers={"Accept": "application/json"})
        self._translate_response(resp, has_body=True)
        return self

    def update(self, session, volume_id, has_body=True, **attrs):
        uri = utils.urljoin(self.base_path, volume_id)
        body = {"snapshot": attrs}
        args = {'json': body}
        resp = session.put(uri, endpoint_filter=self.service, **args)
        self._translate_response(resp, has_body)
        return self

    def restore(self, session):
        """Restore volume from specified snapshot"""
        body = {'restore': None}
        self._action(session, body)