@@ -225,12 +225,12 @@ def upload_template(self, node, storage, content_type, realpath, timeout):
225
225
except Exception as e :
226
226
self .module .fail_json (msg = "Uploading template %s failed with error: %s" % (realpath , e ))
227
227
228
- def fetch_template (self , node , storage , content_type , url , timeout ):
228
+ def fetch_template (self , node , storage , content_type , url , timeout , template ):
229
229
"""Fetch a template from a web url source using the proxmox download-url endpoint
230
230
"""
231
231
try :
232
232
taskid = self .proxmox_api .nodes (node ).storage (storage )("download-url" ).post (
233
- url = url , content = content_type , filename = os . path . basename ( url )
233
+ url = url , content = content_type , filename = template
234
234
)
235
235
return self .task_status (node , taskid , timeout )
236
236
except Exception as e :
@@ -256,13 +256,13 @@ def delete_template(self, node, storage, content_type, template, timeout):
256
256
time .sleep (1 )
257
257
return False
258
258
259
- def fetch_and_verify (self , node , storage , url , content_type , timeout , checksum , checksum_algorithm ):
259
+ def fetch_and_verify (self , node , storage , url , content_type , timeout , checksum , checksum_algorithm , template ):
260
260
""" Fetch a template from a web url, then verify it using a checksum.
261
261
"""
262
262
data = {
263
263
'url' : url ,
264
264
'content' : content_type ,
265
- 'filename' : os . path . basename ( url ) ,
265
+ 'filename' : template ,
266
266
'checksum' : checksum ,
267
267
'checksum-algorithm' : checksum_algorithm }
268
268
try :
@@ -310,11 +310,10 @@ def main():
310
310
content_type = module .params ['content_type' ]
311
311
src = module .params ['src' ]
312
312
url = module .params ['url' ]
313
+ template = module .params ['template' ]
313
314
314
315
# download appliance template
315
316
if content_type == 'vztmpl' and not (src or url ):
316
- template = module .params ['template' ]
317
-
318
317
if not template :
319
318
module .fail_json (msg = 'template param for downloading appliance template is mandatory' )
320
319
@@ -336,17 +335,19 @@ def main():
336
335
if proxmox .upload_template (node , storage , content_type , src , timeout ):
337
336
module .exit_json (changed = True , msg = 'template with volid=%s:%s/%s uploaded' % (storage , content_type , template ))
338
337
elif not src :
339
- template = os .path .basename (urlparse (url ).path )
338
+ if not template :
339
+ template = os .path .basename (urlparse (url ).path )
340
+
340
341
if proxmox .has_template (node , storage , content_type , template ):
341
342
if not module .params ['force' ]:
342
343
module .exit_json (changed = False , msg = 'template with volid=%s:%s/%s already exists' % (storage , content_type , template ))
343
344
elif not proxmox .delete_template (node , storage , content_type , template , timeout ):
344
345
module .fail_json (changed = False , msg = 'failed to delete template with volid=%s:%s/%s' % (storage , content_type , template ))
345
346
346
347
if checksum :
347
- if proxmox .fetch_and_verify (node , storage , url , content_type , timeout , checksum , checksum_algorithm ):
348
+ if proxmox .fetch_and_verify (node , storage , url , content_type , timeout , checksum , checksum_algorithm , template ):
348
349
module .exit_json (changed = True , msg = "Checksum verified, template with volid=%s:%s/%s uploaded" % (storage , content_type , template ))
349
- if proxmox .fetch_template (node , storage , content_type , url , timeout ):
350
+ if proxmox .fetch_template (node , storage , content_type , url , timeout , template ):
350
351
module .exit_json (changed = True , msg = 'template with volid=%s:%s/%s uploaded' % (storage , content_type , template ))
351
352
352
353
elif state == 'absent' :
0 commit comments