Search in sources :

Example 1 with DescribeInstanceAttributeRequest

use of com.amazonaws.services.ec2.model.DescribeInstanceAttributeRequest in project herd by FINRAOS.

the class MockEc2OperationsImpl method describeInstanceAttribute.

@Override
public DescribeInstanceAttributeResult describeInstanceAttribute(AmazonEC2Client ec2Client, DescribeInstanceAttributeRequest describeInstanceAttributeRequest) {
    InstanceAttribute instanceAttribute = new InstanceAttribute();
    instanceAttribute.withGroups(new GroupIdentifier().withGroupId("A_TEST_SECURITY_GROUP"));
    return new DescribeInstanceAttributeResult().withInstanceAttribute(instanceAttribute);
}
Also used : DescribeInstanceAttributeResult(com.amazonaws.services.ec2.model.DescribeInstanceAttributeResult) InstanceAttribute(com.amazonaws.services.ec2.model.InstanceAttribute) GroupIdentifier(com.amazonaws.services.ec2.model.GroupIdentifier)

Example 2 with DescribeInstanceAttributeRequest

use of com.amazonaws.services.ec2.model.DescribeInstanceAttributeRequest 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);
}
Also used : DescribeInstanceAttributeResult(com.amazonaws.services.ec2.model.DescribeInstanceAttributeResult) DescribeInstanceAttributeRequest(com.amazonaws.services.ec2.model.DescribeInstanceAttributeRequest) ArrayList(java.util.ArrayList) ModifyInstanceAttributeRequest(com.amazonaws.services.ec2.model.ModifyInstanceAttributeRequest) HashSet(java.util.HashSet) GroupIdentifier(com.amazonaws.services.ec2.model.GroupIdentifier)

Aggregations

DescribeInstanceAttributeResult (com.amazonaws.services.ec2.model.DescribeInstanceAttributeResult)2 GroupIdentifier (com.amazonaws.services.ec2.model.GroupIdentifier)2 DescribeInstanceAttributeRequest (com.amazonaws.services.ec2.model.DescribeInstanceAttributeRequest)1 InstanceAttribute (com.amazonaws.services.ec2.model.InstanceAttribute)1 ModifyInstanceAttributeRequest (com.amazonaws.services.ec2.model.ModifyInstanceAttributeRequest)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1