Skip to content

Commit f20a785

Browse files
committed
fix: mod-cloud on --no-wipe
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
1 parent 5efc99a commit f20a785

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

quads/helpers.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ def param_check(data, params, defaults={}):
1515

1616
if data:
1717
# check for missing params
18-
for p in params:
19-
if p not in data:
20-
result.append("Missing required parameter: %s" % p)
21-
elif not (data[p] or data[p] is None):
22-
result.append("Could not parse %s parameter" % p)
23-
elif data[p] == 'None':
24-
data[p] = None
25-
if p == "_id":
26-
data["_id"] = ObjectIdField(data[p])
18+
for param in params:
19+
if param not in data:
20+
result.append("Missing required parameter: %s" % param)
21+
elif not data[param]:
22+
result.append("Could not parse %s parameter" % param)
23+
elif data[param] == 'None':
24+
data[param] = None
25+
if param == "_id":
26+
data["_id"] = ObjectIdField(data[param])
2727

2828
return result, data
2929

quads/model.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,18 @@ class Cloud(Document):
123123
def prep_data(data, fields=None, mod=False):
124124
if 'vlan' in data and data['vlan']:
125125
vlan_id = data.pop('vlan')
126-
vlan_obj = Vlan.objects(vlan_id=vlan_id).first()
127-
if not vlan_obj:
128-
return ["No VLAN object defined with id: %s" % vlan_id], {}
129-
cloud_obj = Cloud.objects(vlan=vlan_obj).first()
130-
if cloud_obj:
131-
return ["VLAN %s already in use." % vlan_id], {}
132-
data["vlan"] = vlan_obj
133-
else:
134-
data["vlan"] = None
126+
try:
127+
int(vlan_id)
128+
except ValueError:
129+
data['vlan'] = None
130+
else:
131+
vlan_obj = Vlan.objects(vlan_id=vlan_id).first()
132+
if not vlan_obj:
133+
return ["No VLAN object defined with id: %s" % vlan_id], {}
134+
cloud_obj = Cloud.objects(vlan=vlan_obj).first()
135+
if cloud_obj:
136+
return ["VLAN %s already in use." % vlan_id], {}
137+
data["vlan"] = vlan_obj
135138
if 'ccuser' in data:
136139
data['ccuser'] = data['ccuser'].split()
137140
if 'wipe' in data:
@@ -147,6 +150,9 @@ def prep_data(data, fields=None, mod=False):
147150
if not fields:
148151
fields = ['name', 'description', 'owner']
149152

153+
fields = list(fields)
154+
fields.remove("wipe")
155+
150156
result, data = param_check(data, fields)
151157

152158
return result, data

quads/tools/foreman_heal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def main():
7979
if host == schedule.host.name
8080
]
8181
if not match:
82-
# want to run these separetely to avoid ServerDisconnect
82+
# want to run these separately to avoid ServerDisconnect
8383
_host_id = loop.run_until_complete(foreman_admin.get_host_id(schedule.host.name))
8484
loop.run_until_complete(
8585
foreman_admin.put_element("hosts", _host_id, "owner_id", user_id)

0 commit comments

Comments
 (0)