List of usage examples for com.amazonaws.services.ec2.model InstanceAttribute getUserData
public String getUserData()
The user data.
From source file:org.excalibur.service.aws.ec2.EC2.java
License:Open Source License
private VirtualMachine toExcaliburInstance(Instance instance, KeyPair keyPair) { Map<String, Tag> tags = TAGS.apply(instance.getTags()); VirtualMachine vm = new VirtualMachine().setName(instance.getInstanceId()).setImageId(instance.getImageId()) .setType(InstanceType.valueOf(instance.getInstanceType()) .setProvider(this.credentials_.getProvider())) .setState(new InstanceStateDetails(InstanceStateType.valueOfFrom(instance.getState().getName()), new Date())) //TODO we need to improve this .setConfiguration(new VmConfiguration().setKeyName(instance.getKeyName()) .setKeyPairs(new KeyPairs().setPrivateKey(keyPair)) .setPlatform(/*from w w w .ja v a2 s. c o m*/ isNullOrEmpty(instance.getPlatform()) ? DEFAULT_PLATFORM : instance.getPlatform()) .setPlatformUserName(tags.get(DEFAULT_PLATFORM_INSTANCE_USERNAME_TAG) != null ? tags.get(DEFAULT_PLATFORM_INSTANCE_USERNAME_TAG).getValue() : System.getProperty("org.excalibur.default.platform.username")) .setPrivateIpAddress(instance.getPrivateIpAddress()) .setPublicIpAddress(instance.getPublicIpAddress()) .setPublicDnsName(instance.getPublicDnsName())) .setLaunchTime(instance.getLaunchTime()) // .setLocation(new Region().setName(instance.getPlacement().getAvailabilityZone())) // .setLocation(credentials_.getRegion()) .setLocation(new Zone().setName(instance.getPlacement().getAvailabilityZone()) .setRegion(credentials_.getRegion())) .setPlacement(new org.excalibur.core.cloud.api.Placement() .setGroupName(instance.getPlacement().getGroupName()) .setZone(instance.getPlacement().getAvailabilityZone())) .setOwner(new User(this.credentials_.getUserId()) .setUsername(tags.get("username") != null ? tags.get("username").getValue() : null)); if (tags.containsKey("keyname")) { if (vm.getConfiguration().getKeyPairs().getPrivateKey() == null) { vm.getConfiguration().getKeyPairs().setPrivateKey(new KeyPair()); } vm.getConfiguration().getKeyPairs().getPrivateKey().setKeyName(tags.get("keyname").getValue()); } else { return null; } InstanceAttribute attribute = new AmazonEC2Client(awsCredentials_) .describeInstanceAttribute(new DescribeInstanceAttributeRequest() .withInstanceId(instance.getInstanceId()).withAttribute("userData")) .getInstanceAttribute(); // List<InstanceStatus> instanceStatuses = new AmazonEC2Client(awsCredentials_).describeInstanceStatus( // new DescribeInstanceStatusRequest().withInstanceIds(instance.getInstanceId())).getInstanceStatuses(); if (!isNullOrEmpty(attribute.getUserData())) { String userData = new String(Base64.decodeBase64(attribute.getUserData().getBytes())); int i = userData.indexOf("#start-data"), f = userData.indexOf("#end-data"); if (i > -1 && f > -1) { String[] keys = userData.substring(i, f).split("#"); checkState(keys.length == 4); vm.getConfiguration().getKeyPairs().getPrivateKey().setKeyMaterial(keys[2]); vm.getConfiguration().getKeyPairs().setPublicKey( new KeyPair().setKeyName(tags.get("keyname").getValue()).setKeyMaterial(keys[3].trim())); } vm.setUserData(attribute.getUserData()); } for (Tag tag : tags.values()) { vm.getTags().add(org.excalibur.core.cloud.api.domain.Tag.valueOf(tag.getKey(), tag.getValue())); } return vm; }