use of com.sequenceiq.cloudbreak.cloud.model.Network in project cloudbreak by hortonworks.
the class HeatTemplateBuilderTest method createNeutronNetworkView.
private NeutronNetworkView createNeutronNetworkView(String publicNetId) {
Map<String, Object> parameters = new HashMap<>();
if (publicNetId != null) {
parameters.put("publicNetId", publicNetId);
}
Network network = new Network(null, parameters);
return new NeutronNetworkView(network);
}
use of com.sequenceiq.cloudbreak.cloud.model.Network in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit24Vpc.
@Test
public void testFindNonOverLappingCIDRWit24Vpc() {
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
Map<String, Object> networkParameters = new HashMap<>();
networkParameters.put("vpcId", "vpc-12345678");
networkParameters.put("internetGatewayId", "igw-12345678");
Network network = new Network(new Subnet(null), networkParameters);
CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
Location location = mock(Location.class);
Vpc vpc = mock(Vpc.class);
DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
com.amazonaws.services.ec2.model.Subnet subnet1 = mock(com.amazonaws.services.ec2.model.Subnet.class);
DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
when(vpc.getCidrBlock()).thenReturn("10.0.0.0/24");
when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
when(subnetsResult.getSubnets()).thenReturn(singletonList(subnet1));
when(subnet1.getCidrBlock()).thenReturn("10.0.0.0/24");
thrown.expect(CloudConnectorException.class);
thrown.expectMessage("The selected VPC has to be in a bigger CIDR range than /24");
underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
}
use of com.sequenceiq.cloudbreak.cloud.model.Network in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit20Vpc2.
@Test
public void testFindNonOverLappingCIDRWit20Vpc2() {
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
Map<String, Object> networkParameters = new HashMap<>();
networkParameters.put("vpcId", "vpc-12345678");
networkParameters.put("internetGatewayId", "igw-12345678");
Network network = new Network(new Subnet(null), networkParameters);
CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
Location location = mock(Location.class);
Vpc vpc = mock(Vpc.class);
DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
com.amazonaws.services.ec2.model.Subnet subnet1 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet2 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet3 = mock(com.amazonaws.services.ec2.model.Subnet.class);
com.amazonaws.services.ec2.model.Subnet subnet4 = mock(com.amazonaws.services.ec2.model.Subnet.class);
DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(cloudContext.getName()).thenReturn(new String(new byte[] { 16 }));
when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
when(vpc.getCidrBlock()).thenReturn("10.0.0.0/20");
when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
when(subnetsResult.getSubnets()).thenReturn(Arrays.asList(subnet1, subnet2, subnet3, subnet4));
when(subnet1.getCidrBlock()).thenReturn("10.0.0.0/24");
when(subnet2.getCidrBlock()).thenReturn("10.0.1.0/24");
when(subnet3.getCidrBlock()).thenReturn("10.0.2.0/24");
when(subnet4.getCidrBlock()).thenReturn("10.0.3.0/24");
String cidr = underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
Assert.assertEquals("10.0.4.0/24", cidr);
}
use of com.sequenceiq.cloudbreak.cloud.model.Network in project cloudbreak by hortonworks.
the class AwsResourceConnectorTest method testFindNonOverLappingCIDRWit24VpcEmptySubnet.
@Test
public void testFindNonOverLappingCIDRWit24VpcEmptySubnet() {
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
Group group1 = new Group("group1", InstanceGroupType.CORE, Collections.emptyList(), null, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
Map<String, Object> networkParameters = new HashMap<>();
networkParameters.put("vpcId", "vpc-12345678");
networkParameters.put("internetGatewayId", "igw-12345678");
Network network = new Network(new Subnet(null), networkParameters);
CloudStack cloudStack = new CloudStack(singletonList(group1), network, null, emptyMap(), emptyMap(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudContext cloudContext = mock(CloudContext.class);
Location location = mock(Location.class);
Vpc vpc = mock(Vpc.class);
DescribeVpcsResult describeVpcsResult = mock(DescribeVpcsResult.class);
AmazonEC2Client ec2Client = mock(AmazonEC2Client.class);
DescribeSubnetsResult subnetsResult = mock(DescribeSubnetsResult.class);
when(authenticatedContext.getCloudContext()).thenReturn(cloudContext);
when(cloudContext.getLocation()).thenReturn(location);
when(location.getRegion()).thenReturn(Region.region("eu-west-1"));
when(awsClient.createAccess(any(), any())).thenReturn(ec2Client);
when(ec2Client.describeVpcs(any())).thenReturn(describeVpcsResult);
when(describeVpcsResult.getVpcs()).thenReturn(singletonList(vpc));
when(vpc.getCidrBlock()).thenReturn("10.0.0.0/24");
when(ec2Client.describeSubnets(any())).thenReturn(subnetsResult);
when(subnetsResult.getSubnets()).thenReturn(Collections.emptyList());
thrown.expect(CloudConnectorException.class);
thrown.expectMessage("The selected VPC has to be in a bigger CIDR range than /24");
underTest.findNonOverLappingCIDR(authenticatedContext, cloudStack);
}
use of com.sequenceiq.cloudbreak.cloud.model.Network in project cloudbreak by hortonworks.
the class AzureTemplateBuilder method build.
public String build(String stackName, String customImageId, AzureCredentialView armCredentialView, AzureStackView armStack, CloudContext cloudContext, CloudStack cloudStack) {
try {
String imageUrl = cloudStack.getImage().getImageName();
String imageName = imageUrl.substring(imageUrl.lastIndexOf('/') + 1);
Network network = cloudStack.getNetwork();
Map<String, Object> model = new HashMap<>();
AzureInstanceCredentialView azureInstanceCredentialView = new AzureInstanceCredentialView(cloudStack);
model.put("credential", azureInstanceCredentialView);
String rootDiskStorage = azureStorage.getImageStorageName(armCredentialView, cloudContext, cloudStack);
AzureSecurityView armSecurityView = new AzureSecurityView(cloudStack.getGroups());
// needed for pre 1.16.5 templates
model.put("existingSubnetName", azureUtils.getCustomSubnetIds(network).stream().findFirst().orElse(""));
model.put("customImageId", customImageId);
model.put("storage_account_name", rootDiskStorage);
model.put("image_storage_container_name", AzureStorage.IMAGES_CONTAINER);
model.put("storage_container_name", azureStorage.getDiskContainerName(cloudContext));
model.put("storage_vhd_name", imageName);
model.put("stackname", stackName);
model.put("region", cloudContext.getLocation().getRegion().value());
model.put("subnet1Prefix", network.getSubnet().getCidr());
model.put("groups", armStack.getGroups());
model.put("igs", armStack.getInstanceGroups());
model.put("securities", armSecurityView.getPorts());
model.put("securityGroups", armSecurityView.getSecurityGroupIds());
model.put("corecustomData", base64EncodedUserData(cloudStack.getImage().getUserDataByType(InstanceGroupType.CORE)));
model.put("gatewaycustomData", base64EncodedUserData(cloudStack.getImage().getUserDataByType(InstanceGroupType.GATEWAY)));
model.put("disablePasswordAuthentication", !azureInstanceCredentialView.passwordAuthenticationRequired());
model.put("existingVPC", azureUtils.isExistingNetwork(network));
model.put("resourceGroupName", azureUtils.getCustomResourceGroupName(network));
model.put("existingVNETName", azureUtils.getCustomNetworkId(network));
model.put("noPublicIp", azureUtils.isPrivateIp(network));
model.put("noFirewallRules", azureUtils.isNoSecurityGroups(network));
model.put("userDefinedTags", cloudStack.getTags());
model.putAll(defaultCostTaggingService.prepareAllTagsForTemplate());
String generatedTemplate = processTemplateIntoString(getTemplate(cloudStack), model);
LOGGER.debug("Generated Arm template: {}", generatedTemplate);
return generatedTemplate;
} catch (IOException | TemplateException e) {
throw new CloudConnectorException("Failed to process the Arm TemplateBuilder", e);
}
}
Aggregations