@Override protected ListenableFuture<AtomicReference<NodeMetadata>> createNodeInGroupWithNameAndTemplate(String group, final String name, Template template) { ListenableFuture<AtomicReference<NodeMetadata>> future = super.createNodeInGroupWithNameAndTemplate(group, name, template); NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(template.getOptions()); if (templateOptions.shouldAutoAssignFloatingIp()) { return Futures.transform(future, createAndAddFloatingIpToNode, userExecutor); } else { return future; } }
@Override public LoginCredentials apply(Template template) { RunScriptOptions options = template.getOptions(); LoginCredentials defaultCreds = template.getImage().getDefaultCredentials(); return overrideDefaultCredentialsWithOptionsIfPresent(defaultCreds, options); }
@Override public LoginCredentials apply(Template template) { RunScriptOptions options = template.getOptions(); LoginCredentials defaultCreds = template.getImage().getDefaultCredentials(); return overrideDefaultCredentialsWithOptionsIfPresent(defaultCreds, options); }
@Override public LoginCredentials apply(Template template) { RunScriptOptions options = template.getOptions(); LoginCredentials defaultCreds = template.getImage().getDefaultCredentials(); return overrideDefaultCredentialsWithOptionsIfPresent(defaultCreds, options); }
@Override public InstantiateVAppTemplateOptions apply(Template from) { InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(getCores(from.getHardware())).intValue()) .memory(from.getHardware().getRam()); if (!from.getOptions().shouldBlockUntilRunning()) options.block(false); String sshKeyFingerprint = TerremarkVCloudTemplateOptions.class.cast(from.getOptions()).getSshKeyFingerprint(); if (sshKeyFingerprint != null) options.sshKeyFingerprint(sshKeyFingerprint); return options; } }
public void testWhenLoginCredentialsNotPresentInTemplateOptionsReturnsOneInImage() { Image image = createMock(Image.class); Template template = createMock(Template.class); expect(template.getImage()).andReturn(image); expect(image.getDefaultCredentials()).andReturn(expected); expect(template.getOptions()).andReturn(new TemplateOptions()); replay(template, image); assertEquals(fn.apply(template), expected); verify(template, image); }
public void testWhenCredentialsNotPresentInImageTemplateOptionsOrParameterReturnNull() { Credentials expected = null; Image image = createMock(Image.class); Template template = createMock(Template.class); expect(template.getImage()).andReturn(image); expect(image.getDefaultCredentials()).andReturn(null); expect(template.getOptions()).andReturn(new TemplateOptions()); replay(template, image); assertEquals(fn.apply(template, null), expected); verify(template); verify(image); }
public void testWhenLoginCredentialsNotPresentInImageOrTemplateOptionsReturnNull() { LoginCredentials expected = null; Image image = createMock(Image.class); Template template = createMock(Template.class); expect(template.getImage()).andReturn(image); expect(image.getDefaultCredentials()).andReturn(null); expect(template.getOptions()).andReturn(new TemplateOptions()); replay(template, image); assertEquals(fn.apply(template), expected); verify(template, image); }
public void testWhenLoginCredentialsNotPresentInImageReturnsOneInTemplateOptions() { Image image = createMock(Image.class); Template template = createMock(Template.class); expect(template.getImage()).andReturn(image); expect(image.getDefaultCredentials()).andReturn(null); expect(template.getOptions()).andReturn(TemplateOptions.Builder.overrideLoginCredentials(expected)); replay(template, image); assertEquals(fn.apply(template), expected); verify(template, image); }
public void testWhenCredentialsNotPresentInImageTemplateOptionsReturnsFromParameter() { LoginCredentials expected = LoginCredentials.builder().user("foo").password("bar").build(); Image image = createMock(Image.class); Template template = createMock(Template.class); expect(template.getImage()).andReturn(image); expect(image.getDefaultCredentials()).andReturn(null); expect(template.getOptions()).andReturn(new TemplateOptions()); replay(template, image); assertEquals(fn.apply(template, expected), expected); verify(template); verify(image); }
public void testWhenLoginCredentialsPresentInImageOverridesCredentialFromLoginCredentialsInTemplateOptions() { Image image = createMock(Image.class); Template template = createMock(Template.class); expect(template.getImage()).andReturn(image); expect(image.getDefaultCredentials()).andReturn(LoginCredentials.builder().user("ubuntu").password("password2").build()); expect(template.getOptions()).andReturn(TemplateOptions.Builder.overrideLoginPassword("password")); replay(template, image); assertEquals(fn.apply(template), expected); verify(template, image); } }
public void testWhenLoginCredentialsPresentInImageOverridesIdentityFromLoginCredentialsInTemplateOptions() { Image image = createMock(Image.class); Template template = createMock(Template.class); expect(template.getImage()).andReturn(image); expect(image.getDefaultCredentials()).andReturn(LoginCredentials.builder().user("user").password("password").build()); expect(template.getOptions()).andReturn(TemplateOptions.Builder.overrideLoginUser("ubuntu")); replay(template, image); assertEquals(fn.apply(template), expected); verify(template, image); }
@Override public NodeMetadata addNodeWithTag(String tag, String name, Template template) { InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory( template.getHardware().getRam()).disk( (long) ((template.getHardware().getVolumes().get(0).getSize()) * 1024 * 1024l)); if (!template.getOptions().shouldBlockUntilRunning()) options.block(false); VCloudExpressVApp vApp = computeClient.start(URI.create(template.getLocation().getId()), URI.create(template.getImage().getId()), name, options, template.getOptions().getInboundPorts()); return vAppToNodeMetadata.apply(vApp); }
public void testWhenCredentialsNotPresentInImageReturnsCredentialFromTemplateOptionsAndUserFromParameter() { Credentials expected = new Credentials("ubuntu", "password"); Image image = createMock(Image.class); Template template = createMock(Template.class); expect(template.getImage()).andReturn(image); expect(image.getDefaultCredentials()).andReturn(null); expect(template.getOptions()).andReturn(TemplateOptions.Builder.overrideLoginUser("ubuntu")); replay(template, image); assertEquals(fn.apply(template, LoginCredentials.builder().user("foo").password("password").build()), expected); verify(template); verify(image); }
/** * {@inheritDoc} */ @Override public TemplateBuilder fromTemplate(Template template) { location = template.getLocation(); fromHardware(template.getHardware()); fromImage(template.getImage()); options(template.getOptions()); return this; }
public void testWhenCredentialsNotPresentInTemplateOptionsReturnsOneInImageAndNotParameter() { LoginCredentials expected = LoginCredentials.builder().user("ubuntu").password("password").build(); Image image = createMock(Image.class); Template template = createMock(Template.class); expect(template.getImage()).andReturn(image); expect(image.getDefaultCredentials()).andReturn(expected); expect(template.getOptions()).andReturn(new TemplateOptions()); replay(template, image); assertEquals(fn.apply(template, LoginCredentials.builder().user("foo").password("bar").build()), expected); verify(template); verify(image); }
public void testWhenCredentialsNotPresentInImageReturnsOneInTemplateOptionsAndNotParameter() { LoginCredentials expected = LoginCredentials.builder().user("ubuntu").password("password").build(); Image image = createMock(Image.class); Template template = createMock(Template.class); expect(template.getImage()).andReturn(image); expect(image.getDefaultCredentials()).andReturn(null); expect(template.getOptions()).andReturn(TemplateOptions.Builder.overrideLoginCredentials(expected)); replay(template, image); assertEquals(fn.apply(template, LoginCredentials.builder().user("foo").password("bar").build()), expected); verify(template); verify(image); }
public void testWhenCredentialsPresentInImageOverridesIdentityFromCredentialsInTemplateOptionsAndNotParameter() { Credentials expected = new Credentials("ubuntu", "password"); Image image = createMock(Image.class); Template template = createMock(Template.class); expect(template.getImage()).andReturn(image); expect(image.getDefaultCredentials()).andReturn(LoginCredentials.builder().user("ubuntu").password("password").build()); expect(template.getOptions()).andReturn(TemplateOptions.Builder.overrideLoginUser("ubuntu")); replay(template, image); assertEquals(fn.apply(template, LoginCredentials.builder().user("foo").password("bar").build()), expected); verify(template, image); }
@Override public NodeAndInitialCredentials<Server> createNodeWithGroupEncodedIntoName(String group, String name, Template template) { Server server = client .createServer(name, Integer.parseInt(template.getImage().getProviderId()), Integer.parseInt(template .getHardware().getProviderId()), withMetadata(metadataAndTagsAsCommaDelimitedValue(template.getOptions()))); return new NodeAndInitialCredentials<Server>(server, server.getId() + "", LoginCredentials.builder().password( server.getAdminPass()).build()); }
@Override public Map<?, ListenableFuture<Void>> execute(String tag, int count, Template template, Set<NodeMetadata> goodNodes, Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) { assert template.getLocation().getParent().getScope() == LocationScope.REGION : "template location should have a parent of org, which should be mapped to region: " + template.getLocation(); String orgId = template.getLocation().getParent().getId(); assert orgId.startsWith("http") : "parent id should be a rest url: " + template.getLocation().getParent(); createNewKeyPairUnlessUserSpecifiedOtherwise.execute(URI.create(orgId), tag, template.getImage() .getDefaultCredentials().identity, template.getOptions().as(TerremarkVCloudTemplateOptions.class)); return super.execute(tag, count, template, goodNodes, badNodes, customizationResponses); } }