1 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2 : Copyright (c) 2017 Mirantis Inc., Enea AB and others.
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: Add VLAN DHCP enable support
13 MaaS custom py module does not support VLAN configuration.
14 This should be implemented by adding a dedicated class for VLAN.
15 However, we are only interested in updating an existign VLAN to
16 enable DHCP on an existing IP range (set up via subnet configuration),
17 so extend existing subnet handling to include basic VLAN update.
19 NOTE: Design-wise, this is hacky, and its only purpose is to allow
20 setting 'dhcp_on=True' for an existing VLAN.
22 Example reclass model usage:
34 Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
37 diff --git a/_modules/maas.py b/_modules/maas.py
38 index d3227ca..8a2243d 100644
39 --- a/_modules/maas.py
40 +++ b/_modules/maas.py
42 'gateway_ip': subnet['gateway_ip'],
44 self._iprange = subnet['iprange']
45 + self._vlans = subnet['vlans']
48 def update(self, new, old):
50 response = super(Subnet, self).send(data)
51 res_json = json.loads(response)
52 self._process_iprange(res_json['id'])
53 + self._process_dhcp_vlans_update(data)
56 def _get_fabric_from_cidr(self, cidr):
59 self._maas.post(u'api/2.0/ipranges/', None, **data)
61 + def _process_dhcp_vlans_update(self, subnet_data):
62 + fabric_vlans = json.loads(self._maas.get(u'api/2.0/fabrics/{0}/vlans/'
63 + .format(subnet_data['fabric'])).read())
64 + LOG.warn('all fabric %s vlans %s', subnet_data['fabric'], fabric_vlans)
65 + for vlan_name, vlan_data in self._vlans.iteritems():
68 + for fabric_vlan in fabric_vlans:
69 + if fabric_vlan['vid'] == vlan_data['vid']:
71 + old_data = fabric_vlan
74 + 'mtu': str(vlan_data.get('mtu', 1500)),
75 + 'dhcp_on': str(vlan_data.get('dhcp_on')),
76 + 'primary_rack': str(vlan_data.get('primary_rack')),
77 + 'secondary_rack': str(vlan_data.get('secondary_rack', ''))
80 + LOG.warn('UPDATING %s %s', data, old_data)
81 + self._maas.put(u'api/2.0/fabrics/{0}/vlans/{1}/'
82 + .format(subnet_data['fabric'], old_data['vid']),
85 + LOG.warn('MISSING vlan %s, not doing anything', data)
88 class DHCPSnippet(MaasObject):