python-openstackclient 6.3.0__py3-none-any.whl → 6.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. openstackclient/common/availability_zone.py +4 -4
  2. openstackclient/common/pagination.py +82 -0
  3. openstackclient/compute/v2/flavor.py +2 -16
  4. openstackclient/compute/v2/hypervisor.py +2 -21
  5. openstackclient/compute/v2/keypair.py +2 -9
  6. openstackclient/compute/v2/server.py +220 -131
  7. openstackclient/compute/v2/server_event.py +30 -19
  8. openstackclient/compute/v2/server_group.py +2 -23
  9. openstackclient/compute/v2/server_migration.py +2 -22
  10. openstackclient/compute/v2/usage.py +4 -6
  11. openstackclient/identity/v3/mapping.py +25 -3
  12. openstackclient/identity/v3/policy.py +3 -1
  13. openstackclient/image/v2/cache.py +218 -0
  14. openstackclient/image/v2/image.py +40 -17
  15. openstackclient/image/v2/metadef_namespaces.py +25 -21
  16. openstackclient/image/v2/metadef_objects.py +189 -0
  17. openstackclient/image/v2/metadef_properties.py +284 -0
  18. openstackclient/network/utils.py +100 -0
  19. openstackclient/network/v2/default_security_group_rule.py +418 -0
  20. openstackclient/network/v2/local_ip_association.py +1 -1
  21. openstackclient/network/v2/ndp_proxy.py +7 -3
  22. openstackclient/network/v2/network.py +2 -2
  23. openstackclient/network/v2/port.py +65 -19
  24. openstackclient/network/v2/security_group_rule.py +18 -111
  25. openstackclient/network/v2/subnet.py +1 -0
  26. openstackclient/object/v1/container.py +2 -12
  27. openstackclient/object/v1/object.py +2 -11
  28. openstackclient/tests/functional/base.py +13 -6
  29. openstackclient/tests/functional/identity/v3/test_role.py +11 -3
  30. openstackclient/tests/functional/network/v2/common.py +7 -1
  31. openstackclient/tests/functional/network/v2/test_address_group.py +2 -4
  32. openstackclient/tests/functional/network/v2/test_address_scope.py +0 -6
  33. openstackclient/tests/functional/network/v2/test_default_security_group_rule.py +67 -0
  34. openstackclient/tests/functional/network/v2/test_floating_ip.py +3 -6
  35. openstackclient/tests/functional/network/v2/test_ip_availability.py +3 -8
  36. openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py +3 -4
  37. openstackclient/tests/functional/network/v2/test_local_ip.py +2 -4
  38. openstackclient/tests/functional/network/v2/test_network.py +18 -17
  39. openstackclient/tests/functional/network/v2/test_network_agent.py +24 -21
  40. openstackclient/tests/functional/network/v2/test_network_flavor.py +0 -6
  41. openstackclient/tests/functional/network/v2/test_network_flavor_profile.py +0 -6
  42. openstackclient/tests/functional/network/v2/test_network_meter.py +6 -6
  43. openstackclient/tests/functional/network/v2/test_network_meter_rule.py +7 -8
  44. openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py +1 -3
  45. openstackclient/tests/functional/network/v2/test_network_qos_policy.py +4 -4
  46. openstackclient/tests/functional/network/v2/test_network_qos_rule.py +16 -20
  47. openstackclient/tests/functional/network/v2/test_network_qos_rule_type.py +4 -4
  48. openstackclient/tests/functional/network/v2/test_network_rbac.py +1 -4
  49. openstackclient/tests/functional/network/v2/test_network_segment.py +7 -12
  50. openstackclient/tests/functional/network/v2/test_network_segment_range.py +3 -4
  51. openstackclient/tests/functional/network/v2/test_network_service_provider.py +2 -4
  52. openstackclient/tests/functional/network/v2/test_network_trunk.py +3 -3
  53. openstackclient/tests/functional/network/v2/test_port.py +2 -8
  54. openstackclient/tests/functional/network/v2/test_router.py +0 -6
  55. openstackclient/tests/functional/network/v2/test_security_group.py +1 -4
  56. openstackclient/tests/functional/network/v2/test_security_group_rule.py +1 -4
  57. openstackclient/tests/functional/network/v2/test_subnet.py +4 -22
  58. openstackclient/tests/functional/network/v2/test_subnet_pool.py +0 -6
  59. openstackclient/tests/unit/common/test_availability_zone.py +28 -30
  60. openstackclient/tests/unit/common/test_extension.py +1 -4
  61. openstackclient/tests/unit/common/test_limits.py +2 -4
  62. openstackclient/tests/unit/common/test_project_cleanup.py +3 -10
  63. openstackclient/tests/unit/common/test_quota.py +18 -24
  64. openstackclient/tests/unit/compute/v2/fakes.py +24 -11
  65. openstackclient/tests/unit/compute/v2/test_agent.py +1 -1
  66. openstackclient/tests/unit/compute/v2/test_aggregate.py +62 -72
  67. openstackclient/tests/unit/compute/v2/test_console.py +18 -30
  68. openstackclient/tests/unit/compute/v2/test_flavor.py +85 -89
  69. openstackclient/tests/unit/compute/v2/test_host.py +12 -19
  70. openstackclient/tests/unit/compute/v2/test_hypervisor.py +23 -25
  71. openstackclient/tests/unit/compute/v2/test_hypervisor_stats.py +2 -6
  72. openstackclient/tests/unit/compute/v2/test_keypair.py +25 -39
  73. openstackclient/tests/unit/compute/v2/test_server.py +316 -365
  74. openstackclient/tests/unit/compute/v2/test_server_backup.py +5 -17
  75. openstackclient/tests/unit/compute/v2/test_server_event.py +23 -25
  76. openstackclient/tests/unit/compute/v2/test_server_group.py +41 -33
  77. openstackclient/tests/unit/compute/v2/test_server_image.py +6 -18
  78. openstackclient/tests/unit/compute/v2/test_server_migration.py +45 -45
  79. openstackclient/tests/unit/compute/v2/test_server_volume.py +15 -31
  80. openstackclient/tests/unit/compute/v2/test_service.py +51 -56
  81. openstackclient/tests/unit/compute/v2/test_usage.py +10 -13
  82. openstackclient/tests/unit/fakes.py +4 -0
  83. openstackclient/tests/unit/identity/v3/test_mappings.py +9 -4
  84. openstackclient/tests/unit/identity/v3/test_trust.py +0 -2
  85. openstackclient/tests/unit/image/v1/fakes.py +2 -1
  86. openstackclient/tests/unit/image/v1/test_image.py +1 -1
  87. openstackclient/tests/unit/image/v2/fakes.py +82 -0
  88. openstackclient/tests/unit/image/v2/test_cache.py +214 -0
  89. openstackclient/tests/unit/image/v2/test_image.py +62 -4
  90. openstackclient/tests/unit/image/v2/test_metadef_namespaces.py +5 -19
  91. openstackclient/tests/unit/image/v2/test_metadef_objects.py +162 -0
  92. openstackclient/tests/unit/image/v2/test_metadef_properties.py +227 -0
  93. openstackclient/tests/unit/integ/cli/test_shell.py +0 -2
  94. openstackclient/tests/unit/network/test_common.py +3 -3
  95. openstackclient/tests/unit/network/v2/fakes.py +1 -0
  96. openstackclient/tests/unit/network/v2/test_default_security_group_rule.py +1133 -0
  97. openstackclient/tests/unit/network/v2/test_floating_ip_compute.py +5 -13
  98. openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py +1 -9
  99. openstackclient/tests/unit/network/v2/test_network.py +33 -0
  100. openstackclient/tests/unit/network/v2/test_network_compute.py +5 -11
  101. openstackclient/tests/unit/network/v2/test_network_trunk.py +6 -8
  102. openstackclient/tests/unit/network/v2/test_port.py +83 -38
  103. openstackclient/tests/unit/network/v2/test_security_group_compute.py +7 -15
  104. openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py +19 -27
  105. openstackclient/tests/unit/network/v2/test_security_group_rule_network.py +3 -6
  106. openstackclient/tests/unit/network/v2/test_subnet.py +92 -0
  107. openstackclient/tests/unit/network/v2/test_subnet_pool.py +11 -13
  108. openstackclient/tests/unit/test_shell.py +1 -7
  109. openstackclient/tests/unit/utils.py +10 -4
  110. openstackclient/tests/unit/volume/v1/fakes.py +7 -1
  111. openstackclient/tests/unit/volume/v1/test_qos_specs.py +2 -2
  112. openstackclient/tests/unit/volume/v1/test_service.py +1 -1
  113. openstackclient/tests/unit/volume/v1/test_transfer_request.py +2 -2
  114. openstackclient/tests/unit/volume/v1/test_type.py +2 -4
  115. openstackclient/tests/unit/volume/v1/test_volume.py +5 -7
  116. openstackclient/tests/unit/volume/v1/test_volume_backup.py +4 -4
  117. openstackclient/tests/unit/volume/v2/fakes.py +32 -12
  118. openstackclient/tests/unit/volume/v2/test_backup_record.py +1 -1
  119. openstackclient/tests/unit/volume/v2/test_consistency_group.py +4 -6
  120. openstackclient/tests/unit/volume/v2/test_consistency_group_snapshot.py +2 -4
  121. openstackclient/tests/unit/volume/v2/test_qos_specs.py +2 -2
  122. openstackclient/tests/unit/volume/v2/test_service.py +1 -1
  123. openstackclient/tests/unit/volume/v2/test_volume.py +78 -16
  124. openstackclient/tests/unit/volume/v2/test_volume_backend.py +10 -22
  125. openstackclient/tests/unit/volume/v2/test_volume_backup.py +76 -89
  126. openstackclient/tests/unit/volume/v2/test_volume_host.py +1 -1
  127. openstackclient/tests/unit/volume/v2/test_volume_snapshot.py +5 -7
  128. openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py +4 -8
  129. openstackclient/tests/unit/volume/v2/test_volume_type.py +164 -24
  130. openstackclient/tests/unit/volume/v3/fakes.py +91 -15
  131. openstackclient/tests/unit/volume/v3/test_block_storage_cleanup.py +3 -7
  132. openstackclient/tests/unit/volume/v3/test_block_storage_cluster.py +11 -31
  133. openstackclient/tests/unit/volume/v3/test_block_storage_log_level.py +6 -16
  134. openstackclient/tests/unit/volume/v3/test_block_storage_manage.py +219 -157
  135. openstackclient/tests/unit/volume/v3/test_block_storage_resource_filter.py +32 -23
  136. openstackclient/tests/unit/volume/v3/test_volume.py +50 -48
  137. openstackclient/tests/unit/volume/v3/test_volume_attachment.py +17 -47
  138. openstackclient/tests/unit/volume/v3/test_volume_group.py +23 -65
  139. openstackclient/tests/unit/volume/v3/test_volume_group_snapshot.py +88 -77
  140. openstackclient/tests/unit/volume/v3/test_volume_group_type.py +14 -42
  141. openstackclient/tests/unit/volume/v3/test_volume_message.py +10 -28
  142. openstackclient/volume/v1/volume.py +2 -14
  143. openstackclient/volume/v2/volume.py +30 -15
  144. openstackclient/volume/v2/volume_backend.py +10 -18
  145. openstackclient/volume/v2/volume_backup.py +18 -15
  146. openstackclient/volume/v2/volume_snapshot.py +2 -12
  147. openstackclient/volume/v2/volume_type.py +211 -14
  148. openstackclient/volume/v3/block_storage_manage.py +72 -11
  149. openstackclient/volume/v3/block_storage_resource_filter.py +33 -11
  150. openstackclient/volume/v3/volume_attachment.py +2 -14
  151. openstackclient/volume/v3/volume_group_snapshot.py +27 -27
  152. openstackclient/volume/v3/volume_message.py +2 -13
  153. {python_openstackclient-6.3.0.dist-info → python_openstackclient-6.5.0.dist-info}/AUTHORS +11 -0
  154. {python_openstackclient-6.3.0.dist-info → python_openstackclient-6.5.0.dist-info}/METADATA +6 -5
  155. {python_openstackclient-6.3.0.dist-info → python_openstackclient-6.5.0.dist-info}/RECORD +160 -151
  156. {python_openstackclient-6.3.0.dist-info → python_openstackclient-6.5.0.dist-info}/entry_points.txt +23 -5
  157. python_openstackclient-6.5.0.dist-info/pbr.json +1 -0
  158. openstackclient/tests/unit/common/test_parseractions.py +0 -233
  159. python_openstackclient-6.3.0.dist-info/pbr.json +0 -1
  160. {python_openstackclient-6.3.0.dist-info → python_openstackclient-6.5.0.dist-info}/LICENSE +0 -0
  161. {python_openstackclient-6.3.0.dist-info → python_openstackclient-6.5.0.dist-info}/WHEEL +0 -0
  162. {python_openstackclient-6.3.0.dist-info → python_openstackclient-6.5.0.dist-info}/top_level.txt +0 -0
