331 lines
13 KiB
Diff
331 lines
13 KiB
Diff
From c4f2db9901b54217e1737987a19a8b48209f40ab Mon Sep 17 00:00:00 2001
|
|
From: rpm-build <rpm-build>
|
|
Date: Mon, 5 Feb 2018 14:06:32 -0500
|
|
Subject: [PATCH 1/1] US106901 Openstack CLI Adoption: Cinder/Glance/Ceilometer
|
|
|
|
CI partII: OSC equivalence of cinder cli with WRS extension
|
|
---
|
|
openstackclient/volume/v1/volume.py | 58 ++++++++++++++++++++++++++++
|
|
openstackclient/volume/v1/volume_snapshot.py | 26 +++++++++++++
|
|
openstackclient/volume/v2/volume.py | 57 +++++++++++++++++++++++++++
|
|
openstackclient/volume/v2/volume_snapshot.py | 27 +++++++++++++
|
|
setup.cfg | 11 +++++-
|
|
5 files changed, 178 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/openstackclient/volume/v1/volume.py b/openstackclient/volume/v1/volume.py
|
|
index b29429e..85caf3e 100644
|
|
--- a/openstackclient/volume/v1/volume.py
|
|
+++ b/openstackclient/volume/v1/volume.py
|
|
@@ -12,6 +12,13 @@
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
#
|
|
+# Copyright (c) 2013-2018 Wind River Systems, Inc.
|
|
+# SPDX-License-Identifier: Apache-2.0
|
|
+#
|
|
+#
|
|
+#
|
|
+#
|
|
+
|
|
|
|
"""Volume v1 Volume action implementations"""
|
|
|
|
@@ -25,6 +32,7 @@ from osc_lib import utils
|
|
import six
|
|
|
|
from openstackclient.i18n import _
|
|
+from cinderclient import utils as cinder_utils
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
@@ -624,3 +632,53 @@ class UnsetVolume(command.Command):
|
|
volume.id,
|
|
parsed_args.property,
|
|
)
|
|
+
|
|
+
|
|
+# WRS extension
|
|
+class ExportVolume(command.Command):
|
|
+ _description = _("Export volume to a file.")
|
|
+
|
|
+ def get_parser(self, prog_name):
|
|
+ parser = super(ExportVolume, self).get_parser(prog_name)
|
|
+ parser.add_argument(
|
|
+ 'volume',
|
|
+ metavar='<volume>',
|
|
+ help=_('Name or ID of the volume to export'),
|
|
+ )
|
|
+ return parser
|
|
+
|
|
+ def take_action(self, parsed_args):
|
|
+ volume_client = self.app.client_manager.volume
|
|
+ volume = utils.find_resource(
|
|
+ volume_client.volumes, parsed_args.volume)
|
|
+ volume_client.volumes.export(volume)
|
|
+
|
|
+
|
|
+# WRS extension
|
|
+class ImportVolume(command.Command):
|
|
+ _description = _("Import a volume from a file.")
|
|
+
|
|
+ def get_parser(self, prog_name):
|
|
+ parser = super(ImportVolume, self).get_parser(prog_name)
|
|
+ parser.add_argument(
|
|
+ 'file_name',
|
|
+ metavar='<file-name>',
|
|
+ help=_('Name of the file to import'),
|
|
+ )
|
|
+ return parser
|
|
+
|
|
+ def take_action(self, parsed_args):
|
|
+ volume_client = self.app.client_manager.volume
|
|
+
|
|
+ # Parse the volume ID from the filename which is in this format:
|
|
+ # volume-<id>-<timestamp>.tgz
|
|
+ if(parsed_args.file_name.find("volume-") != 0 or
|
|
+ parsed_args.file_name.rfind(".tgz") == -1 or
|
|
+ len(parsed_args.file_name) < 28):
|
|
+ raise exceptions.CommandError(
|
|
+ "Invalid filename - volume files must have the following format: "
|
|
+ "volume-<id>-<timestamp>.tgz")
|
|
+
|
|
+ volume_id = parsed_args.file_name[7:-20]
|
|
+ volume = cinder_utils.find_volume(volume_client, volume_id)
|
|
+ volume_client.volumes.import_volume(volume, parsed_args.file_name)
|
|
diff --git a/openstackclient/volume/v1/volume_snapshot.py b/openstackclient/volume/v1/volume_snapshot.py
|
|
index 3e83da5..a4d44a8 100644
|
|
--- a/openstackclient/volume/v1/volume_snapshot.py
|
|
+++ b/openstackclient/volume/v1/volume_snapshot.py
|
|
@@ -12,6 +12,12 @@
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
#
|
|
+# Copyright (c) 2013-2018 Wind River Systems, Inc.
|
|
+# SPDX-License-Identifier: Apache-2.0
|
|
+#
|
|
+#
|
|
+#
|
|
+#
|
|
|
|
"""Volume v1 Snapshot action implementations"""
|
|
|
|
@@ -25,6 +31,7 @@ from osc_lib import utils
|
|
import six
|
|
|
|
from openstackclient.i18n import _
|
|
+from cinderclient import utils as cinder_utils
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
@@ -352,3 +359,22 @@ class UnsetVolumeSnapshot(command.Command):
|
|
snapshot.id,
|
|
parsed_args.property,
|
|
)
|
|
+
|
|
+# WRS extension
|
|
+class ExportVolumeSnapshot(command.Command):
|
|
+ _description = _("Export a snapshot to a file.")
|
|
+
|
|
+ def get_parser(self, prog_name):
|
|
+ parser = super(ExportVolumeSnapshot, self).get_parser(prog_name)
|
|
+ parser.add_argument(
|
|
+ 'snapshot',
|
|
+ metavar='<snapshot>',
|
|
+ help=_('Name or ID of the snapshot to export'),
|
|
+ )
|
|
+ return parser
|
|
+
|
|
+ def take_action(self, parsed_args):
|
|
+ volume_client = self.app.client_manager.volume
|
|
+ snapshot = cinder_utils.find_resource(
|
|
+ volume_client.volume_snapshots, parsed_args.snapshot)
|
|
+ volume_client.volume_snapshots.export(snapshot)
|
|
diff --git a/openstackclient/volume/v2/volume.py b/openstackclient/volume/v2/volume.py
|
|
index 61f846b..c2ea7a4 100644
|
|
--- a/openstackclient/volume/v2/volume.py
|
|
+++ b/openstackclient/volume/v2/volume.py
|
|
@@ -11,6 +11,12 @@
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
#
|
|
+# Copyright (c) 2013-2018 Wind River Systems, Inc.
|
|
+# SPDX-License-Identifier: Apache-2.0
|
|
+#
|
|
+#
|
|
+#
|
|
+#
|
|
|
|
"""Volume V2 Volume action implementations"""
|
|
|
|
@@ -25,6 +31,7 @@ import six
|
|
|
|
from openstackclient.i18n import _
|
|
from openstackclient.identity import common as identity_common
|
|
+from cinderclient import utils as cinder_utils
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
@@ -784,3 +791,53 @@ class UnsetVolume(command.Command):
|
|
if result > 0:
|
|
raise exceptions.CommandError(_("One or more of the "
|
|
"unset operations failed"))
|
|
+
|
|
+
|
|
+# WRS extension
|
|
+class ExportVolume(command.Command):
|
|
+ _description = _("Export volume to a file.")
|
|
+
|
|
+ def get_parser(self, prog_name):
|
|
+ parser = super(ExportVolume, self).get_parser(prog_name)
|
|
+ parser.add_argument(
|
|
+ 'volume',
|
|
+ metavar='<volume>',
|
|
+ help=_('Name or ID of the volume to export'),
|
|
+ )
|
|
+ return parser
|
|
+
|
|
+ def take_action(self, parsed_args):
|
|
+ volume_client = self.app.client_manager.volume
|
|
+ volume = cinder_utils.find_resource(
|
|
+ volume_client.volumes, parsed_args.volume)
|
|
+ volume_client.volumes.export(volume)
|
|
+
|
|
+
|
|
+# WRS extension
|
|
+class ImportVolume(command.Command):
|
|
+ _description = _("Import a volume from a file.")
|
|
+
|
|
+ def get_parser(self, prog_name):
|
|
+ parser = super(ImportVolume, self).get_parser(prog_name)
|
|
+ parser.add_argument(
|
|
+ 'file_name',
|
|
+ metavar='<file-name>',
|
|
+ help=_('Name of the file to import'),
|
|
+ )
|
|
+ return parser
|
|
+
|
|
+ def take_action(self, parsed_args):
|
|
+ volume_client = self.app.client_manager.volume
|
|
+
|
|
+ # Parse the volume ID from the filename which is in this format:
|
|
+ # volume-<id>-<timestamp>.tgz
|
|
+ if(parsed_args.file_name.find("volume-") != 0 or
|
|
+ parsed_args.file_name.rfind(".tgz") == -1 or
|
|
+ len(parsed_args.file_name) < 28):
|
|
+ raise exceptions.CommandError(
|
|
+ "Invalid filename - volume files must have the following format: "
|
|
+ "volume-<id>-<timestamp>.tgz")
|
|
+
|
|
+ volume_id = parsed_args.file_name[7:-20]
|
|
+ volume = cinder_utils.find_volume(volume_client, volume_id)
|
|
+ volume_client.volumes.import_volume(volume, parsed_args.file_name)
|
|
diff --git a/openstackclient/volume/v2/volume_snapshot.py b/openstackclient/volume/v2/volume_snapshot.py
|
|
index fe96941..704ef75 100644
|
|
--- a/openstackclient/volume/v2/volume_snapshot.py
|
|
+++ b/openstackclient/volume/v2/volume_snapshot.py
|
|
@@ -11,6 +11,12 @@
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
#
|
|
+# Copyright (c) 2013-2018 Wind River Systems, Inc.
|
|
+# SPDX-License-Identifier: Apache-2.0
|
|
+#
|
|
+#
|
|
+#
|
|
+#
|
|
|
|
"""Volume v2 snapshot action implementations"""
|
|
|
|
@@ -25,6 +31,7 @@ import six
|
|
|
|
from openstackclient.i18n import _
|
|
from openstackclient.identity import common as identity_common
|
|
+from cinderclient import utils as cinder_utils
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
@@ -437,3 +444,23 @@ class UnsetVolumeSnapshot(command.Command):
|
|
snapshot.id,
|
|
parsed_args.property,
|
|
)
|
|
+
|
|
+
|
|
+# WRS extension
|
|
+class ExportVolumeSnapshot(command.Command):
|
|
+ _description = _("Export a snapshot to a file.")
|
|
+
|
|
+ def get_parser(self, prog_name):
|
|
+ parser = super(ExportVolumeSnapshot, self).get_parser(prog_name)
|
|
+ parser.add_argument(
|
|
+ 'snapshot',
|
|
+ metavar='<snapshot>',
|
|
+ help=_('Name or ID of the snapshot to export'),
|
|
+ )
|
|
+ return parser
|
|
+
|
|
+ def take_action(self, parsed_args):
|
|
+ volume_client = self.app.client_manager.volume
|
|
+ snapshot = cinder_utils.find_resource(
|
|
+ volume_client.volume_snapshots, parsed_args.snapshot)
|
|
+ volume_client.volume_snapshots.export(snapshot)
|
|
diff --git a/setup.cfg b/setup.cfg
|
|
index 627ff87..11f7261 100644
|
|
--- a/setup.cfg
|
|
+++ b/setup.cfg
|
|
@@ -468,6 +468,8 @@ openstack.volume.v1 =
|
|
snapshot_unset = openstackclient.volume.v1.snapshot:UnsetSnapshot
|
|
volume_create = openstackclient.volume.v1.volume:CreateVolume
|
|
volume_delete = openstackclient.volume.v1.volume:DeleteVolume
|
|
+ volume_export = openstackclient.volume.v1.volume:ExportVolume
|
|
+ volume_import = openstackclient.volume.v1.volume:ImportVolume
|
|
volume_list = openstackclient.volume.v1.volume:ListVolume
|
|
volume_migrate = openstackclient.volume.v1.volume:MigrateVolume
|
|
volume_set = openstackclient.volume.v1.volume:SetVolume
|
|
@@ -480,6 +482,7 @@ openstack.volume.v1 =
|
|
volume_backup_show = openstackclient.volume.v1.backup:ShowVolumeBackup
|
|
volume_snapshot_create = openstackclient.volume.v1.volume_snapshot:CreateVolumeSnapshot
|
|
volume_snapshot_delete = openstackclient.volume.v1.volume_snapshot:DeleteVolumeSnapshot
|
|
+ volume_snapshot_export = openstackclient.volume.v1.volume_snapshot:ExportVolumeSnapshot
|
|
volume_snapshot_list = openstackclient.volume.v1.volume_snapshot:ListVolumeSnapshot
|
|
volume_snapshot_set = openstackclient.volume.v1.volume_snapshot:SetVolumeSnapshot
|
|
volume_snapshot_show = openstackclient.volume.v1.volume_snapshot:ShowVolumeSnapshot
|
|
@@ -529,7 +532,9 @@ openstack.volume.v2 =
|
|
snapshot_show = openstackclient.volume.v2.snapshot:ShowSnapshot
|
|
snapshot_unset = openstackclient.volume.v2.snapshot:UnsetSnapshot
|
|
volume_create = openstackclient.volume.v2.volume:CreateVolume
|
|
- volume_delete = openstackclient.volume.v2.volume:DeleteVolume
|
|
+ volume_delete = openstackclient.volume.v2.volume:DeleteVolume
|
|
+ volume_export = openstackclient.volume.v2.volume:ExportVolume
|
|
+ volume_import = openstackclient.volume.v2.volume:ImportVolume
|
|
volume_list = openstackclient.volume.v2.volume:ListVolume
|
|
volume_migrate = openstackclient.volume.v2.volume:MigrateVolume
|
|
volume_set = openstackclient.volume.v2.volume:SetVolume
|
|
@@ -545,6 +550,7 @@ openstack.volume.v2 =
|
|
volume_host_set = openstackclient.volume.v2.volume_host:SetVolumeHost
|
|
volume_snapshot_create = openstackclient.volume.v2.volume_snapshot:CreateVolumeSnapshot
|
|
volume_snapshot_delete = openstackclient.volume.v2.volume_snapshot:DeleteVolumeSnapshot
|
|
+ volume_snapshot_export = openstackclient.volume.v2.volume_snapshot:ExportVolumeSnapshot
|
|
volume_snapshot_list = openstackclient.volume.v2.volume_snapshot:ListVolumeSnapshot
|
|
volume_snapshot_set = openstackclient.volume.v2.volume_snapshot:SetVolumeSnapshot
|
|
volume_snapshot_show = openstackclient.volume.v2.volume_snapshot:ShowVolumeSnapshot
|
|
@@ -584,6 +590,8 @@ openstack.volume.v3 =
|
|
consistency_group_snapshot_show = openstackclient.volume.v2.consistency_group_snapshot:ShowConsistencyGroupSnapshot
|
|
volume_create = openstackclient.volume.v2.volume:CreateVolume
|
|
volume_delete = openstackclient.volume.v2.volume:DeleteVolume
|
|
+ volume_export = openstackclient.volume.v2.volume:ExportVolume
|
|
+ volume_import = openstackclient.volume.v2.volume:ImportVolume
|
|
volume_list = openstackclient.volume.v2.volume:ListVolume
|
|
volume_migrate = openstackclient.volume.v2.volume:MigrateVolume
|
|
volume_set = openstackclient.volume.v2.volume:SetVolume
|
|
@@ -598,6 +606,7 @@ openstack.volume.v3 =
|
|
volume_host_set = openstackclient.volume.v2.volume_host:SetVolumeHost
|
|
volume_snapshot_create = openstackclient.volume.v2.volume_snapshot:CreateVolumeSnapshot
|
|
volume_snapshot_delete = openstackclient.volume.v2.volume_snapshot:DeleteVolumeSnapshot
|
|
+ volume_snapshot_export = openstackclient.volume.v2.volume_snapshot:ExportVolumeSnapshot
|
|
volume_snapshot_list = openstackclient.volume.v2.volume_snapshot:ListVolumeSnapshot
|
|
volume_snapshot_set = openstackclient.volume.v2.volume_snapshot:SetVolumeSnapshot
|
|
volume_snapshot_show = openstackclient.volume.v2.volume_snapshot:ShowVolumeSnapshot
|
|
--
|
|
1.8.3.1
|
|
|