def get(self, share, export_location):
     """Get a share export location."""
     share_id = common_base.getid(share)
     export_location_id = common_base.getid(export_location)
     return self._get(
         "/shares/%(share_id)s/export_locations/%(export_location_id)s" % {
             "share_id": share_id,
             "export_location_id": export_location_id}, "export_location")
    def get(self, export_location, snapshot=None):
        params = {
            "snapshot_id": common_base.getid(snapshot),
            "export_location_id": common_base.getid(export_location),
        }

        return self._get("/snapshots/%(snapshot_id)s/export-locations/"
                         "%(export_location_id)s" % params,
                         "share_snapshot_export_location")
 def get(self, share_replica, export_location):
     """Get a share replica export location."""
     share_replica_id = common_base.getid(share_replica)
     export_location_id = common_base.getid(export_location)
     return self._get(
         ("/share-replicas/%(share_replica_id)s/export-locations/"
          "%(export_location_id)s") % {
              "share_replica_id": share_replica_id,
              "export_location_id": export_location_id,
         },
         "export_location")
예제 #4
0
    def create(self, share_group_type=None, share_types=None,
               share_network=None, name=None, description=None,
               source_share_group_snapshot=None, availability_zone=None):
        """Create a Share Group.

        :param share_group_type: either instance of ShareGroupType or text
            with UUID
        :param share_types: list of the share types allowed in the group. May
            not be supplied when 'source_group_snapshot_id' is provided.  These
            may be ShareType objects or UUIDs.
        :param share_network: either the share network object or text of the
            UUID - represents the share network to use when creating a
            share group when driver_handles_share_servers = True.
        :param name: text - name of the new share group
        :param description: text - description of the share group
        :param source_share_group_snapshot: text - either instance of
            ShareGroupSnapshot or text with UUID from which this shar_group is
            to be created. May not be supplied when 'share_types' is provided.
        :param availability_zone: name of the availability zone where the
            group is to be created
        :rtype: :class:`ShareGroup`
        """

        if share_types and source_share_group_snapshot:
            raise ValueError('Cannot specify a share group with both'
                             'share_types and source_share_group_snapshot.')

        body = {}

        if name:
            body['name'] = name
        if description:
            body['description'] = description
        if availability_zone:
            body['availability_zone'] = availability_zone
        if share_group_type:
            body['share_group_type_id'] = common_base.getid(share_group_type)
        if share_network:
            body['share_network_id'] = common_base.getid(share_network)

        if source_share_group_snapshot:
            body['source_share_group_snapshot_id'] = common_base.getid(
                source_share_group_snapshot)
        elif share_types:
            body['share_types'] = [common_base.getid(share_type)
                                   for share_type in share_types]

        return self._create(
            RESOURCES_PATH, {RESOURCE_NAME: body}, RESOURCE_NAME)
 def _action(self, action, share_group_type, info, **kwargs):
     """Perform a share group type action."""
     body = {action: info}
     self.run_hooks('modify_body_for_action', body, **kwargs)
     share_group_type_id = common_base.getid(share_group_type)
     url = RESOURCE_PATH_ACTION % share_group_type_id
     return self.api.client.post(url, body=body)
    def _create_share_replica(self, share, availability_zone=None):
        """Create a replica for a share.

        :param share: The share to create the replica of. Can be the share
        object or its UUID.
        :param availability_zone: The 'availability_zone' object or its UUID.
        """

        share_id = common_base.getid(share)
        body = {'share_id': share_id}

        if availability_zone:
            body['availability_zone'] = common_base.getid(availability_zone)

        return self._create(RESOURCES_PATH, {RESOURCE_NAME: body},
                            RESOURCE_NAME)
    def update(self, share_network, neutron_net_id=None,
               neutron_subnet_id=None, name=None,
               description=None):
        """Updates a share network.

        :param share_network: share network to update.
        :rtype: :class:`ShareNetwork`
        """
        values = {}
        if neutron_net_id is not None:
            values['neutron_net_id'] = neutron_net_id
        if neutron_subnet_id is not None:
            values['neutron_subnet_id'] = neutron_subnet_id
        if name is not None:
            values['name'] = name
        if description is not None:
            values['description'] = description

        for k, v in values.items():
            if v == '':
                values[k] = None

        if not values:
            msg = "Must specify fields to be updated"
            raise exceptions.CommandError(msg)

        body = {RESOURCE_NAME: values}
        return self._update(RESOURCE_PATH % common_base.getid(share_network),
                            body,
                            RESOURCE_NAME)
    def manage(self,
               share,
               provider_location,
               driver_options=None,
               name=None,
               description=None):
        """Manage an existing share snapshot.

        :param share: The share object.
        :param provider_location: The provider location of
                                  the snapshot on the backend.
        :param driver_options: dict - custom set of key-values.
        :param name: text - name of new snapshot
        :param description: - description for new snapshot
        """
        driver_options = driver_options if driver_options else {}
        body = {
            'share_id': common_base.getid(share),
            'provider_location': provider_location,
            'driver_options': driver_options,
            'name': name,
            'description': description,
        }
        return self._create('/snapshots/manage', {'snapshot': body},
                            'snapshot')
 def _action(self, action, instance, info=None, **kwargs):
     """Perform a snapshot instance 'action'."""
     body = {action: info}
     self.run_hooks('modify_body_for_action', body, **kwargs)
     url = ('/snapshot-instances/%s/action' %
            common_base.getid(instance))
     return self.api.client.post(url, body=body)
