674813574961515276b5ae751e70af8cdc783d64
[fuel.git] / mcp / patches / 0001-maasng-Allow-fabric-ID-to-be-determined-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: Fri, 29 Jun 2018 02:48:55 +0200
11 Subject: [PATCH] maasng: Allow fabric ID to be determined from CIDR
12
13 MaaS usually creates network resources (e.g. subnets, fabrics)
14 automatically based on existing network interface definitions.
15 However, the fabric naming is not guaranteed across deployments,
16 so the same interface/subnet CIDR might end up as 'fabric-2' or
17 'fabric-5' depending on non-deterministic factors.
18
19 To allow configuring VLAN DHCP on such network segments we need a
20 mechanism that does not hardcode the fabric ID in pillar data, but
21 instead determines it at runtime based on subnet CIDR.
22
23 maasng module: Fix 'name' arg in update_vlan
24
25 name argument is silently overridden to use the state name if the
26 value passed is not a string, leading to all kinds of breakage.
27
28 While at it, default to using the VLAN ID as the name if not
29 explicitly set.
30
31 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
32 ---
33  _modules/maasng.py |  7 ++++++-
34  maas/region.sls    | 15 ++++++++++++++-
35  3 files changed, 39 insertions(+), 3 deletions(-)
36
37 diff --git a/_modules/maasng.py b/_modules/maasng.py
38 index ce8e99e..706c0ec 100644
39 --- a/_modules/maasng.py
40 +++ b/_modules/maasng.py
41 @@ -966,7 +966,12 @@ def get_fabricid(fabric):
42      try:
43          return list_fabric()[fabric]['id']
44      except KeyError:
45 -        return {"error": "Frabic not found on MaaS server"}
46 +        # fabric might be specified as CIDR, try to find the actual fabric ID
47 +        maas_subnets = list_subnet()
48 +        for subnet in maas_subnets.keys():
49 +            if maas_subnets[subnet]['cidr'] == fabric:
50 +                return maas_subnets[subnet]['vlan']['fabric_id']
51 +        return {"error": "Fabric not found on MaaS server"}
52
53
54  def update_vlan(name, fabric, vid, description, primary_rack, dhcp_on=False):
55 diff --git a/maas/region.sls b/maas/region.sls
56 index f50b901..71bfefa 100644
57 --- a/maas/region.sls
58 +++ b/maas/region.sls
59 @@ -305,6 +305,19 @@ maas_create_subnet_{{ subnet_name }}:
60      {%- endif %}
61  {%- endfor %}
62
63 +{%- for subnet_name, subnet in region.subnets.iteritems() %}
64 +{%- for vid, vlan in subnet.get('vlan', {}).items() %}
65 +maas_update_vlan_for_{{ subnet_name }}_{{ vid }}:
66 +  maasng.update_vlan:
67 +  - vid: {{ vid }}
68 +  - fabric: {{ subnet.cidr }}
69 +  - name: '{{ vlan.get('name', vid) }}'
70 +  - description: {{ vlan.description }}
71 +  - primary_rack: {{ region.maas_config.maas_name }}
72 +  - dhcp_on: {{ vlan.get('dhcp','False') }}
73 +{%- endfor %}
74 +{%- endfor %}
75 +
76  {%- for subnet_name, subnet in region.subnets.iteritems() %}
77  {%- if subnet.get('multiple') == True %}
78  {%- for range_name, iprange in subnet.get('iprange',{}).items() %}
79 @@ -375,7 +388,7 @@ maas_update_vlan_for_{{ fabric_name }}_{{ vid }}:
80    maasng.update_vlan:
81    - vid: {{ vid }}
82    - fabric: {{ fabric_name }}
83 -  - name: {{ vlan.get('name','') }}
84 +  - name: '{{ vlan.get('name', vid) }}'
85    - description: {{ vlan.description }}
86    - primary_rack: {{ region.maas_config.maas_name }}
87    - dhcp_on: {{ vlan.get('dhcp','False') }}