@Override public Iterable<Template> listImages() { // TODO: we may need to filter these further // we may also want to see if we can work with ssh keys return filter(client.getTemplateClient().listTemplates(), isReady()); }
public static String getTemplateForZone(CloudStackClient client, String zoneId) { // TODO enum, as this is way too easy to mess up. Set<String> acceptableCategories = ImmutableSet.of("Ubuntu", "CentOS"); final Predicate<Template> hypervisorPredicate = new CorrectHypervisorForZone(client).apply(zoneId); final Predicate<Template> osTypePredicate = new OSCategoryIn(client).apply(acceptableCategories); @SuppressWarnings("unchecked") Predicate<Template> templatePredicate = Predicates.<Template> and(TemplatePredicates.isReady(), hypervisorPredicate, osTypePredicate); Iterable<Template> templates = filter( client.getTemplateClient().listTemplates(ListTemplatesOptions.Builder.zoneId(zoneId)), templatePredicate); if (Iterables.any(templates, TemplatePredicates.isPasswordEnabled())) { templates = filter(templates, TemplatePredicates.isPasswordEnabled()); } if (Iterables.size(templates) == 0) { throw new NoSuchElementException(templatePredicate.toString()); } String templateId = get(templates, 0).getId(); return templateId; }
@Test public void testTemplateIsPasswordEnabled() { assertTrue(isPasswordEnabled().apply( Template.builder().id("anid").passwordEnabled(true).build() )); assertFalse(isPasswordEnabled().apply( Template.builder().id("someid").passwordEnabled(false).build() )); } }
public static String getTemplateForZone(CloudStackApi client, String zoneId) { // TODO enum, as this is way too easy to mess up. Set<String> acceptableCategories = ImmutableSet.of("Ubuntu", "CentOS"); final Predicate<Template> hypervisorPredicate = new CorrectHypervisorForZone(client).apply(zoneId); final Predicate<Template> osTypePredicate = new OSCategoryIn(client).apply(acceptableCategories); @SuppressWarnings("unchecked") Predicate<Template> templatePredicate = Predicates.<Template> and(TemplatePredicates.isReady(), hypervisorPredicate, osTypePredicate); Iterable<Template> templates = filter( client.getTemplateApi().listTemplates(ListTemplatesOptions.Builder.zoneId(zoneId)), templatePredicate); if (Iterables.any(templates, TemplatePredicates.isPasswordEnabled())) { templates = filter(templates, TemplatePredicates.isPasswordEnabled()); } if (Iterables.size(templates) == 0) { throw new NoSuchElementException(templatePredicate.toString()); } String templateId = get(templates, 0).getId(); return templateId; }
@Test public void testTemplateIsPasswordEnabled() { assertTrue(isPasswordEnabled().apply( Template.builder().id("anid").passwordEnabled(true).build() )); assertFalse(isPasswordEnabled().apply( Template.builder().id("someid").passwordEnabled(false).build() )); } }
@Override public Iterable<Template> listImages() { // TODO: we may need to filter these further // we may also want to see if we can work with ssh keys return filter(client.getTemplateClient().listTemplates(), isReady()); }
@Override public Iterable<Template> listImages() { TemplateApi templateApi = client.getTemplateApi(); ImmutableSet.Builder<Template> templates = ImmutableSet.builder(); templates.addAll(templateApi.listTemplates()); for (String project : projectSupplier.get().keySet()) { templates.addAll(templateApi.listTemplates(ListTemplatesOptions.Builder.projectId(project))); } return filter(templates.build(), isReady()); }
@Test public void testListImages() { Iterable<org.jclouds.cloudstack.domain.Template> templates = adapter.listImages(); assertFalse(Iterables.isEmpty(templates)); for (org.jclouds.cloudstack.domain.Template template : templates) { assert TemplatePredicates.isReady().apply(template) : template; } }
@Test public void testListImages() { Iterable<org.jclouds.cloudstack.domain.Template> templates = adapter.listImages(); assertFalse(Iterables.isEmpty(templates)); for (org.jclouds.cloudstack.domain.Template template : templates) { assert TemplatePredicates.isReady().apply(template) : template; } }