예제 #10
0
 def _action(self, action, share_group_type, info, **kwargs):
     """Perform a share group type action."""
     body = {action: info}
     self.run_hooks('modify_body_for_action', body, **kwargs)
     share_group_type_id = common_base.getid(share_group_type)
     url = RESOURCE_PATH_ACTION % share_group_type_id
     return self.api.client.post(url, body=body)
예제 #11
0
    def delete(self, server):
        """Delete share server.

        :param server: ID of the :class:`ShareServer` to delete.
        """
        server_id = common_base.getid(server)
        self._delete(RESOURCE_PATH % server_id)
예제 #12
0
    def create(self, name, share_types, is_public=False, group_specs=None):
        """Create a share group type.

        :param name: Descriptive name of the share group type
        :param share_types: list of either instances of ShareType or text
           with share type UUIDs
        :param is_public: True to create a public share group type
        :param group_specs: dict containing group spec key-value pairs
        :rtype: :class:`ShareGroupType`
        """
        if not share_types:
            raise ValueError('At least one share type must be specified when '
                             'creating a share group type.')
        body = {
            'name':
            name,
            'is_public':
            is_public,
            'group_specs':
            group_specs or {},
            'share_types':
            [common_base.getid(share_type) for share_type in share_types],
        }
        return self._create(RESOURCES_PATH, {RESOURCE_NAME: body},
                            RESOURCE_NAME)
    def update(self, share_network, neutron_net_id=None,   # noqa
               neutron_subnet_id=None, name=None,
               description=None):
        """Updates a share network.

        :param share_network: share network to update.
        :rtype: :class:`ShareNetwork`
        """
        values = {}
        if neutron_net_id is not None:
            values['neutron_net_id'] = neutron_net_id
        if neutron_subnet_id is not None:
            values['neutron_subnet_id'] = neutron_subnet_id
        if name is not None:
            values['name'] = name
        if description is not None:
            values['description'] = description

        for k, v in values.items():
            if v == '':
                values[k] = None

        if not values:
            msg = "Must specify fields to be updated"
            raise exceptions.CommandError(msg)

        body = {RESOURCE_NAME: values}
        return self._update(RESOURCE_PATH % common_base.getid(share_network),
                            body,
                            RESOURCE_NAME)
예제 #14
0
    def get_metadata(self, share):
        """Get metadata of a share.

        :param share: either share object or text with its ID.
        """
        return self._get("/shares/%s/metadata" % common_base.getid(share),
                         "metadata")
예제 #15
0
    def delete(self, server):
        """Delete share server.

        :param server: ID of the :class:`ShareServer` to delete.
        """
        server_id = common_base.getid(server)
        self._delete(RESOURCE_PATH % server_id)
