Browse Source

fixed_ips for PT and reuse_bd option for L2P

fixed_ips option was added to the GBP neutron mapping
a while back and is similar to the fixed_ips option
for the Neutron Port.

The reuse_bd option is used by the apic driver.

Change-Id: Ie3f76ac4b9ed04354079e28a6be911b85856cc6b
Sumit Naiksatam 2 years ago
parent
commit
77b2787cdd

+ 53
- 8
gbpautomation/heat/engine/resources/grouppolicy.py View File

@@ -25,16 +25,22 @@ class PolicyTarget(gbpresource.GBPResource):
25 25
 
26 26
     PROPERTIES = (
27 27
         TENANT_ID, NAME, DESCRIPTION, POLICY_TARGET_GROUP_ID,
28
-        PORT_ID
28
+        PORT_ID, FIXED_IPS
29 29
     ) = (
30 30
         'tenant_id', 'name', 'description', 'policy_target_group_id',
31
-        'port_id'
31
+        'port_id', 'fixed_ips'
32
+    )
33
+
34
+    _FIXED_IP_KEYS = (
35
+        FIXED_IP_SUBNET_ID, FIXED_IP_IP_ADDRESS,
36
+    ) = (
37
+        'subnet_id', 'ip_address',
32 38
     )
33 39
 
34 40
     ATTRIBUTES = (
35
-        PORT_ID_ATTR
41
+        PORT_ID_ATTR, FIXED_IPS_ATTR
36 42
     ) = (
37
-        'port_id'
43
+        'port_id', 'fixed_ips'
38 44
     )
39 45
 
40 46
     properties_schema = {
@@ -62,13 +68,39 @@ class PolicyTarget(gbpresource.GBPResource):
62 68
             properties.Schema.STRING,
63 69
             _('Neutron port id of the policy target.'),
64 70
             update_allowed=False
65
-        )
71
+        ),
72
+        FIXED_IPS: properties.Schema(
73
+            properties.Schema.LIST,
74
+            _('Desired IPs for this port.'),
75
+            default=[],
76
+            schema=properties.Schema(
77
+                properties.Schema.MAP,
78
+                schema={
79
+                    FIXED_IP_SUBNET_ID: properties.Schema(
80
+                        properties.Schema.STRING,
81
+                        _('Subnet ID to associate with this interface.'),
82
+                    ),
83
+                    FIXED_IP_IP_ADDRESS: properties.Schema(
84
+                        properties.Schema.STRING,
85
+                        _('IP address desired in the subnet for this port.'),
86
+                        constraints=[
87
+                            constraints.CustomConstraint('ip_addr')
88
+                        ]
89
+                    ),
90
+                },
91
+            ),
92
+            update_allowed=True
93
+        ),
66 94
     }
67 95
 
68 96
     attributes_schema = {
69 97
         PORT_ID_ATTR: attributes.Schema(
70 98
             _('Neutron port id of this policy target.')
71
-        )
99
+        ),
100
+        FIXED_IPS_ATTR: attributes.Schema(
101
+            _("Fixed IP addresses."),
102
+            type=attributes.Schema.LIST
103
+        ),
72 104
     }
73 105
 
74 106
     def _show_resource(self):
@@ -83,6 +115,7 @@ class PolicyTarget(gbpresource.GBPResource):
83 115
         for key in self.properties:
84 116
             if self.properties.get(key) is not None:
85 117
                 props[key] = self.properties.get(key)
118
+        self._prepare_port_properties(props)
86 119
 
87 120
         pt = client.create_policy_target(
88 121
             {'policy_target': props})['policy_target']
@@ -106,6 +139,12 @@ class PolicyTarget(gbpresource.GBPResource):
106 139
             self.grouppolicy().update_policy_target(
107 140
                 self.resource_id, {'policy_target': prop_diff})
108 141
 
142
+    def _prepare_port_properties(self, props):
143
+        for fixed_ip in props.get(self.FIXED_IPS, []):
144
+            for key, value in list(fixed_ip.items()):
145
+                if value is None:
146
+                    fixed_ip.pop(key)
147
+
109 148
 
110 149
 class PolicyTargetGroup(gbpresource.GBPResource):
111 150
 
@@ -258,9 +297,10 @@ class PolicyTargetGroup(gbpresource.GBPResource):
258 297
 class L2Policy(gbpresource.GBPResource):
259 298
 
260 299
     PROPERTIES = (
261
-        TENANT_ID, NAME, DESCRIPTION, L3_POLICY_ID, SHARED
300
+        TENANT_ID, NAME, DESCRIPTION, L3_POLICY_ID, SHARED, REUSE_BD
262 301
     ) = (
263
-        'tenant_id', 'name', 'description', 'l3_policy_id', 'shared'
302
+        'tenant_id', 'name', 'description', 'l3_policy_id', 'shared',
303
+        'reuse_bd'
264 304
     )
