From 6e4831cc4950ff75f1e278511a66ccb30449e384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Harald=20Jens=C3=A5s?= Date: Wed, 9 May 2018 01:47:50 +0200 Subject: [PATCH] Add segments attribute to OS::Neutron::Net Adds a attribute to the neutron Net resource to get the segments of a network. Story: 2001988 Task: 19610 Change-Id: I7acb3d29a01fa92bebdb2c85094655e27cb16a29 --- .../engine/resources/openstack/neutron/net.py | 20 +++++++++++++++++-- .../openstack/neutron/test_neutron_net.py | 4 ++-- ...k-attribute-segments-984ec5b3e75d657b.yaml | 14 +++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/network-attribute-segments-984ec5b3e75d657b.yaml diff --git a/heat/engine/resources/openstack/neutron/net.py b/heat/engine/resources/openstack/neutron/net.py index 00f61b0f10..62a19e1ff7 100644 --- a/heat/engine/resources/openstack/neutron/net.py +++ b/heat/engine/resources/openstack/neutron/net.py @@ -42,10 +42,12 @@ class Net(neutron.NeutronResource): ATTRIBUTES = ( STATUS, NAME_ATTR, SUBNETS, ADMIN_STATE_UP_ATTR, TENANT_ID_ATTR, - PORT_SECURITY_ENABLED_ATTR, MTU_ATTR, QOS_POLICY_ATTR, L2_ADJACENCY + PORT_SECURITY_ENABLED_ATTR, MTU_ATTR, QOS_POLICY_ATTR, L2_ADJACENCY, + SEGMENTS, ) = ( "status", "name", "subnets", "admin_state_up", "tenant_id", - "port_security_enabled", "mtu", 'qos_policy_id', 'l2_adjacency' + "port_security_enabled", "mtu", 'qos_policy_id', 'l2_adjacency', + 'segments', ) properties_schema = { @@ -167,6 +169,11 @@ class Net(neutron.NeutronResource): type=attributes.Schema.BOOLEAN, support_status=support.SupportStatus(version='9.0.0'), ), + SEGMENTS: attributes.Schema( + _("The segments of this network."), + type=attributes.Schema.LIST, + support_status=support.SupportStatus(version='11.0.0'), + ), } def translation_rules(self, properties): @@ -273,6 +280,15 @@ class Net(neutron.NeutronResource): pass return result + def _resolve_attribute(self, name): + if self.resource_id is None: + return + if name == self.SEGMENTS: + return [segment.to_dict() for segment in list(self.client( + 'openstack').network.segments(network_id=self.resource_id))] + attributes = self._show_resource() + return attributes[name] + def resource_mapping(): return { diff --git a/heat/tests/openstack/neutron/test_neutron_net.py b/heat/tests/openstack/neutron/test_neutron_net.py index 65fbc3f457..0937de51b8 100644 --- a/heat/tests/openstack/neutron/test_neutron_net.py +++ b/heat/tests/openstack/neutron/test_neutron_net.py @@ -27,7 +27,7 @@ from heat.tests import utils neutron_template = ''' -heat_template_version: 2015-04-30 +heat_template_version: rocky description: Template to test network Neutron resource resources: network: @@ -288,7 +288,7 @@ class NeutronNetTest(common.HeatTestCase): def test_net_get_live_state(self): tmpl = """ - heat_template_version: 2015-10-15 + heat_template_version: rocky resources: net: type: OS::Neutron::Net diff --git a/releasenotes/notes/network-attribute-segments-984ec5b3e75d657b.yaml b/releasenotes/notes/network-attribute-segments-984ec5b3e75d657b.yaml new file mode 100644 index 0000000000..c32826fbda --- /dev/null +++ b/releasenotes/notes/network-attribute-segments-984ec5b3e75d657b.yaml @@ -0,0 +1,14 @@ +--- +features: + - | + Adds a new attribute ``segments`` to the ``OS::Neutron::Net`` resource. + The attribute resolves the network segments on the network. The attribute + is useful when migrating from a non routed provider network to a routed + provider network. The example below show how to migrate an existing subnet + to one that is associated with the segment:: + + TestSubnet: + type: OS::Neutron::Subnet + name: the_subnet + properties: + segment: {get_attr: [the_network, segments, 0, id]}