Add "openstack server shelve" into OSC
Currently, the shelve operation is not supported by OSC. So, this patch attempts to add it into OSC. Change-Id: I92545300bef006a069338168d2de800e8a58af69 Implements: blueprint introduce-shelve-into-osc
This commit is contained in:
parent
42a5909f6a
commit
a41a8c42af
@ -495,6 +495,21 @@ Resume server
|
||||
|
||||
Server (name or ID)
|
||||
|
||||
server shelve
|
||||
-------------
|
||||
|
||||
Shelve server(s)
|
||||
|
||||
.. program:: server shelve
|
||||
.. code:: bash
|
||||
|
||||
os server shelve
|
||||
<server> [<server> ...]
|
||||
|
||||
.. describe:: <server>
|
||||
|
||||
Server(s) to shelve (name or ID)
|
||||
|
||||
server set
|
||||
----------
|
||||
|
||||
|
@ -182,6 +182,7 @@ Those actions with an opposite action are noted in parens if applicable.
|
||||
* ``revoke`` (``issue``) - revoke a token
|
||||
* ``save`` - download an object locally
|
||||
* ``set`` (``unset``) - set a property on the object, formerly called metadata
|
||||
* ``shelve`` (``unshelve``) - shelve one or more server
|
||||
* ``show`` - display detailed information about the specific object
|
||||
* ``start`` (``stop``) - start one or more servers
|
||||
* ``stop`` (``start``) - stop one or more servers
|
||||
|
@ -1387,6 +1387,31 @@ class ShowServer(show.ShowOne):
|
||||
return zip(*sorted(six.iteritems(data)))
|
||||
|
||||
|
||||
class ShelveServer(command.Command):
|
||||
"""Shelve server(s)"""
|
||||
|
||||
log = logging.getLogger(__name__ + '.ShelveServer')
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShelveServer, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'server',
|
||||
metavar='<server>',
|
||||
nargs='+',
|
||||
help=_('Server(s) to shelve (name or ID)'),
|
||||
)
|
||||
return parser
|
||||
|
||||
@utils.log_method(log)
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.compute
|
||||
for server in parsed_args.server:
|
||||
utils.find_resource(
|
||||
compute_client.servers,
|
||||
server,
|
||||
).shelve()
|
||||
|
||||
|
||||
class SshServer(command.Command):
|
||||
"""Ssh to server"""
|
||||
|
||||
|
@ -766,3 +766,57 @@ class TestServerGeneral(testtools.TestCase):
|
||||
server._get_ip_address, self.OLD, 'public', [4, 6])
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
server._get_ip_address, self.OLD, 'private', [6])
|
||||
|
||||
|
||||
class TestShelveServer(TestServer):
|
||||
|
||||
def setUp(self):
|
||||
super(TestShelveServer, self).setUp()
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = server.ShelveServer(self.app, None)
|
||||
|
||||
# Set shelve method to be tested.
|
||||
self.methods = {
|
||||
'shelve': None,
|
||||
}
|
||||
|
||||
def setup_servers_mock(self, count=1):
|
||||
servers = fakes.FakeServer.create_servers(methods=self.methods,
|
||||
count=count)
|
||||
|
||||
self.servers_mock.get = fakes.FakeServer.get_servers(servers, 1)
|
||||
|
||||
return servers
|
||||
|
||||
def test_shelve_one_server(self):
|
||||
server = self.setup_servers_mock(1)[0]
|
||||
|
||||
arglist = [
|
||||
server.id,
|
||||
]
|
||||
verifylist = [
|
||||
('server', [server.id]),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
server.shelve.assert_called_with()
|
||||
|
||||
def test_shelve_multi_servers(self):
|
||||
servers = self.setup_servers_mock(3)
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
||||
for i in range(0, len(servers)):
|
||||
arglist.append(servers[i].id)
|
||||
verifylist = [
|
||||
('server', arglist),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
for i in range(0, len(servers)):
|
||||
servers[i].shelve.assert_called_with()
|
||||
|
@ -130,6 +130,7 @@ openstack.compute.v2 =
|
||||
server_resize = openstackclient.compute.v2.server:ResizeServer
|
||||
server_resume = openstackclient.compute.v2.server:ResumeServer
|
||||
server_set = openstackclient.compute.v2.server:SetServer
|
||||
server_shelve = openstackclient.compute.v2.server:ShelveServer
|
||||
server_show = openstackclient.compute.v2.server:ShowServer
|
||||
server_ssh = openstackclient.compute.v2.server:SshServer
|
||||
server_start = openstackclient.compute.v2.server:StartServer
|
||||
|
Loading…
Reference in New Issue
Block a user