/** * Find the next node names that can be used. These will be derived from the group and the * template. We will pre-allocate a specified quantity, and attempt to verify that there is no * name conflict with the current service. * * @param group * @param count * @param template * @return */ protected Set<String> getNextNames(final String group, final Template template, int count) { Set<String> names = newLinkedHashSet(); Iterable<? extends ComputeMetadata> currentNodes = listNodesStrategy.listNodes(); int maxTries = 100; int currentTries = 0; while (names.size() < count && currentTries++ < maxTries) { final String name = namingConvention.createWithoutPrefix().uniqueNameForGroup(group); if (!any(currentNodes, new Predicate<ComputeMetadata>() { @Override public boolean apply(ComputeMetadata input) { return name.equals(input.getName()); } })) { names.add(name); } } return names; }
@VisibleForTesting KeyPair createNewKeyPairInRegion(String region, String group) { checkNotNull(region, "region"); checkNotNull(group, "group"); logger.debug(">> creating keyPair region(%s) group(%s)", region, group); KeyPair keyPair = null; String prefix = group; while (keyPair == null) { String keyName = namingConvention.create().uniqueNameForGroup(prefix); try { keyPair = ec2Api.getKeyPairApi().get().createKeyPairInRegion(region, keyName); } catch (IllegalStateException e) { logger.trace(" invalid keyname (%s in %s); retrying", keyName, region); } } logger.debug("<< created keyPair(%s)", keyPair); return keyPair; } }
@VisibleForTesting KeyPair createNewKeyPairInRegion(String region, String group) { checkNotNull(region, "region"); checkNotNull(group, "group"); logger.debug(">> creating keyPair region(%s) group(%s)", region, group); KeyPair keyPair = null; String prefix = group; while (keyPair == null) { String keyName = namingConvention.create().uniqueNameForGroup(prefix); try { keyPair = ec2Api.getKeyPairApi().get().createKeyPairInRegion(region, keyName); } catch (IllegalStateException e) { logger.trace(" invalid keyname (%s in %s); retrying", keyName, region); } } logger.debug("<< created keyPair(%s)", keyPair); return keyPair; } }
@VisibleForTesting KeyPair createNewKeyPairInRegion(String region, String group) { checkNotNull(region, "region"); checkNotNull(group, "group"); logger.debug(">> creating keyPair region(%s) group(%s)", region, group); KeyPair keyPair = null; String prefix = group; while (keyPair == null) { String keyName = namingConvention.create().uniqueNameForGroup(prefix); try { keyPair = ec2Api.getKeyPairApi().get().createKeyPairInRegion(region, keyName); } catch (IllegalStateException e) { logger.trace(" invalid keyname (%s in %s); retrying", keyName, region); } } logger.debug("<< created keyPair(%s)", keyPair); return keyPair; } }
@VisibleForTesting KeyPair createNewKeyPairInRegion(String region, String group) { checkNotNull(region, "region"); checkNotNull(group, "group"); logger.debug(">> creating keyPair region(%s) group(%s)", region, group); KeyPair keyPair = null; String prefix = group; while (keyPair == null) { String keyName = namingConvention.create().uniqueNameForGroup(prefix); try { keyPair = ec2Client.getKeyPairServices().createKeyPairInRegion(region, keyName); } catch (IllegalStateException e) { logger.trace(" invalid keyname (%s in %s); retrying", keyName, region); } } logger.debug("<< created keyPair(%s)", keyPair); return keyPair; } }
@VisibleForTesting KeyPair createNewKeyPairInRegion(String region, String group) { checkNotNull(region, "region"); checkNotNull(group, "group"); logger.debug(">> creating keyPair region(%s) group(%s)", region, group); KeyPair keyPair = null; String prefix = group; while (keyPair == null) { String keyName = namingConvention.create().uniqueNameForGroup(prefix); try { keyPair = ec2Client.getKeyPairServices().createKeyPairInRegion(region, keyName); } catch (IllegalStateException e) { logger.trace(" invalid keyname (%s in %s); retrying", keyName, region); } } logger.debug("<< created keyPair(%s)", keyPair); return keyPair; } }
private PublicIPAddress createPublicIp(String resourceGroup, String location, String nodeName) { String name = namingConvention.uniqueNameForGroup(nodeName); PublicIPAddressProperties properties = PublicIPAddressProperties.builder() .publicIPAllocationMethod("Static") .idleTimeoutInMinutes(4) .build(); logger.debug(">> allocating new public ip address: %s", name); PublicIPAddress ip = api.getPublicIPAddressApi(resourceGroup).createOrUpdate(name, location, ImmutableMap.of("jclouds", nodeName, AUTOGENERATED_IP_KEY, "true"), properties); checkState(publicIpAvailable.create(resourceGroup).apply(name), "Public IP was not provisioned in the configured timeout"); return ip; }
@Override public KeyPair load(ZoneAndName zoneAndName) { String zoneId = checkNotNull(zoneAndName, "zoneAndName").getZone(); String prefix = zoneAndName.getName(); Optional<? extends KeyPairApi> api = novaApi.getKeyPairExtensionForZone(zoneId); checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in zone %s!", zoneId); logger.debug(">> creating keyPair zone(%s) prefix(%s)", zoneId, prefix); KeyPair keyPair = null; while (keyPair == null) { try { keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix)); } catch (IllegalStateException e) { } } logger.debug("<< created keyPair(%s)", keyPair.getName()); return keyPair; }
private void generateKeyPairAndAddKeyToSet(PacketTemplateOptions options, Set<String> generatedSshKeyIds, String prefix) { logger.debug(">> creating default keypair for node..."); Map<String, String> defaultKeys = keyGenerator.get(); SshKey sshKey = api.sshKeyApi().create(namingConvention.create().uniqueNameForGroup(prefix), defaultKeys.get("public")); generatedSshKeyIds.add(sshKey.id()); logger.debug(">> keypair created! %s", sshKey); // If a private key has not been explicitly set, configure the generated // one if (Strings.isNullOrEmpty(options.getLoginPrivateKey())) { options.overrideLoginPrivateKey(defaultKeys.get("private")); } }
private PublicIPAddress createPublicIp(String resourceGroup, String location, String nodeName) { String name = namingConvention.uniqueNameForGroup(nodeName); PublicIPAddressProperties properties = PublicIPAddressProperties.builder() .publicIPAllocationMethod("Static") .idleTimeoutInMinutes(4) .build(); logger.debug(">> allocating new public ip address: %s", name); PublicIPAddress ip = api.getPublicIPAddressApi(resourceGroup).createOrUpdate(name, location, ImmutableMap.of("jclouds", nodeName, AUTOGENERATED_IP_KEY, "true"), null, properties); checkState(publicIpAvailable.create(resourceGroup).apply(name), "Public IP was not provisioned in the configured timeout"); return ip; }
@Override public KeyPair load(ZoneAndName zoneAndName) { String zoneId = checkNotNull(zoneAndName, "zoneAndName").getZone(); String prefix = zoneAndName.getName(); Optional<? extends KeyPairApi> api = novaApi.getKeyPairExtensionForZone(zoneId); checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in zone %s!", zoneId); logger.debug(">> creating keyPair zone(%s) prefix(%s)", zoneId, prefix); KeyPair keyPair = null; while (keyPair == null) { try { keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix)); } catch (IllegalStateException e) { } } logger.debug("<< created keyPair(%s)", keyPair.getName()); return keyPair; }
@Override public KeyPair load(RegionAndName regionAndName) { String regionId = checkNotNull(regionAndName, "regionAndName").getRegion(); String prefix = regionAndName.getName(); Optional<? extends KeyPairApi> api = novaApi.getKeyPairApi(regionId); checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in region %s!", regionId); logger.debug(">> creating keyPair region(%s) prefix(%s)", regionId, prefix); KeyPair keyPair = null; while (keyPair == null) { try { keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix)); } catch (IllegalStateException e) { } } logger.debug("<< created keyPair(%s)", keyPair.getName()); return keyPair; }
@Override public KeyPair load(ZoneAndName zoneAndName) { String zoneId = checkNotNull(zoneAndName, "zoneAndName").getZone(); String prefix = zoneAndName.getName(); Optional<? extends KeyPairApi> api = novaApi.getKeyPairExtensionForZone(zoneId); checkArgument(api.isPresent(), "Key pairs are required, but the extension is not available in zone %s!", zoneId); logger.debug(">> creating keyPair zone(%s) prefix(%s)", zoneId, prefix); KeyPair keyPair = null; while (keyPair == null) { try { keyPair = api.get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix)); } catch (IllegalStateException e) { } } logger.debug("<< created keyPair(%s)", keyPair.getName()); return keyPair; }
private KeyPair generateKeyPair(String region, String prefix) { logger.debug(">> creating default keypair for node..."); KeyPair keyPair = novaApi.getKeyPairApi(region).get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix)); logger.debug(">> keypair created! %s", keyPair.getName()); return keyPair; }
private KeyPair generateKeyPair(String region, String prefix) { logger.debug(">> creating default keypair for node..."); KeyPair keyPair = novaApi.getKeyPairApi(region).get().create(namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix)); logger.debug(">> keypair created! %s", keyPair.getName()); return keyPair; }
public void testCanChangeSuffixSupplier() { GroupNamingConvention fn = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(new TypeLiteral<Supplier<String>>() { }).toInstance(Suppliers.ofInstance("foo")); } }).getInstance(GroupNamingConvention.Factory.class).create(); assertEquals(fn.uniqueNameForGroup("cluster"), "jclouds-cluster-foo"); // note accidental treatment of a unique node as a shared one can lead to // incorrect group names, as long as we permit delimiter to be in group name assertEquals(fn.groupInSharedNameOrNull("jclouds-cluster-foo"), "cluster-foo"); assertEquals(fn.groupInUniqueNameOrNull("jclouds-cluster-foo"), "cluster"); assertTrue(fn.containsGroup("cluster").apply("jclouds-cluster-foo")); }
public void testCanChangeSuffixSupplier() { GroupNamingConvention fn = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind(new TypeLiteral<Supplier<String>>() { }).toInstance(Suppliers.ofInstance("foo")); } }).getInstance(GroupNamingConvention.Factory.class).create(); assertEquals(fn.uniqueNameForGroup("cluster"), "jclouds-cluster-foo"); // note accidental treatment of a unique node as a shared one can lead to // incorrect group names, as long as we permit delimiter to be in group name assertEquals(fn.groupInSharedNameOrNull("jclouds-cluster-foo"), "cluster-foo"); assertEquals(fn.groupInUniqueNameOrNull("jclouds-cluster-foo"), "cluster"); assertTrue(fn.containsGroup("cluster").apply("jclouds-cluster-foo")); }
@Override public KeyAndPrivateKey load(DatacenterAndName datacenterAndName) { String datacenterId = checkNotNull(datacenterAndName, "datacenterAndName").getDatacenter(); String prefix = datacenterAndName.getName(); Map<String, String> keyPair = SshKeys.generate(crypto.rsaKeyPairGenerator(), secureRandom.get()); String publicKey = keyPair.get("public"); String privateKey = keyPair.get("private"); logger.debug(">> creating key datacenter(%s) prefix(%s)", datacenterId, prefix); Key key = null; while (key == null) { String name = namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix); try { key = sdcClient.getKeyClient().create(Key.builder().name(name).key(publicKey).build()); } catch (IllegalStateException e) { logger.trace("error creating keypair named %s, %s", name, e.getMessage()); } } logger.debug("<< created key(%s)", key.getName()); return KeyAndPrivateKey.fromKeyAndPrivateKey(key, privateKey); }
@Override public KeyAndPrivateKey load(DatacenterAndName datacenterAndName) { String datacenterId = checkNotNull(datacenterAndName, "datacenterAndName").getDatacenter(); String prefix = datacenterAndName.getName(); Map<String, String> keyPair = sshKeyPairGenerator.get(); String publicKey = keyPair.get("public"); String privateKey = keyPair.get("private"); logger.debug(">> creating key datacenter(%s) prefix(%s)", datacenterId, prefix); Key key = null; while (key == null) { String name = namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix); try { key = cloudApiApi.getKeyApi().create(Key.builder().name(name).key(publicKey).build()); } catch (IllegalStateException e) { logger.trace("error creating keypair named %s, %s", name, e.getMessage()); } } logger.debug("<< created key(%s)", key.getName()); return KeyAndPrivateKey.fromKeyAndPrivateKey(key, privateKey); }
@Override public KeyAndPrivateKey load(DatacenterAndName datacenterAndName) { String datacenterId = checkNotNull(datacenterAndName, "datacenterAndName").getDatacenter(); String prefix = datacenterAndName.getName(); Map<String, String> keyPair = sshKeyPairGenerator.get(); String publicKey = keyPair.get("public"); String privateKey = keyPair.get("private"); logger.debug(">> creating key datacenter(%s) prefix(%s)", datacenterId, prefix); Key key = null; while (key == null) { String name = namingConvention.createWithoutPrefix().uniqueNameForGroup(prefix); try { key = cloudApiApi.getKeyApi().create(Key.builder().name(name).key(publicKey).build()); } catch (IllegalStateException e) { logger.trace("error creating keypair named %s, %s", name, e.getMessage()); } } logger.debug("<< created key(%s)", key.getName()); return KeyAndPrivateKey.fromKeyAndPrivateKey(key, privateKey); }