예제 #16
0
    def unmanage(self, share):
        """Unmanage a share.

        :param share: either share object or text with its ID.
        """
        return self.api.client.post("/os-share-unmanage/%s/unmanage" %
                                    common_base.getid(share))
    def get(self, share_network):
        """Get a share network.

        :param policy: share network to get.
        :rtype: :class:`NetworkInfo`
        """
        return self._get(RESOURCE_PATH % common_base.getid(share_network),
                         RESOURCE_NAME)
    def add_security_service(self, share_network, security_service):
        """Associate given security service with a share network.

        :param share_network: share network name, id or ShareNetwork instance
        :param security_service: name, id or SecurityService instance
        :rtype: :class:`ShareNetwork`
        """
        body = {
            'add_security_service': {
                'security_service_id': common_base.getid(security_service),
            },
        }
        return self._create(
            RESOURCE_PATH % common_base.getid(share_network) + '/action',
            body,
            RESOURCE_NAME,
        )
예제 #19
0
 def _list_share_group_type_access(self,
                                   share_group_type,
                                   search_opts=None):
     if share_group_type.is_public:
         return None
     share_group_type_id = common_base.getid(share_group_type)
     url = RESOURCE_PATH % share_group_type_id
     return self._list(url, RESOURCE_NAME)
예제 #20
0
    def list_instances(self, share):
        """List instances of the specified share.

        :param share: either share object or text with its ID.
        """
        return self._list('/shares/%s/instances' % common_base.getid(share),
                          'share_instances',
                          obj_class=share_instances.ShareInstance)
예제 #21
0
    def show(self, share_type):
        """Get a share.

        :param share: either share object or text with its ID.
        :rtype: :class:`Share`
        """
        type_id = common_base.getid(share_type)
        return self._get("/types/%s" % type_id, "share_type")
    def get(self, share_network):
        """Get a share network.

        :param policy: share network to get.
        :rtype: :class:`NetworkInfo`
        """
        return self._get(RESOURCE_PATH % common_base.getid(share_network),
                         RESOURCE_NAME)
    def remove_security_service(self, share_network, security_service):
        """Dissociate security service from a share network.

        :param share_network: share network name, id or ShareNetwork instance
        :param security_service: name, id or SecurityService instance
        :rtype: :class:`ShareNetwork`
        """
        body = {
            'remove_security_service': {
                'security_service_id': common_base.getid(security_service),
            },
        }
        return self._create(
            RESOURCE_PATH % common_base.getid(share_network) + '/action',
            body,
            RESOURCE_NAME,
        )
    def get(self, instance):
        """Get a share instance.

        :param instance: either share object or text with its ID.
        :rtype: :class:`ShareInstance`
        """
        share_id = common_base.getid(instance)
        return self._get("/share_instances/%s" % share_id, "share_instance")
예제 #25
0
    def get(self, share_type="default"):
        """Get a specific share type.

        :param share_type: The ID of the :class:`ShareType` to get.
        :rtype: :class:`ShareType`
        """
        return self._get("/types/%s" % common_base.getid(share_type),
                         "share_type")
    def update_share_network_security_service(self, share_network,
                                              current_security_service,
                                              new_security_service):
        """Update current security service to new one of a given share network.

        :param share_network: share network name, id or ShareNetwork instance
        :param current_security_service: current name, id or
        SecurityService instance that will be changed
        :param new_security_service: new name, id or
        SecurityService instance that will be updated
        :rtype: :class:`ShareNetwork`
        """
        info = {
            'current_service_id': common_base.getid(current_security_service),
            'new_service_id': common_base.getid(new_security_service)}

        return self._action('update_security_service', share_network, info)
예제 #27
0
    def get(self, share_type="default"):
        """Get a specific share type.

        :param share_type: The ID of the :class:`ShareType` to get.
        :rtype: :class:`ShareType`
        """
        return self._get("/types/%s" % common_base.getid(share_type),
                         "share_type")
예제 #28
0
    def get(self, replica):
        """Get a share replica.

        :param replica: either replica object or its UUID.
        :rtype: :class:`ShareReplica`
        """
        replica_id = common_base.getid(replica)
        return self._get(RESOURCE_PATH % replica_id, RESOURCE_NAME)
