本文整理匯總了Java中com.amazonaws.services.ec2.model.Instance.getSecurityGroups方法的典型用法代碼示例。如果您正苦於以下問題:Java Instance.getSecurityGroups方法的具體用法?Java Instance.getSecurityGroups怎麽用?Java Instance.getSecurityGroups使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.amazonaws.services.ec2.model.Instance
的用法示例。
在下文中一共展示了Instance.getSecurityGroups方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPropertyValue
import com.amazonaws.services.ec2.model.Instance; //導入方法依賴的package包/類
@Override
protected String getPropertyValue(Instance instance) {
List<String> result = Lists.newArrayList();
for (GroupIdentifier group : instance.getSecurityGroups()) {
result.add(String.format("%s(%s)", group.getGroupName(), group.getGroupId()));
}
return Joiner.on(", ").join(result);
}
示例2: assertAndSetVMSecurityGroupsToBeDeleted
import com.amazonaws.services.ec2.model.Instance; //導入方法依賴的package包/類
private void assertAndSetVMSecurityGroupsToBeDeleted(Instance instance, ComputeState vm) {
// This assert is only suitable for real (non-mocking env).
if (this.isMock) {
return;
}
this.host.log(Level.INFO, "%s: Assert security groups configuration for [%s] VM",
this.currentTestName.getMethodName(), this.vmState.name);
// Get the SecurityGroupStates that were provided in the request ComputeState
Collector<SecurityGroupService.SecurityGroupState, ?, Map<String, SecurityGroupService.SecurityGroupState>> convertToMap =
Collectors.<SecurityGroupService.SecurityGroupState, String, SecurityGroupService.SecurityGroupState>toMap(
sg -> sg.name, sg -> sg);
Map<String, SecurityGroupService.SecurityGroupState> currentSGNamesToStates = vm.networkInterfaceLinks
.stream()
// collect all NIC states in a List
.map(nicLink -> this.host.getServiceState(null,
NetworkInterfaceService.NetworkInterfaceState.class,
UriUtils.buildUri(this.host, nicLink)))
//collect all SecurityGroup States from all NIC states
.<SecurityGroupService.SecurityGroupState>flatMap(
nicState -> nicState.securityGroupLinks.stream()
// obtain SecurityGroupState from each SG link
.map(sgLink -> {
SecurityGroupService.SecurityGroupState sgState = this.host
.getServiceState(null,
SecurityGroupService.SecurityGroupState.class,
UriUtils.buildUri(this.host, sgLink));
return sgState;
}))
// collect security group states in a map with key = SG name
.collect(convertToMap);
// Compare ComputeState after provisioning to the ComputeState in the request
assertNotNull("Instance should have security groups attached.",
instance.getSecurityGroups());
// Provisioned Instance should have the same number of SecurityGroups as requested
assertEquals(instance.getSecurityGroups().size(), currentSGNamesToStates.size());
for (SecurityGroupService.SecurityGroupState currentSGState : currentSGNamesToStates
.values()) {
// Get corresponding requested state
GroupIdentifier provisionedGroupIdentifier = null;
for (GroupIdentifier awsGroupIdentifier : instance.getSecurityGroups()) {
if (awsGroupIdentifier.getGroupId().equals(currentSGState.id)) {
provisionedGroupIdentifier = awsGroupIdentifier;
break;
}
}
// Ensure that the requested SecurityGroup was actually provisioned
assertNotNull(provisionedGroupIdentifier);
if (currentSGState.name.contains(TestAWSSetupUtils.AWS_NEW_GROUP_PREFIX)) {
this.sgToCleanUp = currentSGState.id;
SecurityGroup awsSecurityGroup = getSecurityGroupsIdUsingEC2Client(this.client,
provisionedGroupIdentifier.getGroupId());
assertNotNull(awsSecurityGroup);
// Validate rules are correctly created as requested
IpPermission awsIngressRule = awsSecurityGroup.getIpPermissions().get(0);
IpPermission awsEgressRule = awsSecurityGroup.getIpPermissionsEgress().get(1);
assertNotNull(awsIngressRule);
assertNotNull(awsEgressRule);
assertEquals("Error in created ingress rule", awsIngressRule.getIpProtocol(),
currentSGState.ingress.get(0).protocol);
assertEquals("Error in created ingress rule",
awsIngressRule.getIpv4Ranges().get(0).getCidrIp(),
currentSGState.ingress.get(0).ipRangeCidr);
assertEquals("Error in created egress rule", awsEgressRule.getIpProtocol(),
currentSGState.egress.get(0).protocol);
assertEquals("Error in created egress rule",
awsEgressRule.getIpv4Ranges().get(0).getCidrIp(),
currentSGState.egress.get(0).ipRangeCidr);
}
}
}
示例3: assertAndSetVMSecurityGroupsToBeDeleted
import com.amazonaws.services.ec2.model.Instance; //導入方法依賴的package包/類
private void assertAndSetVMSecurityGroupsToBeDeleted(Instance instance, ComputeState vm) {
// This assert is only suitable for real (non-mocking env).
if (this.isMock) {
return;
}
this.host.log(Level.INFO, "%s: Assert security groups configuration for [%s] VM",
this.currentTestName.getMethodName(), this.vmState.name);
// Get the SecurityGroupStates that were provided in the request ComputeState
Collector<SecurityGroupState, ?, Map<String, SecurityGroupState>> convertToMap =
Collectors.<SecurityGroupState, String, SecurityGroupState> toMap(sg -> sg.name, sg -> sg);
Map<String, SecurityGroupState> currentSGNamesToStates = vm.networkInterfaceLinks.stream()
// collect all NIC states in a List
.map(nicLink -> this.host.getServiceState(null,
NetworkInterfaceState.class,
UriUtils.buildUri(this.host, nicLink)))
//collect all SecurityGroup States from all NIC states
.<SecurityGroupState> flatMap(nicState -> nicState.securityGroupLinks.stream()
// obtain SecurityGroupState from each SG link
.map(sgLink -> {
SecurityGroupState sgState = this.host.getServiceState(null,
SecurityGroupState.class,
UriUtils.buildUri(this.host, sgLink));
return sgState;
}))
// collect security group states in a map with key = SG name
.collect(convertToMap);
// Compare ComputeState after provisioning to the ComputeState in the request
assertNotNull("Instance should have security groups attached.",
instance.getSecurityGroups());
// Provisioned Instance should have the same number of SecurityGroups as requested
assertEquals(instance.getSecurityGroups().size(), currentSGNamesToStates.size());
for (SecurityGroupState currentSGState : currentSGNamesToStates.values()) {
// Get corresponding requested state
GroupIdentifier provisionedGroupIdentifier = null;
for (GroupIdentifier awsGroupIdentifier : instance.getSecurityGroups()) {
if (awsGroupIdentifier.getGroupId().equals(currentSGState.id)) {
provisionedGroupIdentifier = awsGroupIdentifier;
break;
}
}
// Ensure that the requested SecurityGroup was actually provisioned
assertNotNull(provisionedGroupIdentifier);
if (currentSGState.name.contains(TestAWSSetupUtils.AWS_NEW_GROUP_PREFIX)) {
this.sgToCleanUp = currentSGState.id;
SecurityGroup awsSecurityGroup = getSecurityGroupsIdUsingEC2Client(this.client, provisionedGroupIdentifier.getGroupId());
assertNotNull(awsSecurityGroup);
// Validate rules are correctly created as requested
IpPermission awsIngressRule = awsSecurityGroup.getIpPermissions().get(0);
IpPermission awsEgressRule = awsSecurityGroup.getIpPermissionsEgress().get(1);
assertNotNull(awsIngressRule);
assertNotNull(awsEgressRule);
assertEquals("Error in created ingress rule", awsIngressRule.getIpProtocol(), currentSGState.ingress.get(0).protocol);
assertEquals("Error in created ingress rule", awsIngressRule.getIpv4Ranges().get(0).getCidrIp(), currentSGState.ingress.get(0).ipRangeCidr);
assertEquals("Error in created egress rule", awsEgressRule.getIpProtocol(), currentSGState.egress.get(0).protocol);
assertEquals("Error in created egress rule", awsEgressRule.getIpv4Ranges().get(0).getCidrIp(), currentSGState.egress.get(0).ipRangeCidr);
}
}
}
示例4: assertVMSercurityGroupsConfiguration
import com.amazonaws.services.ec2.model.Instance; //導入方法依賴的package包/類
private void assertVMSercurityGroupsConfiguration(Instance instance, ComputeState vm) {
// This assert is only suitable for real (non-mocking env).
if (this.isMock) {
return;
}
this.host.log(Level.INFO, "%s: Assert security groups configuration for [%s] VM",
this.currentTestName.getMethodName(), this.vmState.name);
// Get the SecurityGroupStates that were provided in the request ComputeState
Collector<SecurityGroupState, ?, Map<String, SecurityGroupState>> convertToMap =
Collectors.<SecurityGroupState, String, SecurityGroupState> toMap(sg -> sg.name, sg -> sg);
Map<String, SecurityGroupState> currentSGNamesToStates = vm.networkInterfaceLinks.stream()
// collect all NIC states in a List
.map(nicLink -> this.host.getServiceState(null,
NetworkInterfaceState.class,
UriUtils.buildUri(this.host, nicLink)))
//collect all SecurityGroup States from all NIC states
.<SecurityGroupState> flatMap(nicState -> nicState.securityGroupLinks.stream()
// obtain SecurityGroupState from each SG link
.map(sgLink -> {
SecurityGroupState sgState = this.host.getServiceState(null,
SecurityGroupState.class,
UriUtils.buildUri(this.host, sgLink));
return sgState;
}))
// collect security group states in a map with key = SG name
.collect(convertToMap);
// Compare ComputeState after provisioning to the ComputeState in the request
assertNotNull("Instance should have security groups attached.",
instance.getSecurityGroups());
// Provisioned Instance should have the same number of SecurityGroups as requested
assertEquals(instance.getSecurityGroups().size(), currentSGNamesToStates.size());
for (SecurityGroupState currentSGState : currentSGNamesToStates.values()) {
// Get corresponding requested state
GroupIdentifier provisionedGroupIdentifier = null;
for (GroupIdentifier awsGroupIdentifier : instance.getSecurityGroups()) {
if (awsGroupIdentifier.getGroupId().equals(currentSGState.id)) {
provisionedGroupIdentifier = awsGroupIdentifier;
break;
}
}
// Ensure that the requested SecurityGroup was actually provisioned
assertNotNull(provisionedGroupIdentifier);
if (currentSGState.name.contains(TestAWSSetupUtils.AWS_NEW_GROUP_PREFIX)) {
this.sgToCleanUp = currentSGState.id;
SecurityGroup awsSecurityGroup = getSecurityGroupsIdUsingEC2Client(this.client, provisionedGroupIdentifier.getGroupId());
assertNotNull(awsSecurityGroup);
// Validate rules are correctly created as requested
IpPermission awsIngressRule = awsSecurityGroup.getIpPermissions().get(0);
IpPermission awsEgressRule = awsSecurityGroup.getIpPermissionsEgress().get(1);
assertNotNull(awsIngressRule);
assertNotNull(awsEgressRule);
assertEquals("Error in created ingress rule", awsIngressRule.getIpProtocol(), currentSGState.ingress.get(0).protocol);
assertEquals("Error in created ingress rule", awsIngressRule.getIpv4Ranges().get(0).getCidrIp(), currentSGState.ingress.get(0).ipRangeCidr);
assertEquals("Error in created egress rule", awsEgressRule.getIpProtocol(), currentSGState.egress.get(0).protocol);
assertEquals("Error in created egress rule", awsEgressRule.getIpv4Ranges().get(0).getCidrIp(), currentSGState.egress.get(0).ipRangeCidr);
}
}
}