-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support security groups with stateless rules
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
Showing
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters