@Override public Long getIdPublicAddressOfVM(VirtualMachine vm) { if (vm.publicIpAddress() != null) { return vm.publicIpAddress().get().getId(); } return null; }
public WindowsInstaller( RemoteConnection remoteConnection, VirtualMachine virtualMachine, Tenant tenant) { super(remoteConnection, virtualMachine, tenant); this.user = virtualMachine.loginName().get(); checkArgument( virtualMachine.loginPassword().isPresent(), "Expected login password for WindowsInstaller"); this.password = virtualMachine.loginPassword().get(); this.homeDir = "C:\\Users\\" + this.user; }
public boolean isInstanceOf(Instance instance, List<VirtualMachine> vms, long cloudId) { boolean result = false; for (VirtualMachine vm : vms) { Long vmId = vm.getId(); if (vm.cloud().getId().equals(cloudId) && instance.getVirtualMachine().getId().equals(vmId)) { result = true; } } return result; }
@Override public RemoteConnection apply(VirtualMachine virtualMachine) { checkArgument(virtualMachine.publicIpAddress().isPresent()); checkArgument(virtualMachine.loginName().isPresent()); checkArgument(virtualMachine.loginPassword().isPresent()); int remotePort = virtualMachine.remotePort(); OSFamily osFamily = virtualMachine.osFamily(); return connectionService.getRemoteConnection( HostAndPort.fromParts(virtualMachine.publicIpAddress().get().getIp(), remotePort), osFamily, LoginCredentialBuilder.newBuilder() .password(virtualMachine.loginPassword().get()) .username(virtualMachine.loginName().get()) .build()); }
@Override public boolean isApplicable(VirtualMachine virtualMachine) { return virtualMachine.loginName().isPresent() && virtualMachine.loginPassword().isPresent(); }
@Override public List<VirtualMachine> getVirtualMachines( Long applicationId, Long componentId, Long instanceId, Long cloudId) { List<VirtualMachine> vms; List<VirtualMachine> result = new ArrayList<VirtualMachine>(); vms = virtualMachineModelService.getAll(); for (VirtualMachine vm : vms) { boolean suitable = true; List<Instance> instances = null; List<ApplicationComponent> appComps = null; // Filter for application id if (applicationId != null) { instances = this.getInstances(vm.getId()); appComps = new ArrayList<>(); for (Instance instance : instances) { if (instance.getVirtualMachine().getId().equals(vm.getId())) { LOGGER.info("Instance " + instance.getId() + " belongs to VM " + vm.getId()); appComps.add( getApplicationComponentForInstance(instance.getApplicationComponent().getId())); } } boolean oneInstanceFit = false; for (ApplicationComponent ac : appComps) { if (ac.getApplication().getId() == applicationId) { oneInstanceFit = true; } } suitable = oneInstanceFit; } // Filter for component id if (suitable && componentId != null) { if (instances == null) { instances = this.getInstances(vm.getId()); appComps = new ArrayList<ApplicationComponent>(); for (Instance instance : instances) { appComps.add( getApplicationComponentForInstance(instance.getApplicationComponent().getId())); } } boolean oneInstanceFit = false; for (ApplicationComponent ac : appComps) { if (ac.getComponent().getId() == componentId) { oneInstanceFit = true; } } suitable = oneInstanceFit; } // Filter for instance id if (suitable && instanceId != null) { if (instances == null) { instances = this.getInstances(vm.getId()); } boolean oneInstanceFit = false; for (Instance instance : instances) { if (instance.getId() == instanceId) { oneInstanceFit = true; } } suitable = oneInstanceFit; } // Filter for cloud id if (suitable && cloudId != null) { if (vm.cloud().getId() != cloudId) { suitable = false; } } // Add to result if (suitable) { result.add(vm); } } return result; }