@Test public void testGetVpcCidrsEmpty() { AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class); CloudStack cloudStack = mock(CloudStack.class); when(cloudStack.getNetwork()).thenReturn(new Network(new Subnet(null))); List<String> vpcCidrs = underTest.getVpcCidrs(authenticatedContext, cloudStack); assertTrue(vpcCidrs.isEmpty()); }
public List<String> getVpcCidrs(AuthenticatedContext ac, CloudStack stack) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); if (awsNetworkView.isExistingVPC()) { String region = ac.getCloudContext().getLocation().getRegion().value(); AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region); DescribeVpcsRequest vpcRequest = new DescribeVpcsRequest().withVpcIds(awsNetworkView.getExistingVpc()); Vpc vpc = ec2Client.describeVpcs(vpcRequest).getVpcs().get(0); List<String> cidrBlockAssociationSet = vpc.getCidrBlockAssociationSet().stream() .map(VpcCidrBlockAssociation::getCidrBlock) .collect(Collectors.toList()); LOGGER.info("VPC associated CIDR blocks: [{}]", cidrBlockAssociationSet); return cidrBlockAssociationSet; } else { return Collections.emptyList(); } }
AwsNetworkService { public List<String> getVpcCidrs(AuthenticatedContext ac, CloudStack stack) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); if (awsNetworkView.isExistingVPC()) { String region = ac.getCloudContext().getLocation().getRegion().value(); AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region); DescribeVpcsRequest vpcRequest = new DescribeVpcsRequest().withVpcIds(awsNetworkView.getExistingVpc()); Vpc vpc = ec2Client.describeVpcs(vpcRequest).getVpcs().get(0); List<String> cidrBlockAssociationSet = vpc.getCidrBlockAssociationSet().stream() .map(VpcCidrBlockAssociation::getCidrBlock) .collect(Collectors.toList()); LOGGER.info("VPC associated CIDR blocks: [{}]", cidrBlockAssociationSet); return cidrBlockAssociationSet; } else { return Collections.emptyList(); } } }
AwsNetworkService { public List<String> getVpcCidrs(AuthenticatedContext ac, CloudStack stack) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); if (awsNetworkView.isExistingVPC()) { String region = ac.getCloudContext().getLocation().getRegion().value(); AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region); DescribeVpcsRequest vpcRequest = new DescribeVpcsRequest().withVpcIds(awsNetworkView.getExistingVpc()); Vpc vpc = ec2Client.describeVpcs(vpcRequest).getVpcs().get(0); List<String> cidrBlockAssociationSet = vpc.getCidrBlockAssociationSet().stream() .map(VpcCidrBlockAssociation::getCidrBlock) .collect(Collectors.toList()); LOGGER.info("VPC associated CIDR blocks: [{}]", cidrBlockAssociationSet); return cidrBlockAssociationSet; } else { return Collections.emptyList(); } }  }
AwsNetworkService { public List<String> getVpcCidrs(AuthenticatedContext ac, CloudStack stack) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); if (awsNetworkView.isExistingVPC()) { String region = ac.getCloudContext().getLocation().getRegion().value(); AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region); DescribeVpcsRequest vpcRequest = new DescribeVpcsRequest().withVpcIds(awsNetworkView.getExistingVpc()); Vpc vpc = ec2Client.describeVpcs(vpcRequest).getVpcs().get(0); List<String> cidrBlockAssociationSet = vpc.getCidrBlockAssociationSet().stream() .map(VpcCidrBlockAssociation::getCidrBlock) .collect(Collectors.toList()); LOGGER.info("VPC associated CIDR blocks: [{}]", cidrBlockAssociationSet); return cidrBlockAssociationSet; } else { return Collections.emptyList(); } }  List<Group> getGatewayGroups(Collection<Group> groups); List<String> getExistingSubnetCidr(AuthenticatedContext ac, CloudStack stack); boolean isMapPublicOnLaunch(AwsNetworkView awsNetworkView, AmazonEC2 amazonEC2Client); String findNonOverLappingCIDR(AuthenticatedContext ac, CloudStack stack); List<String> getVpcCidrs(AuthenticatedContext ac, CloudStack stack); }
AwsNetworkService { public List<String> getVpcCidrs(AuthenticatedContext ac, CloudStack stack) { AwsNetworkView awsNetworkView = new AwsNetworkView(stack.getNetwork()); if (awsNetworkView.isExistingVPC()) { String region = ac.getCloudContext().getLocation().getRegion().value(); AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(ac.getCloudCredential()), region); DescribeVpcsRequest vpcRequest = new DescribeVpcsRequest().withVpcIds(awsNetworkView.getExistingVpc()); Vpc vpc = ec2Client.describeVpcs(vpcRequest).getVpcs().get(0); List<String> cidrBlockAssociationSet = vpc.getCidrBlockAssociationSet().stream() .map(VpcCidrBlockAssociation::getCidrBlock) .collect(Collectors.toList()); LOGGER.info("VPC associated CIDR blocks: [{}]", cidrBlockAssociationSet); return cidrBlockAssociationSet; } else { return Collections.emptyList(); } }  List<Group> getGatewayGroups(Collection<Group> groups); List<String> getExistingSubnetCidr(AuthenticatedContext ac, CloudStack stack); boolean isMapPublicOnLaunch(AwsNetworkView awsNetworkView, AmazonEC2 amazonEC2Client); String findNonOverLappingCIDR(AuthenticatedContext ac, CloudStack stack); List<String> getVpcCidrs(AuthenticatedContext ac, CloudStack stack);  }