List of usage examples for com.amazonaws.services.ec2.model BlockDeviceMapping getVirtualName
public String getVirtualName()
The virtual device name (ephemeral
N).
From source file:jp.primecloud.auto.process.aws.AwsInstanceProcess.java
License:Open Source License
protected List<BlockDeviceMapping> createInstanceStoreBlockDeviceMappings(AwsProcessClient awsProcessClient, ImageAws imageAws, AwsInstance awsInstance, com.amazonaws.services.ec2.model.Image image) { int count = AwsInstanceTypeDefinition.getInstanceStoreCount(awsInstance.getInstanceType()); if (count == 0) { return null; }/*from ww w . j ava 2 s. c o m*/ // ???????????????? String maxInstanceStore = Config.getProperty("aws.maxInstanceStore"); if (StringUtils.isNotEmpty(maxInstanceStore)) { int max = Integer.parseInt(maxInstanceStore); if (count > max) { count = max; } } // ?BlockDeviceMapping???? Set<String> deviceNames = new HashSet<String>(); for (BlockDeviceMapping mapping : image.getBlockDeviceMappings()) { deviceNames.add(mapping.getDeviceName()); } List<BlockDeviceMapping> mappings = new ArrayList<BlockDeviceMapping>(); for (int i = 0; i < count; i++) { String virtualName = "ephemeral" + i; // ?BlockDeviceMapping???????? boolean exist = false; for (BlockDeviceMapping mapping : image.getBlockDeviceMappings()) { if (virtualName.equals(mapping.getVirtualName())) { exist = true; break; } } if (exist) { continue; } // ????????? String identifier = null; for (int j = 0; j < 25; j++) { char id = (char) ('b' + j); if (!deviceNames.contains("/dev/sd" + id) && !deviceNames.contains("xvd" + id)) { identifier = String.valueOf(id); break; } } if (identifier == null) { // b ? z ?????????????? continue; } String deviceName; if (StringUtils.equals(image.getPlatform(), PlatformValues.Windows.toString())) { deviceName = "xvd" + identifier; } else { deviceName = "/dev/sd" + identifier; } BlockDeviceMapping mapping = new BlockDeviceMapping(); mapping.withVirtualName(virtualName); mapping.withDeviceName(deviceName); mappings.add(mapping); deviceNames.add(deviceName); } return mappings; }