/** * Create an image of the VM * @param vmi a VMInstance * @return id of the image */ public String createImage(VMInstance vmi){ String id=""; Image i = checkIfImageExist(vmi.getName()+"-image"); if(i == null){ NodeMetadata nm=getVMById(vmi.getId()); ServerApi serverApi1=serverApi.getServerApiForZone(vmi.getType().getRegion()); journal.log(Level.INFO, ">> Creating an image of VM: "+vmi.getName()+" "+nm.getId()+" :: "+vmi.getType().getRegion()); id=serverApi1.createImageFromServer(vmi.getName()+"-image",nm.getId().split("/")[1]); String status=""; while (!status.toLowerCase().equals("available")){ Image im=novaComputeService.getImage(vmi.getType().getRegion()+"/"+id); status=im.getStatus().name(); try { Thread.sleep(3000); } catch (InterruptedException e) { journal.log(Level.SEVERE, e.getMessage()); } } journal.log(Level.INFO, ">> Image created with ID: "+id); }else{ id=i.getId().split("/")[1]; } return id; }
if(vm.getRegion() == null) journal.log(Level.INFO, ">> No Region " ); if((vm.getRegion() != null) && (!vm.getRegion().equals("")) && (!vm.getImageId().contains("/"))){ journal.log(Level.INFO, ">> Region: " +vm.getRegion()); fullId=vm.getRegion()+"/"+vm.getImageId(); }else{ fullId=vm.getImageId(); if(vm.getRegion() != null){ if(!vm.getRegion().equals("")){ region=vm.getRegion()+"/";
v=new VM(name+"-scaled",provider); v.setGroupName(existingVM.getGroupName()); v.setRegion(existingVM.getRegion()); v.setImageId(existingVM.getImageId()); v.setLocation(existingVM.getLocation());
v=new VM(name+"-fromImage",existingVM.getProvider()); v.setGroupName(existingVM.getGroupName()); v.setRegion(existingVM.getRegion()); v.setImageId("tempID"); v.setLocation(existingVM.getLocation());
v=new VM(name+"-fromImage",existingVM.getProvider()); v.setGroupName(existingVM.getGroupName()); v.setRegion(existingVM.getRegion()); v.setImageId("tempID"); v.setLocation(existingVM.getLocation());
kNode.setSshKey(vm.getSshKey()); if(ec.getRegion() != null) kNode.setRegion(vm.getRegion()); if(ec.getLogin() != null) kNode.setLogin(ec.getLogin());