@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); }