Merge "Add CLI support for add_security_group"
This commit is contained in:
commit
544be4cb42
@ -55,6 +55,7 @@ openstack.container.v1 =
|
||||
appcontainer_cp = zunclient.osc.v1.containers:CopyContainer
|
||||
appcontainer_stats = zunclient.osc.v1.containers:StatsContainer
|
||||
appcontainer_commit = zunclient.osc.v1.containers:CommitContainer
|
||||
appcontainer_add_security_group = zunclient.osc.v1.containers:AddSecurityGroup
|
||||
appcontainer_image_list = zunclient.osc.v1.images:ListImage
|
||||
appcontainer_image_pull = zunclient.osc.v1.images:PullImage
|
||||
appcontainer_host_list = zunclient.osc.v1.hosts:ListHost
|
||||
|
@ -947,3 +947,34 @@ class CommitContainer(command.Command):
|
||||
except Exception as e:
|
||||
print("commit container %(container)s failed: %(e)s" %
|
||||
{'container': container, 'e': e})
|
||||
|
||||
|
||||
class AddSecurityGroup(command.Command):
|
||||
"""Add security group for specified container."""
|
||||
log = logging.getLogger(__name__ + ".AddSecurityGroup")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(AddSecurityGroup, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the container to add security group.')
|
||||
parser.add_argument(
|
||||
'security_group',
|
||||
metavar='<security_group>',
|
||||
help='The security group for 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.add_security_group(**opts)
|
||||
print("Request to add security group for container %s "
|
||||
"has been accepted." % parsed_args.container)
|
||||
except Exception as e:
|
||||
print("Add security group for container %(container)s failed: "
|
||||
"%(e)s" % {'container': parsed_args.container, 'e': e})
|
||||
|
@ -68,6 +68,7 @@ path = "/tmp/test.txt"
|
||||
data = "/tmp/test.tar"
|
||||
repo = "repo-test"
|
||||
tag = "tag-test"
|
||||
security_group = "testsg"
|
||||
|
||||
fake_responses = {
|
||||
'/v1/containers':
|
||||
@ -298,6 +299,14 @@ fake_responses = {
|
||||
None,
|
||||
),
|
||||
},
|
||||
'/v1/containers/%s/add_security_group?%s'
|
||||
% (CONTAINER1['id'], parse.urlencode({'name': security_group})):
|
||||
{
|
||||
'POST': (
|
||||
{},
|
||||
None,
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -614,3 +623,15 @@ class ContainerManagerTest(testtools.TestCase):
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertIsNone(containers)
|
||||
|
||||
def test_containers_add_security_group(self):
|
||||
containers = self.mgr.add_security_group(
|
||||
CONTAINER1['id'], security_group)
|
||||
expect = [
|
||||
('POST', '/v1/containers/%s/add_security_group?%s'
|
||||
% (CONTAINER1['id'],
|
||||
parse.urlencode({'name': security_group})),
|
||||
{'Content-Length': '0'}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertTrue(containers)
|
||||
|
@ -202,3 +202,7 @@ class ContainerManager(base.Manager):
|
||||
else:
|
||||
return self._action(id, '/commit', qparams={
|
||||
'repository': repository})[1]
|
||||
|
||||
def add_security_group(self, id, security_group):
|
||||
return self._action(id, '/add_security_group',
|
||||
qparams={'name': security_group})
|
||||
|
@ -675,3 +675,24 @@ def do_commit(cs, args):
|
||||
except Exception as e:
|
||||
print("Commit for container %(container)s failed: %(e)s" %
|
||||
{'container': args.container, 'e': e})
|
||||
|
||||
|
||||
@utils.arg('container',
|
||||
metavar='<container>',
|
||||
help='ID or name of the container to add security group.')
|
||||
@utils.arg('security_group',
|
||||
metavar='<security_group>',
|
||||
help='The security group for specified container.')
|
||||
def do_add_security_group(cs, args):
|
||||
"""Add 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.add_security_group(**opts)
|
||||
print("Request to add security group for container %s "
|
||||
"has been accepted." % args.container)
|
||||
except Exception as e:
|
||||
print("Add security group for container %(container)s "
|
||||
"failed: %(e)s" % {'container': args.container, 'e': e})
|
||||
|
Loading…
x
Reference in New Issue
Block a user