예제 #29
0
    def get(self, share):
        """Get a share.

        :param share: either share object or text with its ID.
        :rtype: :class:`Share`
        """
        share_id = common_base.getid(share)
        return self._get("/shares/%s" % share_id, "share")
예제 #30
0
    def create(self,
               share_proto,
               size,
               snapshot_id=None,
               name=None,
               description=None,
               metadata=None,
               share_network=None,
               share_type=None,
               is_public=False,
               availability_zone=None,
               share_group_id=None):
        """Create a share.

        :param share_proto: text - share protocol for new share available
            values are NFS, CIFS, CephFS, GlusterFS, HDFS and MAPRFS.
        :param size: int - size in GiB
        :param snapshot_id: text - ID of the snapshot
        :param name: text - name of new share
        :param description: text - description of a share
        :param metadata: dict - optional metadata to set on share creation
        :param share_network: either instance of ShareNetwork or text with ID
        :param share_type: either instance of ShareType or text with ID
        :param is_public: bool, whether to set share as public or not.
        :param share_group_id: text - ID of the share group to which the share
            should belong
        :rtype: :class:`Share`
        """
        share_metadata = metadata if metadata is not None else dict()
        body = {
            'size': size,
            'snapshot_id': snapshot_id,
            'name': name,
            'description': description,
            'metadata': share_metadata,
            'share_proto': share_proto,
            'share_network_id': common_base.getid(share_network),
            'share_type': common_base.getid(share_type),
            'is_public': is_public,
            'availability_zone': availability_zone,
        }
        if share_group_id:
            body['share_group_id'] = share_group_id

        return self._create('/shares', {'share': body}, 'share')
예제 #31
0
    def update_all_metadata(self, share, metadata):
        """Update all metadata of a share.

        :param share: either share object or text with its ID.
        :param metadata: A list of keys to be updated.
        """
        body = {'metadata': metadata}
        return self._update("/shares/%s/metadata" % common_base.getid(share),
                            body)
예제 #32
0
    def set_metadata(self, share, metadata):
        """Set or update metadata for share.

        :param share: either share object or text with its ID.
        :param metadata: A list of keys to be set.
        """
        body = {'metadata': metadata}
        return self._create("/shares/%s/metadata" % common_base.getid(share),
                            body, "metadata")
예제 #33
0
    def details(self, server):
        """Get a share server details.

        :param server: ID of the :class:`ShareServer` to get details from.
        :rtype: list of :class:`ShareServerBackendDetails
        """
        server_id = common_base.getid(server)
        return self._get("%s/%s/details" % (RESOURCES_PATH, server_id),
                         "details")
    def get(self, snapshot):
        """Get a snapshot.

        :param snapshot: The :class:`ShareSnapshot` instance or string with ID
            of snapshot to delete.
        :rtype: :class:`ShareSnapshot`
        """
        snapshot_id = common_base.getid(snapshot)
        return self._get('/snapshots/%s' % snapshot_id, 'snapshot')
예제 #35
0
    def get(self, snapshot):
        """Get a snapshot.

        :param snapshot: The :class:`ShareSnapshot` instance or string with ID
            of snapshot to delete.
        :rtype: :class:`ShareSnapshot`
        """
        snapshot_id = common_base.getid(snapshot)
        return self._get('/snapshots/%s' % snapshot_id, 'snapshot')
    def get(self, instance):
        """Get a snapshot instance.

        :param instance: either snapshot instance object or text with its ID.
        :rtype: :class:`ShareSnapshotInstance`
        """
        snapshot_instance_id = common_base.getid(instance)
        return self._get("/snapshot-instances/%s" % snapshot_instance_id,
                         "snapshot_instance")
    def delete(self, share_group_type):
        """Delete a specific share group type.

        :param share_group_type: either instance of ShareGroupType, or text
           with UUID
        """
        share_group_type_id = common_base.getid(share_group_type)
        url = RESOURCE_PATH % share_group_type_id
        self._delete(url)
