Merge "Allow multiple PXE mac addresses"
diff --git a/_modules/maas.py b/_modules/maas.py
index 426aff5..aa57498 100644
--- a/_modules/maas.py
+++ b/_modules/maas.py
@@ -445,13 +445,22 @@
return data
def update(self, new, old):
+ LOG.debug('Updating machine')
old_macs = set(v['mac_address'].lower() for v in old['interface_set'])
- if new['mac_addresses'].lower() not in old_macs:
+ LOG.debug('old_macs: %s' % old_macs)
+ if isinstance(new['mac_addresses'], list):
+ new_macs = set(v.lower() for v in new['mac_addresses'])
+ else:
+ new_macs = set([new['mac_addresses'].lower()])
+ LOG.debug('new_macs: %s' % new_macs)
+ intersect = list(new_macs.intersection(old_macs))
+ if not intersect:
self._update = False
LOG.info('Mac changed deleting old machine %s', old['system_id'])
self._maas.delete(u'api/2.0/machines/{0}/'
.format(old['system_id']))
else:
+ new['mac_addresses'] = intersect
new[self._update_key] = str(old[self._update_key])
return new
diff --git a/_modules/multipart.py b/_modules/multipart.py
index 7ed17a6..45aebf3 100644
--- a/_modules/multipart.py
+++ b/_modules/multipart.py
@@ -88,9 +88,12 @@
def build_multipart_message(data):
message = MIMEMultipart("form-data")
- for name, content in data:
- for payload in make_payloads(name, content):
- message.attach(payload)
+ for name, contents in data:
+ if not isinstance(contents, list):
+ contents = [contents]
+ for content in contents:
+ for payload in make_payloads(name, content):
+ message.attach(payload)
return message