@Override public boolean apply(Template template) { if (template == null) return false; Template t2 = client.getTemplateClient().getTemplateInZone(template.getId(), zoneId); Logger.CONSOLE.info("%s", t2.getStatus()); return t2.getStatus() == Template.Status.DOWNLOADED; } };
@Test(enabled = true) public void testCreateTemplate() throws Exception { Zone zone = Iterables.getFirst(client.getZoneClient().listZones(), null); assertNotNull(zone); Iterable<Network> networks = client.getNetworkClient().listNetworks(ListNetworksOptions.Builder.zoneId(zone.getId()).isDefault(true)); networks = Iterables.filter(networks, new Predicate<Network>() { @Override public boolean apply(Network network) { return network != null && network.getState().equals("Implemented"); } }); assertTrue(Iterables.size(networks) >= 1); Network network = Iterables.get(networks, 0); assertNotNull(network); // Create a VM and stop it String defaultTemplate = template != null ? template.getImageId() : null; vmForCreation = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, defaultTemplate, client, jobComplete, virtualMachineRunning); assertTrue(jobComplete.apply(client.getVirtualMachineClient().stopVirtualMachine(vmForCreation.getId())), vmForCreation.toString()); // Work out the VM's volume Set<Volume> volumes = client.getVolumeClient().listVolumes(ListVolumesOptions.Builder.virtualMachineId(vmForCreation.getId())); assertEquals(volumes.size(), 1); Volume volume = Iterables.getOnlyElement(volumes); // Create a template CreateTemplateOptions options = CreateTemplateOptions.Builder.volumeId(volume.getId()); AsyncCreateResponse response = client.getTemplateClient().createTemplate(TemplateMetadata.builder().name(prefix+"-createTemplate").osTypeId(vmForCreation.getGuestOSId()).displayText("jclouds live testCreateTemplate").build(), options); assertTrue(jobComplete.apply(response.getJobId()), vmForCreation.toString()); createdTemplate = client.getTemplateClient().getTemplateInZone(response.getId(), vmForCreation.getZoneId()); // Assertions assertNotNull(createdTemplate); }
@Test public void testCreateNodeWithGroupEncodedIntoName() { String group = prefix + "-foo"; String name = group + "-node-" + new Random().nextInt(); Template template = view.getComputeService().templateBuilder().build(); if (!client .getTemplateClient() .getTemplateInZone(template.getImage().getId(), template.getLocation().getId()).isPasswordEnabled()) { // TODO: look at SecurityGroupClientLiveTest for how to do this template.getOptions().as(CloudStackTemplateOptions.class).keyPair(keyPairName); } vm = adapter.createNodeWithGroupEncodedIntoName(group, name, template); assertEquals(vm.getNode().getDisplayName(), name); // check to see if we setup a NAT rule (conceding we could check this from // cache) IPForwardingRule rule = getFirst( client.getNATClient().getIPForwardingRulesForVirtualMachine(vm.getNode().getId()), null); String address = rule != null ? rule.getIPAddress() : vm.getNode().getIPAddress(); loginCredentials = prioritizeCredentialsFromTemplate.apply(template, vm.getCredentials()); assert InetAddresses.isInetAddress(address) : vm; HostAndPort socket = HostAndPort.fromParts(address, 22); checkSSH(socket); }
assertEquals(template, client.getTemplateClient().getTemplateInZone(template.getId(), template.getZoneId())); assert template.getId() != null : template; assert template.getName() != null : template;