public static double getSpace(Hardware input) { double total = 0; for (Volume volume : input.getVolumes()) { Float size = volume.getSize(); if (size != null) { total += size; } } return total; }
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()); }
@Test public void testHardware() { Hardware hardware = toHardware.apply(ImmutableSet.of(cpuItem, ramItem, volumeItem)); assertEquals("123,456,789", hardware.getId()); List<? extends Processor> processors = hardware.getProcessors(); assertEquals(1, processors.size()); assertEquals(2.0, processors.get(0).getCores()); assertEquals(2, hardware.getRam()); List<? extends Volume> volumes = hardware.getVolumes(); assertEquals(1, volumes.size()); Volume volume = volumes.get(0); assertEquals(100F, volume.getSize()); assertEquals(Volume.Type.SAN, volume.getType()); assertEquals(true, volume.isBootDevice()); }
private static int getBootableDeviceType(Hardware hardware) { List<? extends Volume> volumes = hardware.getVolumes(); Optional<? extends Volume> optionalBootableVolume = tryFind(volumes, new Predicate<Volume>() { @Override public boolean apply(Volume volume) { return volume.getDevice().equals(BOOTABLE_DEVICE); } }); if (!optionalBootableVolume.isPresent()) { return Type.LOCAL.ordinal(); } return optionalBootableVolume.get().getType().ordinal(); }
private void mapDevices(EC2TemplateOptions ec2TemplateOptions, Template template, String user) { String mkfsOptions = simulatorProperties.get("INSTANCE_STORAGE_MKFS_OPTIONS", DEFAULT_MKFS_OPTIONS); String mountOptions = simulatorProperties.get("INSTANCE_STORAGE_MOUNT_OPTIONS", DEFAULT_MOUNT_OPTIONS); int ephemeralCounter = 0; for (Volume volume : template.getHardware().getVolumes()) { if (!volume.isBootDevice() && LOCAL.equals(volume.getType())) { String device = volume.getDevice(); LOGGER.info(format("Mapping device %s (%d GB)", device, round(volume.getSize()))); ec2TemplateOptions.mapEphemeralDeviceToDeviceName(device, "ephemeral" + ephemeralCounter++); mountDevice(device, mkfsOptions, mountOptions, user); } } }
public Map<String, String> getDeviceMappings(ClusterSpec clusterSpec, Instance instance) { Map<String, String> mappings = Maps.newLinkedHashMap(); int number = 0; Hardware hardware = instance.getNodeMetadata().getHardware(); /* null when using the BYON jclouds compute provider */ if (hardware != null) { List<? extends Volume> volumes = instance.getNodeMetadata().getHardware().getVolumes(); boolean foundBootDevice = false; SortedSet<String> volumeDevicesSansBoot = new TreeSet<String>(); for (Volume volume : volumes) { if (!volume.isBootDevice()) { volumeDevicesSansBoot.add(volume.getDevice()); } else { foundBootDevice = true; } } // if no boot device is reported from the cloud provider (as is sometimes the case) // assume it is the first in the natural order list of devices if (!foundBootDevice && !volumeDevicesSansBoot.isEmpty()) { volumeDevicesSansBoot.remove(volumeDevicesSansBoot.iterator().next()); } for (String device : volumeDevicesSansBoot) { mappings.put(MOUNT_PREFIX + number++, device); } } return mappings; }
@Override public boolean apply(Volume input) { return !input.isBootDevice(); }
@Override public boolean apply(Volume volume) { return volume.getDevice().equals(BOOTABLE_DEVICE); } });
// 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");
public static double getSpace(Hardware input) { double total = 0; for (Volume volume : input.getVolumes()) { Float size = volume.getSize(); if (size != null) { total += size; } } return total; }
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()); }
@Test public void testHardwareWithTwoDisks() { ProductItem localVolumeItem = ProductItem.builder().id(4).description("25 GB").capacity(25F).prices( ProductItemPrice.builder().id(987).build()).categories( ProductItemCategory.builder().categoryCode("guest_disk1").build()).build(); Hardware hardware = toHardware.apply(ImmutableSet.of(cpuItem, ramItem, volumeItem,localVolumeItem)); List<? extends Volume> volumes = hardware.getVolumes(); assertEquals(2, volumes.size()); Volume volume = volumes.get(0); assertEquals(100F, volume.getSize()); assertEquals(Volume.Type.SAN, volume.getType()); assertEquals(true, volume.isBootDevice()); Volume volume1 = volumes.get(1); assertEquals(25F, volume1.getSize()); assertEquals(Volume.Type.LOCAL, volume1.getType()); assertEquals(false, volume1.isBootDevice()); } }
private static int getBootableDeviceType(Hardware hardware) { List<? extends Volume> volumes = hardware.getVolumes(); Optional<? extends Volume> optionalBootableVolume = tryFind(volumes, new Predicate<Volume>() { @Override public boolean apply(Volume volume) { return volume.getDevice().equals(BOOTABLE_DEVICE); } }); if (!optionalBootableVolume.isPresent()) { return Type.LOCAL.ordinal(); } return optionalBootableVolume.get().getType().ordinal(); }
public Map<String, String> getDeviceMappings(ClusterSpec clusterSpec, Instance instance) { Map<String, String> mappings = Maps.newLinkedHashMap(); int number = 0; Hardware hardware = instance.getNodeMetadata().getHardware(); /* null when using the BYON jclouds compute provider */ if (hardware != null) { List<? extends Volume> volumes = instance.getNodeMetadata().getHardware().getVolumes(); for (Volume volume : volumes) { if (volume.isBootDevice()) { continue; } mappings.put(MOUNT_PREFIX + number++, volume.getDevice()); } } return mappings; }
@Override public boolean apply(Volume input) { return !input.isBootDevice(); }
@Override public boolean apply(Volume volume) { return volume.getDevice().equals(BOOTABLE_DEVICE); } });
/** * 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(); }