Show all updatable options in (fw/fw-policy)-update CLI
Currently firewall-policy-update and firewall-update CLIs do not show all the options which can be updated in its help section. This patch adds the following updatable options # Firewall-Policy: - shared - audited - description - name # Firewall: - admin-state - description - name This patch adds the information to the above FW CLIs. Change-Id: I66a80ff68fc369298528cd59923c294ed39f4e80 Closes-Bug: #1504411
This commit is contained in:
@@ -13,11 +13,52 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from neutronclient._i18n import _
|
||||
from neutronclient.common import utils
|
||||
from neutronclient.neutron import v2_0 as neutronv20
|
||||
|
||||
|
||||
def add_common_args(parser):
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
help=_('Name for the firewall.'))
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
help=_('Description for the firewall.'))
|
||||
router = parser.add_mutually_exclusive_group()
|
||||
router.add_argument(
|
||||
'--router',
|
||||
dest='routers',
|
||||
metavar='ROUTER',
|
||||
action='append',
|
||||
help=_('Firewall associated router name or ID (requires FWaaS '
|
||||
'router insertion extension, this option can be repeated)'))
|
||||
router.add_argument(
|
||||
'--no-routers',
|
||||
action='store_true',
|
||||
help=_('Associate no routers with the firewall (requires FWaaS '
|
||||
'router insertion extension)'))
|
||||
|
||||
|
||||
def parse_common_args(client, parsed_args):
|
||||
body = {}
|
||||
if parsed_args.policy:
|
||||
body['firewall_policy_id'] = neutronv20.find_resourceid_by_name_or_id(
|
||||
client, 'firewall_policy',
|
||||
parsed_args.policy)
|
||||
|
||||
if parsed_args.routers:
|
||||
body['router_ids'] = [
|
||||
neutronv20.find_resourceid_by_name_or_id(client, 'router', r)
|
||||
for r in parsed_args.routers]
|
||||
elif parsed_args.no_routers:
|
||||
body['router_ids'] = []
|
||||
|
||||
neutronv20.update_dict(parsed_args, body,
|
||||
['name', 'description'])
|
||||
return body
|
||||
|
||||
|
||||
class ListFirewall(neutronv20.ListCommand):
|
||||
"""List firewalls that belong to a given tenant."""
|
||||
|
||||
@@ -40,41 +81,20 @@ class CreateFirewall(neutronv20.CreateCommand):
|
||||
resource = 'firewall'
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
add_common_args(parser)
|
||||
parser.add_argument(
|
||||
'firewall_policy_id', metavar='POLICY',
|
||||
'policy', metavar='POLICY',
|
||||
help=_('Firewall policy name or ID.'))
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
help=_('Name for the firewall.'))
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
help=_('Description for the firewall rule.'))
|
||||
parser.add_argument(
|
||||
'--admin-state-down',
|
||||
dest='admin_state',
|
||||
action='store_false',
|
||||
help=_('Set admin state up to false.'))
|
||||
parser.add_argument(
|
||||
'--router',
|
||||
dest='routers',
|
||||
metavar='ROUTER',
|
||||
action='append',
|
||||
help=_('Firewall associated router names or IDs (requires FWaaS '
|
||||
'router insertion extension, this option can be repeated)'))
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
client = self.get_client()
|
||||
_policy_id = neutronv20.find_resourceid_by_name_or_id(
|
||||
client, 'firewall_policy',
|
||||
parsed_args.firewall_policy_id)
|
||||
body = {'firewall_policy_id': _policy_id,
|
||||
'admin_state_up': parsed_args.admin_state, }
|
||||
if parsed_args.routers:
|
||||
body['router_ids'] = [
|
||||
neutronv20.find_resourceid_by_name_or_id(client, 'router', r)
|
||||
for r in parsed_args.routers]
|
||||
neutronv20.update_dict(parsed_args, body,
|
||||
['name', 'description', 'tenant_id'])
|
||||
body = parse_common_args(self.get_client(), parsed_args)
|
||||
neutronv20.update_dict(parsed_args, body, ['tenant_id'])
|
||||
body['admin_state_up'] = parsed_args.admin_state
|
||||
return {self.resource: body}
|
||||
|
||||
|
||||
@@ -84,38 +104,19 @@ class UpdateFirewall(neutronv20.UpdateCommand):
|
||||
resource = 'firewall'
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
add_common_args(parser)
|
||||
parser.add_argument(
|
||||
'--policy', metavar='POLICY',
|
||||
help=_('Firewall policy name or ID.'))
|
||||
router_sg = parser.add_mutually_exclusive_group()
|
||||
router_sg.add_argument(
|
||||
'--router',
|
||||
dest='routers',
|
||||
metavar='ROUTER',
|
||||
action='append',
|
||||
help=_('Firewall associated router names or IDs (requires FWaaS '
|
||||
'router insertion extension, this option can be repeated)'))
|
||||
router_sg.add_argument(
|
||||
'--no-routers',
|
||||
action='store_true',
|
||||
help=_('Associate no routers with the firewall (requires FWaaS '
|
||||
'router insertion extension)'))
|
||||
utils.add_boolean_argument(
|
||||
parser, '--admin-state-up', dest='admin_state_up',
|
||||
help=_('Update the admin state for the firewall'
|
||||
'(True means UP)'))
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
data = {}
|
||||
client = self.get_client()
|
||||
if parsed_args.policy:
|
||||
_policy_id = neutronv20.find_resourceid_by_name_or_id(
|
||||
client, 'firewall_policy',
|
||||
parsed_args.policy)
|
||||
data['firewall_policy_id'] = _policy_id
|
||||
if parsed_args.routers:
|
||||
data['router_ids'] = [
|
||||
neutronv20.find_resourceid_by_name_or_id(client, 'router', r)
|
||||
for r in parsed_args.routers]
|
||||
elif parsed_args.no_routers:
|
||||
data['router_ids'] = []
|
||||
return {self.resource: data}
|
||||
body = parse_common_args(self.get_client(), parsed_args)
|
||||
neutronv20.update_dict(parsed_args, body, ['admin_state_up'])
|
||||
return {self.resource: body}
|
||||
|
||||
|
||||
class DeleteFirewall(neutronv20.DeleteCommand):
|
||||
|
@@ -19,6 +19,7 @@ from __future__ import print_function
|
||||
import argparse
|
||||
|
||||
from neutronclient._i18n import _
|
||||
from neutronclient.common import utils
|
||||
from neutronclient.neutron import v2_0 as neutronv20
|
||||
|
||||
|
||||
@@ -31,14 +32,17 @@ def _format_firewall_rules(firewall_policy):
|
||||
return ''
|
||||
|
||||
|
||||
def common_add_known_arguments(parser):
|
||||
def add_common_args(parser):
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
help=_('Description for the firewall policy.'))
|
||||
parser.add_argument(
|
||||
'--firewall-rules', type=lambda x: x.split(),
|
||||
help=_('Ordered list of whitespace-delimited firewall rule '
|
||||
'names or IDs; e.g., --firewall-rules \"rule1 rule2\"'))
|
||||
|
||||
|
||||
def common_args2body(client, parsed_args):
|
||||
def parse_common_args(client, parsed_args):
|
||||
if parsed_args.firewall_rules:
|
||||
_firewall_rules = []
|
||||
for f in parsed_args.firewall_rules:
|
||||
@@ -81,24 +85,20 @@ class CreateFirewallPolicy(neutronv20.CreateCommand):
|
||||
'name',
|
||||
metavar='NAME',
|
||||
help=_('Name for the firewall policy.'))
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
help=_('Description for the firewall policy.'))
|
||||
parser.add_argument(
|
||||
'--shared',
|
||||
dest='shared',
|
||||
action='store_true',
|
||||
help=_('Create a shared policy.'),
|
||||
default=argparse.SUPPRESS)
|
||||
common_add_known_arguments(parser)
|
||||
parser.add_argument(
|
||||
'--audited',
|
||||
action='store_true',
|
||||
help=_('Sets audited to True.'),
|
||||
default=argparse.SUPPRESS)
|
||||
add_common_args(parser)
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return common_args2body(self.get_client(), parsed_args)
|
||||
return parse_common_args(self.get_client(), parsed_args)
|
||||
|
||||
|
||||
class UpdateFirewallPolicy(neutronv20.UpdateCommand):
|
||||
@@ -107,10 +107,21 @@ class UpdateFirewallPolicy(neutronv20.UpdateCommand):
|
||||
resource = 'firewall_policy'
|
||||
|
||||
def add_known_arguments(self, parser):
|
||||
common_add_known_arguments(parser)
|
||||
add_common_args(parser)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
help=_('Name for the firewall policy.'))
|
||||
utils.add_boolean_argument(
|
||||
parser, '--shared',
|
||||
help=_('Update the sharing status of the policy. '
|
||||
'(True means shared)'))
|
||||
utils.add_boolean_argument(
|
||||
parser, '--audited',
|
||||
help=_('Update the audit status of the policy. '
|
||||
'(True means auditing is enabled)'))
|
||||
|
||||
def args2body(self, parsed_args):
|
||||
return common_args2body(self.get_client(), parsed_args)
|
||||
return parse_common_args(self.get_client(), parsed_args)
|
||||
|
||||
|
||||
class DeleteFirewallPolicy(neutronv20.DeleteCommand):
|
||||
|
@@ -160,3 +160,11 @@ class CLITestV20FirewallJSON(test_cli20.CLITestV20Base):
|
||||
my_id = 'my-id'
|
||||
args = [my_id]
|
||||
self._test_delete_resource(resource, cmd, my_id, args)
|
||||
|
||||
def test_update_firewall_admin_state(self):
|
||||
# firewall-update myid --admin-state-up True.
|
||||
resource = 'firewall'
|
||||
cmd = firewall.UpdateFirewall(test_cli20.MyApp(sys.stdout), None)
|
||||
self._test_update_resource(resource, cmd, 'myid',
|
||||
['myid', '--admin-state-up', 'True'],
|
||||
{'admin_state_up': 'True'})
|
||||
|
@@ -213,3 +213,14 @@ class CLITestV20FirewallPolicyJSON(test_cli20.CLITestV20Base):
|
||||
shell.run_command(cmd, cmd_parser, args)
|
||||
self.mox.VerifyAll()
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
def test_update_firewall_policy_name_shared_audited(self):
|
||||
# firewall-policy-update myid --name newname2 --shared --audited
|
||||
resource = 'firewall_policy'
|
||||
cmd = firewallpolicy.UpdateFirewallPolicy(test_cli20.MyApp(sys.stdout),
|
||||
None)
|
||||
self._test_update_resource(resource, cmd, 'myid',
|
||||
['myid', '--name', 'newname2',
|
||||
'--shared', 'True', '--audited', 'True'],
|
||||
{'name': 'newname2',
|
||||
'shared': 'True', 'audited': 'True'})
|
||||
|
Reference in New Issue
Block a user