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);
}
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);
}
Aggregations