3636from IM .VirtualMachine import VirtualMachine
3737
3838from radl import radl_parse
39- from radl .radl import Feature , RADL
39+ from radl .radl import Feature , RADL , system
4040from radl .radl_json import dump_radl as dump_radl_json
4141
4242from IM .openid .JWT import JWT
@@ -387,6 +387,26 @@ def _compute_score(system_score, requested_radl):
387387
388388 return concrete_system , score
389389
390+ @staticmethod
391+ def search_vm (inf , radl_sys , auth ):
392+ # If an images is already set do not search
393+ if radl_sys .getValue ("disk.0.image.url" ):
394+ return []
395+
396+ dist = radl_sys .getValue ('disk.0.os.flavour' )
397+ version = radl_sys .getValue ('disk.0.os.version' )
398+ res = []
399+ for c in CloudInfo .get_cloud_list (auth ):
400+ cloud_site = c .getCloudConnector (inf )
401+ for image in cloud_site .list_images (auth ):
402+ if ((dist is None or dist .lower () in image ["name" ].lower ()) and
403+ (version is None or version .lower () in image ["name" ].lower ())):
404+ new_sys = system (radl_sys .name )
405+ new_sys .setValue ("disk.0.image.url" , image ["uri" ])
406+ res .append (new_sys )
407+ break
408+ return res
409+
390410 @staticmethod
391411 def systems_with_iis (sel_inf , radl , auth ):
392412 """
@@ -412,9 +432,6 @@ def systems_with_iis(sel_inf, radl, auth):
412432 for system_id in set ([d .id for d in radl .deploys if d .vm_number > 0 ]):
413433 s = radl .get_system_by_name (system_id )
414434
415- if not s .getValue ("disk.0.image.url" ) and len (vmrc_list + appdbis_list ) == 0 :
416- raise Exception ("No correct VMRC or AppDBIS auth data provided nor image URL" )
417-
418435 if Config .SINGLE_SITE :
419436 image_id = os .path .basename (s .getValue ("disk.0.image.url" ))
420437 url_prefix = Config .SINGLE_SITE_IMAGE_URL_PREFIX
@@ -436,13 +453,14 @@ def systems_with_iis(sel_inf, radl, auth):
436453
437454 vmrc_res = [s0 for vmrc in vmrc_list for s0 in vmrc .search_vm (s )]
438455 appdbis_res = [s0 for appdbis in appdbis_list for s0 in appdbis .search_vm (s )]
456+ local_res = InfrastructureManager .search_vm (sel_inf , s , auth )
439457 # Check that now the image URL is in the RADL
440- if not s .getValue ("disk.0.image.url" ) and not vmrc_res and not appdbis_res :
441- sel_inf .add_cont_msg ("No VMI obtained from VMRC nor AppDBIS to system: " + system_id )
442- raise Exception ("No VMI obtained from VMRC nor AppDBIS to system: " + system_id )
458+ if not s .getValue ("disk.0.image.url" ) and not vmrc_res and not appdbis_res and not local_res :
459+ sel_inf .add_cont_msg ("No VMI obtained from VMRC nor AppDBIS nor Sites to system: " + system_id )
460+ raise Exception ("No VMI obtained from VMRC nor AppDBIS not Sites to system: " + system_id )
443461
444462 n = [s_without_apps .clone ().applyFeatures (s0 , conflict = "other" , missing = "other" )
445- for s0 in (vmrc_res + appdbis_res )]
463+ for s0 in (vmrc_res + appdbis_res + local_res )]
446464 systems_with_vmrc [system_id ] = n if n else [s_without_apps ]
447465
448466 return systems_with_vmrc
0 commit comments