use of com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs.NetSpec in project photon-model by vmware.
the class TestAWSSetupUtils method setUpTestVpc.
public static void setUpTestVpc(AmazonEC2AsyncClient client, Map<String, Object> awsTestContext, boolean isMock, String zoneId) {
// If the pre-set VPC does not exist, get the test VPC for the given account and use it in the tests.
if (!isMock && !vpcIdExists(client, AWS_DEFAULT_VPC_ID)) {
String vpcId = createorGetVPCForAccount(client);
awsTestContext.put(VPC_KEY, vpcId);
Subnet subnet = createOrGetSubnet(client, AWS_DEFAULT_SUBNET_CIDR, vpcId, zoneId);
awsTestContext.put(SUBNET_KEY, subnet.getSubnetId());
String internetGatewayId = createOrGetInternetGatewayForGivenVPC(client, vpcId);
awsTestContext.put(INTERNET_GATEWAY_KEY, internetGatewayId);
SecurityGroup sg = createOrGetDefaultSecurityGroupForGivenVPC(client, vpcId);
awsTestContext.put(SECURITY_GROUP_KEY, sg.getGroupId());
awsTestContext.put(SECURITY_GROUP_NAME_KEY, sg.getGroupName());
NetSpec network = new NetSpec(vpcId, vpcId, AWS_DEFAULT_VPC_CIDR);
List<NetSpec> subnets = new ArrayList<>();
subnets.add(new NetSpec(subnet.getSubnetId(), AWS_DEFAULT_SUBNET_NAME, subnet.getCidrBlock(), zoneId == null ? TestAWSSetupUtils.zoneId + avalabilityZoneIdentifier : zoneId));
NicSpec nicSpec = NicSpec.create().withSubnetSpec(subnets.get(0)).withDynamicIpAssignment();
awsTestContext.put(NIC_SPECS_KEY, new AwsNicSpecs(network, Collections.singletonList(nicSpec)));
return;
}
awsTestContext.put(VPC_KEY, AWS_DEFAULT_VPC_ID);
awsTestContext.put(NIC_SPECS_KEY, SINGLE_NIC_SPEC);
awsTestContext.put(SUBNET_KEY, AWS_DEFAULT_SUBNET_ID);
awsTestContext.put(SECURITY_GROUP_KEY, AWS_DEFAULT_GROUP_ID);
awsTestContext.put(SECURITY_GROUP_NAME_KEY, AWS_DEFAULT_GROUP_NAME);
}
use of com.vmware.photon.controller.model.adapters.awsadapter.TestAWSSetupUtils.AwsNicSpecs.NetSpec in project photon-model by vmware.
the class TestAWSSetupUtils method multiNicSpecs.
/**
* Return two-NIC spec where first NIC should be assigned to 'secondary' subnet and second NIC
* should be assigned to a randomly generated subnet that should be created.
* <p>
* For a matrix of maximum supported NICs per Instance type check:
* http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI
*
* @see {@value #instanceType} instance type
*/
public static AwsNicSpecs multiNicSpecs() throws UnknownHostException {
String nextSubnetIp;
{
// 172.31.1000 0000.0000 0000
final String startingSubnetIp = "172.31.128.0";
Random r = new Random();
// Convert IP as String -to-> byte[4] -to-> IP as integer
int startingIpAsInt = ByteBuffer.wrap(InetAddress.getByName(startingSubnetIp).getAddress()).getInt();
/*
* The random subnet generated is between 172.31.1[000 0000.0000] 0000 and 172.31.1[111
* 1111.1111] 0000. The last 4 zero bits are for the IPs within the subnet generated.
*/
int nextSubnetIpAsInt = startingIpAsInt | (r.nextInt(1 << 11) << 4);
// Convert IP as integer -to-> byte[4] -to-> IP as String
nextSubnetIp = InetAddress.getByAddress(ByteBuffer.allocate(4).putInt(nextSubnetIpAsInt).array()).getHostAddress();
}
NetSpec network = new NetSpec(AWS_DEFAULT_VPC_ID, AWS_DEFAULT_VPC_ID, AWS_DEFAULT_VPC_CIDR);
// Configure with TWO NICS.
List<NetSpec> subnets = new ArrayList<>();
// 'secondary' subnet which is existing
subnets.add(new NetSpec(AWS_SECONDARY_SUBNET_ID, AWS_SECONDARY_SUBNET_NAME, AWS_SECONDARY_SUBNET_CIDR, zoneId + avalabilityZoneIdentifier));
// Random generated subnet with /28 mask to be created
subnets.add(new NetSpec(null, "third", nextSubnetIp + "/28", zoneId + avalabilityZoneIdentifier));
NicSpec nicSpec = NicSpec.create().withSubnetSpec(subnets.get(0)).withStaticIpAssignment();
return new AwsNicSpecs(network, Collections.singletonList(nicSpec));
}
Aggregations