commit 878a8d944d125a650c3e1b45d7e4ebfaa2aa04e7 Author: Rafael Weingärtner Date: Mon Aug 17 15:20:51 2020 -0300 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/746203/ Depends-On: https://review.opendev.org/#/c/744702/ Depends-On: https://review.opendev.org/#/c/743828/ Depends-On: https://review.opendev.org/#/c/746142/ Depends-On: https://review.opendev.org/#/c/746347/ Change-Id: Ib288e276fbe5337e2dfc92a8f0f11dfcb425322b diff --git a/openstack/network/v2/metering_label_rule.py b/openstack/network/v2/metering_label_rule.py index acc8100..3016709 100644 --- a/openstack/network/v2/metering_label_rule.py +++ b/openstack/network/v2/metering_label_rule.py @@ -27,7 +27,7 @@ class MeteringLabelRule(resource.Resource): _query_mapping = resource.QueryParameters( 'direction', 'metering_label_id', 'remote_ip_prefix', - project_id='tenant_id', + 'source_ip_prefix', 'destination_ip_prefix', project_id='tenant_id', ) # Properties @@ -52,3 +52,8 @@ class MeteringLabelRule(resource.Resource): "'source_ip_prefix' and/or 'destination_ip_prefix' " "parameters. For more details, you can check the " "spec: https://review.opendev.org/#/c/744702/.") + + #: The source IP prefix to be associated with this metering label rule. + source_ip_prefix = resource.Body('source_ip_prefix') + #: The destination IP prefix to be associated with this metering label rule + destination_ip_prefix = resource.Body('destination_ip_prefix') diff --git a/openstack/tests/unit/network/v2/test_metering_label_rule.py b/openstack/tests/unit/network/v2/test_metering_label_rule.py index ce3057e..c11f283 100644 --- a/openstack/tests/unit/network/v2/test_metering_label_rule.py +++ b/openstack/tests/unit/network/v2/test_metering_label_rule.py @@ -46,3 +46,23 @@ class TestMeteringLabelRule(base.TestCase): self.assertEqual(EXAMPLE['metering_label_id'], sot.metering_label_id) self.assertEqual(EXAMPLE['tenant_id'], sot.project_id) self.assertEqual(EXAMPLE['remote_ip_prefix'], sot.remote_ip_prefix) + + def test_make_it_source_and_destination(self): + custom_example = EXAMPLE.copy() + custom_example["source_ip_prefix"] = "192.168.0.11/32" + custom_example["destination_ip_prefix"] = "0.0.0.0/0" + + sot = metering_label_rule.MeteringLabelRule(**custom_example) + self.assertEqual(custom_example['direction'], sot.direction) + self.assertFalse(sot.is_excluded) + self.assertEqual(custom_example['id'], sot.id) + self.assertEqual( + custom_example['metering_label_id'], sot.metering_label_id) + self.assertEqual(custom_example['tenant_id'], sot.project_id) + self.assertEqual( + custom_example['remote_ip_prefix'], sot.remote_ip_prefix) + + self.assertEqual( + custom_example['source_ip_prefix'], sot.source_ip_prefix) + self.assertEqual( + custom_example['destination_ip_prefix'], sot.destination_ip_prefix) diff --git a/releasenotes/notes/introduce-source-and-destination-ip-prefixes-into-metering-label-rules-e04b797adac5d0d0.yaml b/releasenotes/notes/introduce-source-and-destination-ip-prefixes-into-metering-label-rules-e04b797adac5d0d0.yaml new file mode 100644 index 0000000..5de538b --- /dev/null +++ b/releasenotes/notes/introduce-source-and-destination-ip-prefixes-into-metering-label-rules-e04b797adac5d0d0.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``source_ip_prefix`` and ``destination_ip_prefix`` to Neutron metering + label rules. \ No newline at end of file