use of com.sequenceiq.cloudbreak.api.model.NetworkRequest in project cloudbreak by hortonworks.
the class AwsCreateVpcNetworkTest method createNetwork.
@Test
@Parameters({ "networkName", "description", "publicInAccount", "regionName", "vpcStackName", "vpcName", "existingSubnet" })
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount, String regionName, @Optional("it-vpc-stack") String vpcStackName, @Optional("it-vpc") String vpcName, boolean existingSubnet) {
AmazonCloudFormationClient client = new AmazonCloudFormationClient();
client.setRegion(RegionUtils.getRegion(regionName));
Map<String, Object> networkMap = new HashMap<>();
String vpcCreationJson = existingSubnet ? "public_vpc_with_subnet.json" : "public_vpc_wihout_subnet.json";
try (InputStream vpcJsonInputStream = getClass().getResourceAsStream("/cloudformation/" + vpcCreationJson)) {
String vpcCFTemplateString = IOUtils.toString(vpcJsonInputStream);
CreateStackRequest stackRequest = createStackRequest(vpcStackName, vpcName, vpcCFTemplateString);
client.createStack(stackRequest);
List<Output> outputForRequest = getOutputForRequest(vpcStackName, client);
if (existingSubnet) {
networkMap.put("vpcId", outputForRequest.get(0).getOutputValue());
networkMap.put("subnetId", outputForRequest.get(1).getOutputValue());
} else {
networkMap.put("vpcId", outputForRequest.get(1).getOutputValue());
networkMap.put("internetGatewayId", outputForRequest.get(0).getOutputValue());
}
} catch (IOException e) {
LOGGER.error("can't read vpc cloudformation template file");
throw new RuntimeException(e);
}
NetworkRequest networkRequest = new NetworkRequest();
networkRequest.setName(networkName);
networkRequest.setDescription(description);
networkRequest.setParameters(networkMap);
if (!existingSubnet) {
networkRequest.setSubnetCIDR("10.0.0.0/24");
}
networkRequest.setCloudPlatform("AWS");
String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
use of com.sequenceiq.cloudbreak.api.model.NetworkRequest in project cloudbreak by hortonworks.
the class OpenStackNetworkCreationTest method testOpenstackNetworkCreation.
@Test
@Parameters({ "networkName", "subnetCIDR", "publicNetId" })
public void testOpenstackNetworkCreation(@Optional("it-openstack-network") String networkName, @Optional("10.0.36.0/24") String subnetCIDR, @Optional("") String publicNetId) {
// GIVEN
publicNetId = getPublicNetId(publicNetId, defaultPublicNetId);
// WHEN
NetworkRequest networkRequest = new NetworkRequest();
networkRequest.setDescription("OpenStack network for integration testing");
networkRequest.setName(networkName);
networkRequest.setSubnetCIDR(subnetCIDR);
Map<String, Object> map = new HashMap<>();
map.put("publicNetId", publicNetId);
networkRequest.setParameters(map);
networkRequest.setCloudPlatform("OPENSTACK");
String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
// THEN
Assert.assertNotNull(id);
getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
Aggregations