summaryrefslogtreecommitdiff
path: root/openstackclient/network/utils.py
diff options
context:
space:
mode:
authorRichard Theis <rtheis@us.ibm.com>2016-02-26 11:33:45 -0600
committerRichard Theis <rtheis@us.ibm.com>2016-03-10 08:33:52 -0600
commit564c8ff2403da87b96562076865f42426a4f8eac (patch)
tree6ff87996ca4a35647361d14866dc685dd5fef526 /openstackclient/network/utils.py
parentf8ac17ac52fa42067c881254e243ebe4514624be (diff)
downloadpython-openstackclient-564c8ff2403da87b96562076865f42426a4f8eac.tar.gz
Refactor security group show to use SDK
Refactored the 'os security group show' command to use the SDK when neutron is enabled, but continue to use the nova client when nova network is enabled. Added a release note for the change in security group rules output due to Network v2. The column names remain unchanged to maintain backwards compatibility. Change-Id: I25233ddb8115d18b8b88affb3de13346084a339d Partial-Bug: #1519511 Implements: blueprint neutron-client
Diffstat (limited to 'openstackclient/network/utils.py')
-rw-r--r--openstackclient/network/utils.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/openstackclient/network/utils.py b/openstackclient/network/utils.py
new file mode 100644
index 00000000..287f0271
--- /dev/null
+++ b/openstackclient/network/utils.py
@@ -0,0 +1,41 @@
+# 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.
+#
+
+
+# Transform compute security group rule for display.
+def transform_compute_security_group_rule(sg_rule):
+ info = {}
+ info.update(sg_rule)
+ from_port = info.pop('from_port')
+ to_port = info.pop('to_port')
+ if isinstance(from_port, int) and isinstance(to_port, int):
+ port_range = {'port_range': "%u:%u" % (from_port, to_port)}
+ elif from_port is None and to_port is None:
+ port_range = {'port_range': ""}
+ else:
+ port_range = {'port_range': "%s:%s" % (from_port, to_port)}
+ info.update(port_range)
+ if 'cidr' in info['ip_range']:
+ info['ip_range'] = info['ip_range']['cidr']
+ else:
+ info['ip_range'] = ''
+ if info['ip_protocol'] is None:
+ info['ip_protocol'] = ''
+ elif info['ip_protocol'].lower() == 'icmp':
+ info['port_range'] = ''
+ group = info.pop('group')
+ if 'name' in group:
+ info['remote_security_group'] = group['name']
+ else:
+ info['remote_security_group'] = ''
+ return info