Skip to content

Commit bd69d55

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add "volume host set" command"
2 parents 5428e09 + 71e6d44 commit bd69d55

6 files changed

Lines changed: 174 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
===========
2+
volume host
3+
===========
4+
5+
Volume v2
6+
7+
volume host set
8+
---------------
9+
10+
Set volume host properties
11+
12+
.. program:: volume host set
13+
.. code:: bash
14+
15+
os volume host set
16+
[--enable | --disable]
17+
<host-name>
18+
19+
.. option:: --enable
20+
21+
Thaw and enable the specified volume host
22+
23+
.. option:: --disable
24+
25+
Freeze and disable the specified volume host
26+
27+
.. _volume-host-set:
28+
.. describe:: <host-name>
29+
30+
Name of volume host

doc/source/commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ referring to both Compute and Volume quotas.
144144
* ``user role``: (**Identity**) roles assigned to a user
145145
* ``volume``: (**Volume**) block volumes
146146
* ``volume backup``: (**Volume**) backup for volumes
147+
* ``volume host``: (**Volume**) the physical computer for volumes
147148
* ``volume qos``: (**Volume**) quality-of-service (QoS) specification for volumes
148149
* ``volume snapshot``: (**Volume**) a point-in-time copy of a volume
149150
* ``volume type``: (**Volume**) deployment-specific types of volumes available
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
#
14+
15+
from openstackclient.tests.unit.volume.v2 import fakes as host_fakes
16+
from openstackclient.volume.v2 import volume_host
17+
18+
19+
class TestVolumeHost(host_fakes.TestVolume):
20+
21+
def setUp(self):
22+
super(TestVolumeHost, self).setUp()
23+
24+
self.host_mock = self.app.client_manager.volume.services
25+
self.host_mock.reset_mock()
26+
27+
28+
class TestVolumeHostSet(TestVolumeHost):
29+
30+
service = host_fakes.FakeService.create_one_service()
31+
32+
def setUp(self):
33+
super(TestVolumeHostSet, self).setUp()
34+
35+
self.host_mock.freeze_host.return_value = None
36+
self.host_mock.thaw_host.return_value = None
37+
38+
self.cmd = volume_host.SetVolumeHost(self.app, None)
39+
40+
def test_volume_host_set_nothing(self):
41+
arglist = [
42+
self.service.host,
43+
]
44+
verifylist = [
45+
('host', self.service.host),
46+
]
47+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
48+
result = self.cmd.take_action(parsed_args)
49+
50+
self.host_mock.freeze_host.assert_not_called()
51+
self.host_mock.thaw_host.assert_not_called()
52+
self.assertIsNone(result)
53+
54+
def test_volume_host_set_enable(self):
55+
arglist = [
56+
'--enable',
57+
self.service.host,
58+
]
59+
verifylist = [
60+
('enable', True),
61+
('host', self.service.host),
62+
]
63+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
64+
65+
result = self.cmd.take_action(parsed_args)
66+
67+
self.host_mock.thaw_host.assert_called_with(self.service.host)
68+
self.host_mock.freeze_host.assert_not_called()
69+
self.assertIsNone(result)
70+
71+
def test_volume_host_set_disable(self):
72+
arglist = [
73+
'--disable',
74+
self.service.host,
75+
]
76+
verifylist = [
77+
('disable', True),
78+
('host', self.service.host),
79+
]
80+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
81+
82+
result = self.cmd.take_action(parsed_args)
83+
84+
self.host_mock.freeze_host.assert_called_with(self.service.host)
85+
self.host_mock.thaw_host.assert_not_called()
86+
self.assertIsNone(result)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
#
14+
15+
"""Volume v2 host action implementations"""
16+
17+
from osc_lib.command import command
18+
19+
from openstackclient.i18n import _
20+
21+
22+
class SetVolumeHost(command.Command):
23+
_description = _("Set volume host properties")
24+
25+
def get_parser(self, prog_name):
26+
parser = super(SetVolumeHost, self).get_parser(prog_name)
27+
parser.add_argument(
28+
"host",
29+
metavar="<host-name>",
30+
help=_("Name of volume host")
31+
)
32+
enabled_group = parser.add_mutually_exclusive_group()
33+
enabled_group.add_argument(
34+
"--disable",
35+
action="store_true",
36+
help=_("Freeze and disable the specified volume host.")
37+
)
38+
enabled_group.add_argument(
39+
"--enable",
40+
action="store_true",
41+
help=_("Thaw and enable the specified volume host.")
42+
)
43+
return parser
44+
45+
def take_action(self, parsed_args):
46+
service_client = self.app.client_manager.volume
47+
if parsed_args.enable:
48+
service_client.services.thaw_host(parsed_args.host)
49+
if parsed_args.disable:
50+
service_client.services.freeze_host(parsed_args.host)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- Add ``volume host set`` command, it allows a user to enable or disable a volume host.
4+
[Blueprint `cinder-command-support <https://blueprints.launchpad.net/python-openstackclient/+spec/cinder-command-support>`_]
5+

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ openstack.volume.v2 =
547547
volume_backup_set = openstackclient.volume.v2.backup:SetVolumeBackup
548548
volume_backup_show = openstackclient.volume.v2.backup:ShowVolumeBackup
549549

550+
volume_host_set = openstackclient.volume.v2.volume_host:SetVolumeHost
551+
550552
volume_snapshot_create = openstackclient.volume.v2.volume_snapshot:CreateVolumeSnapshot
551553
volume_snapshot_delete = openstackclient.volume.v2.volume_snapshot:DeleteVolumeSnapshot
552554
volume_snapshot_list = openstackclient.volume.v2.volume_snapshot:ListVolumeSnapshot

0 commit comments

Comments
 (0)