use of com.amazonaws.services.ec2.model.ModifyInstanceAttributeRequest in project photon-model by vmware.
the class AWSUtils method setDeleteOnTerminateAttribute.
public static DeferredResult<DiskService.DiskState> setDeleteOnTerminateAttribute(AmazonEC2AsyncClient client, String instanceId, Map<String, Pair<String, Boolean>> deleteDiskMapByDeviceName, OperationContext opCtx) {
List<InstanceBlockDeviceMappingSpecification> instanceBlockDeviceMappingSpecificationList = deleteDiskMapByDeviceName.entrySet().stream().map(entry -> new InstanceBlockDeviceMappingSpecification().withDeviceName(entry.getKey()).withEbs(new EbsInstanceBlockDeviceSpecification().withDeleteOnTermination(entry.getValue().right).withVolumeId(entry.getValue().left))).collect(Collectors.toList());
DeferredResult<DiskService.DiskState> modifyInstanceAttrDr = new DeferredResult();
ModifyInstanceAttributeRequest modifyInstanceAttrReq = new ModifyInstanceAttributeRequest().withInstanceId(instanceId).withAttribute(InstanceAttributeName.BlockDeviceMapping).withBlockDeviceMappings(instanceBlockDeviceMappingSpecificationList);
AWSAsyncHandler<ModifyInstanceAttributeRequest, ModifyInstanceAttributeResult> modifyInstanceAttrHandler = new AWSAsyncHandler<ModifyInstanceAttributeRequest, ModifyInstanceAttributeResult>() {
@Override
protected void handleError(Exception exception) {
OperationContext.restoreOperationContext(opCtx);
modifyInstanceAttrDr.fail(exception);
}
@Override
protected void handleSuccess(ModifyInstanceAttributeRequest request, ModifyInstanceAttributeResult result) {
OperationContext.restoreOperationContext(opCtx);
modifyInstanceAttrDr.complete(new DiskService.DiskState());
}
};
client.modifyInstanceAttributeAsync(modifyInstanceAttrReq, modifyInstanceAttrHandler);
return modifyInstanceAttrDr;
}
use of com.amazonaws.services.ec2.model.ModifyInstanceAttributeRequest in project herd by FINRAOS.
the class Ec2DaoImpl method addSecurityGroupsToEc2Instance.
/**
* Adds the security groups to an EC2 instance.
*
* @param ec2InstanceId the ec2 instance id.
* @param securityGroups security groups to be added.
* @param awsParams awsParamsDto object
*
* @return updated security groups.
*/
@Override
public List<String> addSecurityGroupsToEc2Instance(String ec2InstanceId, List<String> securityGroups, AwsParamsDto awsParams) {
Set<String> updatedSecurityGroups = new HashSet<>();
for (String securityGroup : securityGroups) {
updatedSecurityGroups.add(securityGroup);
}
// Get existing security groups
DescribeInstanceAttributeRequest describeInstanceAttributeRequest = new DescribeInstanceAttributeRequest().withInstanceId(ec2InstanceId).withAttribute(InstanceAttributeName.GroupSet);
DescribeInstanceAttributeResult describeInstanceAttributeResult = ec2Operations.describeInstanceAttribute(getEc2Client(awsParams), describeInstanceAttributeRequest);
List<GroupIdentifier> groups = describeInstanceAttributeResult.getInstanceAttribute().getGroups();
for (GroupIdentifier groupIdentifier : groups) {
updatedSecurityGroups.add(groupIdentifier.getGroupId());
}
// Add security group on master EC2 instance
ModifyInstanceAttributeRequest modifyInstanceAttributeRequest = new ModifyInstanceAttributeRequest().withInstanceId(ec2InstanceId).withGroups(updatedSecurityGroups);
ec2Operations.modifyInstanceAttribute(getEc2Client(awsParams), modifyInstanceAttributeRequest);
return new ArrayList<>(updatedSecurityGroups);
}
Aggregations