예제 #38
0
    def details(self, server):
        """Get a share server details.

        :param server: ID of the :class:`ShareServer` to get details from.
        :rtype: list of :class:`ShareServerBackendDetails
        """
        server_id = common_base.getid(server)
        return self._get("%s/%s/details" % (RESOURCES_PATH, server_id),
                         "details")
    def unset_metadata(self, access, keys):
        """Unset metadata on a share access rule.

        :param keys: A list of keys on this object to be unset
        :return: None if successful, else API response on failure
        """
        for k in keys:
            url = RESOURCE_METADATA_PATH % (common_base.getid(access), k)
            self._delete(url)
예제 #40
0
    def update(self,
               security_service,
               dns_ip=None,
               ou=None,
               server=None,
               domain=None,
               password=None,
               user=None,
               name=None,
               description=None):
        """Updates a security service.

        :param security_service: security service to update.
        :param dns_ip: dns ip address used inside tenant's network
        :param ou: security service organizational unit
        :param server: security service server ip address or hostname
        :param domain: security service domain
        :param user: security identifier used by tenant
        :param password: password used by user
        :param name: security service name
        :param description: security service description
        :rtype: :class:`SecurityService`
        """

        values = {}
        if dns_ip is not None:
            values['dns_ip'] = dns_ip
        if ou is not None:
            values['ou'] = ou
        if server is not None:
            values['server'] = server
        if domain is not None:
            values['domain'] = domain
        if user is not None:
            values['user'] = user
        if password is not None:
            values['password'] = password
        if name is not None:
            values['name'] = name
        if description is not None:
            values['description'] = description

        for k, v in values.items():
            if v == '':
                values[k] = None

        if not values:
            msg = "Must specify fields to be updated"
            raise exceptions.CommandError(msg)

        body = {RESOURCE_NAME: values}

        return self._update(
            RESOURCE_PATH % common_base.getid(security_service),
            body,
            RESOURCE_NAME,
        )
예제 #41
0
    def get(self, share_group):
        """Get a share group.

        :param share_group: either ShareGroup object or text with its UUID
        :rtype: :class:`ShareGroup`
        """
        share_group_id = common_base.getid(share_group)
        url = RESOURCE_PATH % share_group_id
        return self._get(url, RESOURCE_NAME)
    def _delete_share_group_type(self, share_group_type):
        """Delete a specific share group type.

        :param share_group_type: either instance of ShareGroupType, or text
           with UUID
        """
        share_group_type_id = common_base.getid(share_group_type)
        url = RESOURCE_PATH % share_group_type_id
        self._delete(url)
    def _do_list(self, share_type, action_name="share_type_access"):
        if share_type.is_public:
            return None

        return self._list(
            "/types/%(st_id)s/%(action_name)s" % {
                "st_id": common_base.getid(share_type),
                "action_name": action_name},
            "share_type_access")
    def get(self, instance):
        """Get a snapshot instance.

        :param instance: either snapshot instance object or text with its ID.
        :rtype: :class:`ShareSnapshotInstance`
        """
        snapshot_instance_id = common_base.getid(instance)
        return self._get("/snapshot-instances/%s" % snapshot_instance_id,
                         "snapshot_instance")
    def unset_metadata(self, access, keys):
        """Unset metadata on a share access rule.

        :param keys: A list of keys on this object to be unset
        :return: None if successful, else API response on failure
        """
        for k in keys:
            url = RESOURCE_METADATA_PATH % (common_base.getid(access), k)
            self._delete(url)
    def list(self, detailed=False, snapshot=None, search_opts=None):
        """List all snapshot instances."""
        if detailed:
            url = '/snapshot-instances/detail'
        else:
            url = '/snapshot-instances'

        if snapshot:
            url += '?snapshot_id=%s' % common_base.getid(snapshot)
        return self._list(url, 'snapshot_instances')
    def get(self, security_service):
        """Get a security service info.

        :param security_service: security service to get.
        :rtype: :class:`SecurityService`
        """
        return self._get(
            RESOURCE_PATH % common_base.getid(security_service),
            RESOURCE_NAME,
        )
    def get(self, share_group_snapshot):
        """Get a share group snapshot.

        :param share_group_snapshot: either share group snapshot object or text
            with its UUID
        :rtype: :class:`ShareGroupSnapshot`
        """
        share_group_snapshot_id = common_base.getid(share_group_snapshot)
        url = RESOURCE_PATH % share_group_snapshot_id
        return self._get(url, RESOURCE_NAME)
    def get(self, share_group_type="default"):
        """Get a specific share group type.

        :param share_group_type: either instance of ShareGroupType, or text
           with UUID, or 'default'
        :rtype: :class:`ShareGroupType`
        """
        share_group_type_id = common_base.getid(share_group_type)
        url = RESOURCE_PATH % share_group_type_id
        return self._get(url, RESOURCE_NAME)
