[virtual/odl] Apply missing neutron.compute state
[fuel.git] / mcp / patches / 0005-maas-module-Obtain-fabric-ID-from-CIDR.patch
1 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2 : Copyright (c) 2018 Mirantis Inc., Enea AB and others.
3 :
4 : All rights reserved. This program and the accompanying materials
5 : are made available under the terms of the Apache License, Version 2.0
6 : which accompanies this distribution, and is available at
7 : http://www.apache.org/licenses/LICENSE-2.0
8 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
9 From: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
10 Date: Sat, 19 Aug 2017 02:03:01 +0200
11 Subject: [PATCH] maas: module: Obtain fabric ID from CIDR
12
13 MaaS subnet update requires specifying the correct fabric via reclass,
14 which we used to hardcode in our OPNFV reclass model to fabric-2.
15 However, fabric index numbers are not deterministic, so the old
16 method is unreliable.
17
18 Update MaaS custom py module to determine fabric name/ID on the
19 fly, based on CIDR matching (assuming we don't have CIDR conflicts).
20
21 This change maintains backwards compatibility:
22 - if fabric is specified via reclass model, it will be used as-is;
23 - if fabric is not specified via reclass model, we try to deduce it
24   based on CIDR; if no match is found, the old default ('') is used;
25
26 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
27 Signed-off-by: Guillermo Herrero <Guillermo.Herrero@enea.com>
28 ---
29
30 diff --git a/_modules/maas.py b/_modules/maas.py
31 --- a/_modules/maas.py
32 +++ b/_modules/maas.py
33 @@ -126,6 +126,8 @@
34
35              def process_single(name, config_data):
36                  self._update = False
37 +                if isinstance(config_data, dict) and 'name' in config_data:
38 +                    name = config_data['name']
39                  try:
40                      data = self.fill_data(name, config_data, **extra)
41                      if data is None:
42 @@ -198,7 +198,8 @@
43      def fill_data(self, name, subnet, fabrics):
44          data = {
45              'name': name,
46 -            'fabric': str(fabrics[subnet.get('fabric', '')]),
47 +            'fabric': str(fabrics[subnet.get('fabric',
48 +                self._get_fabric_from_cidr(subnet.get('cidr')))]),
49              'cidr': subnet.get('cidr'),
50              'gateway_ip': subnet['gateway_ip'],
51          }
52 @@ -215,6 +216,13 @@
53          self._process_iprange(res_json['id'])
54          return response
55
56 +    def _get_fabric_from_cidr(self, cidr):
57 +        subnets = json.loads(self._maas.get(u'api/2.0/subnets/').read())
58 +        for subnet in subnets:
59 +            if subnet['cidr'] == cidr:
60 +                return subnet['vlan']['fabric']
61 +        return ''
62 +
63      def _process_iprange(self, subnet_id):
64          ipranges = json.loads(self._maas.get(u'api/2.0/ipranges/').read())
65          LOG.warn('all %s ipranges %s', subnet_id, ipranges)