@@ -81,3 +81,103 @@ def str2dict(strdict):
81
81
  key, sep, value = kv.partition(':')
82
82
  result[key] = value
83
83
  return result
84
+
85
+
86
+ def format_security_group_rule_show(obj):
87
+ data = transform_compute_security_group_rule(obj)
88
+ return zip(*sorted(data.items()))
89
+
90
+
91
+ def format_network_port_range(rule):
92
+ # Display port range or ICMP type and code. For example:
93
+ # - ICMP type: 'type=3'
94
+ # - ICMP type and code: 'type=3:code=0'
95
+ # - ICMP code: Not supported
96
+ # - Matching port range: '443:443'
97
+ # - Different port range: '22:24'
98
+ # - Single port: '80:80'
99
+ # - No port range: ''
100
+ port_range = ''
101
+ if is_icmp_protocol(rule['protocol']):
102
+ if rule['port_range_min']:
103
+ port_range += 'type=' + str(rule['port_range_min'])
104
+ if rule['port_range_max']:
105
+ port_range += ':code=' + str(rule['port_range_max'])
106
+ elif rule['port_range_min'] or rule['port_range_max']:
107
+ port_range_min = str(rule['port_range_min'])
108
+ port_range_max = str(rule['port_range_max'])
109
+ if rule['port_range_min'] is None:
110
+ port_range_min = port_range_max
111
+ if rule['port_range_max'] is None:
112
+ port_range_max = port_range_min
113
+ port_range = port_range_min + ':' + port_range_max
114
+ return port_range
115
+
116
+
117
+ def format_remote_ip_prefix(rule):
118
+ remote_ip_prefix = rule['remote_ip_prefix']
119
+ if remote_ip_prefix is None:
120
+ ethertype = rule['ether_type']
121
+ if ethertype == 'IPv4':
122
+ remote_ip_prefix = '0.0.0.0/0'
123
+ elif ethertype == 'IPv6':
124
+ remote_ip_prefix = '::/0'
125
+ return remote_ip_prefix
126
+
127
+
128
+ def convert_ipvx_case(string):
129
+ if string.lower() == 'ipv4':
130
+ return 'IPv4'
131
+ if string.lower() == 'ipv6':
132
+ return 'IPv6'
133
+ return string
134
+
135
+
136
+ def is_icmp_protocol(protocol):
137
+ # NOTE(rtheis): Neutron has deprecated protocol icmpv6.
138
+ # However, while the OSC CLI doesn't document the protocol,
139
+ # the code must still handle it. In addition, handle both
140
+ # protocol names and numbers.
141
+ if protocol in ['icmp', 'icmpv6', 'ipv6-icmp', '1', '58']:
142
+ return True
143
+ else:
144
+ return False
145
+
146
+
147
+ def convert_to_lowercase(string):
148
+ return string.lower()
149
+
150
+
151
+ def get_protocol(parsed_args, default_protocol='any'):
152
+ protocol = default_protocol
153
+ if parsed_args.protocol is not None:
154
+ protocol = parsed_args.protocol
155
+ if hasattr(parsed_args, "proto") and parsed_args.proto is not None:
156
+ protocol = parsed_args.proto
157
+ if protocol == 'any':
158
+ protocol = None
159
+ return protocol
160
+
161
+
162
+ def get_ethertype(parsed_args, protocol):
163
+ ethertype = 'IPv4'
164
+ if parsed_args.ethertype is not None:
165
+ ethertype = parsed_args.ethertype
166
+ elif is_ipv6_protocol(protocol):
167
+ ethertype = 'IPv6'
168
+ return ethertype
169
+
170
+
171
+ def is_ipv6_protocol(protocol):
172
+ # NOTE(rtheis): Neutron has deprecated protocol icmpv6.
173
+ # However, while the OSC CLI doesn't document the protocol,
174
+ # the code must still handle it. In addition, handle both
175
+ # protocol names and numbers.
176
+ if (
177
+ protocol is not None
178
+ and protocol.startswith('ipv6-')
179
+ or protocol in ['icmpv6', '41', '43', '44', '58', '59', '60']
180
+ ):
181
+ return True
182
+ else:
183
+ return False
@@ -0,0 +1,418 @@
1
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
2
+ # not use this file except in compliance with the License. You may obtain
3
+ # a copy of the License at
4
+ #
5
+ # http://www.apache.org/licenses/LICENSE-2.0
6
+ #
7
+ # Unless required by applicable law or agreed to in writing, software
8
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+ # License for the specific language governing permissions and limitations
11
+ # under the License.
12
+ #
13
+
14
+ """Default Security Group Rule action implementations"""
15
+
16
+ import logging
17
+
18
+ from osc_lib.cli import parseractions
19
+ from osc_lib.command import command
20
+ from osc_lib import exceptions
21
+ from osc_lib import utils
22
+
23
+ from openstackclient.i18n import _
24
+ from openstackclient.network import common
25
+ from openstackclient.network import utils as network_utils
26
+
27
+ LOG = logging.getLogger(__name__)
28
+
29
+
30
+ def _get_columns(item):
31
+ column_map = {}
32
+ hidden_columns = ['location', 'name', 'revision_number']
33
+ return utils.get_osc_show_columns_for_sdk_resource(
34
+ item, column_map, hidden_columns
35
+ )
36
+
37
+
38
+ class CreateDefaultSecurityGroupRule(
39
+ command.ShowOne, common.NeutronCommandWithExtraArgs
40
+ ):
41
+ """Add a new security group rule to the default security group template.
42
+
43
+ These rules will be applied to the default security groups created for any
44
+ new project. They will not be applied to any existing default security
45
+ groups.
46
+ """
47
+
48
+ def get_parser(self, prog_name):
49
+ parser = super().get_parser(prog_name)
50
+
51
+ parser.add_argument(
52
+ '--description',
53
+ metavar='<description>',
54
+ help=_("Set default security group rule description"),
55
+ )
56
+ parser.add_argument(
57
+ '--icmp-type',
58
+ metavar='<icmp-type>',
59
+ type=int,
60
+ help=_("ICMP type for ICMP IP protocols"),
61
+ )
62
+ parser.add_argument(
63
+ '--icmp-code',
64
+ metavar='<icmp-code>',
65
+ type=int,
66
+ help=_("ICMP code for ICMP IP protocols"),
67
+ )
68
+ direction_group = parser.add_mutually_exclusive_group()
69
+ direction_group.add_argument(
70
+ '--ingress',
71
+ action='store_true',
72
+ help=_("Rule will apply to incoming network traffic (default)"),
73
+ )
74
+ direction_group.add_argument(
75
+ '--egress',
76
+ action='store_true',
77
+ help=_("Rule will apply to outgoing network traffic"),
78
+ )
79
+ parser.add_argument(
80
+ '--ethertype',
81
+ metavar='<ethertype>',
82
+ choices=['IPv4', 'IPv6'],
83
+ type=network_utils.convert_ipvx_case,
84
+ help=_(
85
+ "Ethertype of network traffic "
86
+ "(IPv4, IPv6; default: based on IP protocol)"
87
+ ),
88
+ )
89
+ remote_group = parser.add_mutually_exclusive_group()
90
+ remote_group.add_argument(
91
+ "--remote-ip",
92
+ metavar="<ip-address>",
93
+ help=_(
94
+ "Remote IP address block (may use CIDR notation; "
95
+ "default for IPv4 rule: 0.0.0.0/0, "
96
+ "default for IPv6 rule: ::/0)"
97
+ ),
98
+ )
99
+ remote_group.add_argument(
100
+ "--remote-group",
101
+ metavar="<group>",
102
+ help=_("Remote security group (ID)"),
103
+ )
104
+ remote_group.add_argument(
105
+ "--remote-address-group",
106
+ metavar="<group>",
107
+ help=_("Remote address group (ID)"),
108
+ )
109
+
110
+ parser.add_argument(
111
+ '--dst-port',
112
+ metavar='<port-range>',
113
+ action=parseractions.RangeAction,
114
+ help=_(
115
+ "Destination port, may be a single port or a starting and "
116
+ "ending port range: 137:139. Required for IP protocols TCP "
117
+ "and UDP. Ignored for ICMP IP protocols."
118
+ ),
119
+ )
120
+ parser.add_argument(
121
+ '--protocol',
122
+ metavar='<protocol>',
123
+ type=network_utils.convert_to_lowercase,
124
+ help=_(
125
+ "IP protocol (ah, dccp, egp, esp, gre, icmp, igmp, "
126
+ "ipv66-encap, ipv6-frag, ipv6-icmp, ipv6-nonxt, ipv6-opts, "
127
+ "ipv6-route, ospf, pgm, rsvp, sctp, tcp, udp, udplite, vrrp "
128
+ "and integer representations [0-255] or any; "
129
+ "default: any (all protocols))"
130
+ ),
131
+ )
132
+ parser.add_argument(
133
+ '--for-default-sg',
134
+ action='store_true',
135
+ default=False,
136
+ help=_(
137
+ "Set this default security group rule to be used in all "
138
+ "default security groups created automatically for each "
139
+ "project"
140
+ ),
141
+ )
142
+ parser.add_argument(
143
+ '--for-custom-sg',
144
+ action='store_true',
145
+ default=True,
146
+ help=_(
147
+ "Set this default security group rule to be used in all "
148
+ "custom security groups created manually by users"
149
+ ),
150
+ )
151
+ return parser
152
+
153
+ def take_action(self, parsed_args):
154
+ client = self.app.client_manager.sdk_connection.network
155
+ # Build the create attributes.
156
+ attrs = {}
157
+ attrs['protocol'] = network_utils.get_protocol(parsed_args)
158
+
159
+ if parsed_args.description is not None:
160
+ attrs['description'] = parsed_args.description
161
+
162
+ # NOTE: A direction must be specified and ingress
163
+ # is the default.
164
+ if parsed_args.ingress or not parsed_args.egress:
165
+ attrs['direction'] = 'ingress'
166
+ if parsed_args.egress:
167
+ attrs['direction'] = 'egress'
168
+
169
+ # NOTE(rtheis): Use ethertype specified else default based
170
+ # on IP protocol.
171
+ attrs['ethertype'] = network_utils.get_ethertype(
172
+ parsed_args, attrs['protocol']
173
+ )
174
+
175
+ # NOTE(rtheis): Validate the port range and ICMP type and code.
176
+ # It would be ideal if argparse could do this.
177
+ if parsed_args.dst_port and (
178
+ parsed_args.icmp_type or parsed_args.icmp_code
179
+ ):
180
+ msg = _(
181
+ 'Argument --dst-port not allowed with arguments '
182
+ '--icmp-type and --icmp-code'
183
+ )
184
+ raise exceptions.CommandError(msg)
185
+ if parsed_args.icmp_type is None and parsed_args.icmp_code is not None:
186
+ msg = _('Argument --icmp-type required with argument --icmp-code')
187
+ raise exceptions.CommandError(msg)
188
+ is_icmp_protocol = network_utils.is_icmp_protocol(attrs['protocol'])
189
+ if not is_icmp_protocol and (
190
+ parsed_args.icmp_type or parsed_args.icmp_code
191
+ ):
192
+ msg = _(
193
+ 'ICMP IP protocol required with arguments '
194
+ '--icmp-type and --icmp-code'
195
+ )
196
+ raise exceptions.CommandError(msg)
197
+ # NOTE(rtheis): For backwards compatibility, continue ignoring
198
+ # the destination port range when an ICMP IP protocol is specified.
199
+ if parsed_args.dst_port and not is_icmp_protocol:
200
+ attrs['port_range_min'] = parsed_args.dst_port[0]
201
+ attrs['port_range_max'] = parsed_args.dst_port[1]
202
+ if parsed_args.icmp_type is not None and parsed_args.icmp_type >= 0:
203
+ attrs['port_range_min'] = parsed_args.icmp_type
204
+ if parsed_args.icmp_code is not None and parsed_args.icmp_code >= 0:
205
+ attrs['port_range_max'] = parsed_args.icmp_code
206
+
207
+ if parsed_args.remote_group is not None:
208
+ attrs['remote_group_id'] = parsed_args.remote_group
209
+ elif parsed_args.remote_address_group is not None:
210
+ attrs['remote_address_group_id'] = parsed_args.remote_address_group
211
+ elif parsed_args.remote_ip is not None:
212
+ attrs['remote_ip_prefix'] = parsed_args.remote_ip
213
+ elif attrs['ethertype'] == 'IPv4':
214
+ attrs['remote_ip_prefix'] = '0.0.0.0/0'
215
+ elif attrs['ethertype'] == 'IPv6':
216
+ attrs['remote_ip_prefix'] = '::/0'
217
+
218
+ attrs['used_in_default_sg'] = parsed_args.for_default_sg
219
+ attrs['used_in_non_default_sg'] = parsed_args.for_custom_sg
220
+
221
+ attrs.update(
222
+ self._parse_extra_properties(parsed_args.extra_properties)
223
+ )
224
+
225
+ # Create and show the security group rule.
226
+ obj = client.create_default_security_group_rule(**attrs)
227
+ display_columns, columns = _get_columns(obj)
228
+ data = utils.get_item_properties(obj, columns)
229
+ return (display_columns, data)
230
+
231
+
232
+ class DeleteDefaultSecurityGroupRule(command.Command):
233
+ """Remove security group rule(s) from the default security group template.
234
+
235
+ These rules will not longer be applied to the default security groups
236
+ created for any new project. They will not be removed from any existing
237
+ default security groups.
238
+ """
239
+
240
+ def get_parser(self, prog_name):
241
+ parser = super().get_parser(prog_name)
242
+ parser.add_argument(
243
+ 'rule',
244
+ metavar='<rule>',
245
+ nargs="+",
246
+ help=_("Default security group rule(s) to delete (ID only)"),
247
+ )
248
+ return parser
249
+
250
+ def take_action(self, parsed_args):
251
+ result = 0
252
+ client = self.app.client_manager.sdk_connection.network
253
+ for r in parsed_args.rule:
254
+ try:
255
+ obj = client.find_default_security_group_rule(
256
+ r, ignore_missing=False
257
+ )
258
+ client.delete_default_security_group_rule(obj)
259
+ except Exception as e:
260
+ result += 1
261
+ LOG.error(
262
+ _(
263
+ "Failed to delete default SG rule with "
264
+ "ID '%(rule_id)s': %(e)s"
265
+ ),
266
+ {'rule_id': r, 'e': e},
267
+ )
268
+
269
+ if result > 0:
270
+ total = len(parsed_args.rule)
271
+ msg = _(
272
+ "%(result)s of %(total)s default rules failed to delete."
273
+ ) % {'result': result, 'total': total}
274
+ raise exceptions.CommandError(msg)
275
+
276
+
277
+ class ListDefaultSecurityGroupRule(command.Lister):
278
+ """List security group rules used for new default security groups.
279
+
280
+ This shows the rules that will be added to any new default security groups
281
+ created. These rules may differ for the rules present on existing default
282
+ security groups.
283
+ """
284
+
285
+ def _format_network_security_group_rule(self, rule):
286
+ """Transform the SDK DefaultSecurityGroupRule object to a dict
287
+
288
+ The SDK object gets in the way of reformatting columns...
289
+ Create port_range column from port_range_min and port_range_max
290
+ """
291
+ rule = rule.to_dict()
292
+ rule['port_range'] = network_utils.format_network_port_range(rule)
293
+ rule['remote_ip_prefix'] = network_utils.format_remote_ip_prefix(rule)
294
+ return rule
295
+
296
+ def get_parser(self, prog_name):
297
+ parser = super().get_parser(prog_name)
298
+
299
+ parser.add_argument(
300
+ '--protocol',
301
+ metavar='<protocol>',
302
+ type=network_utils.convert_to_lowercase,
303
+ help=_(
304
+ "List rules by the IP protocol (ah, dhcp, egp, esp, gre, "
305
+ "icmp, igmp, ipv6-encap, ipv6-frag, ipv6-icmp, "
306
+ "ipv6-nonxt, ipv6-opts, ipv6-route, ospf, pgm, rsvp, "
307
+ "sctp, tcp, udp, udplite, vrrp and integer "
308
+ "representations [0-255] or any; "
309
+ "default: any (all protocols))"
310
+ ),
311
+ )
312
+ parser.add_argument(
313
+ '--ethertype',
314
+ metavar='<ethertype>',
315
+ type=network_utils.convert_to_lowercase,
316
+ help=_("List default rules by the Ethertype (IPv4 or IPv6)"),
317
+ )
318
+ direction_group = parser.add_mutually_exclusive_group()
319
+ direction_group.add_argument(
320
+ '--ingress',
321
+ action='store_true',
322
+ help=_(
323
+ "List default rules which will be applied to incoming "
324
+ "network traffic"
325
+ ),
326
+ )
327
+ direction_group.add_argument(
328
+ '--egress',
329
+ action='store_true',
330
+ help=_(
331
+ "List default rules which will be applied to outgoing "
332
+ "network traffic"
333
+ ),
334
+ )
335
+ return parser
336
+
337
+ def take_action(self, parsed_args):
338
+ client = self.app.client_manager.sdk_connection.network
339
+ column_headers = (
340
+ 'ID',
341
+ 'IP Protocol',
342
+ 'Ethertype',
343
+ 'IP Range',
344
+ 'Port Range',
345
+ 'Direction',
346
+ 'Remote Security Group',
347
+ 'Remote Address Group',
348
+ 'Used in default Security Group',
349
+ 'Used in custom Security Group',
350
+ )
351
+ columns = (
352
+ 'id',
353
+ 'protocol',
354
+ 'ether_type',
355
+ 'remote_ip_prefix',
356
+ 'port_range',
357
+ 'direction',
358
+ 'remote_group_id',
359
+ 'remote_address_group_id',
360
+ 'used_in_default_sg',
361
+ 'used_in_non_default_sg',
362
+ )
363
+
364
+ # Get the security group rules using the requested query.
365
+ query = {}
366
+ if parsed_args.ingress:
367
+ query['direction'] = 'ingress'
368
+ if parsed_args.egress:
369
+ query['direction'] = 'egress'
370
+ if parsed_args.protocol is not None:
371
+ query['protocol'] = parsed_args.protocol
372
+
373
+ rules = [
374
+ self._format_network_security_group_rule(r)
375
+ for r in client.default_security_group_rules(**query)
376
+ ]
377
+
378
+ return (
379
+ column_headers,
380
+ (
381
+ utils.get_dict_properties(
382
+ s,
383
+ columns,
384
+ )
385
+ for s in rules
386
+ ),
387
+ )
388
+
389
+
390
+ class ShowDefaultSecurityGroupRule(command.ShowOne):
391
+ """Show a security group rule used for new default security groups.
392
+
393
+ This shows a rule that will be added to any new default security groups
394
+ created. This rule may not be present on existing default security groups.
395
+ """
396
+
397
+ def get_parser(self, prog_name):
398
+ parser = super().get_parser(prog_name)
399
+ parser.add_argument(
400
+ 'rule',
401
+ metavar="<rule>",
402
+ help=_("Default security group rule to display (ID only)"),
403
+ )
404
+ return parser
405
+
406
+ def take_action(self, parsed_args):
407
+ client = self.app.client_manager.sdk_connection.network
408
+ obj = client.find_default_security_group_rule(
409
+ parsed_args.rule, ignore_missing=False
410
+ )
411
+ # necessary for old rules that have None in this field
412
+ if not obj['remote_ip_prefix']:
413
+ obj['remote_ip_prefix'] = network_utils.format_remote_ip_prefix(
414
+ obj
415
+ )
416
+ display_columns, columns = _get_columns(obj)
417
+ data = utils.get_item_properties(obj, columns)
418
+ return (display_columns, data)
@@ -124,7 +124,7 @@ class DeleteLocalIPAssociation(command.Command):
124
124
  "fixed port "
