private void generateKeyPairAndAddKeyToSet(DigitalOcean2TemplateOptions options, Set<Integer> generatedSshKeyIds, String prefix) { logger.debug(">> creating default keypair for node..."); Map<String, String> defaultKeys = keyGenerator.get(); Key defaultKey = api.keyApi().create(prefix + "-" + System.getProperty("user.name"), defaultKeys.get("public")); generatedSshKeyIds.add(defaultKey.id()); logger.debug(">> keypair created! %s", defaultKey); // If a private key has not been explicitly set, configure the auto-generated one if (Strings.isNullOrEmpty(options.getLoginPrivateKey())) { options.overrideLoginPrivateKey(defaultKeys.get("private")); } }
private void generateKeyPairAndAddKeyToSet(DigitalOcean2TemplateOptions options, Set<Integer> generatedSshKeyIds, String prefix) { logger.debug(">> creating default keypair for node..."); Map<String, String> defaultKeys = keyGenerator.get(); Key defaultKey = api.keyApi().create(prefix + "-" + System.getProperty("user.name"), defaultKeys.get("public")); generatedSshKeyIds.add(defaultKey.id()); logger.debug(">> keypair created! %s", defaultKey); // If a private key has not been explicitly set, configure the auto-generated one if (Strings.isNullOrEmpty(options.getLoginPrivateKey())) { options.overrideLoginPrivateKey(defaultKeys.get("private")); } }
private void generateKeyPairAndAddKeyToSet(DigitalOcean2TemplateOptions options, Set<Integer> generatedSshKeyIds, String prefix) { logger.debug(">> creating default keypair for node..."); Map<String, String> defaultKeys = keyGenerator.get(); Key defaultKey = api.keyApi().create(prefix + "-" + System.getProperty("user.name"), defaultKeys.get("public")); generatedSshKeyIds.add(defaultKey.id()); logger.debug(">> keypair created! %s", defaultKey); // If a private key has not been explicitly set, configure the auto-generated one if (Strings.isNullOrEmpty(options.getLoginPrivateKey())) { options.overrideLoginPrivateKey(defaultKeys.get("private")); } }
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")); } }
@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); }
@Override public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { GoogleComputeEngineTemplateOptions templateOptions = GoogleComputeEngineTemplateOptions.class .cast(template.getOptions()); assert template.getOptions().equals(templateOptions) : "options didn't clone properly"; // Configure networking configureNetworking(group, templateOptions, template.getLocation()); templateOptions.userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group); // Configure the default credentials, if needed if (templateOptions.autoCreateKeyPair() && Strings.isNullOrEmpty(templateOptions.getPublicKey())) { logger.debug(">> creating default keypair..."); Map<String, String> defaultKeys = keyGenerator.get(); templateOptions.authorizePublicKey(defaultKeys.get("public")); templateOptions.overrideLoginPrivateKey(defaultKeys.get("private")); } if (templateOptions.getRunScript() != null && templateOptions.getLoginPrivateKey() == null) { logger.warn(">> a runScript has been configured but no SSH key has been provided." + " Authentication will delegate to the ssh-agent"); } return super.execute(group, count, template, goodNodes, badNodes, customizationResponses); }
@Override public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { Template mutableTemplate = template.clone(); GoogleComputeEngineTemplateOptions templateOptions = GoogleComputeEngineTemplateOptions.class .cast(mutableTemplate.getOptions()); assert template.getOptions().equals(templateOptions) : "options didn't clone properly"; // Get Network Network network = getNetwork(templateOptions.getNetworks()); // Setup Firewall rules getOrCreateFirewalls(templateOptions, network, firewallTagNamingConvention.get(group)); templateOptions.networks(ImmutableSet.of(network.selfLink().toString())); templateOptions.userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group); // Configure the default credentials, if needed if (templateOptions.autoCreateKeyPair() && Strings.isNullOrEmpty(templateOptions.getPublicKey())) { logger.debug(">> creating default keypair..."); Map<String, String> defaultKeys = keyGenerator.get(); templateOptions.authorizePublicKey(defaultKeys.get("public")); templateOptions.overrideLoginPrivateKey(defaultKeys.get("private")); } if (templateOptions.getRunScript() != null && templateOptions.getLoginPrivateKey() == null) { logger.warn(">> A runScript has been configured but no SSH key has been provided." + " Authentication will delegate to the ssh-agent"); } return super.execute(group, count, mutableTemplate, goodNodes, badNodes, customizationResponses); }
@Override public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { GoogleComputeEngineTemplateOptions templateOptions = GoogleComputeEngineTemplateOptions.class .cast(template.getOptions()); assert template.getOptions().equals(templateOptions) : "options didn't clone properly"; // Configure networking configureNetworking(group, templateOptions, template.getLocation()); templateOptions.userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group); // Configure the default credentials, if needed if (templateOptions.autoCreateKeyPair() && Strings.isNullOrEmpty(templateOptions.getPublicKey())) { logger.debug(">> creating default keypair..."); Map<String, String> defaultKeys = keyGenerator.get(); templateOptions.authorizePublicKey(defaultKeys.get("public")); templateOptions.overrideLoginPrivateKey(defaultKeys.get("private")); } if (templateOptions.getRunScript() != null && templateOptions.getLoginPrivateKey() == null) { logger.warn(">> a runScript has been configured but no SSH key has been provided." + " Authentication will delegate to the ssh-agent"); } return super.execute(group, count, template, goodNodes, badNodes, customizationResponses); }
@Override public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { String sharedResourceName = namingConvention.create().sharedNameForGroup(group); Template mutableTemplate = template.clone(); GoogleComputeEngineTemplateOptions templateOptions = GoogleComputeEngineTemplateOptions.class .cast(mutableTemplate.getOptions()); assert template.getOptions().equals(templateOptions) : "options didn't clone properly"; // get or insert the network and insert a firewall with the users // configuration Network network = getOrCreateNetwork(templateOptions, sharedResourceName); getOrCreateFirewalls(templateOptions, network, firewallTagNamingConvention.get(group)); templateOptions.network(network.selfLink()); templateOptions.userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group); // Configure the default credentials, if needed if (templateOptions.autoCreateKeyPair() && Strings.isNullOrEmpty(templateOptions.getPublicKey())) { logger.debug(">> creating default keypair..."); Map<String, String> defaultKeys = keyGenerator.get(); templateOptions.authorizePublicKey(defaultKeys.get("public")); templateOptions.overrideLoginPrivateKey(defaultKeys.get("private")); } if (templateOptions.getRunScript() != null && templateOptions.getLoginPrivateKey() == null) { logger.warn(">> A runScript has been configured but no SSH key has been provided." + " Authentication will delegate to the ssh-agent"); } return super.execute(group, count, mutableTemplate, goodNodes, badNodes, customizationResponses); }