Skip to content

Commit

Permalink
Support security groups with stateless rules
Browse files Browse the repository at this point in the history
Add an extension to the Neutron client to allow to pass the boolean
argument `--stateful` (default: True) when creating or updating a
security group.

Change-Id: Idf523d81bd09004e462b7aed03e7ad09d5f17ad7
Closes-Bug: PROD-6791
  • Loading branch information
gield authored and Giel Dops committed Feb 1, 2018
1 parent 54e0f83 commit 6cd8c03
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
AUTHORS
build/*
build-stamp
ChangeLog
cover/
covhtml/
dist/
doc/build
*.orig
*.DS_Store
*.pyc
nuage_openstack_neutronclient.egg-info/
nuage_neutron.egg-info/
pbr*.egg/
setuptools*.egg/
*.log
*.mo
*.sw?
*~
/.*
!/.coveragerc
!/.gitignore
!/.gitreview
!/.mailmap
!/.pylintrc
!/.testr.conf
61 changes: 61 additions & 0 deletions nuage_neutronclient/securitygroup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2018 NOKIA
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from neutronclient.common import extension
from neutronclient.common import utils
from neutronclient.neutron import v2_0 as neutronV20
from neutronclient.neutron.v2_0 import securitygroup

from nuage_neutronclient._i18n import _


class CreateSecurityGroup(extension.ClientExtensionCreate,
securitygroup.CreateSecurityGroup):
shell_command = 'security-group-create'
object_path = '/security-groups'

def add_known_arguments(self, parser):
super(CreateSecurityGroup, self).add_known_arguments(parser)
utils.add_boolean_argument(
parser, '--stateful',
help=_('Defines whether the security group is stateful or not.'))

def args2body(self, parsed_args):
body = super(CreateSecurityGroup, self).args2body(parsed_args)
if hasattr(parsed_args, 'stateful') and parsed_args.stateful:
sec_group = body['security_group']
sec_group['stateful'] = utils.str2bool(parsed_args.stateful)
return body


class UpdateSecurityGroup(extension.ClientExtensionUpdate,
securitygroup.UpdateSecurityGroup):
shell_command = 'security-group-update'
resource_path = '/security-groups/%s'

def add_known_arguments(self, parser):
super(UpdateSecurityGroup, self).add_known_arguments(parser)
utils.add_boolean_argument(
parser, '--stateful',
help=_('Defines whether the security group is stateful or not.'))

def args2body(self, parsed_args):
body = super(UpdateSecurityGroup, self).args2body(parsed_args)
neutron_client = self.get_client()
parsed_args.id = neutronV20.find_resourceid_by_name_or_id(
neutron_client, self.resource, parsed_args.id)
if hasattr(parsed_args, 'stateful') and parsed_args.stateful:
sec_group = body['security_group']
sec_group['stateful'] = utils.str2bool(parsed_args.stateful)
return body
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ neutronclient.extension =
subnet = nuage_neutronclient.subnet
net_topology = nuage_neutronclient.net_topology
nuage_flow_classifier = nuage_neutronclient.nuage_flow_classifier
security_group = nuage_neutronclient.securitygroup

0 comments on commit 6cd8c03

Please sign in to comment.