From c7503882786500fe01dd5fdee2d01347ae2f65d6 Mon Sep 17 00:00:00 2001 From: mariapavlova Date: Wed, 29 Jul 2015 18:00:48 +0300 Subject: [PATCH] FB 7388, convert listProducts to use vmproducts.json --- .../org/dasein/cloud/vsphere/compute/Vm.java | 506 +++++++++--------- .../org/dasein/cloud/vsphere/vmproducts.json | 210 ++++++++ 2 files changed, 472 insertions(+), 244 deletions(-) create mode 100644 src/main/resources/org/dasein/cloud/vsphere/vmproducts.json diff --git a/src/main/java/org/dasein/cloud/vsphere/compute/Vm.java b/src/main/java/org/dasein/cloud/vsphere/compute/Vm.java index 5e28206..71a9944 100644 --- a/src/main/java/org/dasein/cloud/vsphere/compute/Vm.java +++ b/src/main/java/org/dasein/cloud/vsphere/compute/Vm.java @@ -18,6 +18,10 @@ package org.dasein.cloud.vsphere.compute; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.rmi.RemoteException; import java.util.*; @@ -54,8 +58,12 @@ import org.dasein.util.uom.storage.Kilobyte; import org.dasein.util.uom.storage.Megabyte; import org.dasein.util.uom.storage.Storage; +import org.dasein.util.uom.time.Day; import org.dasein.util.uom.time.Minute; import org.dasein.util.uom.time.TimePeriod; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -452,13 +460,11 @@ private ManagedEntity[] randomize(ManagedEntity[] source) { config.setCpuHotAddEnabled(true); config.setNumCoresPerSocket(cpuCount); - // record all networks we will end up with so that we can configure NICs correctly - List resultingNetworks = new ArrayList(); //networking section //borrowed heavily from https://github.com/jedi4ever/jvspherecontrol String vlan = options.getVlanId(); - + int count = 0; if( vlan != null ) { // we don't need to do network config if the selected network @@ -467,70 +473,58 @@ private ManagedEntity[] randomize(ManagedEntity[] source) { Iterable accessibleNetworks = vlanSupport.listVlans(); boolean changeRequired = true; List machineSpecs = new ArrayList(); - - VirtualDevice[] virtualDevices = template.getConfig().getHardware().getDevice(); - VLAN targetVlan = null; - for(VirtualDevice virtualDevice : virtualDevices) { - if( virtualDevice instanceof VirtualEthernetCard ) { - VirtualEthernetCard veCard = ( VirtualEthernetCard ) virtualDevice; - if( veCard.getBacking() instanceof VirtualEthernetCardNetworkBackingInfo ) { - boolean nicDeleted = false; - VirtualEthernetCardNetworkBackingInfo nicBacking = (VirtualEthernetCardNetworkBackingInfo) veCard.getBacking(); - if( vlan.equals(nicBacking.getNetwork().getVal()) ) { - changeRequired = false; - } - else { - for( VLAN accessibleNetwork : accessibleNetworks ) { - if( accessibleNetwork.getProviderVlanId().equals(nicBacking.getNetwork().getVal()) ) { - VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec(); - nicSpec.setOperation(VirtualDeviceConfigSpecOperation.remove); - - nicSpec.setDevice(veCard); - machineSpecs.add(nicSpec); - nicDeleted = true; - break; - } - else if( accessibleNetwork.getProviderVlanId().equals(vlan) ) { - targetVlan = accessibleNetwork; - } + GuestNicInfo[] nics = template.getGuest().getNet(); + if( nics != null ) { + for( GuestNicInfo nic : nics ) { + if( nic.getNetwork().equals(vlan) ) { + changeRequired = false; + } + else { // remove template nics for networks we have access to + for( VLAN accessibleNetwork : accessibleNetworks ) { + if( accessibleNetwork.getName().equals(nic.getNetwork()) ) { + VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec(); + nicSpec.setOperation(VirtualDeviceConfigSpecOperation.remove); + + VirtualEthernetCard newNic = new VirtualEthernetCard(); + newNic.setKey(nic.getDeviceConfigId()); + + nicSpec.setDevice(newNic); + machineSpecs.add(nicSpec); + break; } } - if( !nicDeleted ) { - resultingNetworks.add(nicBacking.getNetwork().getVal()); - } } - else if ( veCard.getBacking() instanceof VirtualEthernetCardDistributedVirtualPortBackingInfo ){ - boolean nicDeleted = false; - VirtualEthernetCardDistributedVirtualPortBackingInfo nicBacking = (VirtualEthernetCardDistributedVirtualPortBackingInfo) veCard.getBacking(); - if( vlan.equals(nicBacking.getPort().getPortgroupKey()) ) { - changeRequired = false; - } - else { - for( VLAN accessibleNetwork : accessibleNetworks ) { - if( accessibleNetwork.getProviderVlanId().equals(nicBacking.getPort().getPortgroupKey()) ) { - VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec(); - nicSpec.setOperation(VirtualDeviceConfigSpecOperation.remove); - - nicSpec.setDevice(veCard); - machineSpecs.add(nicSpec); - nicDeleted = true; - } - else if( accessibleNetwork.getProviderVlanId().equals(vlan) ) { - targetVlan = accessibleNetwork; - } - if( nicDeleted && targetVlan != null ) { - break; + } + } + else { + log.warn("Template" + template.getName() + " (" + template.getConfig().getInstanceUuid() + ") doesn't have VMware tools installed, going through hardware"); + VirtualDevice[] virtualDevices = template.getConfig().getHardware().getDevice(); + for(VirtualDevice virtualDevice : virtualDevices) { + if( virtualDevice instanceof VirtualEthernetCard ) { + VirtualEthernetCard veCard = ( VirtualEthernetCard ) virtualDevice; + if( veCard.getBacking() instanceof VirtualEthernetCardNetworkBackingInfo ) { + VirtualEthernetCardNetworkBackingInfo nicBacking = (VirtualEthernetCardNetworkBackingInfo) veCard.getBacking(); + if( vlan.equals(nicBacking.getDeviceName()) ) { + changeRequired = false; + } + else { + for( VLAN accessibleNetwork : accessibleNetworks ) { + if( accessibleNetwork.getName().equals(nicBacking.getDeviceName()) ) { + VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec(); + nicSpec.setOperation(VirtualDeviceConfigSpecOperation.remove); + + nicSpec.setDevice(veCard); + machineSpecs.add(nicSpec); + break; + } } } } - if( !nicDeleted ) { - resultingNetworks.add(nicBacking.getPort().getPortgroupKey()); - } } } } - if( changeRequired && targetVlan != null ) { + if( changeRequired ) { VirtualDeviceConfigSpec nicSpec = new VirtualDeviceConfigSpec(); nicSpec.setOperation(VirtualDeviceConfigSpecOperation.add); @@ -540,33 +534,19 @@ else if( accessibleNetwork.getProviderVlanId().equals(vlan) ) { nic.connectable.startConnected = true; Description info = new Description(); - info.setLabel(targetVlan.getName()); - if( targetVlan.getProviderVlanId().startsWith("network") ) { - info.setSummary("Nic for network " + targetVlan.getName()); + info.setLabel(vlan); + info.setSummary("Nic for network " + vlan); - VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo(); - nicBacking.setDeviceName(targetVlan.getName()); + VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo(); + nicBacking.setDeviceName(vlan); + + nic.setAddressType("generated"); + nic.setBacking(nicBacking); + nic.setKey(0); - nic.setAddressType("generated"); - nic.setBacking(nicBacking); - nic.setKey(0); - } - else { - info.setSummary("Nic for DVS " + targetVlan.getName()); - - VirtualEthernetCardDistributedVirtualPortBackingInfo nicBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo(); - DistributedVirtualSwitchPortConnection connection = new DistributedVirtualSwitchPortConnection(); - connection.setPortgroupKey(targetVlan.getProviderVlanId()); - connection.setSwitchUuid(targetVlan.getTag("switch.uuid")); - nicBacking.setPort(connection); - nic.setAddressType("generated"); - nic.setBacking(nicBacking); - nic.setKey(0); - } nicSpec.setDevice(nic); machineSpecs.add(nicSpec); - resultingNetworks.add(vlan); } config.setDeviceChange(machineSpecs.toArray(new VirtualDeviceConfigSpec[machineSpecs.size()])); @@ -606,8 +586,8 @@ else if( accessibleNetwork.getProviderVlanId().equals(vlan) ) { if (platform.isLinux()) { CustomizationLinuxPrep lPrep = new CustomizationLinuxPrep(); - lPrep.setDomain(options.getDnsDomain()); // not null - lPrep.setHostName(new CustomizationVirtualMachineName()); // not null + lPrep.setDomain(options.getDnsDomain()); + lPrep.setHostName(new CustomizationVirtualMachineName()); customizationSpec.setIdentity(lPrep); } else if( platform.isWindows() ) { @@ -643,42 +623,30 @@ else if( platform.isWindows() ) { } if( isCustomised ) { - List adapterMappings = new ArrayList(); - for( String network : resultingNetworks ) { - CustomizationAdapterMapping adapterMap = new CustomizationAdapterMapping(); - if( network.equalsIgnoreCase(vlan) ) { - CustomizationGlobalIPSettings globalIPSettings = new CustomizationGlobalIPSettings(); - globalIPSettings.setDnsServerList(options.getDnsServerList()); - globalIPSettings.setDnsSuffixList(options.getDnsSuffixList()); - customizationSpec.setGlobalIPSettings(globalIPSettings); - - CustomizationIPSettings adapter = new CustomizationIPSettings(); - adapter.setDnsDomain(options.getDnsDomain()); - adapter.setGateway(options.getGatewayList()); - CustomizationFixedIp fixedIp = new CustomizationFixedIp(); - fixedIp.setIpAddress(options.getPrivateIp()); - adapter.setIp(fixedIp); - if( options.getMetaData().containsKey("vSphereNetMaskNothingToSeeHere") ) { - String netmask = ( String ) options.getMetaData().get("vSphereNetMaskNothingToSeeHere"); - adapter.setSubnetMask(netmask); - log.debug("custom subnet mask: " + netmask); - } - else { - adapter.setSubnetMask("255.255.252.0"); - log.debug("default subnet mask"); - } - - adapterMap.setAdapter(adapter); - } - else { - CustomizationIPSettings adapter = new CustomizationIPSettings(); - adapter.setDnsDomain(options.getDnsDomain()); - adapter.setIp(new CustomizationDhcpIpGenerator()); - adapterMap.setAdapter(adapter); - } - adapterMappings.add(adapterMap); + CustomizationGlobalIPSettings globalIPSettings = new CustomizationGlobalIPSettings(); + globalIPSettings.setDnsServerList(options.getDnsServerList()); + globalIPSettings.setDnsSuffixList(options.getDnsSuffixList()); + customizationSpec.setGlobalIPSettings(globalIPSettings); + + CustomizationAdapterMapping adapterMap = new CustomizationAdapterMapping(); + CustomizationIPSettings adapter = new CustomizationIPSettings(); + adapter.setDnsDomain(options.getDnsDomain()); + adapter.setGateway(options.getGatewayList()); + CustomizationFixedIp fixedIp = new CustomizationFixedIp(); + fixedIp.setIpAddress(options.getPrivateIp()); + adapter.setIp(fixedIp); + if( options.getMetaData().containsKey("vSphereNetMaskNothingToSeeHere") ) { + String netmask = ( String ) options.getMetaData().get("vSphereNetMaskNothingToSeeHere"); + adapter.setSubnetMask(netmask); + log.debug("custom subnet mask: " + netmask); } - customizationSpec.setNicSettingMap(adapterMappings.toArray(new CustomizationAdapterMapping[adapterMappings.size()])); + else { + adapter.setSubnetMask("255.255.252.0"); + log.debug("default subnet mask"); + } + + adapterMap.setAdapter(adapter); + customizationSpec.setNicSettingMap(Arrays.asList(adapterMap).toArray(new CustomizationAdapterMapping[1])); } } @@ -1014,6 +982,7 @@ else if( platform.isWindows() ) { for( ManagedEntity me : dc.getHostFolder().getChildEntity() ) { if( me.getName().equals(clusterName) ) { ComputeResource cluster = ( ComputeResource ) me; + for( HostSystem host : cluster.getHosts() ) { if( host.getConfigStatus().equals(ManagedEntityStatus.green) ) { possibles.add(host); @@ -1104,12 +1073,7 @@ else if( platform.isWindows() ) { public @Nullable VirtualMachineProduct getProduct(@Nonnull String productId) throws InternalException, CloudException { APITrace.begin(getProvider(), "Vm.getProduct(String)"); try { - for( VirtualMachineProduct product : listProducts(null, Architecture.I64) ) { - if( product.getProviderProductId().equals(productId) ) { - return product; - } - } - for( VirtualMachineProduct product : listProducts(null, Architecture.I32) ) { + for( VirtualMachineProduct product : listProducts("ignoreme", null) ) { if( product.getProviderProductId().equals(productId) ) { return product; } @@ -1170,26 +1134,16 @@ else if( platform.isWindows() ) { } @Override - public @Nonnull Iterable listProducts(@Nonnull String machineImageId, @Nonnull VirtualMachineProductFilterOptions options) throws InternalException, CloudException { - MachineImageSupport support = getProvider().getComputeServices().getImageSupport(); - if( support == null ) { - throw new CloudException( getProvider().getCloudName() + " does not implement image support services"); - } - MachineImage image = support.getImage(machineImageId); - if( image == null ) { - throw new CloudException("Machine image " + machineImageId + " not found" ); - } - - return listProducts(options, image.getArchitecture()); - } + public Iterable listProducts( + /** ignored **/ @Nonnull String machineImageId, + @Nullable VirtualMachineProductFilterOptions options) throws InternalException, CloudException { - @Override - public Iterable listProducts(VirtualMachineProductFilterOptions options, Architecture architecture) throws InternalException, CloudException { - APITrace.begin(getProvider(), "Vm.listProducts(VirtualMachineProductFilterOptions, Architecture)"); + APITrace.begin(getProvider(), "Vm.listProducts(String, VirtualMachineProductFilterOptions)"); try { - ArrayList allVirtualMachineProducts = new ArrayList(); - - Cache cache = Cache.getInstance(getProvider(), "resourcePools", org.dasein.cloud.dc.ResourcePool.class, CacheLevel.REGION_ACCOUNT, new TimePeriod(15, TimePeriod.MINUTE)); + // get resource pools from cache or live + Cache cache = Cache.getInstance( + getProvider(), "resourcePools", org.dasein.cloud.dc.ResourcePool.class, CacheLevel.REGION_ACCOUNT, + new TimePeriod(15, TimePeriod.MINUTE)); Collection rps = ( Collection ) cache.get(getContext()); if( rps == null ) { @@ -1203,123 +1157,187 @@ public Iterable listProducts(VirtualMachineProductFilterO cache.put(getContext(), rps); } - if( architecture != null ) { - for( Architecture a : getCapabilities().listSupportedArchitectures() ) { - if( a.equals(architecture) ) { - if( a.equals(Architecture.I32) ) { - for( int cpu : new int[]{1, 2} ) { - for( int ram : new int[]{512, 1024, 2048} ) { - // add in product without pool - VirtualMachineProduct product = new VirtualMachineProduct(); - - product.setCpuCount(cpu); - product.setDescription("Custom product " + architecture + " - " + cpu + " CPU, " + ram + "MB RAM"); - product.setName(cpu + " CPU/" + ram + " MB RAM"); - product.setRootVolumeSize(new Storage(1, Storage.GIGABYTE)); - product.setProviderProductId(cpu + ":" + ram); - product.setRamSize(new Storage(ram, Storage.MEGABYTE)); - product.setArchitectures(a); - allVirtualMachineProducts.add(product); - - //resource pools - for( org.dasein.cloud.dc.ResourcePool pool : rps ) { - product = new VirtualMachineProduct(); - product.setCpuCount(cpu); - product.setDescription("Custom product " + architecture + " - " + cpu + " CPU, " + ram + "MB RAM"); - product.setName("Pool "+pool.getName()+"/"+cpu + " CPU/" + ram + " MB RAM"); - product.setRootVolumeSize(new Storage(1, Storage.GIGABYTE)); - product.setProviderProductId(pool.getProvideResourcePoolId() + ":" + cpu + ":" + ram); - product.setRamSize(new Storage(ram, Storage.MEGABYTE)); - allVirtualMachineProducts.add(product); - } - } - } - } - else { - for( int cpu : new int[]{1, 2, 4, 8} ) { - for( int ram : new int[]{1024, 2048, 4096, 10240, 20480} ) { - // add in product without pool - VirtualMachineProduct product = new VirtualMachineProduct(); - - product.setCpuCount(cpu); - product.setDescription("Custom product " + architecture + " - " + cpu + " CPU, " + ram + "MB RAM"); - product.setName(cpu + " CPU/" + ram + " MB RAM"); - product.setRootVolumeSize(new Storage(1, Storage.GIGABYTE)); - product.setProviderProductId(cpu + ":" + ram); - product.setRamSize(new Storage(ram, Storage.MEGABYTE)); - product.setArchitectures(a); - allVirtualMachineProducts.add(product); - - //resource pools - for( org.dasein.cloud.dc.ResourcePool pool : rps ) { - product = new VirtualMachineProduct(); - product.setCpuCount(cpu); - product.setDescription("Custom product " + architecture + " - " + cpu + " CPU, " + ram + "MB RAM"); - product.setName("Pool "+pool.getName()+"/"+cpu + " CPU/" + ram + " MB RAM"); - - product.setRootVolumeSize(new Storage(1, Storage.GIGABYTE)); - product.setProviderProductId(pool.getProvideResourcePoolId() + ":" + cpu + ":" + ram); - product.setRamSize(new Storage(ram, Storage.MEGABYTE)); - allVirtualMachineProducts.add(product); - } - } - } - } - } + List results = new ArrayList(); + Iterable jsonProducts = listProductsJson(); + // first add all matching products from vmproducts.json + for( VirtualMachineProduct product : jsonProducts ) { + if( options == null || options.matches(product) ) { + results.add(product); } } - else { - for( int cpu : new int[]{1, 2, 4, 8} ) { - for( int ram : new int[]{512, 1024, 2048, 4096, 10240, 20480} ) { - // add in product without pool - VirtualMachineProduct product = new VirtualMachineProduct(); - - product.setCpuCount(cpu); - product.setDescription("Custom product " + architecture + " - " + cpu + " CPU, " + ram + "MB RAM"); - product.setName(cpu + " CPU/" + ram + " MB RAM"); - product.setRootVolumeSize(new Storage(1, Storage.GIGABYTE)); - product.setProviderProductId(cpu + ":" + ram); - product.setRamSize(new Storage(ram, Storage.MEGABYTE)); - allVirtualMachineProducts.add(product); - - //resource pools - for( org.dasein.cloud.dc.ResourcePool pool : rps ) { - product = new VirtualMachineProduct(); - product.setCpuCount(cpu); - product.setDescription("Custom product " + architecture + " - " + cpu + " CPU, " + ram + "MB RAM"); - product.setName("Pool "+pool.getName()+"/"+cpu + " CPU/" + ram + " MB RAM"); - - product.setRootVolumeSize(new Storage(1, Storage.GIGABYTE)); - product.setProviderProductId(pool.getProvideResourcePoolId() + ":" + cpu + ":" + ram); - product.setRamSize(new Storage(ram, Storage.MEGABYTE)); - allVirtualMachineProducts.add(product); - } + + // second add same products but augmented with the resource pool info, ordered by pool name + for( org.dasein.cloud.dc.ResourcePool pool : rps ) { + for( VirtualMachineProduct product : jsonProducts ) { + product.setName("Pool " + pool.getName() + "/" + product.getName()); + product.setProviderProductId(pool.getProvideResourcePoolId() + ":" + product.getProviderProductId()); + if( options == null || options.matches(product) ) { + results.add(product); } } } - if( options != null ) { - ArrayList filteredProducts = new ArrayList(); - for( VirtualMachineProduct product : allVirtualMachineProducts ) { - if( options.matches(product) ) { - filteredProducts.add(product); + return results; + } + finally { + APITrace.end(); + } + } + + /** + * Load products list from vmproducts.json filtered by architecture if specified in the options. + * Uses a cache for one day. + * @return list of products + * @throws InternalException + */ + private @Nonnull Iterable listProductsJson() throws InternalException { + APITrace.begin(getProvider(), "VM.listProducts"); + try { + Cache cache = Cache.getInstance(getProvider(), "products", VirtualMachineProduct.class, CacheLevel.REGION_ACCOUNT, new TimePeriod(1, TimePeriod.DAY)); + Iterable products = cache.get(getContext()); + + if( products != null && products.iterator().hasNext() ) { + return products; + } + + List list = new ArrayList(); + + try { + InputStream input = AbstractVMSupport.class.getResourceAsStream("/org/dasein/cloud/vsphere/vmproducts.json"); + + if( input == null ) { + return Collections.emptyList(); + } + BufferedReader reader = new BufferedReader(new InputStreamReader(input)); + StringBuilder json = new StringBuilder(); + String line; + + while( ( line = reader.readLine() ) != null ) { + json.append(line); + json.append("\n"); + } + JSONArray arr = new JSONArray(json.toString()); + JSONObject toCache = null; + + for( int i = 0; i < arr.length(); i++ ) { + JSONObject productSet = arr.getJSONObject(i); + String cloud, provider; + + if( productSet.has("cloud") ) { + cloud = productSet.getString("cloud"); + } + else { + continue; + } + if( productSet.has("provider") ) { + provider = productSet.getString("provider"); + } + else { + continue; + } + if( !productSet.has("products") ) { + continue; + } + if( toCache == null || ( provider.equals("vSphere") && cloud.equals("vSphere") ) ) { + toCache = productSet; + } + if( provider.equalsIgnoreCase(getProvider().getProviderName()) && cloud.equalsIgnoreCase(getProvider().getCloudName()) ) { + toCache = productSet; + break; } } - return filteredProducts; - } - else { - return allVirtualMachineProducts; + if( toCache == null ) { + return Collections.emptyList(); + } + JSONArray plist = toCache.getJSONArray("products"); + + for( int i = 0; i < plist.length(); i++ ) { + JSONObject product = plist.getJSONObject(i); + boolean supported = true; + if( product.has("excludesRegions") ) { + JSONArray regions = product.getJSONArray("excludesRegions"); + + for( int j = 0; j < regions.length(); j++ ) { + String r = regions.getString(j); + + if( r.equals(getContext().getRegionId()) ) { + supported = false; + break; + } + } + } + if( supported ) { + list.add(toProduct(product)); + } + } + // save the products to cache + cache.put(getContext(), list); + } catch( IOException e ) { + throw new InternalException(e); + } catch( JSONException e ) { + throw new InternalException(e); } - } - finally { + return list; + } finally { APITrace.end(); } + } - static private Collection architectures; + private @Nullable VirtualMachineProduct toProduct( @Nonnull JSONObject json ) throws InternalException { + VirtualMachineProduct prd = new VirtualMachineProduct(); - @Override - public Iterable listSupportedArchitectures() throws InternalException, CloudException { - return getCapabilities().listSupportedArchitectures(); + try { + if( json.has("id") ) { + prd.setProviderProductId(json.getString("id")); + } + else { + return null; + } + if( json.has("name") ) { + prd.setName(json.getString("name")); + } + else { + prd.setName(prd.getProviderProductId()); + } + if( json.has("description") ) { + prd.setDescription(json.getString("description")); + } + else { + prd.setDescription(prd.getName()); + } + if( json.has("cpuCount") ) { + prd.setCpuCount(json.getInt("cpuCount")); + } + else { + prd.setCpuCount(1); + } + if( json.has("rootVolumeSizeInGb") ) { + prd.setRootVolumeSize(new Storage(json.getInt("rootVolumeSizeInGb"), Storage.GIGABYTE)); + } + else { + prd.setRootVolumeSize(new Storage(1, Storage.GIGABYTE)); + } + if( json.has("ramSizeInMb") ) { + prd.setRamSize(new Storage(json.getInt("ramSizeInMb"), Storage.MEGABYTE)); + } + else { + prd.setRamSize(new Storage(512, Storage.MEGABYTE)); + } + if( json.has("standardHourlyRates") ) { + JSONArray rates = json.getJSONArray("standardHourlyRates"); + + for( int i = 0; i < rates.length(); i++ ) { + JSONObject rate = rates.getJSONObject(i); + + if( rate.has("rate") ) { + prd.setStandardHourlyRate(( float ) rate.getDouble("rate")); + } + } + } + } catch( JSONException e ) { + throw new InternalException(e); + } + return prd; } @Override diff --git a/src/main/resources/org/dasein/cloud/vsphere/vmproducts.json b/src/main/resources/org/dasein/cloud/vsphere/vmproducts.json new file mode 100644 index 0000000..5cfb43f --- /dev/null +++ b/src/main/resources/org/dasein/cloud/vsphere/vmproducts.json @@ -0,0 +1,210 @@ +[ + { + "provider":"vSphere", + "cloud":"vSphere", + "products":[ + { + "architectures":["I32"], + "id":"1:512", + "name":"1 CPU/512MB RAM", + "description":"Custom product - 1 CPU, 512MB RAM", + "cpuCount":1, + "rootVolumeSizeInGb":1, + "ramSizeInMb":512 + }, + { + "architectures":["I32", "I64"], + "id":"1:1024", + "name":"1 CPU/1024MB RAM", + "description":"Custom product - 1 CPU, 1024MB RAM", + "cpuCount":1, + "rootVolumeSizeInGb":1, + "ramSizeInMb":1024 + }, + { + "architectures":["I32", "I64"], + "id":"1:2048", + "name":"1 CPU/2048MB RAM", + "description":"Custom product - 1 CPU, 2048MB RAM", + "cpuCount":1, + "rootVolumeSizeInGb":1, + "ramSizeInMb":2048 + }, + { + "architectures":["I64"], + "id":"1:4096", + "name":"1 CPU/4096MB RAM", + "description":"Custom product - 1 CPU, 4096MB RAM", + "cpuCount":1, + "rootVolumeSizeInGb":1, + "ramSizeInMb":4096 + }, + { + "architectures":["I64"], + "id":"1:10240", + "name":"1 CPU/10240MB RAM", + "description":"Custom product - 1 CPU, 10240MB RAM", + "cpuCount":1, + "rootVolumeSizeInGb":1, + "ramSizeInMb":10240 + }, + { + "architectures":["I64"], + "id":"1:20480", + "name":"1 CPU/20480MB RAM", + "description":"Custom product - 1 CPU, 20480MB RAM", + "cpuCount":1, + "rootVolumeSizeInGb":1, + "ramSizeInMb":20480 + }, + + { + "architectures":["I32"], + "id":"2:512", + "name":"2 CPU/512MB RAM", + "description":"Custom product - 2 CPU, 512MB RAM", + "cpuCount":2, + "rootVolumeSizeInGb":1, + "ramSizeInMb":512 + }, + { + "architectures":["I32", "I64"], + "id":"2:1024", + "name":"2 CPU/1024MB RAM", + "description":"Custom product - 2 CPU, 1024MB RAM", + "cpuCount":2, + "rootVolumeSizeInGb":1, + "ramSizeInMb":1024 + }, + { + "architectures":["I32", "I64"], + "id":"2:2048", + "name":"2 CPU/2048MB RAM", + "description":"Custom product - 2 CPU, 2048MB RAM", + "cpuCount":2, + "rootVolumeSizeInGb":1, + "ramSizeInMb":2048 + }, + { + "architectures":["I64"], + "id":"2:4096", + "name":"2 CPU/4096MB RAM", + "description":"Custom product - 2 CPU, 4096MB RAM", + "cpuCount":2, + "rootVolumeSizeInGb":1, + "ramSizeInMb":4096 + }, + { + "architectures":["I64"], + "id":"2:10240", + "name":"2 CPU/10240MB RAM", + "description":"Custom product - 2 CPU, 10240MB RAM", + "cpuCount":2, + "rootVolumeSizeInGb":1, + "ramSizeInMb":10240 + }, + { + "architectures":["I64"], + "id":"2:20480", + "name":"2 CPU/20480MB RAM", + "description":"Custom product - 2 CPU, 20480MB RAM", + "cpuCount":2, + "rootVolumeSizeInGb":1, + "ramSizeInMb":20480 + }, + + { + "architectures":["I64"], + "id":"4:1024", + "name":"4 CPU/1024MB RAM", + "description":"Custom product - 4 CPU, 1024MB RAM", + "cpuCount":4, + "rootVolumeSizeInGb":1, + "ramSizeInMb":1024 + }, + { + "architectures":["I64"], + "id":"4:2048", + "name":"4 CPU/2048MB RAM", + "description":"Custom product - 4 CPU, 2048MB RAM", + "cpuCount":4, + "rootVolumeSizeInGb":1, + "ramSizeInMb":2048 + }, + { + "architectures":["I64"], + "id":"4:4096", + "name":"4 CPU/4096MB RAM", + "description":"Custom product - 4 CPU, 4096MB RAM", + "cpuCount":4, + "rootVolumeSizeInGb":1, + "ramSizeInMb":4096 + }, + { + "architectures":["I64"], + "id":"4:10240", + "name":"4 CPU/10240MB RAM", + "description":"Custom product - 4 CPU, 10240MB RAM", + "cpuCount":4, + "rootVolumeSizeInGb":1, + "ramSizeInMb":10240 + }, + { + "architectures":["I64"], + "id":"4:20480", + "name":"4 CPU/20480MB RAM", + "description":"Custom product - 4 CPU, 20480MB RAM", + "cpuCount":4, + "rootVolumeSizeInGb":1, + "ramSizeInMb":20480 + }, + + { + "architectures":["I64"], + "id":"8:1024", + "name":"8 CPU/1024MB RAM", + "description":"Custom product - 8 CPU, 1024MB RAM", + "cpuCount":8, + "rootVolumeSizeInGb":1, + "ramSizeInMb":1024 + }, + { + "architectures":["I64"], + "id":"8:2048", + "name":"8 CPU/2048MB RAM", + "description":"Custom product - 8 CPU, 2048MB RAM", + "cpuCount":8, + "rootVolumeSizeInGb":1, + "ramSizeInMb":2048 + }, + { + "architectures":["I64"], + "id":"8:4096", + "name":"8 CPU/4096MB RAM", + "description":"Custom product - 8 CPU, 4096MB RAM", + "cpuCount":8, + "rootVolumeSizeInGb":1, + "ramSizeInMb":4096 + }, + { + "architectures":["I64"], + "id":"8:10240", + "name":"8 CPU/10240MB RAM", + "description":"Custom product - 8 CPU, 10240MB RAM", + "cpuCount":8, + "rootVolumeSizeInGb":1, + "ramSizeInMb":10240 + }, + { + "architectures":["I64"], + "id":"8:20480", + "name":"8 CPU/20480MB RAM", + "description":"Custom product - 8 CPU, 20480MB RAM", + "cpuCount":8, + "rootVolumeSizeInGb":1, + "ramSizeInMb":20480 + } + ] + } +] +