private VM createNewInstanceOfVMFromImage(VMInstance vmi){ VM existingVM=vmi.asExternal().asVM().getType(); VM v = findVMGenerated(existingVM.getName(),"fromImage"); if(v == null){//in case a type for the snapshot has already been created String name=lib.createUniqueComponentInstanceName(currentModel,existingVM); v=new VM(name+"-fromImage",existingVM.getProvider()); v.setGroupName(existingVM.getGroupName()); v.setRegion(existingVM.getRegion()); v.setImageId("tempID"); v.setLocation(existingVM.getLocation()); v.setMinRam(existingVM.getMinRam()); v.setMinCores(existingVM.getMinCores()); v.setMinStorage(existingVM.getMinStorage()); v.setSecurityGroup(existingVM.getSecurityGroup()); v.setSshKey(existingVM.getSshKey()); v.setProviderSpecificTypeName(existingVM.getProviderSpecificTypeName()); v.setPrivateKey(existingVM.getPrivateKey()); v.setProvider(existingVM.getProvider()); ProvidedExecutionPlatformGroup pepg=new ProvidedExecutionPlatformGroup(); for(ProvidedExecutionPlatform pep: existingVM.getProvidedExecutionPlatforms()){ ArrayList<Property> pg=new ArrayList<Property>(); for(Property property: pep.getOffers()){ pepg.add(p); v.setProvidedExecutionPlatforms(pepg.toList()); currentModel.getComponents().add(v);
@Override public String toString() { return "VMInstance: " + getName() + " Type:" + getType().getName() + "{\n" + "minRam:" + (getType()).getMinRam() + "\n" + "minCore" + (getType()).getMinCores() + "\n" + "minDisk" + (getType()).getMinStorage() + "\n" + "OS" + (getType()).getOs() + "\n" + "location" + (getType()).getLocation() + "\n" + "publicAdress" + getPublicAddress() + "\n" + "groupName" + (getType()).getGroupName(); }
public void install(VMInstance vmi){ try { startPuppetAgent(vmi.getType().getPrivateKey(),vmi.getType().getLogin(), vmi.getType().getPasswd(), vmi.getName(), vmi.getPublicAddress()); } catch (Exception e) { e.printStackTrace(); } }
convertProperties(vm, kNode, factory); convertResources(vm, kNode, factory); kNode.setName(vm.getName()); kNode.setProvider(providers.get(vm.getProvider().getName())); kNode.setGroupName(vm.getGroupName()); kNode.setImageId(vm.getImageId()); kNode.setIs64os(vm.getIs64os()); if(ec.getLocation() != null) kNode.setLocation(vm.getLocation()); kNode.setMinCores(vm.getMinCores()); kNode.setMinStorage(vm.getMinStorage()); kNode.setMinRam(vm.getMinRam()); if(((VM) ec).getOs() != null) kNode.setOs(vm.getOs()); kNode.setPrivateKey(vm.getPrivateKey()); if(((VM) ec).getSecurityGroup() != null) kNode.setSecurityGroup(vm.getSecurityGroup()); kNode.setSshKey(vm.getSshKey()); if(ec.getRegion() != null) kNode.setRegion(vm.getRegion()); if(ec.getLogin() != null) kNode.setLogin(ec.getLogin()); if(ec.getPasswd() != null) kNode.setPasswd(ec.getPasswd()); if(((VM) ec).getProviderSpecificTypeName() != null) kNode.setProviderSpecificTypeName(((VM) ec).getProviderSpecificTypeName()); if(ec.getEndPoint() != null) kNode.setEndPoint(ec.getEndPoint());
public void vmToPOJO(net.cloudml.core.VM kvm) { net.cloudml.core.VM kVM = kvm; VM vm = new VM(kVM.getName(), new Provider("Dummy provider")); convertProperties(kVM, vm); convertResources(kVM, vm); convertPuppetResources(kVM, vm); Provider p = providers.get(kVM.getProvider().getName()); //TODO: extract this to function vm.setProvider(p); vm.setGroupName(kVM.getGroupName()); vm.setImageId(kVM.getImageId()); vm.setIs64os(kVM.getIs64os()); vm.setLocation(kVM.getLocation()); vm.setMinCores(kVM.getMinCores()); vm.setMinStorage(kVM.getMinStorage()); vm.setMinRam(kVM.getMinRam()); vm.setOs(kVM.getOs()); vm.setPrivateKey(kVM.getPrivateKey()); vm.setSecurityGroup(kVM.getSecurityGroup()); vm.setSshKey(kVM.getSshKey()); vm.setRegion(kVM.getRegion()); vm.setLogin(kVM.getLogin()); vm.setPasswd(kVM.getPasswd()); vm.setProviderSpecificTypeName(kVM.getProviderSpecificTypeName()); initProvidedExecutionPlatforms(kVM, vm); vms.put(vm.getName(), vm); model.getComponents().add(vm); }
NodeMetadata nodeInstance = null; String groupName="cloudml-instance"; if(!vm.getGroupName().equals("")) groupName= vm.getGroupName(); if(!vm.getImageId().equals("")){ templateBuilder.imageId(vm.getImageId()); if(vm.getProviderSpecificTypeName().equals("")){ if (vm.getMinRam() > 0) templateBuilder.minRam(vm.getMinRam()); if (vm.getMinCores() > 0) templateBuilder.minCores(vm.getMinCores()); templateBuilder.hardwareId(vm.getProviderSpecificTypeName()); if (!vm.getLocation().equals("")) templateBuilder.locationId(vm.getLocation()); if (!vm.getOs().equals("")) templateBuilder.imageDescriptionMatches(vm.getOs()); else templateBuilder.osFamily(OsFamily.UBUNTU); templateBuilder.os64Bit(vm.getIs64os()); template.getOptions().as(EC2TemplateOptions.class).mapNewVolumeToDeviceName("/dev/sda1", vm.getMinStorage(), true); template.getOptions().as(EC2TemplateOptions.class).securityGroups(vm.getSecurityGroup()); template.getOptions().as(EC2TemplateOptions.class).keyPair(vm.getSshKey()); template.getOptions().as(EC2TemplateOptions.class).userMetadata("Name", a.getName()); template.getOptions().as(EC2TemplateOptions.class).overrideLoginUser(a.getName());
NodeMetadata nodeInstance = null; String groupName="cloudml-instance"; if(!vm.getGroupName().equals("")) groupName= vm.getGroupName(); if(vm.getRegion() == null) journal.log(Level.INFO, ">> No Region " ); if(!vm.getImageId().equals("")){ String fullId=""; 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.getMinRam() > 0) templateBuilder.minRam(vm.getMinRam()); if (vm.getMinCores() > 0) templateBuilder.minCores(vm.getMinCores()); if(vm.getRegion() != null){ if(!vm.getRegion().equals("")){ region=vm.getRegion()+"/"; if (!vm.getLocation().equals("")) templateBuilder.locationId(region+vm.getLocation()); if (!vm.getOs().equals("")) templateBuilder.imageDescriptionMatches(vm.getOs());
FluentIterable<DriveInfo> drives = cloudSigmaApi.listDrivesInfo().concat(); for(DriveInfo d : drives){ if(d.getName().contains(vm.getImageId()) && d.getStatus() == DriveStatus.UNMOUNTED){ driveToClone =d; if(d.getName().contains(vm.getImageId())){ driveToClone =d; break; .description("root drive for " + vm.getImageId()) .media(MediaType.DISK) .build(); if(fp.getName().toLowerCase().equals(vm.getSecurityGroup().toLowerCase())){ p=fp; m.put("ssh_public_key",readSshKey(vm.getSshKey())); .memory(BigInteger.valueOf(vm.getMinRam()).multiply(BigInteger.valueOf(1024 * 1024))) .vncPassword("cloudml") .cpu(vm.getMinCores() * 2600) .nics(ImmutableList.of(nic)) .meta(m) if (vm.getOs().toLowerCase().contains("windows")) { while(!PowerShellConnector.checkConnectivity(ip.getUuid())){ try {
/** * Configure a component * * @param jc a connector * @param n A VM type * @param ni a VM instance * @param configurationCommand the command to configure the component, * parameters are: IP IPDest portDest */ protected void configure(Connector jc, VM n, VMInstance ni, String configurationCommand, Boolean keyRequired) { if (!configurationCommand.equals("")) { if(keyRequired) jc.execCommand(ni.getId(), configurationCommand+" "+ni.getType().getProvider().getCredentials().getLogin()+" "+ni.getType().getProvider().getCredentials().getPassword(), "ubuntu", n.getPrivateKey()); else executeCommand(ni, jc, configurationCommand); } }
if (vm.getMinCores() > 0 && vm.getMinRam() > 0) template.setProductOfferUUID(findProduct(((double) vm.getMinRam()), vm.getMinCores())); if (!vm.getGroupName().equals("")) template.setVdcUUID(findResourceByName(vm.getGroupName(),ResourceType.VDC)); if(!vm.getImageId().equals("")){ String imId=findResourceByName(vm.getImageId(), ResourceType.IMAGE); if(!imId.equals("")) { if(!vm.getSshKey().equals("")) sshKeyList.add(findResourceByName(vm.getSshKey(),ResourceType.SSHKEY)); d.setSize(vm.getMinStorage()); d.setResourceName(a.getName()); template.getDisks().add(d); service.waitForJob(job.getResourceUUID(), false); a.getProperties().add(new Property("ProviderSpecificInstanceType", findProductName(((double) vm.getMinRam()), vm.getMinCores()))); a.setProviderSpecificType(findProductName(((double) vm.getMinRam()), vm.getMinCores())); a.setId(findResourceByName(a.getName(), ResourceType.SERVER)); journal.log(Level.INFO, ">> vm type: "+ findProductName(((double) vm.getMinRam()), vm.getMinCores()) + " named " + template.getResourceName());
@Override public boolean isProvidedBy(Provider provider) { return getProvider().equals(provider); }
public void scaleOut(ResourcePoolInstance resourcePoolInstance, VMInstance vmi){ VM temp = findVMGenerated(vmi.getType().getName(), "fromImage"); Map<InternalComponentInstance, InternalComponentInstance> duplicatedGraph=resourcePoolInstance.replicate(vmi,currentModel); if(temp == null){ Connector c = ConnectorFactory.createIaaSConnector(vmi.getType().getProvider()); String ID=c.createImage(vmi); c.closeConnection(); vmi.getType().setImageId(ID); }else{ vmi.getType().setImageId(temp.getImageId()); } provisionVM(vmi); allConfiguration(duplicatedGraph); journal.log(Level.INFO, ">> Scaling completed!"); }
createHostedService(a.getName(),vm.getLocation(),vm.getSshKey()); } catch (SAXException e) { e.printStackTrace(); rolelist = createRoleList(a, vm, vm.getGroupName(),vm.getGroupName()); } catch (Exception e) { e.printStackTrace(); ArrayList<ConfigurationSet> configurationSets = new ArrayList<ConfigurationSet>(); createParameters.setConfigurationSets(configurationSets); createParameters.setOSVirtualHardDisk(createOSVHD(vm, vm.getGroupName(),vm.getGroupName())); createParameters.setProvisionGuestAgent(true); createParameters.setRoleSize(VirtualMachineRoleSize.SMALL); if(!vm.getLogin().equals("")) login=vm.getLogin(); SSHConnector sc=new SSHConnector(vm.getPrivateKey(), login, ip); while(!sc.checkConnectivity()){ try {
public void setEnvVar(VMInstance vmi, String varName, String value){ if (!vmi.getType().getOs().toLowerCase().contains("windows")) { //String command="echo export "+varName+"="+value+" >> ~/.bashrc"; Connector jc = ConnectorFactory.createIaaSConnector(vmi.getType().getProvider()); //jc.execCommand(vmi.getId(), command, "ubuntu", vmi.getType().getPrivateKey()); String command3="sudo sh -c 'echo export "+varName+"="+value+" >> /etc/environment'"; jc.execCommand(vmi.getId(), command3, "ubuntu", vmi.getType().getPrivateKey()); jc.closeConnection(); } else { //TODO: should we do something for Windows as well? } }
/** * Execute a given command on an component * * @param a the component on which the command will be executed * @param command the related shell command as a String * @param user the user associated */ public void executeOnVM(ComponentInstance a, String command, String user) {//TODO: use the connector factory VM ownerVM = (VM) deployer.getDestination(a).getType();//TODO: generics Provider provider = ownerVM.getProvider(); final Credentials credentials = provider.getCredentials(); JCloudsConnector jc = new JCloudsConnector(provider.getName(), credentials.getLogin(), credentials.getPassword()); jc.execCommand(ownerVM.getGroupName(), command, user, ownerVM.getPrivateKey()); jc.closeConnection(); }
private static VM fromCloudmlToModaMP(VMInstance toTranslate) { VM toReturn = new VM(); //KB entity field String id = toTranslate.getName(); toReturn.setId(id); toReturn.setType(String.valueOf(toTranslate.getType().getName())); toReturn.setCloudProvider(toTranslate.getType().getProvider().getName()); toReturn.setLocation(toTranslate.getType().getLocation()); toReturn.setNumberOfCPUs(toTranslate.getCore()); return toReturn; } //Translate an internal component from cloudML to Monitoring Platform QoS-model
if (!owner.getType().getOs().toLowerCase().contains("windows")) { jc.execCommand(owner.getId(), command, "ubuntu", owner.getType().getPrivateKey()); } else { if (command != null && !command.isEmpty()) { try { Thread.sleep(90000); // crappy stuff: wati for windows .... TODO String cmd = "powershell \"" + command + " " + owner.getType().getPrivateKey() + " " + owner.getPublicAddress() + "\""; journal.log(Level.INFO, ">> Executing command: " + cmd); run = new PowerShellConnector(cmd);
File file = new File(v.getPrivateKey()); if(file.exists() && !file.isDirectory()) { String contentKey = FileUtils.readFileToString(new File(v.getPrivateKey())); v.setPrivateKey(contentKey);
private ConfigurationSet createConfigOS(String vmName, VM vm){ String adminUserPassword= "ubuntu!12"; String adminUserName = "ubuntu"; if(!vm.getLogin().equals("")) adminUserName = vm.getLogin(); if(!vm.getPasswd().equals("")) adminUserPassword=vm.getPasswd(); ConfigurationSet configurationSet = new ConfigurationSet(); String type=ConfigurationSetTypes.LINUXPROVISIONINGCONFIGURATION; if(!vm.getOs().equals("")) if(vm.getOs().toLowerCase().contains("win")) type=ConfigurationSetTypes.WINDOWSPROVISIONINGCONFIGURATION; configurationSet.setConfigurationSetType(type);
private OSVirtualHardDisk createOSVHD(VM vm,String storageAccountName, String storageContainer){ int random = (int)(Math.random()* 100); URI mediaLinkUriValue = null; try { mediaLinkUriValue = new URI("http://"+ storageAccountName + ".blob.core.windows.net/"+storageContainer+ "/ubuntu" + random +".vhd"); String osVHarddiskName ="ubuntuoshdname"+ random; String operatingSystemName ="Linux"; if(!vm.getOs().equals("")) if(vm.getOs().toLowerCase().contains("win")) operatingSystemName="Windows"; String sourceImageName = "Ubuntu"; if(!vm.getImageId().equals("")) sourceImageName=vm.getImageId(); else if(!vm.getOs().equals("")) sourceImageName = getOSSourceImage(vm.getOs()); OSVirtualHardDisk oSVirtualHardDisk = new OSVirtualHardDisk(); //required oSVirtualHardDisk.setName(osVHarddiskName); oSVirtualHardDisk.setHostCaching(VirtualHardDiskHostCaching.READWRITE); oSVirtualHardDisk.setOperatingSystem(operatingSystemName); //required oSVirtualHardDisk.setMediaLink(mediaLinkUriValue); //required oSVirtualHardDisk.setSourceImageName(sourceImageName); return oSVirtualHardDisk; } catch (Exception e) { e.printStackTrace(); } return null; }