Merge "Add "openstack server unshelve" into OSC"

This commit is contained in:
Jenkins 2015-11-30 10:32:13 +00:00 committed by Gerrit Code Review
commit b920245f10
5 changed files with 108 additions and 46 deletions

View File

@ -720,3 +720,18 @@ Unset server properties
.. describe:: <server>
Server (name or ID)
server unshelve
---------------
Unshelve server(s)
.. program:: server unshelve
.. code:: bash
os server unshelve
<server> [<server> ...]
.. describe:: <server>
Server(s) to unshelve (name or ID)

View File

@ -183,7 +183,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
* ``shelve`` (``unshelve``) - shelve one or more servers
* ``show`` - display detailed information about the specific object
* ``start`` (``stop``) - start one or more servers
* ``stop`` (``start``) - stop one or more servers
@ -192,6 +192,7 @@ Those actions with an opposite action are noted in parens if applicable.
* ``unpause`` (``pause``) - return one or more paused servers to running state
* ``unrescue`` (``rescue``) - return a server to normal boot mode
* ``unset`` (``set``) - remove an attribute of the object
* ``unshelve`` (``shelve``) - unshelve one or more servers
Implementation

View File

@ -1352,6 +1352,31 @@ class SetServer(command.Command):
raise exceptions.CommandError(msg)
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 ShowServer(show.ShowOne):
"""Show server details"""
@ -1389,31 +1414,6 @@ 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"""
@ -1748,3 +1748,28 @@ class UnsetServer(command.Command):
server,
parsed_args.property,
)
class UnshelveServer(command.Command):
"""Unshelve server(s)"""
log = logging.getLogger(__name__ + '.UnshelveServer')
def get_parser(self, prog_name):
parser = super(UnshelveServer, self).get_parser(prog_name)
parser.add_argument(
'server',
metavar='<server>',
nargs='+',
help=_('Server(s) to unshelve (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,
).unshelve()

View File

@ -792,6 +792,26 @@ class TestServerResume(TestServer):
self.run_method_with_servers('resume', 3)
class TestServerShelve(TestServer):
def setUp(self):
super(TestServerShelve, 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 test_shelve_one_server(self):
self.run_method_with_servers('shelve', 1)
def test_shelve_multi_servers(self):
self.run_method_with_servers('shelve', 3)
class TestServerStart(TestServer):
def setUp(self):
@ -892,6 +912,26 @@ class TestServerUnpause(TestServer):
self.run_method_with_servers('unpause', 3)
class TestServerUnshelve(TestServer):
def setUp(self):
super(TestServerUnshelve, self).setUp()
# Get the command object to test
self.cmd = server.UnshelveServer(self.app, None)
# Set unshelve method to be tested.
self.methods = {
'unshelve': None,
}
def test_unshelve_one_server(self):
self.run_method_with_servers('unshelve', 1)
def test_unshelve_multi_servers(self):
self.run_method_with_servers('unshelve', 3)
class TestServerGeneral(testtools.TestCase):
OLD = {
'private': [
@ -942,23 +982,3 @@ 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 test_shelve_one_server(self):
self.run_method_with_servers('shelve', 1)
def test_shelve_multi_servers(self):
self.run_method_with_servers('shelve', 3)

View File

@ -140,6 +140,7 @@ openstack.compute.v2 =
server_unpause = openstackclient.compute.v2.server:UnpauseServer
server_unrescue = openstackclient.compute.v2.server:UnrescueServer
server_unset = openstackclient.compute.v2.server:UnsetServer
server_unshelve = openstackclient.compute.v2.server:UnshelveServer
usage_list = openstackclient.compute.v2.usage:ListUsage
usage_show = openstackclient.compute.v2.usage:ShowUsage