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);
private void setEnvVar(VMInstance vmi, String cmd){ 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(), cmd, "ubuntu", vmi.getType().getPrivateKey()); jc.closeConnection(); } else { //TODO: should we do something for Windows as well? } }
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? } }
/** * Upload resources associated to an internal component on a specified * external component * * @param x the internal component with upload commands * @param owner the external component on which the resources are about to * be uploaded * @param jc the connector used to upload */ private void executeUploadCommands(InternalComponentInstance x, VMInstance owner, Connector jc) { journal.log(Level.INFO, ">> Upload "+x.getType().getName()); unlessNotNull("Cannot upload with an argument at null", x, owner, jc); for (Resource r : x.getType().getResources()) { for (String path : r.getUploadCommand().keySet()) { jc.uploadFile(path, r.getUploadCommand().get(path), owner.getId(), "ubuntu", owner.getType().getPrivateKey()); } } }
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(); } }
File file = new File(v.getPrivateKey()); if(file.exists() && !file.isDirectory()) { String contentKey = FileUtils.readFileToString(new File(v.getPrivateKey())); v.setPrivateKey(contentKey);
/** * 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); } }
/** * 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 void executeInstallCommand(InternalComponentInstance x, VMInstance owner, Connector jc) { unlessNotNull("Cannot install with an argument at null", x, owner, jc); for (Resource r : x.getType().getResources()) { if (!r.getInstallCommand().equals("")) { if (r.getRequireCredentials()) { jc.execCommand(owner.getId(), CloudMLQueryUtil.cloudmlStringRecover(r.getInstallCommand(), r, x) + " " + owner.getType().getProvider().getCredentials().getLogin() + " " + owner.getType().getProvider().getCredentials().getPassword(), "ubuntu", owner.getType().getPrivateKey()); } else { executeCommand(owner, jc, CloudMLQueryUtil.cloudmlStringRecover(r.getInstallCommand(), r, x)); } } } }
public void run() { VMInstance vmi = deploy.getComponentInstances().onlyVMs().withID(id); if (vmi != null) { Provider provider = vmi.getType().getProvider(); Connector c = ConnectorFactory.createIaaSConnector(provider); c.startVM(vmi); coordinator.updateStatus(vmi.getName(), ComponentInstance.State.RUNNING, Facade.class.getName()); for(InternalComponentInstance ici : vmi.hostedComponents()){ InternalComponent ic=ici.getType(); for(Resource r : ic.getResources()){ c.execCommand(vmi.getId(),r.getStartCommand(),"ubuntu",vmi.getType().getPrivateKey()); } } c.closeConnection(); } }}); ts.get(i).start();
public void run() { VMInstance vmi = deploy.getComponentInstances().onlyVMs().withID(id); if (vmi != null) { Provider provider = vmi.getType().getProvider(); Connector c = ConnectorFactory.createIaaSConnector(provider); for(InternalComponentInstance ici : vmi.hostedComponents()){ InternalComponent ic=ici.getType(); for(Resource r : ic.getResources()){ c.execCommand(vmi.getId(),r.getStopCommand(),"ubuntu",vmi.getType().getPrivateKey()); } } c.stopVM(vmi); coordinator.updateStatus(vmi.getName(), ComponentInstance.State.STOPPED, Facade.class.getName()); c.closeConnection(); } } });
/** * Install puppet, manage the repo, change the hostname and execute puppet on a VM * @param pr the puppet resource * @param n the vm instance on which puppet will be installed and executed * @param hostname the new hostname of the vm for puppet * @param path the path to the puppet manifest */ private void managePuppet(PuppetResource pr, VMInstance n, String hostname, String path){ PuppetMarionnetteConnector puppet=new PuppetMarionnetteConnector(pr.getMaster(),n); //check if the configuration file is in the repo and manage the repo MercurialConnector mc=new MercurialConnector(pr.getRepo(),pr.getRepositoryKey()); journal.log(Level.INFO, ">> Mercurial connector created"); mc.addFile(path, pr.getUsername()); //Touch the site.pp file puppet.touchSiteFile(); //call the update host command puppet.configureHostname(n.getType().getPrivateKey(), n.getType().getLogin(),n.getType().getPasswd(), n.getPublicAddress(), pr.getMaster(), hostname, pr.getConfigureHostnameCommand()); //start the puppet run puppet.install(n); }
/** * Retrieve the resources associated to an InternalComponent * * @param x the internalComponent we want to retrieve the resource * @param owner the externalComponent on which the resources will be * downloaded * @param jc the connector used to trigger the commands */ private void executeRetrieveCommand(InternalComponentInstance x, VMInstance owner, Connector jc) { unlessNotNull("Cannot retrieve resources of null!", x, owner, jc); for (Resource r : x.getType().getResources()) { if (!r.getRetrieveCommand().equals("")) { if (r.getRequireCredentials()) jc.execCommand(owner.getId(), CloudMLQueryUtil.cloudmlStringRecover(r.getRetrieveCommand(), r, x) + " " + owner.getType().getProvider().getCredentials().getLogin() + "" + owner.getType().getProvider().getCredentials().getPassword(), "ubuntu", owner.getType().getPrivateKey()); else executeCommand(owner, jc, CloudMLQueryUtil.cloudmlStringRecover(r.getRetrieveCommand(), r, x)); } } }
jcServer.execCommand(ownerVMServer.getId(), CloudMLQueryUtil.cloudmlStringRecover(server.getRetrieveCommand(), server, bi) + " \"" + ipAddress + "\" \"" + destinationIpAddress + "\" " + destinationPortNumber, "ubuntu", VMserver.getPrivateKey()); jcClient.execCommand(ownerVMClient.getId(), CloudMLQueryUtil.cloudmlStringRecover(client.getRetrieveCommand(), client, bi) + " \"" + ipAddress + "\" \"" + destinationIpAddress + "\" " + destinationPortNumber, "ubuntu", VMClient.getPrivateKey());
jc = ConnectorFactory.createIaaSConnector(n.getProvider()); jc.execCommand(ownerVM.getId(), r.getRetrieveCommand(), "ubuntu", n.getPrivateKey()); if (r.getConfigureCommand() != null) { String configurationCommand = r.getConfigureCommand() + " \"" + ipAddress + "\" \"" + destinationIpAddress + "\" " + destinationPortNumber;
@Override public void handle(Upload command) { if (isDeploymentLoaded()) { ExternalComponentInstance ownerVM = null; for (ExternalComponentInstance ni: deploy.getComponentInstances().onlyExternals()) { if (ni.getName().equals(command.getArtifactId())) { ownerVM = ni; } } if (ownerVM != null && ownerVM instanceof VMInstance) { Provider p = ((VMInstance) ownerVM).getType().getProvider(); JCloudsConnector jc = new JCloudsConnector(p.getName(), p.getCredentials().getLogin(), p.getCredentials().getPassword()); ComputeMetadata c = jc.getVMByName(command.getArtifactId()); jc.uploadFile(command.getLocalPath(), command.getRemotePath(), c.getId(), "ubuntu", ((VM) ownerVM.getType()).getPrivateKey()); } else { final String text = "There is no VM with this ID!"; final Message message = new Message(command, Category.ERROR, text); dispatch(message); } } else { reportNoDeploymentLoaded(command); } }
v.setSecurityGroup(existingVM.getSecurityGroup()); v.setSshKey(existingVM.getSshKey()); v.setPrivateKey(existingVM.getPrivateKey()); v.setProvider(provider); ProvidedExecutionPlatformGroup pepg=new ProvidedExecutionPlatformGroup();
v.setSshKey(existingVM.getSshKey()); v.setProviderSpecificTypeName(existingVM.getProviderSpecificTypeName()); v.setPrivateKey(existingVM.getPrivateKey()); v.setProvider(existingVM.getProvider()); ProvidedExecutionPlatformGroup pepg=new ProvidedExecutionPlatformGroup();
v.setSecurityGroup(existingVM.getSecurityGroup()); v.setSshKey(existingVM.getSshKey()); v.setPrivateKey(existingVM.getPrivateKey()); v.setProvider(existingVM.getProvider()); ProvidedExecutionPlatformGroup pepg=new ProvidedExecutionPlatformGroup();
if(((VM) ec).getOs() != null) kNode.setOs(vm.getOs()); kNode.setPrivateKey(vm.getPrivateKey()); if(((VM) ec).getSecurityGroup() != null) kNode.setSecurityGroup(vm.getSecurityGroup());