Skip to content

Commit 58f1c90

Browse files
Add source_ip_prefix and destination_ip_prefix to metering label rules
As proposed in the RFE and then approved in the spec, we are adding to the neutron metering rules two new parameters. The source IP prefix, and destination IP prefix. Partially-Implements: https://bugs.launchpad.net/neutron/+bug/1889431 RFE: https://bugs.launchpad.net/neutron/+bug/1889431 Depends-On: https://review.opendev.org/#/c/746586/ Change-Id: Ic44d88fabea0fffef2279f2f2c3d2b1da6426d4d
1 parent 95cc05b commit 58f1c90

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

openstackclient/network/v2/network_meter_rule.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def _get_attrs(client_manager, parsed_args):
4646
attrs['direction'] = 'egress'
4747
if parsed_args.remote_ip_prefix is not None:
4848
attrs['remote_ip_prefix'] = parsed_args.remote_ip_prefix
49+
if parsed_args.source_ip_prefix is not None:
50+
attrs['source_ip_prefix'] = parsed_args.source_ip_prefix
51+
if parsed_args.destination_ip_prefix is not None:
52+
attrs['destination_ip_prefix'] = parsed_args.destination_ip_prefix
4953
if parsed_args.meter is not None:
5054
attrs['metering_label_id'] = parsed_args.meter
5155
if parsed_args.project is not None:
@@ -97,9 +101,21 @@ def get_parser(self, prog_name):
97101
parser.add_argument(
98102
'--remote-ip-prefix',
99103
metavar='<remote-ip-prefix>',
100-
required=True,
104+
required=False,
101105
help=_('The remote IP prefix to associate with this rule'),
102106
)
107+
parser.add_argument(
108+
'--source-ip-prefix',
109+
metavar='<remote-ip-prefix>',
110+
required=False,
111+
help=_('The source IP prefix to associate with this rule'),
112+
)
113+
parser.add_argument(
114+
'--destination-ip-prefix',
115+
metavar='<remote-ip-prefix>',
116+
required=False,
117+
help=_('The destination IP prefix to associate with this rule'),
118+
)
103119
parser.add_argument(
104120
'meter',
105121
metavar='<meter>',
@@ -168,12 +184,16 @@ def take_action(self, parsed_args):
168184
'excluded',
169185
'direction',
170186
'remote_ip_prefix',
187+
'source_ip_prefix',
188+
'destination_ip_prefix',
171189
)
172190
column_headers = (
173191
'ID',
174192
'Excluded',
175193
'Direction',
176194
'Remote IP Prefix',
195+
'Source IP Prefix',
196+
'Destination IP Prefix',
177197
)
178198
data = client.metering_label_rules()
179199
return (column_headers,

openstackclient/tests/unit/network/v2/fakes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,8 @@ def create_one_rule(attrs=None):
15901590
'excluded': False,
15911591
'metering_label_id': 'meter-label-id-' + uuid.uuid4().hex,
15921592
'remote_ip_prefix': '10.0.0.0/24',
1593+
'source_ip_prefix': '8.8.8.8/32',
1594+
'destination_ip_prefix': '10.0.0.0/24',
15931595
'tenant_id': 'project-id-' + uuid.uuid4().hex,
15941596
}
15951597

openstackclient/tests/unit/network/v2/test_network_meter_rule.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,24 @@ class TestCreateMeterRule(TestMeterRule):
4242
)
4343

4444
columns = (
45+
'destination_ip_prefix',
4546
'direction',
4647
'excluded',
4748
'id',
4849
'metering_label_id',
4950
'project_id',
5051
'remote_ip_prefix',
52+
'source_ip_prefix',
5153
)
5254
data = (
55+
new_rule.destination_ip_prefix,
5356
new_rule.direction,
5457
new_rule.excluded,
5558
new_rule.id,
5659
new_rule.metering_label_id,
5760
new_rule.project_id,
5861
new_rule.remote_ip_prefix,
62+
new_rule.source_ip_prefix,
5963
)
6064

6165
def setUp(self):
@@ -228,6 +232,8 @@ class TestListMeterRule(TestMeterRule):
228232
'Excluded',
229233
'Direction',
230234
'Remote IP Prefix',
235+
'Source IP Prefix',
236+
'Destination IP Prefix'
231237
)
232238

233239
data = []
@@ -238,6 +244,8 @@ class TestListMeterRule(TestMeterRule):
238244
rule.excluded,
239245
rule.direction,
240246
rule.remote_ip_prefix,
247+
rule.source_ip_prefix,
248+
rule.destination_ip_prefix
241249
))
242250

243251
def setUp(self):
@@ -270,21 +278,25 @@ class TestShowMeterRule(TestMeterRule):
270278
)
271279

272280
columns = (
281+
'destination_ip_prefix',
273282
'direction',
274283
'excluded',
275284
'id',
276285
'metering_label_id',
277286
'project_id',
278287
'remote_ip_prefix',
288+
'source_ip_prefix',
279289
)
280290

281291
data = (
292+
new_rule.destination_ip_prefix,
282293
new_rule.direction,
283294
new_rule.excluded,
284295
new_rule.id,
285296
new_rule.metering_label_id,
286297
new_rule.project_id,
287298
new_rule.remote_ip_prefix,
299+
new_rule.source_ip_prefix,
288300
)
289301

290302
def setUp(self):

0 commit comments

Comments
 (0)