diff options
author | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2017-08-19 23:33:42 +0200 |
---|---|---|
committer | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2017-08-19 23:43:17 +0200 |
commit | 8c6d4ba39ff626c5f24bd84a2958b07692ea0294 (patch) | |
tree | 22b7ba5c6c2a44ab9487287897a7511a0cd01dec /mcp/patches/0005-maas-module-Obtain-fabric-ID-from-CIDR.patch | |
parent | 30b1f3bdaa5de7e52d41a13d231d2bca3838e449 (diff) |
MaaS: Add support for dynamic fabric numbering
Previously, we hardcoded the fabric name for our 3rd interface
(which serves PXE/DHCP for the target nodes) to "fabric-2",
relying on predictable index numbers to be provided by MaaS based
on the interfaces defined in /etc/network/interfaces.
However, the fabric IDs/names generated by MaaS are not predictable,
and therefore cannot be hardcoded in our reclass model / scripts.
Work around this by:
- adding support for fabric ID deduction based on CIDR matching
during subnet create/update operation in MaaS py module;
- adding support for VLAN DHCP enablement to MaaS py module,
which was previously handled via shell MaaS API operations
from maas/region.sls;
While at it, revert previous commit that disabled network discovery
("MaaS: Disable network discovery"), since it turns out that network
discovery was not the culprit for subnet creation failure, but wrong
fabric numbering.
This reverts commit 8cdf22d1a1bae4694a373873cab4feb6251069b7.
Change-Id: I15fa059004356cb4aaabb38999ea378dd3c0e0bb
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
Diffstat (limited to 'mcp/patches/0005-maas-module-Obtain-fabric-ID-from-CIDR.patch')
-rw-r--r-- | mcp/patches/0005-maas-module-Obtain-fabric-ID-from-CIDR.patch | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/mcp/patches/0005-maas-module-Obtain-fabric-ID-from-CIDR.patch b/mcp/patches/0005-maas-module-Obtain-fabric-ID-from-CIDR.patch new file mode 100644 index 000000000..5c77a63da --- /dev/null +++ b/mcp/patches/0005-maas-module-Obtain-fabric-ID-from-CIDR.patch @@ -0,0 +1,49 @@ +From: Alexandru Avadanii <Alexandru.Avadanii@enea.com> +Date: Sat, 19 Aug 2017 02:03:01 +0200 +Subject: [PATCH] maas: module: Obtain fabric ID from CIDR + +MaaS subnet update requires specifying the correct fabric via reclass, +which we used to hardcode in our OPNFV reclass model to fabric-2. +However, fabric index numbers are not deterministic, so the old +method is unreliable. + +Update MaaS custom py module to determine fabric name/ID on the +fly, based on CIDR matching (assuming we don't have CIDR conflicts). + +This change maintains backwards compatibility: +- if fabric is specified via reclass model, it will be used as-is; +- if fabric is not specified via reclass model, we try to deduce it + based on CIDR; if no match is found, the old default ('') is used; + +Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com> +Signed-off-by: Guillermo Herrero <Guillermo.Herrero@enea.com> +--- + +diff --git a/_modules/maas.py b/_modules/maas.py +index d3227ca..8a2243d 100644 +--- a/_modules/maas.py ++++ b/_modules/maas.py +@@ -198,7 +198,8 @@ + def fill_data(self, name, subnet, fabrics): + data = { + 'name': name, +- 'fabric': str(fabrics[subnet.get('fabric', '')]), ++ 'fabric': str(fabrics[subnet.get('fabric', ++ self._get_fabric_from_cidr(subnet.get('cidr')))]), + 'cidr': subnet.get('cidr'), + 'gateway_ip': subnet['gateway_ip'], + } +@@ -215,6 +216,13 @@ + self._process_iprange(res_json['id']) + return response + ++ def _get_fabric_from_cidr(self, cidr): ++ subnets = json.loads(self._maas.get(u'api/2.0/subnets/').read()) ++ for subnet in subnets: ++ if subnet['cidr'] == cidr: ++ return subnet['vlan']['fabric'] ++ return '' ++ + def _process_iprange(self, subnet_id): + ipranges = json.loads(self._maas.get(u'api/2.0/ipranges/').read()) + LOG.warn('all %s ipranges %s', subnet_id, ipranges) |