예제 #50
0
    def get(self, security_service):
        """Get a security service info.

        :param security_service: security service to get.
        :rtype: :class:`SecurityService`
        """
        return self._get(
            RESOURCE_PATH % common_base.getid(security_service),
            RESOURCE_NAME,
        )
    def get(self, share_access_rule):
        """Get a specific share access rule.

        :param share_access_rule: either instance of ShareAccessRule, or text
           with UUID
        :rtype: :class:`ShareAccessRule`
        """
        share_access_rule_id = common_base.getid(share_access_rule)
        url = RESOURCE_PATH % share_access_rule_id
        return self._get(url, RESOURCE_NAME)
    def _get_share_group_type(self, share_group_type="default"):
        """Get a specific share group type.

        :param share_group_type: either instance of ShareGroupType, or text
           with UUID, or 'default'
        :rtype: :class:`ShareGroupType`
        """
        share_group_type_id = common_base.getid(share_group_type)
        url = RESOURCE_PATH % share_group_type_id
        return self._get(url, RESOURCE_NAME)
    def set_keys(self, group_specs):
        """Set group specs on a share group type.

        :param extra_specs: A dict of key/value pairs to be set on this object
        :return: dict with group specs
        """
        share_group_type_id = common_base.getid(self)
        url = GROUP_SPECS_RESOURCES_PATH % share_group_type_id
        body = {GROUP_SPECS_RESOURCES_NAME: group_specs}
        return self.manager._create(
            url, body, GROUP_SPECS_RESOURCES_NAME, return_raw=True)
예제 #54
0
    def reset_state(self, share_group, state):
        """Update the specified share group with the provided state.

        :param share_group: either ShareGroup object or text with its UUID
        :param state: The new state for the share group
        """

        share_group_id = common_base.getid(share_group)
        url = RESOURCE_PATH_ACTION % share_group_id
        body = {'reset_status': {'status': state}}
        self.api.client.post(url, body=body)
    def reset_state(self, share_group_snapshot, state):
        """Update the specified share group snapshot.

        :param share_group_snapshot: either ShareGroupSnapshot object or text
            with its UUID
        :param state: The new state for the share group snapshot
        """
        share_group_snapshot_id = common_base.getid(share_group_snapshot)
        url = RESOURCE_PATH_ACTION % share_group_snapshot_id
        body = {'reset_status': {'status': state}}
        self.api.client.post(url, body=body)
    def set_metadata(self, access, metadata):
        """Set or update metadata for share access rule.

        :param share_access_rule: either share access rule object or
            text with its ID.
        :param metadata: A list of keys to be set.
        """
        body = {'metadata': metadata}
        access_id = common_base.getid(access)
        url = RESOURCES_METADATA_PATH % access_id
        return self._update(url, body, "metadata")
    def unset_keys(self, keys):
        """Unset group specs on a share group type.

        :param keys: A list of keys on this object to be unset
        :return: None if successful, else API response on failure
        """
        share_group_type_id = common_base.getid(self)
        for k in keys:
            url = GROUP_SPECS_RESOURCE_PATH % (share_group_type_id, k)
            resp = self.manager._delete(url)
            if resp is not None:
                return resp
예제 #58
0
    def _action(self, action, share_server, info=None):
        """Perform a share server 'action'.

        :param action: text with action name.
        :param share_server: either share_server object or text with its ID.
        :param info: dict with data for specified 'action'.
        :param kwargs: dict with data to be provided for action hooks.
        """
        body = {action: info}
        self.run_hooks('modify_body_for_action', body)
        url = ACTION_PATH % common_base.getid(share_server)
        return self.api.client.post(url, body=body)