summaryrefslogtreecommitdiff
path: root/openstackclient/volume
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/volume')
-rw-r--r--openstackclient/volume/v1/volume_snapshot.py34
-rw-r--r--openstackclient/volume/v2/consistency_group.py110
-rw-r--r--openstackclient/volume/v2/volume_host.py50
-rw-r--r--openstackclient/volume/v2/volume_snapshot.py34
4 files changed, 173 insertions, 55 deletions
diff --git a/openstackclient/volume/v1/volume_snapshot.py b/openstackclient/volume/v1/volume_snapshot.py
index c2ecf75b..77c93ad4 100644
--- a/openstackclient/volume/v1/volume_snapshot.py
+++ b/openstackclient/volume/v1/volume_snapshot.py
@@ -135,9 +135,31 @@ class ListVolumeSnapshot(command.Lister):
default=False,
help=_('List additional fields in output'),
)
+ parser.add_argument(
+ '--name',
+ metavar='<name>',
+ default=None,
+ help=_('Filters results by a name.')
+ )
+ parser.add_argument(
+ '--status',
+ metavar='<status>',
+ choices=['available', 'error', 'creating', 'deleting',
+ 'error-deleting'],
+ help=_("Filters results by a status. "
+ "('available', 'error', 'creating', 'deleting'"
+ " or 'error-deleting')")
+ )
+ parser.add_argument(
+ '--volume',
+ metavar='<volume>',
+ default=None,
+ help=_('Filters results by a volume (name or ID).')
+ )
return parser
def take_action(self, parsed_args):
+ volume_client = self.app.client_manager.volume
def _format_volume_id(volume_id):
"""Return a volume name if available
@@ -169,17 +191,25 @@ class ListVolumeSnapshot(command.Lister):
# Cache the volume list
volume_cache = {}
try:
- for s in self.app.client_manager.volume.volumes.list():
+ for s in volume_client.volumes.list():
volume_cache[s.id] = s
except Exception:
# Just forget it if there's any trouble
pass
+ volume_id = None
+ if parsed_args.volume:
+ volume_id = utils.find_resource(
+ volume_client.volumes, parsed_args.volume).id
+
search_opts = {
'all_tenants': parsed_args.all_projects,
+ 'display_name': parsed_args.name,
+ 'status': parsed_args.status,
+ 'volume_id': volume_id,
}
- data = self.app.client_manager.volume.volume_snapshots.list(
+ data = volume_client.volume_snapshots.list(
search_opts=search_opts)
return (column_headers,
(utils.get_item_properties(
diff --git a/openstackclient/volume/v2/consistency_group.py b/openstackclient/volume/v2/consistency_group.py
index f77da59b..2f4f3c95 100644
--- a/openstackclient/volume/v2/consistency_group.py
+++ b/openstackclient/volume/v2/consistency_group.py
@@ -27,51 +27,6 @@ from openstackclient.i18n import _
LOG = logging.getLogger(__name__)
-class DeleteConsistencyGroup(command.Command):
- _description = _("Delete consistency group(s).")
-
- def get_parser(self, prog_name):
- parser = super(DeleteConsistencyGroup, self).get_parser(prog_name)
- parser.add_argument(
- 'consistency_groups',
- metavar='<consistency-group>',
- nargs="+",
- help=_('Consistency group(s) to delete (name or ID)'),
- )
- parser.add_argument(
- '--force',
- action='store_true',
- default=False,
- help=_("Allow delete in state other than error or available"),
- )
- return parser
-
- def take_action(self, parsed_args):
- volume_client = self.app.client_manager.volume
- result = 0
-
- for i in parsed_args.consistency_groups:
- try:
- consistency_group_id = utils.find_resource(
- volume_client.consistencygroups, i).id
- volume_client.consistencygroups.delete(
- consistency_group_id, parsed_args.force)
- except Exception as e:
- result += 1
- LOG.error(_("Failed to delete consistency group with "
- "name or ID '%(consistency_group)s':%(e)s")
- % {'consistency_group': i, 'e': e})
-
- if result > 0:
- total = len(parsed_args.consistency_groups)
- msg = (_("%(result)s of %(total)s consistency groups failed "
- "to delete.") % {'result': result, 'total': total})
- raise exceptions.CommandError(msg)
-
-
-LOG = logging.getLogger(__name__)
-
-
class CreateConsistencyGroup(command.ShowOne):
_description = _("Create new consistency group.")
@@ -94,6 +49,11 @@ class CreateConsistencyGroup(command.ShowOne):
metavar="<consistency-group>",
help=_("Existing consistency group (name or ID)")
)
+ exclusive_group.add_argument(
+ "--consistency-group-snapshot",
+ metavar="<consistency-group-snapshot>",
+ help=_("Existing consistency group snapshot (name or ID)")
+ )
parser.add_argument(
"--description",
metavar="<description>",
@@ -120,17 +80,23 @@ class CreateConsistencyGroup(command.ShowOne):
description=parsed_args.description,
availability_zone=parsed_args.availability_zone
)
- elif parsed_args.consistency_group_source:
+ else:
if parsed_args.availability_zone:
msg = _("'--availability-zone' option will not work "
"if creating consistency group from source")
LOG.warning(msg)
- consistency_group_id = utils.find_resource(
- volume_client.consistencygroups,
- parsed_args.consistency_group_source).id
+
+ consistency_group_id = None
consistency_group_snapshot = None
- # TODO(Huanxuan Ao): Support for creating from consistency group
- # snapshot after adding "consistency_group_snapshot" resource
+ if parsed_args.consistency_group_source:
+ consistency_group_id = utils.find_resource(
+ volume_client.consistencygroups,
+ parsed_args.consistency_group_source).id
+ elif parsed_args.consistency_group_snapshot:
+ consistency_group_snapshot = utils.find_resource(
+ volume_client.cgsnapshots,
+ parsed_args.consistency_group_snapshot).id
+
consistency_group = (
volume_client.consistencygroups.create_from_src(
consistency_group_snapshot,
@@ -143,6 +109,48 @@ class CreateConsistencyGroup(command.ShowOne):
return zip(*sorted(six.iteritems(consistency_group._info)))
+class DeleteConsistencyGroup(command.Command):
+ _description = _("Delete consistency group(s).")
+
+ def get_parser(self, prog_name):
+ parser = super(DeleteConsistencyGroup, self).get_parser(prog_name)
+ parser.add_argument(
+ 'consistency_groups',
+ metavar='<consistency-group>',
+ nargs="+",
+ help=_('Consistency group(s) to delete (name or ID)'),
+ )
+ parser.add_argument(
+ '--force',
+ action='store_true',
+ default=False,
+ help=_("Allow delete in state other than error or available"),
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ volume_client = self.app.client_manager.volume
+ result = 0
+
+ for i in parsed_args.consistency_groups:
+ try:
+ consistency_group_id = utils.find_resource(
+ volume_client.consistencygroups, i).id
+ volume_client.consistencygroups.delete(
+ consistency_group_id, parsed_args.force)
+ except Exception as e:
+ result += 1
+ LOG.error(_("Failed to delete consistency group with "
+ "name or ID '%(consistency_group)s':%(e)s")
+ % {'consistency_group': i, 'e': e})
+
+ if result > 0:
+ total = len(parsed_args.consistency_groups)
+ msg = (_("%(result)s of %(total)s consistency groups failed "
+ "to delete.") % {'result': result, 'total': total})
+ raise exceptions.CommandError(msg)
+
+
class ListConsistencyGroup(command.Lister):
_description = _("List consistency groups.")
diff --git a/openstackclient/volume/v2/volume_host.py b/openstackclient/volume/v2/volume_host.py
new file mode 100644
index 00000000..376e5024
--- /dev/null
+++ b/openstackclient/volume/v2/volume_host.py
@@ -0,0 +1,50 @@
+#
+# 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.
+#
+
+"""Volume v2 host action implementations"""
+
+from osc_lib.command import command
+
+from openstackclient.i18n import _
+
+
+class SetVolumeHost(command.Command):
+ _description = _("Set volume host properties")
+
+ def get_parser(self, prog_name):
+ parser = super(SetVolumeHost, self).get_parser(prog_name)
+ parser.add_argument(
+ "host",
+ metavar="<host-name>",
+ help=_("Name of volume host")
+ )
+ enabled_group = parser.add_mutually_exclusive_group()
+ enabled_group.add_argument(
+ "--disable",
+ action="store_true",
+ help=_("Freeze and disable the specified volume host.")
+ )
+ enabled_group.add_argument(
+ "--enable",
+ action="store_true",
+ help=_("Thaw and enable the specified volume host.")
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ service_client = self.app.client_manager.volume
+ if parsed_args.enable:
+ service_client.services.thaw_host(parsed_args.host)
+ if parsed_args.disable:
+ service_client.services.freeze_host(parsed_args.host)
diff --git a/openstackclient/volume/v2/volume_snapshot.py b/openstackclient/volume/v2/volume_snapshot.py
index 43f30326..86af6d8c 100644
--- a/openstackclient/volume/v2/volume_snapshot.py
+++ b/openstackclient/volume/v2/volume_snapshot.py
@@ -151,9 +151,31 @@ class ListVolumeSnapshot(command.Lister):
metavar='<limit>',
help=_('Maximum number of snapshots to display'),
)
+ parser.add_argument(
+ '--name',
+ metavar='<name>',
+ default=None,
+ help=_('Filters results by a name.')
+ )
+ parser.add_argument(
+ '--status',
+ metavar='<status>',
+ choices=['available', 'error', 'creating', 'deleting',
+ 'error-deleting'],
+ help=_("Filters results by a status. "
+ "('available', 'error', 'creating', 'deleting'"
+ " or 'error-deleting')")
+ )
+ parser.add_argument(
+ '--volume',
+ metavar='<volume>',
+ default=None,
+ help=_('Filters results by a volume (name or ID).')
+ )
return parser
def take_action(self, parsed_args):
+ volume_client = self.app.client_manager.volume
def _format_volume_id(volume_id):
"""Return a volume name if available
@@ -180,17 +202,25 @@ class ListVolumeSnapshot(command.Lister):
# Cache the volume list
volume_cache = {}
try:
- for s in self.app.client_manager.volume.volumes.list():
+ for s in volume_client.volumes.list():
volume_cache[s.id] = s
except Exception:
# Just forget it if there's any trouble
pass
+ volume_id = None
+ if parsed_args.volume:
+ volume_id = utils.find_resource(
+ volume_client.volumes, parsed_args.volume).id
+
search_opts = {
'all_tenants': parsed_args.all_projects,
+ 'name': parsed_args.name,
+ 'status': parsed_args.status,
+ 'volume_id': volume_id,
}
- data = self.app.client_manager.volume.volume_snapshots.list(
+ data = volume_client.volume_snapshots.list(
search_opts=search_opts,
marker=parsed_args.marker,
limit=parsed_args.limit,