Skip to content

Commit

Permalink
fix: mod-cloud on --no-wipe
Browse files Browse the repository at this point in the history
also added logic to pass any string to --vlan on mod-cloud that
would ce accepted as `none` to reset the cloud to use no vlan at all

Change-Id: Ib2af82006a43fe3912a984ede20c84a27c870dfe
Closes: #351
  • Loading branch information
grafuls committed Dec 3, 2020
1 parent 5efc99a commit f20a785
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
18 changes: 9 additions & 9 deletions quads/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
24 changes: 15 additions & 9 deletions quads/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion quads/tools/foreman_heal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f20a785

Please sign in to comment.