@Override public TemplateBuilder from(String spec) { return from(TemplateBuilderSpec.parse(spec)); } }
@Inject PopulateDefaultLoginCredentialsForImageStrategy(@Named(TEMPLATE) String templateSpec, RsaSshKeyPairGenerator keyPairGenerator) throws NoSuchAlgorithmException { this.templateBuilder = TemplateBuilderSpec.parse(checkNotNull(templateSpec, "template builder spec")); checkNotNull(templateBuilder.getLoginUser(), "template builder spec must provide a loginUser"); this.keyPairGenerator = checkNotNull(keyPairGenerator, "keypair generator"); }
@Override public LoginCredentials apply(Object image) { return LoginCredentials.builder() .authenticateSudo(templateBuilder.getAuthenticateSudo() != null ? templateBuilder.getAuthenticateSudo() : false) .privateKey(compoundKey) .user(templateBuilder.getLoginUser()).build(); }
@Override protected Properties setupProperties() { Properties overrides = super.setupProperties(); String spec = setIfTestSystemPropertyPresent(overrides, provider + ".template"); if (spec != null) { template = TemplateBuilderSpec.parse(spec); if (template.getLoginUser() != null) { Iterable<String> userPass = Splitter.on(':').split(template.getLoginUser()); Builder loginCredentialsBuilder = LoginCredentials.builder(); loginCredentialsBuilder.user(Iterables.get(userPass, 0)); if (Iterables.size(userPass) == 2) loginCredentialsBuilder.password(Iterables.get(userPass, 1)); if (template.getAuthenticateSudo() != null) loginCredentialsBuilder.authenticateSudo(template.getAuthenticateSudo()); loginCredentials = loginCredentialsBuilder.build(); } } return overrides; }
@Test public void testHardwareIdPerInstanceTemplate() throws Exception { PropertiesConfiguration conf = new PropertiesConfiguration("whirr-core-test.properties"); conf.setProperty("whirr.instance-templates", "2 noop, 1 role1+role2, 1 role1, 3 spots, 1 spec"); conf.setProperty("whirr.hardware-id", "c1.xlarge"); conf.setProperty("whirr.templates.noop.hardware-id", "m1.large"); conf.setProperty("whirr.templates.role1+role2.hardware-id", "t1.micro"); conf.setProperty("whirr.templates.role1+role2.image-id", "us-east-1/ami-123324"); conf.setProperty("whirr.templates.spots.aws-ec2-spot-price", 0.5f); conf.setProperty("whirr.templates.spec.template", "osFamily=UBUNTU,os64Bit=true,minRam=2048"); ClusterSpec spec = ClusterSpec.withTemporaryKeys(conf); List<InstanceTemplate> templates = spec.getInstanceTemplates(); InstanceTemplate noops = get(templates, 0); assert noops.getRoles().contains("noop"); assertEquals(noops.getTemplate().getHardwareId(), "m1.large"); assertEquals(noops.getTemplate().getImageId(), null); assertEquals(noops.getAwsEc2SpotPrice(), null); InstanceTemplate second = get(templates, 1); assertEquals(second.getTemplate().getHardwareId(), "t1.micro"); assertEquals(second.getTemplate().getImageId(), "us-east-1/ami-123324"); assertEquals(second.getAwsEc2SpotPrice(), null); InstanceTemplate third = get(templates, 2); assertEquals(third.getTemplate(), null); assertEquals(third.getAwsEc2SpotPrice(), null); InstanceTemplate spots = get(templates, 3); assertEquals(spots.getAwsEc2SpotPrice(), new Float(0.5f), 0.001); InstanceTemplate template = get(templates, 4); assertEquals(template.getTemplate(), TemplateBuilderSpec.parse("osFamily=UBUNTU,os64Bit=true,minRam=2048")); assertEquals(template.getAwsEc2SpotPrice(), null); }
/** * AWS EC2 specific optimisation to avoid running queries across * all regiosn when the image-id is know from the property file * * @param spec */ private void enableAWSEC2LazyImageFetching(ClusterSpec spec) { overrides.setProperty(PROPERTY_EC2_AMI_QUERY, ""); overrides.setProperty(PROPERTY_EC2_CC_AMI_QUERY, ""); String[] parts = StringUtils.split(spec.getTemplate().getImageId(), '/'); checkArgument(parts.length == 2, "Expected to find image-id = region/ami-id"); overrides.setProperty(PROPERTY_REGION, parts[0]); }
.getClusterUser() : clusterSpec.getTemplate().getLoginUser();
@Override public TemplateBuilder from(TemplateBuilderSpec spec) { return spec.copyTo(this, options != null ? options : (options = optionsProvider.get())); }
/** * Creates a TemplateBuilderSpec from a string. * * @param templateBuilderSpecification * the string form */ public static TemplateBuilderSpec parse(String templateBuilderSpecification) { TemplateBuilderSpec spec = new TemplateBuilderSpec(templateBuilderSpecification); if (!templateBuilderSpecification.isEmpty()) { for (String keyValuePair : KEYS_SPLITTER.split(templateBuilderSpecification)) { List<String> keyAndValue = ImmutableList.copyOf(KEY_VALUE_SPLITTER.split(keyValuePair)); checkArgument(!keyAndValue.isEmpty(), "blank key-value pair"); checkArgument(keyAndValue.size() <= 2, "key-value pair %s with more than one equals sign", keyValuePair); // Find the ValueParser for the current key. String key = keyAndValue.get(0); ValueParser valueParser = VALUE_PARSERS.get(key); checkArgument(valueParser != null, "unknown key %s", key); String value = keyAndValue.size() == 1 ? null : keyAndValue.get(1); valueParser.parse(spec, key, value); } } return spec; }
@Override protected Properties setupProperties() { Properties overrides = super.setupProperties(); String spec = setIfTestSystemPropertyPresent(overrides, provider + ".template"); if (spec != null) { templateBuilderSpec = TemplateBuilderSpec.parse(spec); if (templateBuilderSpec.getLoginUser() != null) { Iterable<String> userPass = Splitter.on(':').split(templateBuilderSpec.getLoginUser()); Builder loginCredentialsBuilder = LoginCredentials.builder(); loginCredentialsBuilder.user(Iterables.get(userPass, 0)); if (Iterables.size(userPass) == 2) loginCredentialsBuilder.password(Iterables.get(userPass, 1)); if (templateBuilderSpec.getAuthenticateSudo() != null) loginCredentialsBuilder.authenticateSudo(templateBuilderSpec.getAuthenticateSudo()); loginCredentials = loginCredentialsBuilder.build(); } } return overrides; }
/** * AWS EC2 specific optimisation to avoid running queries across * all regiosn when the image-id is know from the property file * * @param spec */ private void enableAWSEC2LazyImageFetching(ClusterSpec spec) { overrides.setProperty(PROPERTY_EC2_AMI_QUERY, ""); overrides.setProperty(PROPERTY_EC2_CC_AMI_QUERY, ""); String[] parts = StringUtils.split(spec.getTemplate().getImageId(), '/'); checkArgument(parts.length == 2, "Expected to find image-id = region/ami-id"); overrides.setProperty(PROPERTY_REGION, parts[0]); }
.getClusterUser() : clusterSpec.getTemplate().getLoginUser();
@Override public TemplateBuilder from(TemplateBuilderSpec spec) { return spec.copyTo(this, options != null ? options : (options = optionsProvider.get())); }
/** * Creates a TemplateBuilderSpec from a string. * * @param templateBuilderSpecification * the string form */ public static TemplateBuilderSpec parse(String templateBuilderSpecification) { TemplateBuilderSpec spec = new TemplateBuilderSpec(templateBuilderSpecification); if (!templateBuilderSpecification.isEmpty()) { for (String keyValuePair : KEYS_SPLITTER.split(templateBuilderSpecification)) { List<String> keyAndValue = ImmutableList.copyOf(KEY_VALUE_SPLITTER.split(keyValuePair)); checkArgument(!keyAndValue.isEmpty(), "blank key-value pair"); checkArgument(keyAndValue.size() <= 2, "key-value pair %s with more than one equals sign", keyValuePair); // Find the ValueParser for the current key. String key = keyAndValue.get(0); ValueParser valueParser = VALUE_PARSERS.get(key); checkArgument(valueParser != null, "unknown key %s", key); String value = keyAndValue.size() == 1 ? null : keyAndValue.get(1); valueParser.parse(spec, key, value); } } return spec; }
@Override public TemplateBuilder from(String spec) { return from(TemplateBuilderSpec.parse(spec)); }
protected Properties setupComputeProperties() { Properties overrides = new Properties(); overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true"); overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true"); computeProvider = setIfTestSystemPropertyPresent(overrides, provider + ".compute.provider"); computeIdentity = setIfTestSystemPropertyPresent(overrides, provider + ".compute.identity"); computeCredential = setIfTestSystemPropertyPresent(overrides, provider + ".compute.credential"); computeEndpoint = setIfTestSystemPropertyPresent(overrides, provider + ".compute.endpoint"); computeApiversion = setIfTestSystemPropertyPresent(overrides, provider + ".compute.api-version"); computeBuildversion = setIfTestSystemPropertyPresent(overrides, provider + ".compute.build-version"); String spec = setIfTestSystemPropertyPresent(overrides, provider + ".compute.template"); if (spec != null) { template = TemplateBuilderSpec.parse(spec); if (template.getLoginUser() != null) { Iterable<String> userPass = Splitter.on(':').split(template.getLoginUser()); Builder loginCredentialsBuilder = LoginCredentials.builder(); loginCredentialsBuilder.user(Iterables.get(userPass, 0)); if (Iterables.size(userPass) == 2) loginCredentialsBuilder.password(Iterables.get(userPass, 1)); if (template.getAuthenticateSudo() != null) loginCredentialsBuilder.authenticateSudo(template.getAuthenticateSudo()); loginCredentials = loginCredentialsBuilder.build(); } } return overrides; }
@Inject PopulateDefaultLoginCredentialsForImageStrategy(@Named(TEMPLATE) String templateSpec, RsaSshKeyPairGenerator keyPairGenerator) throws NoSuchAlgorithmException { this.templateBuilder = TemplateBuilderSpec.parse(checkNotNull(templateSpec, "template builder spec")); checkNotNull(templateBuilder.getLoginUser(), "template builder spec must provide a loginUser"); this.keyPairGenerator = checkNotNull(keyPairGenerator, "keypair generator"); }
@Override public LoginCredentials apply(Object image) { return LoginCredentials.builder() .authenticateSudo(templateBuilder.getAuthenticateSudo() != null ? templateBuilder.getAuthenticateSudo() : false) .privateKey(compoundKey) .user(templateBuilder.getLoginUser()).build(); }
@Test public void testCreateVirtualMachine() throws Exception { String defaultTemplate = template != null ? template.getImageId() : null; vm = createVirtualMachine(client, defaultTemplate, jobComplete, virtualMachineRunning); if (vm.getPassword() != null) { conditionallyCheckSSH(); } assert in(ImmutableSet.of("NetworkFilesystem", "IscsiLUN", "VMFS", "PreSetup")) .apply(vm.getRootDeviceType()) : vm; checkVm(vm); }
@Override public TemplateBuilder from(TemplateBuilderSpec spec) { return spec.copyTo(this, options != null ? options : (options = optionsProvider.get())); }