@Override public Set<? extends Hardware> get() { Set<Hardware> hardware = Sets.newHashSet(); for (int cpus : new int[] { 1, 2, 4, 8 }) for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) { String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10); hardware.add(new HardwareBuilder().ids(id).ram(ram).processors(ImmutableList.of(new Processor(cpus, 1.0))) .volumes(ImmutableList.<Volume> of(new VolumeImpl(10f, true, true))).build()); } return hardware; } }
@Override public Set<? extends Hardware> get() { Set<Hardware> hardware = Sets.newHashSet(); for (int cpus : new int[] { 1, 2, 4, 8 }) for (int ram : new int[] { 512, 1024, 2048, 4096, 8192, 16384 }) { String id = String.format("cpu=%d,ram=%s,disk=%d", cpus, ram, 10); hardware.add(new HardwareBuilder().ids(id).ram(ram).processors(ImmutableList.of(new Processor(cpus, 1.0))) .volumes(ImmutableList.<Volume> of(new VolumeImpl(10f, true, true))).hypervisor("VMware").build()); } return hardware; } }
protected Hardware automaticHardware(double cores, int ram, Optional<Float> diskSize) { HardwareBuilder builder = new HardwareBuilder(); if (diskSize.isPresent() && diskSize.get() > 0.0f) { builder.volume(new VolumeImpl(diskSize.get(), true, true)); } return builder .id(automaticHardwareIdSpecBuilder(cores, ram, diskSize).toString()) .ram(ram) .processor(new Processor(cores, 1.0)) .build(); }
static Hardware stub(String type, int cores, int ram, float disk) { return new org.jclouds.compute.domain.HardwareBuilder().ids(type).name(type) .processors(ImmutableList.of(new Processor(cores, 1.0))).ram(ram) .volumes(ImmutableList.<Volume> of(new VolumeImpl(disk, true, false))).build(); }
@Override public Hardware apply(org.jclouds.servermanager.Hardware from) { HardwareBuilder builder = new HardwareBuilder(); builder.ids(from.id + ""); builder.name(from.name); builder.processors(ImmutableList.of(new Processor(from.cores, 1.0))); builder.ram(from.ram); builder.volumes(ImmutableList.<Volume> of(new VolumeImpl(from.disk, true, false))); return builder.build(); }
static Hardware stub(String type, int cores, int ram, float disk) { return new org.jclouds.compute.domain.HardwareBuilder().ids(type).name(type) .processors(ImmutableList.of(new Processor(cores, 1.0))).ram(ram) .volumes(ImmutableList.<Volume> of(new VolumeImpl(disk, true, false))).build(); }
static Hardware stub(String type, int cores, int ram, float disk) { return new org.jclouds.compute.domain.HardwareBuilder().ids(type).name(type) .processors(ImmutableList.of(new Processor(cores, 1.0))).ram(ram) .volumes(ImmutableList.<Volume> of(new VolumeImpl(disk, true, false))).build(); }
@Override public Iterable<Hardware> listHardwareProfiles() { Set<Hardware> hardware = Sets.newLinkedHashSet(); // todo they are only placeholders at the moment hardware.add(new HardwareBuilder().ids("micro").hypervisor("lxc").name("micro").processor(new Processor(1, 1)).ram(512).build()); hardware.add(new HardwareBuilder().ids("small").hypervisor("lxc").name("small").processor(new Processor(1, 1)).ram(1024).build()); hardware.add(new HardwareBuilder().ids("medium").hypervisor("lxc").name("medium").processor(new Processor(2, 1)).ram(2048).build()); hardware.add(new HardwareBuilder().ids("large").hypervisor("lxc").name("large").processor(new Processor(2, 1)).ram(3072).build()); return hardware; }
@Override public Iterable<Hardware> listHardwareProfiles() { Set<Hardware> hardware = Sets.newLinkedHashSet(); // todo they are only placeholders at the moment hardware.add(new HardwareBuilder().ids("micro").hypervisor("lxc").name("micro").processor(new Processor(1, 1)).ram(512).build()); hardware.add(new HardwareBuilder().ids("small").hypervisor("lxc").name("small").processor(new Processor(1, 1)).ram(1024).build()); hardware.add(new HardwareBuilder().ids("medium").hypervisor("lxc").name("medium").processor(new Processor(2, 1)).ram(2048).build()); hardware.add(new HardwareBuilder().ids("large").hypervisor("lxc").name("large").processor(new Processor(2, 1)).ram(3072).build()); return hardware; }
@Override public Hardware apply(ServerSpec spec) { Location location = FluentIterable.from(locations.get()).firstMatch(idEquals(spec.getDatacenter())).orNull(); assert location != null : String.format("no location matched ServerSpec %s", spec); return new HardwareBuilder().ids(spec.toString()).ram(spec.getMemorySizeMB()).processors( ImmutableList.of(new Processor(spec.getCpuCores(), 1.0))).volumes( ImmutableList.<Volume> of(new VolumeImpl((float) spec.getDiskSizeGB(), true, true))).hypervisor( spec.getPlatform()).location(location).supportsImage( ImagePredicates.idEquals(spec.getTemplateName())).build(); } }
@Override public Hardware apply(FlavorInZone flavorInZone) { Location location = locationIndex.get().get(flavorInZone.getZone()); checkState(location != null, "location %s not in locationIndex: %s", flavorInZone.getZone(), locationIndex.get()); Flavor flavor = flavorInZone.getFlavor(); return new HardwareBuilder().id(flavorInZone.slashEncode()).providerId(flavor.getId()).name(flavor.getName()) .ram(flavor.getRam()).processor(new Processor(flavor.getVcpus(), 1.0)).volume( new VolumeImpl(Float.valueOf(flavor.getDisk()), true, true)).location(location).build(); } }
@Override public Hardware apply(FlavorInRegion flavorInRegion) { Location location = locationIndex.get().get(flavorInRegion.getRegion()); checkState(location != null, "location %s not in locationIndex: %s", flavorInRegion.getRegion(), locationIndex.get()); Flavor flavor = flavorInRegion.getFlavor(); return new HardwareBuilder().id(flavorInRegion.slashEncode()).providerId(flavor.getId()).name(flavor.getName()) .ram(flavor.getRam()).processor(new Processor(flavor.getVcpus(), 1.0)).volume( new VolumeImpl(Float.valueOf(flavor.getDisk()), true, true)).location(location).build(); } }
@Override public Hardware apply(FlavorInRegion flavorInRegion) { Location location = locationIndex.get().get(flavorInRegion.getRegion()); checkState(location != null, "location %s not in locationIndex: %s", flavorInRegion.getRegion(), locationIndex.get()); Flavor flavor = flavorInRegion.getFlavor(); return new HardwareBuilder().id(flavorInRegion.slashEncode()).providerId(flavor.getId()).name(flavor.getName()) .ram(flavor.getRam()).processor(new Processor(flavor.getVcpus(), 1.0)).volume( new VolumeImpl(Float.valueOf(flavor.getDisk()), true, true)).location(location).build(); } }
public Hardware apply(Flavor from) { return new HardwareBuilder().ids(from.getId() + "").name(from.getName()).hypervisor("xen") .processors(ImmutableList.of(new Processor(from.getDisk() / 10.0, 1.0))).ram(from.getRam()) .volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDisk(), true, true))).build(); } }
public Hardware apply(Flavor from) { return new HardwareBuilder().ids(from.getId() + "").name(from.getName()).hypervisor("xen") .processors(ImmutableList.of(new Processor(from.getDisk() / 10.0, 1.0))).ram(from.getRam()) .volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDisk(), true, true))).build(); } }
public Hardware apply(Flavor from) { return new HardwareBuilder() .ids(from.getId() + "") .name(from.getName()) .processors(ImmutableList.of(new Processor(from.getDisk() / 10.0, 1.0))) .ram(from.getRam()) .volumes(ImmutableList.<Volume> of(new VolumeImpl((float) from.getDisk(), true, true))) .uri(from.getURI()) .build(); } }
@SuppressWarnings("unchecked") public static HardwareBuilder fromHardware(Hardware in) { return new HardwareBuilder().id(in.getId()).providerId(in.getProviderId()).location(in.getLocation()).name( in.getName()).uri(in.getUri()).userMetadata(in.getUserMetadata()).tags(in.getTags()).processors( List.class.cast(in.getProcessors())).ram(in.getRam()).volumes(List.class.cast(in.getVolumes())) .supportsImage(in.supportsImage()).hypervisor(in.getHypervisor()); } }
@SuppressWarnings("unchecked") public static HardwareBuilder fromHardware(Hardware in) { return new HardwareBuilder().id(in.getId()).providerId(in.getProviderId()).location(in.getLocation()).name( in.getName()).uri(in.getUri()).userMetadata(in.getUserMetadata()).tags(in.getTags()).processors( List.class.cast(in.getProcessors())).ram(in.getRam()).volumes(List.class.cast(in.getVolumes())) .supportsImage(in.supportsImage()).hypervisor(in.getHypervisor()); } }
@SuppressWarnings("unchecked") public static HardwareBuilder fromHardware(Hardware in) { return new HardwareBuilder().id(in.getId()).providerId(in.getProviderId()).location(in.getLocation()).name( in.getName()).uri(in.getUri()).userMetadata(in.getUserMetadata()).tags(in.getTags()).processors( List.class.cast(in.getProcessors())).ram(in.getRam()).volumes(List.class.cast(in.getVolumes())) .supportsImage(in.supportsImage()).hypervisor(in.getHypervisor()); } }
@Test public void testConvertSize() { Size size = Size.create("2gb", true, 1.0f, 10f, 0.05f, 2048, 1, 20, ImmutableList.<String> of()); Hardware expected = new HardwareBuilder().id("2gb").providerId("2gb").name("2gb") .processor(new Processor(1.0, 1.0)).ram(2048) .volume(new VolumeBuilder().size(20f).type(Type.LOCAL).build()) .userMetadata(ImmutableMap.of("costPerHour", "0.05", "costPerMonth", "10")).build(); SizeToHardware function = new SizeToHardware(); assertEquals(function.apply(size), expected); } }