HashMap<String, String> hm = new HashMap<String,String>(); for(Volume v: vc.volumes){ hm.put(v.getId(), v.getName()); }
// Get node NodeMetadata node = Iterables.getOnlyElement(nodes); // Get AWS EC2 API EC2Api ec2Api = computeServiceContext.unwrapApi(EC2Api.class); // Create 100 GiB Volume Volume volume = ec2Api.getElasticBlockStoreApi().get() .createVolumeInAvailabilityZone(zoneId, 100); // Attach to instance Attachment attachment = ec2Api.getElasticBlockStoreApi().get() .attachVolumeInRegion(region, volume.getId(), node.getId(), "/dev/sdx");
/** * Create a snapshot of the volume attached to the VM * @param vmi a VMInstance */ public String createSnapshot(VMInstance vmi){ NodeMetadata nm=getVMById(vmi.getId()); ElasticBlockStoreApi ebsClient = ec2api.getElasticBlockStoreApi().get(); journal.log(Level.INFO, ">> Creating snapshot of VM: "+vmi.getName()); Snapshot snapshot = ebsClient.createSnapshotInRegion("eu-west-1", nm.getHardware().getVolumes().get(0).getId()); String status=""; while (!status.toLowerCase().equals("completed")){ for(Snapshot s:ebsClient.describeSnapshotsInRegion("eu-west-1")) if(s.getId().equals(snapshot.getId())){ status=s.getStatus().name(); } try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } } journal.log(Level.INFO, ">> Snapshot created with ID: "+snapshot.getId()); return snapshot.getId(); }
public static Volume fromVolume(Volume in) { return new VolumeImpl(in.getId(), in.getType(), in.getSize(), in.getDevice(), in.isBootDevice(), in.isDurable()); } }
public static Volume fromVolume(Volume in) { return new VolumeImpl(in.getId(), in.getType(), in.getSize(), in.getDevice(), in.isBootDevice(), in.isDurable()); } }
public static Volume fromVolume(Volume in) { return new VolumeImpl(in.getId(), in.getType(), in.getSize(), in.getDevice(), in.isBootDevice(), in.isDurable()); } }
public static Volume fromVolume(Volume in) { return new VolumeImpl(in.getId(), in.getType(), in.getSize(), in.getDevice(), in.isBootDevice(), in.isDurable()); } }
@Override public Volume apply(@Nullable org.jclouds.compute.domain.Volume input) { if (input == null) { return null; } return Volume.builder().id(input.getId()).size(input.getSize()).type(input.getType().name()).device(input.getDevice()) .durable(input.isDurable()).bootDevice(input.isBootDevice()).build(); } }
/** * Ensures that an explicitly set null id results in no errors. */ public void testNullDescription() { Volume vol = new VolumeBuilder().id(null) .type(Type.LOCAL) .size(10.0f) .device("/dev/sda1") .bootDevice(true) .durable(false) .build(); assertNull(vol.getId()); } }
private void applyAndAssert(BaseImage baseImage) { final Hardware hardware = baseImageToHardware.apply(baseImage); assertEquals(baseImage.memoryGb() * 1024, hardware.getRam()); assertEquals("vmx", hardware.getHypervisor()); assertEquals(baseImage.id(), hardware.getId()); assertEquals(baseImage.id(), hardware.getProviderId()); assertEquals(baseImage.name(), hardware.getName()); assertEquals(baseImage.disks().size(), hardware.getVolumes().size()); assertEquals(Float.valueOf(baseImage.disks().get(0).sizeGb()), hardware.getVolumes().get(0).getSize()); assertEquals(Volume.Type.LOCAL, hardware.getVolumes().get(0).getType()); assertEquals(baseImage.disks().get(0).id(), hardware.getVolumes().get(0).getId()); assertEquals(baseImage.disks().get(0).scsiId().toString(), hardware.getVolumes().get(0).getDevice()); assertEquals(baseImage.cpu().count(), hardware.getProcessors().size()); assertEquals(Double.valueOf(baseImage.cpu().coresPerSocket()), hardware.getProcessors().get(0).getCores()); assertEquals(CpuSpeed.STANDARD.getSpeed(), hardware.getProcessors().get(0).getSpeed()); }
private void applyAndAssert(Server server) { final Hardware hardware = serverToHardware.apply(server); assertEquals(server.memoryGb() * 1024, hardware.getRam()); assertEquals("vmx", hardware.getHypervisor()); assertEquals(server.id(), hardware.getId()); assertEquals(server.id(), hardware.getProviderId()); assertEquals(server.name(), hardware.getName()); assertEquals(server.disks().size(), hardware.getVolumes().size()); assertEquals(Float.valueOf(server.disks().get(0).sizeGb()), hardware.getVolumes().get(0).getSize()); assertEquals(Volume.Type.LOCAL, hardware.getVolumes().get(0).getType()); assertEquals(server.disks().get(0).id(), hardware.getVolumes().get(0).getId()); assertEquals(server.disks().get(0).scsiId().toString(), hardware.getVolumes().get(0).getDevice()); assertEquals(server.cpu().count(), hardware.getProcessors().size()); assertEquals(Double.valueOf(server.cpu().coresPerSocket()), hardware.getProcessors().get(0).getCores()); assertEquals(CpuSpeed.STANDARD.getSpeed(), hardware.getProcessors().get(0).getSpeed()); }