Exemple #1
0
    def test_getid(self):
        self.assertEqual(base.getid(4), 4)

        class TmpObject(object):
            id = 4

        self.assertEqual(base.getid(TmpObject), 4)
    def get_metadata(self, share):
        """
        Get a shares metadata.

        :param share: The :class:`Share`.
        """
        return self._get("/shares/%s/metadata" % base.getid(share), "metadata")
    def create(self, share_proto, size, snapshot_id=None, name=None,
               description=None, metadata=None, share_network=None,
               volume_type=None):
        """Create NAS.

        :param size: Size of NAS in GB
        :param snapshot_id: ID of the snapshot
        :param name: Name of the NAS
        :param description: Short description of a share
        :param share_proto: Type of NAS (NFS or CIFS)
        :param metadata: Optional metadata to set on volume creation
        :rtype: :class:`Share`
        """

        if metadata is None:
            share_metadata = {}
        else:
            share_metadata = metadata

        body = {'share': {'size': size,
                          'snapshot_id': snapshot_id,
                          'name': name,
                          'description': description,
                          'metadata': share_metadata,
                          'share_proto': share_proto,
                          'share_network_id': base.getid(share_network),
                          'volume_type': volume_type}}
        return self._create('/shares', body, 'share')
    def delete(self, volume_type):
        """
        Delete a specific volume_type.

        :param volume_type: The name or ID of the :class:`VolumeType` to get.
        """
        self._delete("/types/%s" % base.getid(volume_type))
    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:`NetworkInfo`
        """
        values = {}
        if neutron_net_id:
            values['neutron_net_id'] = neutron_net_id
        if neutron_subnet_id:
            values['neutron_subnet_id'] = neutron_subnet_id
        if name:
            values['name'] = name
        if description:
            values['description'] = description

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

        body = {RESOURCE_NAME: values}
        return self._update(RESOURCE_PATH % base.getid(share_network),
                            body,
                            RESOURCE_NAME)
    def update_all_metadata(self, share, metadata):
        """Update all metadata of a share.

        :param share: The :class:`Volume`.
        :param metadata: A list of keys to be updated.
        """
        body = {'metadata': metadata}
        return self._update("/shares/%s/metadata" % base.getid(share), body)
    def get(self, volume_type):
        """
        Get a specific volume type.

        :param volume_type: The ID of the :class:`VolumeType` to get.
        :rtype: :class:`VolumeType`
        """
        return self._get("/types/%s" % base.getid(volume_type), "volume_type")
    def get(self, share_network):
        """Get a share network.

        :param policy: share network to get.
        :rtype: :class:`NetworkInfo`
        """
        return self._get(RESOURCE_PATH % base.getid(share_network),
                         RESOURCE_NAME)
    def get_keys(self):
        """
        Get extra specs from a volume type.

        :param vol_type: The :class:`VolumeType` to get extra specs from
        """
        _resp, body = self.manager.api.client.get("/types/%s/extra_specs" % base.getid(self))
        return body["extra_specs"]
    def delete_metadata(self, share, keys):
        """
        Delete specified keys from volumes metadata.

        :param share: The :class:`Share`.
        :param keys: A list of keys to be removed.
        """
        for k in keys:
            self._delete("/shares/%s/metadata/%s" % (base.getid(share), k))
    def set_keys(self, metadata):
        """
        Set extra specs on a volume type.

        :param type : The :class:`VolumeType` to set extra spec on
        :param metadata: A dict of key/value pairs to be set
        """
        body = {"extra_specs": metadata}
        return self.manager._create("/types/%s/extra_specs" % base.getid(self), body, "extra_specs", return_raw=True)
    def set_metadata(self, share, metadata):
        """
        Update/Set a shares metadata.

        :param share: The :class:`Share`.
        :param metadata: A list of keys to be set.
        """
        body = {'metadata': metadata}
        return self._create("/shares/%s/metadata" % base.getid(share),
                            body, "metadata")
    def create(self, share, force=False, name=None, description=None):
        """Create a snapshot of the given share.

        :param share_id: The ID of the share to snapshot.
        :param force: If force is True, create a snapshot even if the
                      share is busy. Default is False.
        :param name: Name of the snapshot
        :param description: Description of the snapshot
        :rtype: :class:`ShareSnapshot`
        """
        body = {"snapshot": {"share_id": base.getid(share), "force": force, "name": name, "description": description}}
        return self._create("/snapshots", body, "snapshot")
    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: security service name or id
        :rtype: :class:`ShareNetwork`
        """
        body = {'remove_security_service': {'security_service_id':
                                            security_service}}

        return self._create(RESOURCE_PATH % base.getid(share_network) +
                            '/action',
                            body,
                            RESOURCE_NAME)
    def unset_keys(self, keys):
        """
        Unset extra specs on a volume type.

        :param type_id: The :class:`VolumeType` to unset extra spec on
        :param keys: A list of keys to be unset
        """

        # NOTE(jdg): This wasn't actually doing all of the keys before
        # the return in the loop resulted in ony ONE key being unset.
        # since on success the return was NONE, we'll only interrupt the loop
        # and return if there's an error
        resp = None
        for k in keys:
            resp = self.manager._delete("/types/%s/extra_specs/%s" % (base.getid(self), k))
            if resp is not None:
                return resp
 def force_delete(self, snapshot):
     return self._action("os-force_delete", base.getid(snapshot))
    def delete(self, snapshot):
        """Delete a snapshot of a share.

        :param snapshot: The :class:`ShareSnapshot` to delete.
        """
        self._delete("/snapshots/%s" % base.getid(snapshot))
 def _action(self, action, snapshot, info=None, **kwargs):
     """Perform a  snapshot 'action'."""
     body = {action: info}
     self.run_hooks("modify_body_for_action", body, **kwargs)
     url = "/snapshots/%s/action" % base.getid(snapshot)
     return self.api.client.post(url, body=body)
    def test_getid(self):
        self.assertEqual(base.getid(4), 4)

        class TmpObject(object):
            id = 4
        self.assertEqual(base.getid(TmpObject), 4)
    def delete(self, snapshot):
        """Delete a snapshot of a share.

        :param share: The :class:`ShareSnapshot` to delete.
        """
        self._delete("/snapshots/%s" % base.getid(snapshot))
    def delete(self, share_network):
        """Delete a share network.

        :param share_network: share network to be deleted.
        """
        self._delete(RESOURCE_PATH % base.getid(share_network))
 def force_delete(self, share):
     return self._action('os-force_delete', base.getid(share))
Exemple #23
0
 def _action(self, action, share, info=None, **kwargs):
     """Perform a share 'action'."""
     body = {action: info}
     self.run_hooks('modify_body_for_action', body, **kwargs)
     url = '/shares/%s/action' % base.getid(share)
     return self.api.client.post(url, body=body)
Exemple #24
0
    def delete(self, share):
        """Delete a share.

        :param share: The :class:`Share` to delete.
        """
        self._delete("/shares/%s" % base.getid(share))
Exemple #25
0
 def _action(self, action, share, info=None, **kwargs):
     """Perform a share 'action'."""
     body = {action: info}
     self.run_hooks('modify_body_for_action', body, **kwargs)
     url = '/shares/%s/action' % base.getid(share)
     return self.api.client.post(url, body=body)
Exemple #26
0
    def delete(self, share):
        """Delete a share.

        :param share: The :class:`Share` to delete.
        """
        self._delete("/shares/%s" % base.getid(share))