def test_service(self):
     sot = block_store_service.BlockStoreService()
     self.assertEqual("volumev2", 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)
Beispiel #2
0
class Metadata(resource.Resource):
    resource_key = "metadata"
    resources_key = "metadata"
    base_path = "/volumes/%(volume_id)s/metadata"
    service = block_store_service.BlockStoreService()

    # capabilities
    allow_list = True
    allow_create = True
    allow_update = True
Beispiel #3
0
class Quota(resource.Resource):
    resource_key = "quota_set"
    resources_key = "quota_sets"
    base_path = '/os-quota-sets'
    service = block_store_service.BlockStoreService()

    # capabilities
    allow_retrieve = True

    id = resource.prop("id")
Beispiel #4
0
class DefaultQuota(resource.Resource):
    resource_key = "quota_set"
    resources_key = "quota_sets"
    base_path = '/os-quota-sets/%(tenant_id)s/defaults'

    service = block_store_service.BlockStoreService()

    allow_retrieve = True

    id = resource.prop("id")
Beispiel #5
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())
Beispiel #6
0
class Limit(resource.Resource):
    resource_key = "limits"
    resources_key = "limits"
    base_path = "/limits"
    service = block_store_service.BlockStoreService()

    # capabilities
    allow_retrieve = True

    # Properties
    #: A rate representing this Limit.
    rate = resource.prop("rate")
    #: A list of absolute props of the Limit.
    absolute = resource.prop("absolute")
Beispiel #7
0
class Type(resource.Resource):
    resource_key = "volume_type"
    resources_key = "volume_types"
    base_path = "/types"
    service = block_store_service.BlockStoreService()

    # capabilities
    allow_list = True

    # Properties
    #: A ID representing this type.
    id = resource.prop("id")
    #: Name of the type.
    name = resource.prop("name")
    #: A dict of extra specifications. "capabilities" is a usual key.
    extra_specs = resource.prop("extra_specs", type=dict)
Beispiel #8
0
class AvailabilityZone(resource.Resource):
    resources_key = 'availabilityZoneInfo'
    base_path = '/os-availability-zone'

    service = block_store_service.BlockStoreService()

    # capabilities
    allow_list = True

    id_attribute = "name"
    # Properties
    #: name of availability zone
    name = resource.prop('zoneName')
    #: state of availability zone
    state = resource.prop('zoneState')
    #: hosts of availability zone
    hosts = resource.prop('hosts')
Beispiel #9
0
class Metadata(resource.Resource):
    resource_key = "metadata"
    resources_key = "metadata"
    base_path = "/volumes/%(volume_id)s/metadata"
    service = block_store_service.BlockStoreService()

    # capabilities
    allow_list = True
    allow_create = True
    allow_update = True


    def update(self, session, volume_id, **metadata):
        uri = self.base_path % {"volume_id": volume_id}
        body = {"metadata": metadata}
        resp = session.post(
            uri,
            endpoint_filter=self.service,
            json=body,
            headers={"Accept": ""}
        )

        meta = resp.json().get('metadata')
        for key in meta.keys():
            self.__setattr__(key, meta[key])

        return self

    def create(self, session, volume_id, **metadata):
        uri = self.base_path % {"volume_id": volume_id}
        body = {"metadata": metadata}
        resp = session.put(
            uri,
            endpoint_filter=self.service,
            json=body,
            headers={"Accept": ""}
        )

        meta = resp.json().get('metadata')
        for key in meta.keys():
            self.__setattr__(key, meta[key])

        return self
Beispiel #10
0
class Extension(resource.Resource):
    resource_key = "extension"
    resources_key = "extensions"
    base_path = "/extensions"
    service = block_store_service.BlockStoreService()

    # capabilities
    allow_list = True

    # Properties
    #: A updated representing this Extension.
    updated = resource.prop("updated")
    #: Name of the extension.
    name = resource.prop("name")
    #: A list of links.
    links = resource.prop("links", type=list)
    #: Namespace of the extension.
    namespace = resource.prop("namespace")
    #: Alias of the extension.
    alias = resource.prop("alias")
    #: Description of the extension.
    description = resource.prop("description")
Beispiel #11
0
class Volume(resource.Resource):
    resource_key = "volume"
    resources_key = "volumes"
    base_path = "/volumes"
    service = block_store_service.BlockStoreService()

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

    # Properties
    #: A ID representing this volume.
    id = resource.prop("id")
    #: The name of this volume.
    name = resource.prop("name")
    #: A list of links associated with this volume. *Type: list*
    links = resource.prop("links", type=list)

    #: The availability zone.
    availability_zone = resource.prop("availability_zone")
    #: To create a volume from an existing volume, specify the ID of
    #: the existing volume. If specified, the volume is created with
    #: same size of the source volume.
    source_volume_id = resource.prop("source_volid")
    #: The volume description.
    description = resource.prop("description")
    #: To create a volume from an existing snapshot, specify the ID of
    #: the existing volume snapshot. If specified, the volume is created
    #: in same availability zone and with same size of the snapshot.
    snapshot_id = resource.prop("snapshot_id")
    #: The size of the volume, in GBs. *Type: int*
    size = resource.prop("size", type=int)
    #: The ID of the image from which you want to create the volume.
    #: Required to create a bootable volume.
    image_id = resource.prop("imageRef")
    #: The name of the associated volume type.
    volume_type = resource.prop("volume_type")
    #: Enables or disables the bootable attribute. You can boot an
    #: instance from a bootable volume. *Type: bool*
    is_bootable = resource.prop("bootable", type=format.BoolStr)
    #: One or more metadata key and value pairs to associate with the volume.
    metadata = resource.prop("metadata")

    #: One of the following values: creating, available, attaching, in-use
    #: deleting, error, error_deleting, backing-up, restoring-backup,
    #: error_restoring. For details on these statuses, see the
    #: Block Storage API documentation.
    status = resource.prop("status")
    #: TODO(briancurtin): This is currently undocumented in the API.
    attachments = resource.prop("attachments")
    #: The timestamp of this volume creation.
    created_at = resource.prop("created_at")

    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(Volume.base_path, self.id, 'action')
        headers = {'Accept': ''}
        return session.post(url,
                            endpoint_filter=self.service,
                            json=body,
                            headers=headers)

    def extend_size(self, session, new_size):
        body = {"os-extend": {"new_size": new_size}}
        return self._action(session, body)

    def upload_to_image(self,
                        session,
                        container_format=None,
                        disk_format=None,
                        image_name=None,
                        force=False):

        body = dict()
        if container_format:
            body.update({"container_format": container_format})
        if disk_format:
            body.update({"disk_format": disk_format})
        if force:
            body.update({"force": force})
        if image_name:
            body.update({"image_name": image_name})
        return self._action(session, {"os-volume_upload_image": body})

    def update_bootable(self, session, bootable=False):
        body = {"os-set_bootable": {"bootable": bootable}}
        return self._action(session, body)