summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Rosen <arosen@nicira.com>2013-01-31 19:54:11 -0800
committerAaron Rosen <arosen@nicira.com>2013-02-05 20:18:30 -0800
commitdad11b3e757d459f9afed5b4b65b74a86362dbd5 (patch)
treefb0eaebddfc927de6b5e50a2cdacf9d90a69b539
parentaa41734347284a2430dc6f32ce4af23ba84d271d (diff)
downloadpython-neutronclient-dad11b3e757d459f9afed5b4b65b74a86362dbd5.tar.gz
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
-rw-r--r--quantumclient/quantum/v2_0/__init__.py22
-rw-r--r--quantumclient/quantum/v2_0/port.py12
-rw-r--r--quantumclient/tests/unit/test_cli20_port.py8
3 files changed, 33 insertions, 9 deletions
diff --git a/quantumclient/quantum/v2_0/__init__.py b/quantumclient/quantum/v2_0/__init__.py
index fbc64ed..7387e07 100644
--- a/quantumclient/quantum/v2_0/__init__.py
+++ b/quantumclient/quantum/v2_0/__init__.py
@@ -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})
diff --git a/quantumclient/quantum/v2_0/port.py b/quantumclient/quantum/v2_0/port.py
index 27d4998..76468b7 100644
--- a/quantumclient/quantum/v2_0/port.py
+++ b/quantumclient/quantum/v2_0/port.py
@@ -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
diff --git a/quantumclient/tests/unit/test_cli20_port.py b/quantumclient/tests/unit/test_cli20_port.py
index 5580dde..c4d9dad 100644
--- a/quantumclient/tests/unit/test_cli20_port.py
+++ b/quantumclient/tests/unit/test_cli20_port.py
@@ -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'