Add interface for listing security groups of an instance
This is already available in nova but not exposed via client. * novaclient/v1_1/servers.py: New interface to list security groups of an instance. * novaclient/v1_1/shell.py: New sub command list-secgroup. * novaclient/tests/v1_1/fakes.py, novaclient/tests/v1_1/test_servers.py, novaclient/tests/v1_1/test_shell.py: Add corresponding tests. Implements: blueprint servers-list-secgroup Change-Id: I505bcffdbb15b84bfd73cae5ef5a8fb9c69bd7b9
This commit is contained in:
parent
c970dc3dd4
commit
12d5b9578b
novaclient
@ -430,6 +430,16 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
def delete_servers_uuid4_metadata_key1(self, **kw):
|
||||
return (200, {}, {'data': 'Fake diagnostics'})
|
||||
|
||||
def get_servers_1234_os_security_groups(self, **kw):
|
||||
return (200, {}, {
|
||||
"security_groups": [{
|
||||
'id': 1,
|
||||
'name': 'securitygroup1',
|
||||
'description': 'FAKE_SECURITY_GROUP',
|
||||
'tenant_id': '4ffc664c198e435e9853f2538fbcd7a7',
|
||||
'rules': []}]
|
||||
})
|
||||
|
||||
#
|
||||
# Server Addresses
|
||||
#
|
||||
|
@ -501,6 +501,11 @@ class ServersTest(utils.TestCase):
|
||||
cs.servers.remove_security_group(s, 'oldsg')
|
||||
cs.assert_called('POST', '/servers/1234/action')
|
||||
|
||||
def test_list_security_group(self):
|
||||
s = cs.servers.get(1234)
|
||||
s.list_security_group()
|
||||
cs.assert_called('GET', '/servers/1234/os-security-groups')
|
||||
|
||||
def test_evacuate(self):
|
||||
s = cs.servers.get(1234)
|
||||
s.evacuate('fake_target_host', 'True')
|
||||
|
@ -1545,6 +1545,10 @@ class ShellTest(utils.TestCase):
|
||||
self.assert_called('POST', '/servers/1234/action',
|
||||
{'removeSecurityGroup': {'name': 'testgroup'}})
|
||||
|
||||
def test_server_security_group_list(self):
|
||||
self.run_command('list-secgroup 1234')
|
||||
self.assert_called('GET', '/servers/1234/os-security-groups')
|
||||
|
||||
def test_interface_list(self):
|
||||
self.run_command('interface-list 1234')
|
||||
self.assert_called('GET', '/servers/1234/os-interface')
|
||||
|
@ -24,7 +24,7 @@ import six
|
||||
from novaclient import base
|
||||
from novaclient import crypto
|
||||
from novaclient.openstack.common.py3kcompat import urlutils
|
||||
|
||||
from novaclient.v1_1.security_groups import SecurityGroup
|
||||
|
||||
REBOOT_SOFT, REBOOT_HARD = 'SOFT', 'HARD'
|
||||
|
||||
@ -321,6 +321,12 @@ class Server(base.Resource):
|
||||
"""
|
||||
self.manager.remove_security_group(self, security_group)
|
||||
|
||||
def list_security_group(self):
|
||||
"""
|
||||
List security group(s) of an instance.
|
||||
"""
|
||||
return self.manager.list_security_group(self)
|
||||
|
||||
def evacuate(self, host, on_shared_storage, password=None):
|
||||
"""
|
||||
Evacuate an instance from failed host to specified host.
|
||||
@ -851,6 +857,16 @@ class ServerManager(base.BootingManagerWithFind):
|
||||
"""
|
||||
self._action('removeSecurityGroup', server, {'name': security_group})
|
||||
|
||||
def list_security_group(self, server):
|
||||
"""
|
||||
List Security Group(s) of an instance
|
||||
|
||||
:param server: ID of the instance.
|
||||
|
||||
"""
|
||||
return self._list('/servers/%s/os-security-groups' %
|
||||
base.getid(server), 'security_groups', SecurityGroup)
|
||||
|
||||
def evacuate(self, server, host, on_shared_storage, password=None):
|
||||
"""
|
||||
Evacuate a server instance.
|
||||
|
@ -1780,6 +1780,14 @@ def do_remove_secgroup(cs, args):
|
||||
server.remove_security_group(args.secgroup)
|
||||
|
||||
|
||||
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
||||
def do_list_secgroup(cs, args):
|
||||
"""List Security Group(s) of a server."""
|
||||
server = _find_server(cs, args.server)
|
||||
groups = server.list_security_group()
|
||||
_print_secgroups(groups)
|
||||
|
||||
|
||||
@utils.arg('pool',
|
||||
metavar='<floating-ip-pool>',
|
||||
help='Name of Floating IP Pool. (Optional)',
|
||||
|
Loading…
x
Reference in New Issue
Block a user