aboutsummaryrefslogtreecommitdiffstats
path: root/tests/ci/docker
diff options
context:
space:
mode:
authorliang gao <jean.gaoliang@huawei.com>2016-06-30 02:17:16 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-06-30 02:17:17 +0000
commit41dde94d0a4e575317c297e124ba0624e64c8552 (patch)
tree8e81abfb6ffcc8ea8fa2bf3dd2e0c4c472f5980f /tests/ci/docker
parent8a4f8df64b8897bf38e77399099099f92266048b (diff)
parent54eae8aa5db86a983d721f08dd12d7f187af1a09 (diff)
Merge "Change floating ip association method"
Diffstat (limited to 'tests/ci/docker')
0 files changed, 0 insertions, 0 deletions
bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
: Copyright (c) 2018 Mirantis Inc., Enea AB and others.
:
: All rights reserved. This program and the accompanying materials
: are made available under the terms of the Apache License, Version 2.0
: which accompanies this distribution, and is available at
: http://www.apache.org/licenses/LICENSE-2.0
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
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
--- a/_modules/maas.py
+++ b/_modules/maas.py
@@ -126,6 +126,8 @@

             def process_single(name, config_data):
                 self._update = False
+                if isinstance(config_data, dict) and 'name' in config_data:
+                    name = config_data['name']
                 try:
                     data = self.fill_data(name, config_data, **extra)
                     if data is None:
@@ -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)