Allow ability to remove security groups from ports
This commit adds the option --no-security-groups to port-update in order to remove security groups from a port. Fixes bug 1112089 Change-Id: I43a5cc2c8b443f2d34fffe66b442925a5ae312ac
This commit is contained in:
@@ -254,6 +254,12 @@ class QuantumCommand(command.OpenStackCommand):
|
||||
elif v is None:
|
||||
data[self.resource][k] = ''
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
pass
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return {}
|
||||
|
||||
|
||||
class CreateCommand(QuantumCommand, show.ShowOne):
|
||||
"""Create a resource for a given tenant
|
||||
@@ -275,12 +281,6 @@ class CreateCommand(QuantumCommand, show.ShowOne):
|
||||
self.add_known_arguments(parser)
|
||||
return parser
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
pass
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return {}
|
||||
|
||||
def get_data(self, parsed_args):
|
||||
self.log.debug('get_data(%s)' % parsed_args)
|
||||
quantum_client = self.get_client()
|
||||
@@ -318,6 +318,7 @@ class UpdateCommand(QuantumCommand):
|
||||
help='ID or name of %s to update' % self.resource)
|
||||
add_extra_argument(parser, 'value_specs',
|
||||
'new values for the %s' % self.resource)
|
||||
self.add_known_arguments(parser)
|
||||
return parser
|
||||
|
||||
def run(self, parsed_args):
|
||||
@@ -325,16 +326,19 @@ class UpdateCommand(QuantumCommand):
|
||||
quantum_client = self.get_client()
|
||||
quantum_client.format = parsed_args.request_format
|
||||
value_specs = parsed_args.value_specs
|
||||
if not value_specs:
|
||||
dict_args = self.args2body(parsed_args).get(self.resource, {})
|
||||
dict_specs = parse_args_to_dict(value_specs)
|
||||
body = {self.resource: dict(dict_args.items() +
|
||||
dict_specs.items())}
|
||||
if not body[self.resource]:
|
||||
raise exceptions.CommandError(
|
||||
"Must specify new values to update %s" % self.resource)
|
||||
data = {self.resource: parse_args_to_dict(value_specs)}
|
||||
_id = find_resourceid_by_name_or_id(quantum_client,
|
||||
self.resource,
|
||||
parsed_args.id)
|
||||
obj_updator = getattr(quantum_client,
|
||||
"update_%s" % self.resource)
|
||||
obj_updator(_id, data)
|
||||
obj_updator(_id, body)
|
||||
print >>self.app.stdout, (
|
||||
_('Updated %(resource)s: %(id)s') %
|
||||
{'id': parsed_args.id, 'resource': self.resource})
|
||||
|
@@ -174,3 +174,15 @@ class UpdatePort(UpdateCommand):
|
||||
|
||||
resource = 'port'
|
||||
log = logging.getLogger(__name__ + '.UpdatePort')
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--no-security-groups',
|
||||
default=False, action='store_true',
|
||||
help='remove security groups from port')
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
body = {'port': {}}
|
||||
if parsed_args.no_security_groups:
|
||||
body['port'].update({'security_groups': None})
|
||||
return body
|
||||
|
@@ -262,6 +262,14 @@ class CLITestV20Port(CLITestV20Base):
|
||||
{'name': 'myname', 'tags': ['a', 'b'], }
|
||||
)
|
||||
|
||||
def test_update_port_security_group_off(self):
|
||||
"""Update port: --no-security-groups myid."""
|
||||
resource = 'port'
|
||||
cmd = UpdatePort(MyApp(sys.stdout), None)
|
||||
self._test_update_resource(resource, cmd, 'myid',
|
||||
['--no-security-groups', 'myid'],
|
||||
{'security_groups': None})
|
||||
|
||||
def test_show_port(self):
|
||||
"""Show port: --fields id --fields name myid."""
|
||||
resource = 'port'
|
||||
|
Reference in New Issue
Block a user