265 305
 
266 306
     properties_schema = {
@@ -288,6 +328,11 @@ class L2Policy(gbpresource.GBPResource):
288 328
             properties.Schema.BOOLEAN,
289 329
             _('Shared.'),
290 330
             update_allowed=True, required=True
331
+        ),
332
+        REUSE_BD: properties.Schema(
333
+            properties.Schema.STRING,
334
+            _('Existing L2P ID in same L3P.'),
335
+            default=None, update_allowed=False
291 336
         )
292 337
     }
293 338
 

+ 22
- 6
gbpautomation/heat/tests/test_grouppolicy.py View File

@@ -34,7 +34,12 @@ policy_target_template = '''
34 34
       "Properties": {
35 35
         "name": "test-policy-target",
36 36
         "policy_target_group_id": "ptg-id",
37
-        "description": "test policy target resource"
37
+        "description": "test policy target resource",
38
+        "port_id": "some-port-id",
39
+        "fixed_ips": [{
40
+          "subnet_id": "test-subnet",
41
+          "ip_address": "10.0.3.21"
42
+        }]
38 43
       }
39 44
     }
40 45
   }
@@ -84,7 +89,8 @@ l2_policy_template = '''
84 89
         "name": "test-l2-policy",
85 90
         "description": "test L2 policy resource",
86 91
         "l3_policy_id": "l3-policy-id",
87
-        "shared": True
92
+        "shared": True,
93
+        "reuse_bd": "other-l2p"
88 94
       }
89 95
     }
90 96
   }
@@ -318,7 +324,11 @@ class PolicyTargetTest(HeatTestCase):
318 324
             'policy_target': {
319 325
                 'name': 'test-policy-target',
320 326
                 'policy_target_group_id': 'ptg-id',
321
-                "description": "test policy target resource"
327
+                "description": "test policy target resource",
328
+                "port_id": "some-port-id",
329
+                'fixed_ips': [
330
+                    {'subnet_id': u'test-subnet', 'ip_address': u'10.0.3.21'}
331
+                ],
322 332
             }
323 333
         }).AndReturn({'policy_target': {'id': '5678'}})
324 334
 
@@ -340,7 +350,11 @@ class PolicyTargetTest(HeatTestCase):
340 350
             'policy_target': {
341 351
                 'name': 'test-policy-target',
342 352
                 'policy_target_group_id': 'ptg-id',
343
-                "description": "test policy target resource"
353
+                "description": "test policy target resource",
354
+                "port_id": "some-port-id",
355
+                'fixed_ips': [
356
+                    {'subnet_id': u'test-subnet', 'ip_address': u'10.0.3.21'}
357
+                ],
344 358
             }
345 359
         }).AndRaise(grouppolicy.NeutronClientException())
346 360
         self.m.ReplayAll()
@@ -610,7 +624,8 @@ class L2PolicyTest(HeatTestCase):
610 624
                 "name": "test-l2-policy",
611 625
                 "description": "test L2 policy resource",
612 626
                 "l3_policy_id": "l3-policy-id",
613
-                "shared": True
627
+                "shared": True,
628
+                "reuse_bd": "other-l2p",
614 629
             }
615 630
         }).AndReturn({'l2_policy': {'id': '5678'}})
616 631
 
@@ -633,7 +648,8 @@ class L2PolicyTest(HeatTestCase):
633 648
                 "name": "test-l2-policy",
634 649
                 "description": "test L2 policy resource",
635 650
                 "l3_policy_id": "l3-policy-id",
636
-                "shared": True
651
+                "shared": True,
652
+                "reuse_bd": "other-l2p",
637 653
             }
638 654
         }).AndRaise(grouppolicy.NeutronClientException())
639 655
         self.m.ReplayAll()

+ 1
- 0
test-requirements.txt View File

@@ -17,6 +17,7 @@ oslotest>=1.10.0 # Apache-2.0
17 17
 paramiko>=1.16.0 # LGPL
18 18
 qpid-python;python_version=='2.7' # Apache-2.0
19 19
 psycopg2>=2.5 # LGPL/ZPL
20
+python-troveclient<2.6.0
20 21
 sphinx!=1.2.0,!=1.3b1,<1.3,>=1.1.2 # BSD
21 22
 testrepository>=0.0.18 # Apache-2.0/BSD
22 23
 testscenarios>=0.4 # Apache-2.0/BSD

Loading…
Cancel
Save