org.jclouds.domain.LoginCredentials Java Examples
The following examples show how to use
org.jclouds.domain.LoginCredentials.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JcloudsSshMachineLocation.java From brooklyn-server with Apache License 2.0 | 6 votes |
/** * Retrieves the password for this VM, if one exists. The behaviour/implementation is different for different clouds. * e.g. on Rackspace, the password for a windows VM is available immediately; on AWS-EC2, for a Windows VM you need * to poll repeatedly until the password is available which can take up to 15 minutes. * * @deprecated since 0.9.0; use the machine to execute commands, so no need to extract the password */ @Deprecated public String waitForPassword() { Optional<NodeMetadata> node = getOptionalNode(); if (node.isPresent()) { // TODO Hacky; don't want aws specific stuff here but what to do?! if (jcloudsParent.getProvider().equals("aws-ec2")) { try { return JcloudsUtil.waitForPasswordOnAws(jcloudsParent.getComputeService(), node.get(), 15, TimeUnit.MINUTES); } catch (TimeoutException e) { throw Throwables.propagate(e); } } else { LoginCredentials credentials = node.get().getCredentials(); return (credentials != null) ? credentials.getOptionalPassword().orNull() : null; } } else { throw new IllegalStateException("Node "+nodeId+" not present in "+getParent()); } }
Example #2
Source File: AWSEC2ImageParserTest.java From attic-stratos with Apache License 2.0 | 6 votes |
public void testParseVostokImage() { Set<org.jclouds.compute.domain.Image> result = convertImages("/vostok.xml"); assertEquals( Iterables.get(result, 0), new ImageBuilder() .operatingSystem( new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("") .description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml") .is64Bit(false).build()) .description("vostok-builds/vostok-0.95-5622/vostok-0.95-5622.manifest.xml") .defaultCredentials(LoginCredentials.builder().user("root").build()).id("us-east-1/ami-870de2ee") .providerId("ami-870de2ee").location(defaultLocation).version("5622") .userMetadata(ImmutableMap.of("owner", "133804938231", "rootDeviceType", "instance-store")) .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build()); }
Example #3
Source File: AWSEC2ImageParserTest.java From attic-stratos with Apache License 2.0 | 6 votes |
public void testParseCCImage() { Set<org.jclouds.compute.domain.Image> result = convertImages("/describe_images_cc.xml"); assertEquals( Iterables.get(result, 0), new ImageBuilder() .name("EC2 CentOS 5.4 HVM AMI") .operatingSystem( new OperatingSystem.Builder().family(OsFamily.CENTOS).arch("hvm").version("5.4") .description("amazon/EC2 CentOS 5.4 HVM AMI").is64Bit(true).build()) .description("EC2 CentOS 5.4 HVM AMI") .defaultCredentials(LoginCredentials.builder().user("root").build()).id("us-east-1/ami-7ea24a17") .providerId("ami-7ea24a17").location(defaultLocation) .userMetadata(ImmutableMap.of( "owner", "206029621532", "rootDeviceType", "ebs", "virtualizationType", "hvm", "hypervisor", "xen")) .status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build()); assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE); }
Example #4
Source File: MainApp.java From jclouds-examples with Apache License 2.0 | 6 votes |
private static void runScriptOnGroup(final ComputeService compute, final LoginCredentials login, final String groupName, final Statement command) throws RunScriptOnNodesException { // when you run commands, you can pass options to decide whether // to run it as root, supply or own credentials vs from cache, // and wrap in an init script vs directly invoke Map<? extends NodeMetadata, ExecResponse> execResponses = compute.runScriptOnNodesMatching(// inGroup(groupName), // predicate used to select nodes command, // what you actually intend to run overrideLoginCredentials(login)); // use the local user & ssh key for (Entry<? extends NodeMetadata, ExecResponse> response : execResponses.entrySet()) { System.out.printf( "<< node %s: %s%n", response.getKey().getId(), concat(response.getKey().getPrivateAddresses(), response.getKey() .getPublicAddresses()) ); System.out.printf("<< %s%n", response.getValue()); } }
Example #5
Source File: CloudSigmaConnector.java From cloudml with GNU Lesser General Public License v3.0 | 6 votes |
private org.jclouds.domain.LoginCredentials.Builder initCredentials(String login, String key){ String contentKey; org.jclouds.domain.LoginCredentials.Builder b= LoginCredentials.builder(); File f = new File(key); if(f.exists() && !f.isDirectory()) { try { contentKey = FileUtils.readFileToString(new File(key)); b.user(login); b.noPassword(); b.privateKey(contentKey); } catch (IOException e) { journal.log(Level.SEVERE, e.getMessage()); } }else{ b.user(login); b.noPassword(); b.privateKey(key); } return b; }
Example #6
Source File: OpenStackConnector.java From cloudml with GNU Lesser General Public License v3.0 | 6 votes |
/** * Prepare the credential builder * @param login * @param key * @return */ private org.jclouds.domain.LoginCredentials.Builder initCredentials(String login, String key){ String contentKey; org.jclouds.domain.LoginCredentials.Builder b= LoginCredentials.builder(); File f = new File(key); if(f.exists() && !f.isDirectory()) { try { contentKey = FileUtils.readFileToString(new File(key)); b.user(login); b.noPassword(); b.privateKey(contentKey); } catch (IOException e) { journal.log(Level.SEVERE, e.getMessage()); } }else{ b.user(login); b.noPassword(); b.privateKey(key); } return b; }
Example #7
Source File: OpenStackConnector.java From cloudml with GNU Lesser General Public License v3.0 | 6 votes |
/** * Execute a command on a group of VMs * @param group name of the group * @param command the command to be executed * @param login username * @param key sshkey * @throws RunScriptOnNodesException */ public void execCommandInGroup(String group, String command, String login, String key) throws RunScriptOnNodesException { journal.log(Level.INFO, ">> executing command..."); journal.log(Level.INFO, ">> "+ command); org.jclouds.domain.LoginCredentials.Builder b=initCredentials(login, key); Map<? extends NodeMetadata, ExecResponse> responses = novaComputeService.runScriptOnNodesMatching( runningInGroup(group), exec(command), overrideLoginCredentials(b.build()) .runAsRoot(false) .wrapInInitScript(false));// run command directly for(Map.Entry<? extends NodeMetadata, ExecResponse> r : responses.entrySet()) journal.log(Level.INFO, ">> "+r.getValue()); }
Example #8
Source File: JCloudsConnector.java From cloudml with GNU Lesser General Public License v3.0 | 6 votes |
/** * Prepare the credential builder * @param login * @param key * @return */ private org.jclouds.domain.LoginCredentials.Builder initCredentials(String login, String key){ String contentKey; org.jclouds.domain.LoginCredentials.Builder b= LoginCredentials.builder(); File f = new File(key); if(f.exists() && !f.isDirectory()) { try { contentKey = FileUtils.readFileToString(f); b.user(login); b.noPassword(); b.privateKey(contentKey); } catch (IOException e) { journal.log(Level.SEVERE, e.getMessage()); } }else{ b.user(login); b.noPassword(); b.privateKey(key); } return b; }
Example #9
Source File: AWSEC2CreateNodesInGroupThenAddToSet.java From attic-stratos with Apache License 2.0 | 6 votes |
@Inject protected AWSEC2CreateNodesInGroupThenAddToSet( AWSEC2Api client, @Named("ELASTICIP") LoadingCache<RegionAndName, String> elasticIpCache, @Named(TIMEOUT_NODE_RUNNING) Predicate<AtomicReference<NodeMetadata>> nodeRunning, @Named(PROPERTY_EC2_GENERATE_INSTANCE_NAMES) boolean generateInstanceNames, CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions createKeyPairAndSecurityGroupsAsNeededAndReturncustomize, PresentSpotRequestsAndInstances instancePresent, Function<RunningInstance, NodeMetadata> runningInstanceToNodeMetadata, LoadingCache<RunningInstance, Optional<LoginCredentials>> instanceToCredentials, Map<String, Credentials> credentialStore, ComputeUtils utils, SpotInstanceRequestToAWSRunningInstance spotConverter) { super(client, elasticIpCache, nodeRunning, createKeyPairAndSecurityGroupsAsNeededAndReturncustomize, instancePresent, runningInstanceToNodeMetadata, instanceToCredentials, credentialStore, utils); this.client = checkNotNull(client, "client"); this.spotConverter = checkNotNull(spotConverter, "spotConverter"); }
Example #10
Source File: JcloudsLocationUsageTrackingTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override protected NodeCreator newNodeCreator() { return new AbstractNodeCreator() { @Override protected NodeMetadata newNode(String group, Template template) { NodeMetadata result = new NodeMetadataBuilder() .id("myNodeId") .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build()) .loginPort(serverSocket.getLocalPort()) .status(Status.RUNNING) .publicAddresses(ImmutableList.of(serverSocket.getInetAddress().getHostAddress())) .privateAddresses(ImmutableList.of("1.2.3.4")) .imageId(template.getImage().getId()) .tags(template.getOptions().getTags()) .hardware(includeNodeHardwareMetadata ? template.getHardware() : null) .group(template.getOptions().getGroups().isEmpty() ? "myGroup" : Iterables.get(template.getOptions().getGroups(), 0)) .build(); return result; } }; }
Example #11
Source File: JcloudsLocation.java From brooklyn-server with Apache License 2.0 | 6 votes |
/** @return An Iterable of credentials based on nodeCreds containing different parameters. */ Iterable<LoginCredentials> generateCredentials(LoginCredentials nodeCreds, @Nullable String loginUserOverride) { String nodeUser = nodeCreds.getUser(); Set<String> users = MutableSet.of(); if (Strings.isNonBlank(nodeUser)) { users.add(nodeUser); } if (Strings.isNonBlank(loginUserOverride)) { users.add(loginUserOverride); } List<LoginCredentials> credentialsToTry = new ArrayList<>(); for (String user : users) { if (nodeCreds.getOptionalPassword().isPresent() && nodeCreds.getOptionalPrivateKey().isPresent()) { credentialsToTry.add(LoginCredentials.builder(nodeCreds).noPassword().user(user).build()); credentialsToTry.add(LoginCredentials.builder(nodeCreds).noPrivateKey().user(user).build()); } else { credentialsToTry.add(LoginCredentials.builder(nodeCreds).user(user).build()); } } return credentialsToTry; }
Example #12
Source File: StubbedComputeServiceRegistry.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override protected NodeMetadata newNode(String group, Template template) { int suffix = counter.getAndIncrement(); org.jclouds.domain.Location region = new LocationBuilder() .scope(LocationScope.REGION) .id("us-east-1") .description("us-east-1") .parent(new LocationBuilder() .scope(LocationScope.PROVIDER) .id("aws-ec2") .description("aws-ec2") .build()) .build(); NodeMetadata result = new NodeMetadataBuilder() .id("mynodeid"+suffix) .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build()) .loginPort(22) .status(Status.RUNNING) .publicAddresses(ImmutableList.of("173.194.32."+suffix)) .privateAddresses(ImmutableList.of("172.168.10."+suffix)) .location(region) .build(); return result; }
Example #13
Source File: JcloudsTemplateOptionsStubbedTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override protected NodeCreator newNodeCreator() { return new AbstractNodeCreator() { @Override protected NodeMetadata newNode(String group, Template template) { NodeMetadata result = new NodeMetadataBuilder() .id("myid") .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build()) .loginPort(22) .status(Status.RUNNING) .publicAddresses(ImmutableList.of("173.194.32.123")) .privateAddresses(ImmutableList.of("172.168.10.11")) .build(); return result; } }; }
Example #14
Source File: JcloudsSshMachineLocationStubbedTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override protected NodeCreator newNodeCreator() { return new AbstractNodeCreator() { @Override protected NodeMetadata newNode(String group, Template template) { NodeMetadata result = new NodeMetadataBuilder() .id("myid") .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build()) .loginPort(22) .status(Status.RUNNING) .publicAddresses(publicAddresses) .privateAddresses(privateAddresses) .build(); return result; } }; }
Example #15
Source File: JcloudsStubTemplateBuilder.java From brooklyn-server with Apache License 2.0 | 6 votes |
protected Image getImage() { switch (providerName) { case "aws-ec2" : case "ec2" : return new ImageBuilder().providerId("ebs-image-provider").name("image") .id(regionName+"/bogus-image").location(jcloudsDomainLocation) .userMetadata(ImmutableMap.of("rootDeviceType", RootDeviceType.EBS.value())) .operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", VirtualizationType.PARAVIRTUAL.value(), "ubuntu", true)) .description("description").version("1.0").defaultCredentials(LoginCredentials.builder().user("root").build()) .status(Image.Status.AVAILABLE) .build(); case "google-compute-engine" : return new ImageBuilder().providerId("gce-image-provider").name("image") .id(regionName+"/bogus-image").location(jcloudsDomainLocation) .operatingSystem(new OperatingSystem(OsFamily.UBUNTU, null, "1.0", VirtualizationType.PARAVIRTUAL.value(), "ubuntu", true)) .description("description").version("1.0").defaultCredentials(LoginCredentials.builder().user("root").build()) .status(Image.Status.AVAILABLE) .build(); default: throw new UnsupportedOperationException("Unsupported stubbed Image for provider "+providerName); } }
Example #16
Source File: JcloudsLocation.java From brooklyn-server with Apache License 2.0 | 6 votes |
protected String getPrivateHostname(NodeMetadata node, Optional<HostAndPort> sshHostAndPort, Supplier<? extends LoginCredentials> userCredentials, ConfigBag setup) { Boolean useMachinePublicAddressAsPrivateAddress = (setup != null) ? setup.get(USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS) : false; if(useMachinePublicAddressAsPrivateAddress) { LOG.debug("Overriding private hostname as public hostname because config "+ USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS.getName()+" is set to true"); return getPublicHostname(node, sshHostAndPort, userCredentials, setup); } String provider = (setup != null) ? setup.get(CLOUD_PROVIDER) : null; Boolean lookupAwsHostname = (setup != null) ? setup.get(LOOKUP_AWS_HOSTNAME) : null; if (provider == null) provider = getProvider(); // TODO Discouraged to do cloud-specific things; think of this code for aws as an // exceptional situation rather than a pattern to follow. We need a better way to // do cloud-specific things. if ("aws-ec2".equals(provider) && Boolean.TRUE.equals(lookupAwsHostname)) { Maybe<String> result = getHostnameAws(node, sshHostAndPort, userCredentials, setup); if (result.isPresent()) return result.get(); } Optional<String> preferredAddress = sshHostAndPort.isPresent() ? Optional.of(sshHostAndPort.get().getHostText()) : Optional.<String>absent(); return getPrivateHostnameGeneric(node, setup, preferredAddress); }
Example #17
Source File: JcloudsLocation.java From brooklyn-server with Apache License 2.0 | 6 votes |
String getHostnameAws(HostAndPort hostAndPort, LoginCredentials userCredentials, ConfigBag setup) { // TODO messy way to get an SSH session SshMachineLocation sshLocByIp = createTemporarySshMachineLocation(hostAndPort, userCredentials, setup); try { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); ByteArrayOutputStream errStream = new ByteArrayOutputStream(); int exitcode = sshLocByIp.execCommands( MutableMap.of("out", outStream, "err", errStream), "get public AWS hostname", ImmutableList.of( BashCommands.INSTALL_CURL, "echo `curl --silent --retry 20 http://169.254.169.254/latest/meta-data/public-hostname`; exit")); String outString = new String(outStream.toByteArray()); String[] outLines = outString.split("\n"); for (String line : outLines) { if (line.startsWith("ec2-")) return line.trim(); } throw new IllegalStateException("Could not obtain aws-ec2 hostname for vm "+hostAndPort+"; exitcode="+exitcode+"; stdout="+outString+"; stderr="+new String(errStream.toByteArray())); } finally { if (getManagementContext().getLocationManager().isManaged(sshLocByIp)) { getManagementContext().getLocationManager().unmanage(sshLocByIp); } Streams.closeQuietly(sshLocByIp); } }
Example #18
Source File: JcloudsByonLocationResolverStubbedTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override protected NodeCreator newNodeCreator() { return new AbstractNodeCreator() { @Override public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<? super NodeMetadata> filter) { NodeMetadata result = new NodeMetadataBuilder() .id(nodeId) .credentials(LoginCredentials.builder().identity("dummy").credential("dummy").build()) .loginPort(22) .status(Status.RUNNING) .publicAddresses(ImmutableList.of(nodePublicAddress)) .privateAddresses(ImmutableList.of(nodePrivateAddress)) .build(); return ImmutableSet.copyOf(Iterables.filter(ImmutableList.of(result), filter)); } @Override protected NodeMetadata newNode(String group, Template template) { throw new UnsupportedOperationException(); } }; }
Example #19
Source File: DefaultConnectivityResolverTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testTestCredentialWithWindowsMachine() throws Exception { final String allowedUser = "Mr. Big"; // Match every command. RecordingWinRmTool.setCustomResponse(".*", new RecordingWinRmTool.CustomResponseGenerator() { @Override public RecordingWinRmTool.CustomResponse generate(RecordingWinRmTool.ExecParams execParams) { boolean valid = allowedUser.equals(execParams.constructorProps.get("user")); return new RecordingWinRmTool.CustomResponse(valid ? 0 : 1, "", ""); } }); initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of()); DefaultConnectivityResolver customizer = new DefaultConnectivityResolver(); final ConfigBag config = ConfigBag.newInstanceExtending(jcloudsLocation.config().getBag(), ImmutableMap.of( JcloudsLocationConfig.WAIT_FOR_WINRM_AVAILABLE, "1ms", JcloudsLocationConfig.POLL_FOR_FIRST_REACHABLE_ADDRESS, "1ms")); assertTrue(customizer.checkCredential( jcloudsLocation, HostAndPort.fromParts("10.0.0.234", 22), LoginCredentials.builder().user(allowedUser).password("password1").build(), config, true)); assertFalse(customizer.checkCredential( jcloudsLocation, HostAndPort.fromParts("10.0.0.234", 22), credential, config, true)); }
Example #20
Source File: JcloudsSshMachineLocationAddressOverwriteTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override protected NodeCreator newNodeCreator() { return new AbstractNodeCreator() { @Override protected NodeMetadata newNode(String group, Template template) { NodeMetadata result = new NodeMetadataBuilder() .id("myid") .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build()) .loginPort(22) .status(Status.RUNNING) .publicAddresses(publicAddresses) .privateAddresses(privateAddresses) .build(); return result; } }; }
Example #21
Source File: DefaultConnectivityResolverTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testTestCredentialWithLinuxMachine() throws Exception { final String allowedUser = "Mr. Big"; // Match every command. RecordingSshTool.setCustomResponse(".*", new RecordingSshTool.CustomResponseGenerator() { @Override public RecordingSshTool.CustomResponse generate(RecordingSshTool.ExecParams execParams) throws Exception { boolean valid = allowedUser.equals(execParams.constructorProps.get("user")); return new RecordingSshTool.CustomResponse(valid ? 0 : 1, "", ""); } }); initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of()); DefaultConnectivityResolver customizer = new DefaultConnectivityResolver(); final ConfigBag config = ConfigBag.newInstanceExtending(jcloudsLocation.config().getBag(), ImmutableMap.of( JcloudsLocationConfig.WAIT_FOR_SSHABLE, "1ms", JcloudsLocationConfig.POLL_FOR_FIRST_REACHABLE_ADDRESS, "1ms")); assertTrue(customizer.checkCredential( jcloudsLocation, HostAndPort.fromParts("10.0.0.234", 22), LoginCredentials.builder().user(allowedUser).password("password1").build(), config, false)); assertFalse(customizer.checkCredential( jcloudsLocation, HostAndPort.fromParts("10.0.0.234", 22), credential, config, false)); }
Example #22
Source File: JCloudsConnector.java From cloudml with GNU Lesser General Public License v3.0 | 6 votes |
/** * Execute a command on a group of vms * @param group name of the group * @param command the command to be executed * @param login username * @param key sshkey * @throws RunScriptOnNodesException */ public void execCommandInGroup(String group, String command, String login, String key) throws RunScriptOnNodesException{ journal.log(Level.INFO, ">> executing command..."); journal.log(Level.INFO, ">> "+ command); org.jclouds.domain.LoginCredentials.Builder b=initCredentials(login, key); journal.log(Level.INFO, ">> executing command..."+b.build()); Map<? extends NodeMetadata, ExecResponse> responses = compute.runScriptOnNodesMatching( runningInGroup(group), exec(command), overrideLoginCredentials(b.build()) .runAsRoot(false) .wrapInInitScript(false));// run command directly for(Entry<? extends NodeMetadata, ExecResponse> r : responses.entrySet()) journal.log(Level.INFO, ">> "+r.getValue()); }
Example #23
Source File: MainApp.java From jclouds-examples with Apache License 2.0 | 5 votes |
private static LoginCredentials getLoginForCommandExecution(Action action) { try { String user = System.getProperty("user.name"); String privateKey = Files.toString( new File(System.getProperty("user.home") + "/.ssh/id_rsa"), UTF_8); return LoginCredentials.builder(). user(user).privateKey(privateKey).build(); } catch (Exception e) { System.err.println("error reading ssh key " + e.getMessage()); System.exit(1); return null; } }
Example #24
Source File: JcloudsByonLocationResolverStubbedRebindTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public Set<? extends NodeMetadata> listNodesDetailsMatching(Predicate<? super NodeMetadata> filter) { NodeMetadata result = new NodeMetadataBuilder() .id(nodeId) .credentials(LoginCredentials.builder().identity("dummy").credential("dummy").build()) .loginPort(22) .status(Status.RUNNING) .publicAddresses(ImmutableList.of(nodePublicAddress)) .privateAddresses(ImmutableList.of(nodePrivateAddress)) .build(); return ImmutableSet.copyOf(Iterables.filter(ImmutableList.of(result), filter)); }
Example #25
Source File: DefaultConnectivityResolver.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected boolean checkCredential( JcloudsLocation location, HostAndPort hostAndPort, LoginCredentials credentials, ConfigBag config, boolean isWindows) { try { if (isWindows) { location.waitForWinRmAvailable(credentials, hostAndPort, config); } else { location.waitForSshable(hostAndPort, ImmutableList.of(credentials), config); } return true; } catch (IllegalStateException e) { return false; } }
Example #26
Source File: JcloudsUtil.java From brooklyn-server with Apache License 2.0 | 5 votes |
public static String waitForPasswordOnAws(ComputeService computeService, final NodeMetadata node, long timeout, TimeUnit timeUnit) throws TimeoutException { ComputeServiceContext computeServiceContext = computeService.getContext(); AWSEC2Api ec2Client = computeServiceContext.unwrapApi(AWSEC2Api.class); final WindowsApi client = ec2Client.getWindowsApi().get(); final String region = node.getLocation().getParent().getId(); // The Administrator password will take some time before it is ready - Amazon says sometimes 15 minutes. // So we create a predicate that tests if the password is ready, and wrap it in a retryable predicate. Predicate<String> passwordReady = new Predicate<String>() { @Override public boolean apply(String s) { if (Strings.isNullOrEmpty(s)) return false; PasswordData data = client.getPasswordDataInRegion(region, s); if (data == null) return false; return !Strings.isNullOrEmpty(data.getPasswordData()); } }; LOG.info("Waiting for password, for "+node.getProviderId()+":"+node.getId()); Predicate<String> passwordReadyRetryable = Predicates2.retry(passwordReady, timeUnit.toMillis(timeout), 10*1000, TimeUnit.MILLISECONDS); boolean ready = passwordReadyRetryable.apply(node.getProviderId()); if (!ready) throw new TimeoutException("Password not available for "+node+" in region "+region+" after "+timeout+" "+timeUnit.name()); // Now pull together Amazon's encrypted password blob, and the private key that jclouds generated PasswordDataAndPrivateKey dataAndKey = new PasswordDataAndPrivateKey( client.getPasswordDataInRegion(region, node.getProviderId()), node.getCredentials().getPrivateKey()); // And apply it to the decryption function WindowsLoginCredentialsFromEncryptedData f = computeServiceContext.utils().injector().getInstance(WindowsLoginCredentialsFromEncryptedData.class); LoginCredentials credentials = f.apply(dataAndKey); return credentials.getPassword(); }
Example #27
Source File: JcloudsSshMachineLocation.java From brooklyn-server with Apache License 2.0 | 5 votes |
private LoginCredentials getLoginCredentials() { OsCredential creds = LocationConfigUtils.getOsCredential(new ResolvingConfigBag(getManagementContext(), config().getBag())); return LoginCredentials.builder() .user(getUser()) .privateKey(creds.hasKey() ? creds.getPrivateKeyData() : null) .password(creds.hasPassword() ? creds.getPassword() : null) .build(); }
Example #28
Source File: CloudDistributedTLCJob.java From tlaplus with MIT License | 5 votes |
private static LoginCredentials getLoginForCommandExecution() throws IOException { //TODO Lookup user in ~/.ssh/config in case there exists a user-defined mapping for this host. final String user = System.getProperty("user.name"); final String privateKey = Files.toString(new File(System.getProperty("user.home") + "/.ssh/id_rsa"), Charsets.UTF_8); return LoginCredentials.builder().user(user).privateKey(privateKey).build(); }
Example #29
Source File: JcloudsSshMachineLocation.java From brooklyn-server with Apache License 2.0 | 5 votes |
private Supplier<LoginCredentials> getLoginCredentialsSupplier() { return new Supplier<LoginCredentials>() { @Override public LoginCredentials get() { return getLoginCredentials(); } }; }
Example #30
Source File: AWSRunningInstanceToNodeMetadata.java From attic-stratos with Apache License 2.0 | 5 votes |
@Override protected void addCredentialsForInstance(NodeMetadataBuilder builder, RunningInstance instance) { LoginCredentials creds = LoginCredentials.fromCredentials(credentialStore.get("node#" + instance.getRegion() + "/" + instance.getId())); String spotRequestId = AWSRunningInstance.class.cast(instance).getSpotInstanceRequestId(); if (creds == null && spotRequestId != null) { creds = LoginCredentials.fromCredentials(credentialStore.get("node#" + instance.getRegion() + "/" + spotRequestId)); if (creds != null) credentialStore.put("node#" + instance.getRegion() + "/" + instance.getId(), creds); } if (creds != null) builder.credentials(creds); }