summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-07-20 10:12:40 +0000
committerGerrit Code Review <review@openstack.org>2016-07-20 10:12:40 +0000
commit412b29b972e4a6877472147f5b713214ace2ca12 (patch)
treeb8b7a3de20521703ba0b579553e17d5a249910ae /openstackclient
parent07e97b1a8ab76a253a483a5290bcf93fa41c7cc4 (diff)
parent92d0fbeafd146126897934a7ec57ebf2ccef8580 (diff)
downloadpython-openstackclient-412b29b972e4a6877472147f5b713214ace2ca12.tar.gz
Merge "Add port security option to network commands"
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/network/v2/network.py30
-rw-r--r--openstackclient/tests/network/v2/fakes.py3
-rw-r--r--openstackclient/tests/network/v2/test_network.py18
3 files changed, 51 insertions, 0 deletions
diff --git a/openstackclient/network/v2/network.py b/openstackclient/network/v2/network.py
index 31dfc798..ccc02fd8 100644
--- a/openstackclient/network/v2/network.py
+++ b/openstackclient/network/v2/network.py
@@ -58,6 +58,10 @@ def _get_attrs(client_manager, parsed_args):
attrs['shared'] = True
if parsed_args.no_share:
attrs['shared'] = False
+ if parsed_args.enable_port_security:
+ attrs['port_security_enabled'] = True
+ if parsed_args.disable_port_security:
+ attrs['port_security_enabled'] = False
# "network set" command doesn't support setting project.
if 'project' in parsed_args and parsed_args.project is not None:
@@ -197,6 +201,19 @@ class CreateNetwork(common.NetworkAndComputeShowOne):
"(Network Availability Zone extension required, "
"repeat option to set multiple availability zones)")
)
+ port_security_group = parser.add_mutually_exclusive_group()
+ port_security_group.add_argument(
+ '--enable-port-security',
+ action='store_true',
+ help=_("Enable port security by default for ports created on "
+ "this network (default)")
+ )
+ port_security_group.add_argument(
+ '--disable-port-security',
+ action='store_true',
+ help=_("Disable port security by default for ports created on "
+ "this network")
+ )
external_router_grp = parser.add_mutually_exclusive_group()
external_router_grp.add_argument(
'--external',
@@ -403,6 +420,19 @@ class SetNetwork(command.Command):
action='store_true',
help=_("Do not share the network between projects")
)
+ port_security_group = parser.add_mutually_exclusive_group()
+ port_security_group.add_argument(
+ '--enable-port-security',
+ action='store_true',
+ help=_("Enable port security by default for ports created on "
+ "this network")
+ )
+ port_security_group.add_argument(
+ '--disable-port-security',
+ action='store_true',
+ help=_("Disable port security by default for ports created on "
+ "this network")
+ )
external_router_grp = parser.add_mutually_exclusive_group()
external_router_grp.add_argument(
'--external',
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py
index 50d9899c..8d5efe14 100644
--- a/openstackclient/tests/network/v2/fakes.py
+++ b/openstackclient/tests/network/v2/fakes.py
@@ -285,6 +285,7 @@ class FakeNetwork(object):
'availability_zones': [],
'availability_zone_hints': [],
'is_default': False,
+ 'port_security_enabled': True,
}
# Overwrite default attributes.
@@ -296,6 +297,8 @@ class FakeNetwork(object):
# Set attributes with special mapping in OpenStack SDK.
network.project_id = network_attrs['tenant_id']
network.is_router_external = network_attrs['router:external']
+ network.is_port_security_enabled = \
+ network_attrs['port_security_enabled']
return network
diff --git a/openstackclient/tests/network/v2/test_network.py b/openstackclient/tests/network/v2/test_network.py
index 4322bf9a..aa016403 100644
--- a/openstackclient/tests/network/v2/test_network.py
+++ b/openstackclient/tests/network/v2/test_network.py
@@ -56,6 +56,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
'id',
'is_default',
'name',
+ 'port_security_enabled',
'project_id',
'provider_network_type',
'router:external',
@@ -71,6 +72,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
_network.id,
_network.is_default,
_network.name,
+ _network.is_port_security_enabled,
_network.project_id,
_network.provider_network_type,
network._format_router_external(_network.is_router_external),
@@ -144,6 +146,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
"--provider-physical-network", "physnet1",
"--provider-segment", "400",
"--transparent-vlan",
+ "--enable-port-security",
self._network.name,
]
verifylist = [
@@ -158,6 +161,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
('physical_network', 'physnet1'),
('segmentation_id', '400'),
('transparent_vlan', True),
+ ('enable_port_security', True),
('name', self._network.name),
]
@@ -176,6 +180,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
'provider:physical_network': 'physnet1',
'provider:segmentation_id': '400',
'vlan_transparent': True,
+ 'port_security_enabled': True,
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
@@ -184,6 +189,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
arglist = [
"--enable",
"--no-share",
+ "--disable-port-security",
self._network.name,
]
verifylist = [
@@ -191,6 +197,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
('no_share', True),
('name', self._network.name),
('external', False),
+ ('disable_port_security', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -200,6 +207,7 @@ class TestCreateNetworkIdentityV3(TestNetwork):
'admin_state_up': True,
'name': self._network.name,
'shared': False,
+ 'port_security_enabled': False,
})
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
@@ -220,6 +228,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
'id',
'is_default',
'name',
+ 'port_security_enabled',
'project_id',
'provider_network_type',
'router:external',
@@ -235,6 +244,7 @@ class TestCreateNetworkIdentityV2(TestNetwork):
_network.id,
_network.is_default,
_network.name,
+ _network.is_port_security_enabled,
_network.project_id,
_network.provider_network_type,
network._format_router_external(_network.is_router_external),
@@ -537,6 +547,7 @@ class TestSetNetwork(TestNetwork):
'--provider-physical-network', 'physnet1',
'--provider-segment', '400',
'--no-transparent-vlan',
+ '--enable-port-security',
]
verifylist = [
('network', self._network.name),
@@ -549,6 +560,7 @@ class TestSetNetwork(TestNetwork):
('physical_network', 'physnet1'),
('segmentation_id', '400'),
('no_transparent_vlan', True),
+ ('enable_port_security', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -564,6 +576,7 @@ class TestSetNetwork(TestNetwork):
'provider:physical_network': 'physnet1',
'provider:segmentation_id': '400',
'vlan_transparent': False,
+ 'port_security_enabled': True,
}
self.network.update_network.assert_called_once_with(
self._network, **attrs)
@@ -575,12 +588,14 @@ class TestSetNetwork(TestNetwork):
'--disable',
'--no-share',
'--internal',
+ '--disable-port-security',
]
verifylist = [
('network', self._network.name),
('disable', True),
('no_share', True),
('internal', True),
+ ('disable_port_security', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -590,6 +605,7 @@ class TestSetNetwork(TestNetwork):
'admin_state_up': False,
'shared': False,
'router:external': False,
+ 'port_security_enabled': False,
}
self.network.update_network.assert_called_once_with(
self._network, **attrs)
@@ -620,6 +636,7 @@ class TestShowNetwork(TestNetwork):
'id',
'is_default',
'name',
+ 'port_security_enabled',
'project_id',
'provider_network_type',
'router:external',
@@ -635,6 +652,7 @@ class TestShowNetwork(TestNetwork):
_network.id,
_network.is_default,
_network.name,
+ _network.is_port_security_enabled,
_network.project_id,
_network.provider_network_type,
network._format_router_external(_network.is_router_external),