Skip to content

Commit

Permalink
Allow to specify policy by name in firewall-update
Browse files Browse the repository at this point in the history
Currently only firewall policy ids are supported in firewall-update,
this change allows to use firewall policy names in firewall-update:

  neutron firewall-update my-firewall --policy my-new-policy

DocImpact
Change-Id: I84ad97fc7f1f2e81cad98497d4d983606fa03077
  • Loading branch information
ZZelle committed Sep 15, 2014
1 parent f22dbd2 commit b81d650
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
16 changes: 15 additions & 1 deletion neutronclient/neutron/v2_0/fw/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CreateFirewall(neutronv20.CreateCommand):
def add_known_arguments(self, parser):
parser.add_argument(
'firewall_policy_id', metavar='POLICY',
help=_('Firewall policy ID.'))
help=_('Firewall policy name or ID.'))
parser.add_argument(
'--name',
help=_('Name for the firewall.'))
Expand Down Expand Up @@ -83,6 +83,20 @@ class UpdateFirewall(neutronv20.UpdateCommand):

resource = 'firewall'

def add_known_arguments(self, parser):
parser.add_argument(
'--policy', metavar='POLICY',
help=_('Firewall policy name or ID.'))

def args2body(self, parsed_args):
data = {}
if parsed_args.policy:
_policy_id = neutronv20.find_resourceid_by_name_or_id(
self.get_client(), 'firewall_policy',
parsed_args.policy)
data['firewall_policy_id'] = _policy_id
return {self.resource: data}


class DeleteFirewall(neutronv20.DeleteCommand):
"""Delete a given firewall."""
Expand Down
8 changes: 8 additions & 0 deletions neutronclient/tests/unit/fw/test_cli20_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ def test_update_firewall(self):
['myid', '--name', 'newname'],
{'name': 'newname', })

def test_update_firewall_using_policy_name(self):
"""firewall-update myid --policy newpolicy."""
resource = 'firewall'
cmd = firewall.UpdateFirewall(test_cli20.MyApp(sys.stdout), None)
self._test_update_resource(resource, cmd, 'myid',
['myid', '--policy', 'newpolicy'],
{'firewall_policy_id': 'newpolicy'})

def test_delete_firewall(self):
"""firewall-delete my-id."""
resource = 'firewall'
Expand Down

0 comments on commit b81d650

Please sign in to comment.