@Override public boolean matches(VirtualMachine from, Image input) { return input.getProviderId().equals(from.getTemplateId() + "") // either location free image (location is null) // or in the same zone as the VM && (input.getLocation() == null || input.getId().equals(from.getZoneId() + "")); }
@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(@Nullable Network network) { return network != null && network.getState().equals("Implemented"); } }); assertEquals(Iterables.size(networks), 1); Network network = Iterables.getOnlyElement(networks, null); assertNotNull(network); // Create a VM and stop it Long templateId = (imageId != null && !"".equals(imageId)) ? new Long(imageId) : null; vmForCreation = VirtualMachineClientLiveTest.createVirtualMachineInNetwork( network, templateId, 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); }
@Override public boolean matches(VirtualMachine from, Location input) { return input.getId().equals(Long.toString(from.getZoneId())); }