diff --git a/quads/helpers.py b/quads/helpers.py index 0bf8822a8..cad261182 100644 --- a/quads/helpers.py +++ b/quads/helpers.py @@ -15,15 +15,15 @@ def param_check(data, params, defaults={}): if data: # check for missing params - for p in params: - if p not in data: - result.append("Missing required parameter: %s" % p) - elif not (data[p] or data[p] is None): - result.append("Could not parse %s parameter" % p) - elif data[p] == 'None': - data[p] = None - if p == "_id": - data["_id"] = ObjectIdField(data[p]) + for param in params: + if param not in data: + result.append("Missing required parameter: %s" % param) + elif not data[param]: + result.append("Could not parse %s parameter" % param) + elif data[param] == 'None': + data[param] = None + if param == "_id": + data["_id"] = ObjectIdField(data[param]) return result, data diff --git a/quads/model.py b/quads/model.py index 1059ad93a..406e95935 100644 --- a/quads/model.py +++ b/quads/model.py @@ -123,15 +123,18 @@ class Cloud(Document): def prep_data(data, fields=None, mod=False): if 'vlan' in data and data['vlan']: vlan_id = data.pop('vlan') - vlan_obj = Vlan.objects(vlan_id=vlan_id).first() - if not vlan_obj: - return ["No VLAN object defined with id: %s" % vlan_id], {} - cloud_obj = Cloud.objects(vlan=vlan_obj).first() - if cloud_obj: - return ["VLAN %s already in use." % vlan_id], {} - data["vlan"] = vlan_obj - else: - data["vlan"] = None + try: + int(vlan_id) + except ValueError: + data['vlan'] = None + else: + vlan_obj = Vlan.objects(vlan_id=vlan_id).first() + if not vlan_obj: + return ["No VLAN object defined with id: %s" % vlan_id], {} + cloud_obj = Cloud.objects(vlan=vlan_obj).first() + if cloud_obj: + return ["VLAN %s already in use." % vlan_id], {} + data["vlan"] = vlan_obj if 'ccuser' in data: data['ccuser'] = data['ccuser'].split() if 'wipe' in data: @@ -147,6 +150,9 @@ def prep_data(data, fields=None, mod=False): if not fields: fields = ['name', 'description', 'owner'] + fields = list(fields) + fields.remove("wipe") + result, data = param_check(data, fields) return result, data diff --git a/quads/tools/foreman_heal.py b/quads/tools/foreman_heal.py index 60f318537..71d80cdb8 100755 --- a/quads/tools/foreman_heal.py +++ b/quads/tools/foreman_heal.py @@ -79,7 +79,7 @@ def main(): if host == schedule.host.name ] if not match: - # want to run these separetely to avoid ServerDisconnect + # want to run these separately to avoid ServerDisconnect _host_id = loop.run_until_complete(foreman_admin.get_host_id(schedule.host.name)) loop.run_until_complete( foreman_admin.put_element("hosts", _host_id, "owner_id", user_id)