125
125
  "name or ID '%(fixed_port_id)s': %(e)s"
126
126
  ),
127
- {'fixed port ID': fixed_port_id, 'e': e},
127
+ {'fixed_port_id': fixed_port_id, 'e': e},
128
128
  )
129
129
 
130
130
  if result > 0:
@@ -129,7 +129,7 @@ class DeleteNDPProxy(command.Command):
129
129
  if result > 0:
130
130
  total = len(parsed_args.ndp_proxy)
131
131
  msg = _(
132
- "%(result)s of %(total)s NDP Proxy failed " "to delete."
132
+ "%(result)s of %(total)s NDP proxies failed " "to delete."
133
133
  ) % {'result': result, 'total': total}
134
134
  raise exceptions.CommandError(msg)
135
135
 
@@ -142,12 +142,16 @@ class ListNDPProxy(command.Lister):
142
142
  parser.add_argument(
143
143
  '--router',
144
144
  metavar='<router>',
145
- help=_("List only NDP proxies belong to this router (name or ID)"),
145
+ help=_(
146
+ "List only NDP proxies belonging to this router (name or ID)"
147
+ ),
146
148
  )
147
149
  parser.add_argument(
148
150
  '--port',
149
151
  metavar='<port>',
150
- help=_("List only NDP proxies assocate to this port (name or ID)"),
152
+ help=_(
153
+ "List only NDP proxies associated to this port (name or ID)"
154
+ ),
151
155
  )
152
156
  parser.add_argument(
153
157
  '--ip-address',
@@ -107,7 +107,7 @@ def _get_attrs_network(client_manager, parsed_args):
107
107
  attrs['availability_zone_hints'] = parsed_args.availability_zone_hints
108
108
 
109
109
  # set description
110
- if parsed_args.description:
110
+ if parsed_args.description is not None:
111
111
  attrs['description'] = parsed_args.description
112
112
 
113
113
  # set mtu
@@ -139,7 +139,7 @@ def _get_attrs_network(client_manager, parsed_args):
139
139
  if 'no_qos_policy' in parsed_args and parsed_args.no_qos_policy:
140
140
  attrs['qos_policy_id'] = None
141
141
  # Update DNS network options
142
- if parsed_args.dns_domain:
142
+ if parsed_args.dns_domain is not None:
143
143
  attrs['dns_domain'] = parsed_args.dns_domain
144
144
  return attrs
145
145