Add cli for remove security group

Change-Id: I35919f3e6edd0239a4edc0b68c6622f910d85be6
Closes-Bug: #1737152
This commit is contained in:
cooldharma06 2018-01-11 14:44:11 +05:30
parent 5405428168
commit ead62e0374
5 changed files with 78 additions and 0 deletions

View File

@ -63,6 +63,7 @@ openstack.container.v1 =
appcontainer_network_detach = zunclient.osc.v1.containers:NetworkDetach
appcontainer_network_attach = zunclient.osc.v1.containers:NetworkAttach
appcontainer_image_search = zunclient.osc.v1.images:SearchImage
appcontainer_remove_security_group = zunclient.osc.v1.containers:RemoveSecurityGroup
[build_sphinx]
source-dir = doc/source

View File

@ -1017,6 +1017,37 @@ class AddSecurityGroup(command.Command):
"%(e)s" % {'container': parsed_args.container, 'e': e})
class RemoveSecurityGroup(command.Command):
"""Remove security group for specified container."""
log = logging.getLogger(__name__ + ".RemoveSecurityGroup")
def get_parser(self, prog_name):
parser = super(RemoveSecurityGroup, self).get_parser(prog_name)
parser.add_argument(
'container',
metavar='<container>',
help='ID or name of the container to remove security group.')
parser.add_argument(
'security_group',
metavar='<security_group>',
help='The security group to remove from specified container. ')
return parser
def take_action(self, parsed_args):
client = _get_client(self, parsed_args)
opts = {}
opts['id'] = parsed_args.container
opts['security_group'] = parsed_args.security_group
opts = zun_utils.remove_null_parms(**opts)
try:
client.containers.remove_security_group(**opts)
print("Request to remove security group from container %s "
"has been accepted." % parsed_args.container)
except Exception as e:
print("Remove security group from container %(container)s failed: "
"%(e)s" % {'container': parsed_args.container, 'e': e})
class NetworkDetach(command.Command):
"""Detach neutron network from specified container."""
log = logging.getLogger(__name__ + ".NetworkDetach")

View File

@ -327,6 +327,15 @@ fake_responses = {
None,
),
},
'/v1/containers/%s/remove_security_group?%s'
% (CONTAINER1['id'], parse.urlencode({'name': security_group})):
{
'POST': (
{},
None,
),
},
}
@ -679,3 +688,15 @@ class ContainerManagerTest(testtools.TestCase):
]
self.assertEqual(expect, self.api.calls)
self.assertTrue(containers)
def test_containers_remove_security_group(self):
containers = self.mgr.remove_security_group(
CONTAINER1['id'], security_group)
expect = [
('POST', '/v1/containers/%s/remove_security_group?%s'
% (CONTAINER1['id'],
parse.urlencode({'name': security_group})),
{'Content-Length': '0'}, None)
]
self.assertEqual(expect, self.api.calls)
self.assertTrue(containers)

View File

@ -215,3 +215,7 @@ class ContainerManager(base.Manager):
def network_attach(self, container, network):
return self._action(container, '/network_attach',
qparams={'network': network})
def remove_security_group(self, id, security_group):
return self._action(id, '/remove_security_group',
qparams={'name': security_group})

View File

@ -769,3 +769,24 @@ def do_network_attach(cs, args):
except Exception as e:
print("Attach network to container %(container)s "
"failed: %(e)s" % {'container': args.container, 'e': e})
@utils.arg('container',
metavar='<container>',
help='ID or name of the container to remove security group.')
@utils.arg('security_group',
metavar='<security_group>',
help='The security group to remove from specified container.')
def do_remove_security_group(cs, args):
"""Remove security group for specified container."""
opts = {}
opts['id'] = args.container
opts['security_group'] = args.security_group
opts = zun_utils.remove_null_parms(**opts)
try:
cs.containers.remove_security_group(**opts)
print("Request to remove security group for container %s "
"has been accepted." % args.container)
except Exception as e:
print("Remove security group for container %(container)s "
"failed: %(e)s" % {'container': args.container, 'e': e})