summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhiyong.dai <zhiyong.dai@easystack.cn>2016-12-14 21:14:17 +0800
committerzhiyong.dai <zhiyong.dai@easystack.cn>2016-11-21 22:56:41 +0800
commit55195cec46fadd88f6151783b1e17557d5e94940 (patch)
tree8dc3c0390d551c551f821d4c39e9d93f2c4abf28
parent3816b4b90a84ed3917d07af4c95a46cce0519ea7 (diff)
downloadpython-openstackclient-55195cec46fadd88f6151783b1e17557d5e94940.tar.gz
Add "volume host failover" command
Add "volume host failover" command in volume v2 (v2 only). Change-Id: Ia39e6d20bf5c9d3096e46f3432804a240827548d Implements: bp cinder-command-support
-rw-r--r--doc/source/command-objects/volume-host.rst26
-rw-r--r--doc/source/commands.rst1
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume_host.py31
-rw-r--r--openstackclient/volume/v2/volume_host.py29
-rw-r--r--releasenotes/notes/add-volume-host-failover-8fc77b24533b7fed.yaml5
-rw-r--r--setup.cfg1
6 files changed, 89 insertions, 4 deletions
diff --git a/doc/source/command-objects/volume-host.rst b/doc/source/command-objects/volume-host.rst
index a225e53e..1e513cb7 100644
--- a/doc/source/command-objects/volume-host.rst
+++ b/doc/source/command-objects/volume-host.rst
@@ -4,6 +4,28 @@ volume host
Volume v2
+volume host failover
+--------------------
+
+Failover volume host to different backend
+
+.. program:: volume host failover
+.. code:: bash
+
+ openstack volume host failover
+ --volume-backend <backend-id>
+ <host-name>
+
+.. option:: --volume-backend <backend-id>
+
+ The ID of the volume backend replication
+ target where the host will failover to (required)
+
+.. _volume_host_failover-host-name:
+.. describe:: <host-name>
+
+ Name of volume host
+
volume host set
---------------
@@ -18,13 +40,13 @@ Set volume host properties
.. option:: --enable
- Thaw and enable the specified volume host
+ Thaw and enable the specified volume host.
.. option:: --disable
Freeze and disable the specified volume host
-.. _volume-host-set:
+.. _volume_host_set-host-name:
.. describe:: <host-name>
Name of volume host
diff --git a/doc/source/commands.rst b/doc/source/commands.rst
index 206b18af..815a29bb 100644
--- a/doc/source/commands.rst
+++ b/doc/source/commands.rst
@@ -234,6 +234,7 @@ Those actions with an opposite action are noted in parens if applicable.
* ``create`` (``delete``) - create a new occurrence of the specified object
* ``delete`` (``create``) - delete specific occurrences of the specified objects
* ``expand`` (``shrink``) - increase the capacity of a cluster
+* ``failover`` - failover volume host to different backend
* ``issue`` (``revoke``) - issue a token
* ``list`` - display summary information about multiple objects
* ``lock`` (``unlock``) - lock one or more servers so that non-admin user won't be able to execute actions
diff --git a/openstackclient/tests/unit/volume/v2/test_volume_host.py b/openstackclient/tests/unit/volume/v2/test_volume_host.py
index aad7bb0b..b024329a 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume_host.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume_host.py
@@ -35,6 +35,7 @@ class TestVolumeHostSet(TestVolumeHost):
self.host_mock.freeze_host.return_value = None
self.host_mock.thaw_host.return_value = None
+ # Get the command object to mock
self.cmd = volume_host.SetVolumeHost(self.app, None)
def test_volume_host_set_nothing(self):
@@ -84,3 +85,33 @@ class TestVolumeHostSet(TestVolumeHost):
self.host_mock.freeze_host.assert_called_with(self.service.host)
self.host_mock.thaw_host.assert_not_called()
self.assertIsNone(result)
+
+
+class TestVolumeHostFailover(TestVolumeHost):
+
+ service = host_fakes.FakeService.create_one_service()
+
+ def setUp(self):
+ super(TestVolumeHostFailover, self).setUp()
+
+ self.host_mock.failover_host.return_value = None
+
+ # Get the command object to mock
+ self.cmd = volume_host.FailoverVolumeHost(self.app, None)
+
+ def test_volume_host_failover(self):
+ arglist = [
+ '--volume-backend', 'backend_test',
+ self.service.host,
+ ]
+ verifylist = [
+ ('volume_backend', 'backend_test'),
+ ('host', self.service.host),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.host_mock.failover_host.assert_called_with(
+ self.service.host, 'backend_test')
+ self.assertIsNone(result)
diff --git a/openstackclient/volume/v2/volume_host.py b/openstackclient/volume/v2/volume_host.py
index 376e5024..2fdeb968 100644
--- a/openstackclient/volume/v2/volume_host.py
+++ b/openstackclient/volume/v2/volume_host.py
@@ -19,6 +19,31 @@ from osc_lib.command import command
from openstackclient.i18n import _
+class FailoverVolumeHost(command.Command):
+ _description = _("Failover volume host to different backend")
+
+ def get_parser(self, prog_name):
+ parser = super(FailoverVolumeHost, self).get_parser(prog_name)
+ parser.add_argument(
+ "host",
+ metavar="<host-name>",
+ help=_("Name of volume host")
+ )
+ parser.add_argument(
+ "--volume-backend",
+ metavar="<backend-id>",
+ required=True,
+ help=_("The ID of the volume backend replication "
+ "target where the host will failover to (required)")
+ )
+ return parser
+
+ def take_action(self, parsed_args):
+ service_client = self.app.client_manager.volume
+ service_client.services.failover_host(parsed_args.host,
+ parsed_args.volume_backend)
+
+
class SetVolumeHost(command.Command):
_description = _("Set volume host properties")
@@ -33,12 +58,12 @@ class SetVolumeHost(command.Command):
enabled_group.add_argument(
"--disable",
action="store_true",
- help=_("Freeze and disable the specified volume host.")
+ help=_("Freeze and disable the specified volume host")
)
enabled_group.add_argument(
"--enable",
action="store_true",
- help=_("Thaw and enable the specified volume host.")
+ help=_("Thaw and enable the specified volume host")
)
return parser
diff --git a/releasenotes/notes/add-volume-host-failover-8fc77b24533b7fed.yaml b/releasenotes/notes/add-volume-host-failover-8fc77b24533b7fed.yaml
new file mode 100644
index 00000000..8630f742
--- /dev/null
+++ b/releasenotes/notes/add-volume-host-failover-8fc77b24533b7fed.yaml
@@ -0,0 +1,5 @@
+---
+features:
+ - |
+ Add ``volume host failover`` command.
+ [Blueprint `cinder-command-support <https://blueprints.launchpad.net/python-openstackclient/+spec/cinder-command-support>`_]
diff --git a/setup.cfg b/setup.cfg
index 8c5c6630..f184d038 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -548,6 +548,7 @@ openstack.volume.v2 =
volume_backup_set = openstackclient.volume.v2.backup:SetVolumeBackup
volume_backup_show = openstackclient.volume.v2.backup:ShowVolumeBackup
+ volume_host_failover = openstackclient.volume.v2.volume_host:FailoverVolumeHost
volume_host_set = openstackclient.volume.v2.volume_host:SetVolumeHost
volume_snapshot_create = openstackclient.volume.v2.volume_snapshot:CreateVolumeSnapshot