public Password build() { return new Password(id, username, password); }
public T fromPassword(Password in) { return this .id(in.getId()) .username(in.getUsername()) .password(in.getPassword()); } }
@Override public String toString() { return string().toString(); } }
@Override public NodeAndInitialCredentials<VirtualGuest> createNodeWithGroupEncodedIntoName(String group, String name, Template template) { checkNotNull(template, "template was null"); checkNotNull(template.getOptions(), "template options was null"); checkArgument(template.getOptions().getClass().isAssignableFrom(SoftLayerTemplateOptions.class), "options class %s should have been assignable from SoftLayerTemplateOptions", template.getOptions() .getClass()); String domainName = template.getOptions().as(SoftLayerTemplateOptions.class).getDomainName(); VirtualGuest newGuest = VirtualGuest.builder().domain(domainName).hostname(name).build(); ProductOrder order = ProductOrder.builder().packageId(productPackageSupplier.get().getId()) .location(template.getLocation().getId()).quantity(1).useHourlyPricing(true).prices(getPrices(template)) .virtualGuests(newGuest).build(); logger.debug(">> ordering new virtualGuest domain(%s) hostname(%s)", domainName, name); ProductOrderReceipt productOrderReceipt = client.getVirtualGuestClient().orderVirtualGuest(order); VirtualGuest result = get(productOrderReceipt.getOrderDetails().getVirtualGuests(), 0); logger.trace("<< virtualGuest(%s)", result.getId()); logger.debug(">> awaiting login details for virtualGuest(%s)", result.getId()); boolean orderInSystem = loginDetailsTester.apply(result); logger.trace("<< virtualGuest(%s) complete(%s)", result.getId(), orderInSystem); checkState(orderInSystem, "order for guest %s doesn't have login details within %sms", result, Long.toString(guestLoginDelay)); result = client.getVirtualGuestClient().getVirtualGuest(result.getId()); Password pw = get(result.getOperatingSystem().getPasswords(), 0); return new NodeAndInitialCredentials<VirtualGuest>(result, result.getId() + "", LoginCredentials.builder().user(pw.getUsername()).password( pw.getPassword()).build()); }
@Test public void testGetBestPasswordTwoSame() { Set<Password> passwords = Sets.newLinkedHashSet(); passwords.add(new Password(1, "root", "word")); passwords.add(new Password(2, "root", "pass")); VirtualGuestToNodeMetadata f = new VirtualGuestToNodeMetadata(locationSupplier, namingConvention, virtualGuestToImage, virtualGuestToHardware); Password best = f.getBestPassword(passwords, null); assertEquals(best.getUsername(), "root"); // should take the first assertEquals(best.getPassword(), "word"); }
@Test public void testGetBestPasswordTwoDifferent() { Set<Password> passwords = Sets.newLinkedHashSet(); passwords.add(new Password(1, "nonroot", "word")); passwords.add(new Password(2, "root", "pass")); VirtualGuestToNodeMetadata f = new VirtualGuestToNodeMetadata(locationSupplier, namingConvention, virtualGuestToImage, virtualGuestToHardware); Password best = f.getBestPassword(passwords, null); assertEquals(best.getUsername(), "root"); }
for (Password p : passwords) { int score = -1; if ("root".equals(p.getUsername())) score = 10; else if ("root".equalsIgnoreCase(p.getUsername())) score = 4; else if ("ubuntu".equals(p.getUsername())) score = 8; else if ("ubuntu".equalsIgnoreCase(p.getUsername())) score = 3; else if ("administrator".equals(p.getUsername())) score = 5; else if ("administrator".equalsIgnoreCase(p.getUsername())) score = 2; else if (p.getUsername() != null && p.getUsername().length() > 1) score = 1; logger.warn("Multiple credentials for " + bestPassword.getUsername() + "@" + context + "; using first declared " + bestPassword + " and ignoring " + alternates); } else { logger.debug("Multiple credentials for " + context + "; using preferred username " + bestPassword.getUsername());
@Override @Consumes(MediaType.APPLICATION_JSON) public VirtualGuest expected() { return VirtualGuest .builder() .id(416700).accountId(93750).billingItemId(7184019) .createDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-01T11:47:35-08:00")) .metricPollDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T02:32:00-08:00")) .dedicatedAccountHostOnly(true).domain("me.org").fullyQualifiedDomainName("node1703810489.me.org") .hostname("node1703810489").maxCpu(1).maxCpuUnits("CORE").maxMemory(1024) .modifyDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T03:18:12-08:00")) .primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001) .uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8") .operatingSystem(OperatingSystem.builder().id(913824) .passwords(Password.builder().id(729122).username("root").password("KnJqhC2l").build()) .build()) .datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build()) //TODO: maybe powerState can be flattened like billingItemId .powerState(new PowerState(VirtualGuest.State.PAUSED)).build(); }
@Override public NodeAndInitialCredentials<VirtualGuest> createNodeWithGroupEncodedIntoName(String group, String name, Template template) { checkNotNull(template, "template was null"); checkNotNull(template.getOptions(), "template options was null"); checkArgument(template.getOptions().getClass().isAssignableFrom(SoftLayerTemplateOptions.class), "options class %s should have been assignable from SoftLayerTemplateOptions", template.getOptions() .getClass()); String domainName = template.getOptions().as(SoftLayerTemplateOptions.class).getDomainName(); VirtualGuest newGuest = VirtualGuest.builder().domain(domainName).hostname(name).build(); ProductOrder order = ProductOrder.builder().packageId(productPackageSupplier.get().getId()) .location(template.getLocation().getId()).quantity(1).useHourlyPricing(true).prices(getPrices(template)) .virtualGuests(newGuest).build(); logger.debug(">> ordering new virtualGuest domain(%s) hostname(%s)", domainName, name); ProductOrderReceipt productOrderReceipt = client.getVirtualGuestClient().orderVirtualGuest(order); VirtualGuest result = get(productOrderReceipt.getOrderDetails().getVirtualGuests(), 0); logger.trace("<< virtualGuest(%s)", result.getId()); logger.debug(">> awaiting login details for virtualGuest(%s)", result.getId()); boolean orderInSystem = loginDetailsTester.apply(result); logger.trace("<< virtualGuest(%s) complete(%s)", result.getId(), orderInSystem); checkState(orderInSystem, "order for guest %s doesn't have login details within %sms", result, Long.toString(guestLoginDelay)); result = client.getVirtualGuestClient().getVirtualGuest(result.getId()); Password pw = get(result.getOperatingSystem().getPasswords(), 0); return new NodeAndInitialCredentials<VirtualGuest>(result, result.getId() + "", LoginCredentials.builder().user(pw.getUsername()).password( pw.getPassword()).build()); }
@Test public void testGetBestPasswordOneRoot() { Set<Password> passwords = Sets.newLinkedHashSet(); passwords.add(new Password(1, "root", "pass")); VirtualGuestToNodeMetadata f = new VirtualGuestToNodeMetadata(locationSupplier, namingConvention, virtualGuestToImage, virtualGuestToHardware); Password best = f.getBestPassword(passwords, null); assertEquals(best.getUsername(), "root"); }
for (Password p : passwords) { int score = -1; if ("root".equals(p.getUsername())) score = 10; else if ("root".equalsIgnoreCase(p.getUsername())) score = 4; else if ("ubuntu".equals(p.getUsername())) score = 8; else if ("ubuntu".equalsIgnoreCase(p.getUsername())) score = 3; else if ("administrator".equals(p.getUsername())) score = 5; else if ("administrator".equalsIgnoreCase(p.getUsername())) score = 2; else if (p.getUsername() != null && p.getUsername().length() > 1) score = 1; logger.warn("Multiple credentials for " + bestPassword.getUsername() + "@" + context + "; using first declared " + bestPassword + " and ignoring " + alternates); } else { logger.debug("Multiple credentials for " + context + "; using preferred username " + bestPassword.getUsername());
@Override @Consumes(MediaType.APPLICATION_JSON) public VirtualGuest expected() { return VirtualGuest .builder() .id(416700).accountId(93750).billingItemId(7184019) .createDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-01T11:47:35-08:00")) .metricPollDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T02:32:00-08:00")) .dedicatedAccountHostOnly(true).domain("me.org").fullyQualifiedDomainName("node1703810489.me.org") .hostname("node1703810489").maxCpu(1).maxCpuUnits("CORE").maxMemory(1024) .modifyDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T03:19:43-08:00")) .primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001) .uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8") .operatingSystem(OperatingSystem.builder().id(913824) .passwords(Password.builder().id(729122).username("root").password("KnJqhC2l").build()) .build()) .datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build()) //TODO: maybe powerState can be flattened like billingItemId .powerState(new PowerState(VirtualGuest.State.HALTED)).build(); }
public T fromPassword(Password in) { return this .id(in.getId()) .username(in.getUsername()) .password(in.getPassword()); } }
return new NodeAndInitialCredentials<VirtualGuest>(result, result.getId() + "", LoginCredentials.builder().user(pw.getUsername()).password( pw.getPassword()).build());
@Test public void testGetBestPasswordOneNonRoot() { Set<Password> passwords = Sets.newLinkedHashSet(); passwords.add(new Password(1, "nonroot", "word")); VirtualGuestToNodeMetadata f = new VirtualGuestToNodeMetadata(locationSupplier, namingConvention, virtualGuestToImage, virtualGuestToHardware); Password best = f.getBestPassword(passwords, null); assertEquals(best.getUsername(), "nonroot"); }
public Password build() { return new Password(id, username, password); }
for (Password p : passwords) { int score = -1; if ("root".equals(p.getUsername())) score = 10; else if ("root".equalsIgnoreCase(p.getUsername())) score = 4; else if ("ubuntu".equals(p.getUsername())) score = 8; else if ("ubuntu".equalsIgnoreCase(p.getUsername())) score = 3; else if ("administrator".equals(p.getUsername())) score = 5; else if ("administrator".equalsIgnoreCase(p.getUsername())) score = 2; else if (p.getUsername() != null && p.getUsername().length() > 1) score = 1; logger.warn("Multiple credentials for " + bestPassword.getUsername() + "@" + context + "; using first declared " + bestPassword + " and ignoring " + alternates); } else { logger.debug("Multiple credentials for " + context + "; using preferred username " + bestPassword.getUsername());
@Override public String toString() { return string().toString(); } }
@Override @Consumes(MediaType.APPLICATION_JSON) public VirtualGuest expected() { return VirtualGuest .builder() .id(416700).accountId(93750).billingItemId(7184019) .createDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-01T11:47:35-08:00")) .metricPollDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T02:32:00-08:00")) .dedicatedAccountHostOnly(true).domain("me.org").fullyQualifiedDomainName("node1703810489.me.org") .hostname("node1703810489").maxCpu(1).maxCpuUnits("CORE").maxMemory(1024) .modifyDate(new SimpleDateFormatDateService().iso8601SecondsDateParse("2011-10-02T02:32:40-08:00")) .primaryBackendIpAddress("10.37.102.195").primaryIpAddress("173.192.29.187").startCpus(1).statusId(1001) .uuid("02ddbbba-9225-3d54-6de5-fc603b309dd8") .operatingSystem(OperatingSystem.builder().id(913824) .passwords(Password.builder().id(729122).username("root").password("KnJqhC2l").build()) .build()) .datacenter(Datacenter.builder().id(3).name("dal01").longName("Dallas").build()) //TODO: maybe powerState can be flattened like billingItemId .powerState(new PowerState(VirtualGuest.State.RUNNING)).build(); }
public T fromPassword(Password in) { return this .id(in.getId()) .username(in.getUsername()) .password(in.getPassword()); } }