diff options
author | whoami-rajat <rajatdhasmana@gmail.com> | 2020-07-03 12:31:48 +0000 |
---|---|---|
committer | Brian Rosmaita <rosmaita.fossdev@gmail.com> | 2020-09-16 12:31:54 +0000 |
commit | 7ee7d376a19cebbf7d8bc6d273f7e7daba552526 (patch) | |
tree | 0293af7d13772eeda3e7484f8ec62f1947577203 /cinderclient/v3 | |
parent | 76f2b91d9add6113aa57829d8101647f0a5936d7 (diff) | |
download | python-cinderclient-7ee7d376a19cebbf7d8bc6d273f7e7daba552526.tar.gz |
Add commands for default type overrides
This patch adds command for set,get and delete default volume types
for projects.
This patch adds 3 commands :
1) Set
Set a default volume type for a project
cinder --os-volume-api-version 3.62 default-type-set <vol-type-id> <project-id>
2) Get
Get the default volume type for a project
cinder --os-volume-api-version 3.62 default-type-list --project-id <project-id>
Get all default types
cinder --os-volume-api-version 3.62 default-type-list
3) Unset
Unset default volume type for a project
cinder --os-volume-api-version 3.62 default-type-unset <project-id>
Implements: Blueprint multiple-default-volume-types
Change-Id: Id2fb00c218edbb98df3193577dba6a897c6e73f6
Diffstat (limited to 'cinderclient/v3')
-rw-r--r-- | cinderclient/v3/client.py | 2 | ||||
-rw-r--r-- | cinderclient/v3/default_types.py | 65 | ||||
-rw-r--r-- | cinderclient/v3/shell.py | 51 |
3 files changed, 118 insertions, 0 deletions
diff --git a/cinderclient/v3/client.py b/cinderclient/v3/client.py index 5703826..770d9d6 100644 --- a/cinderclient/v3/client.py +++ b/cinderclient/v3/client.py @@ -21,6 +21,7 @@ from cinderclient.v3 import capabilities from cinderclient.v3 import cgsnapshots from cinderclient.v3 import clusters from cinderclient.v3 import consistencygroups +from cinderclient.v3 import default_types from cinderclient.v3 import group_snapshots from cinderclient.v3 import group_types from cinderclient.v3 import groups @@ -80,6 +81,7 @@ class Client(object): volume_type_access.VolumeTypeAccessManager(self) self.volume_encryption_types = \ volume_encryption_types.VolumeEncryptionTypeManager(self) + self.default_types = default_types.DefaultVolumeTypeManager(self) self.qos_specs = qos_specs.QoSSpecsManager(self) self.quota_classes = quota_classes.QuotaClassSetManager(self) self.quotas = quotas.QuotaSetManager(self) diff --git a/cinderclient/v3/default_types.py b/cinderclient/v3/default_types.py new file mode 100644 index 0000000..58e04cc --- /dev/null +++ b/cinderclient/v3/default_types.py @@ -0,0 +1,65 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +"""Default Volume Type interface.""" + +from cinderclient import base + + +class DefaultVolumeType(base.Resource): + """Default volume types for projects.""" + def __repr__(self): + return "<DefaultVolumeType: %s>" % self.project_id + + +class DefaultVolumeTypeManager(base.ManagerWithFind): + """Manage :class:`DefaultVolumeType` resources.""" + resource_class = DefaultVolumeType + + def create(self, volume_type, project_id): + """Creates a default volume type for a project + + :param volume_type: Name or ID of the volume type + :param project_id: Project to set default type for + """ + + body = { + "default_type": { + "volume_type": volume_type + } + } + + return self._create_update_with_base_url( + 'v3/default-types/%s' % project_id, body, + response_key='default_type') + + def list(self, project_id=None): + """List the default types.""" + + url = 'v3/default-types' + response_key = "default_types" + + if project_id: + url += '/' + project_id + response_key = "default_type" + + return self._get_all_with_base_url(url, response_key) + + def delete(self, project_id): + """Removes the default volume type for a project + + :param project_id: The ID of the project to unset default for. + """ + + return self._delete_with_base_url('v3/default-types/%s' % project_id) diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index 1ccf02e..eaded7e 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -2598,3 +2598,54 @@ def do_transfer_list(cs, args): columns = ['ID', 'Volume ID', 'Name'] utils.print_list(transfers, columns) AppendFilters.filters = [] + + +@api_versions.wraps('3.62') +@utils.arg('volume_type', + metavar='<volume_type>', + help='Name or ID of the volume type.') +@utils.arg('project', + metavar='<project_id>', + help='ID of project for which to set default type.') +def do_default_type_set(cs, args): + """Sets a default volume type for a project.""" + volume_type = args.volume_type + project = args.project + + default_type = cs.default_types.create(volume_type, project) + utils.print_dict(default_type._info) + + +@api_versions.wraps('3.62') +@utils.arg('--project-id', + metavar='<project_id>', + default=None, + help='ID of project for which to show the default type.') +def do_default_type_list(cs, args): + """Lists all default volume types.""" + + project_id = args.project_id + default_types = cs.default_types.list(project_id) + columns = ['Volume Type ID', 'Project ID'] + if project_id: + utils.print_dict(default_types._info) + else: + utils.print_list(default_types, columns) + + +@api_versions.wraps('3.62') +@utils.arg('project_id', + metavar='<project_id>', + nargs='+', + help='ID of project for which to unset default type.') +def do_default_type_unset(cs, args): + """Unset default volume types.""" + + for project_id in args.project_id: + try: + cs.default_types.delete(project_id) + print("Default volume type for project %s has been unset " + "successfully." % (project_id)) + except Exception as e: + print("Unset for default volume type for project %s failed: %s" + % (project_id, e)) |