use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.
the class HeatTemplateBuilderTest method buildTestWithExistingNetworkAndAssignFloatingIpWithoutExistingSubnet.
@Test
public void buildTestWithExistingNetworkAndAssignFloatingIpWithoutExistingSubnet() throws Exception {
// GIVEN
boolean existingNetwork = true;
boolean existingSubnet = false;
NeutronNetworkView neutronNetworkView = createNeutronNetworkView("floating_pool_id");
// WHEN
when(openStackUtil.adjustStackNameLength(Mockito.anyString())).thenReturn("t");
ModelContext modelContext = new ModelContext();
modelContext.withExistingNetwork(existingNetwork);
modelContext.withExistingSubnet(existingSubnet);
modelContext.withGroups(groups);
modelContext.withInstanceUserData(image);
modelContext.withLocation(location());
modelContext.withStackName(stackName);
modelContext.withNeutronNetworkView(neutronNetworkView);
modelContext.withTemplateString(heatTemplateBuilder.getTemplate());
String templateString = heatTemplateBuilder.build(modelContext);
// THEN
assertThat(templateString, containsString("name: cb-sec-group_" + 't'));
assertThat(templateString, containsString("app_net_id"));
assertThat(templateString, not(containsString("app_network")));
assertThat(templateString, containsString("subnet_id"));
assertThat(templateString, containsString("app_subnet"));
assertThat(templateString, containsString("network_id"));
assertThat(templateString, containsString("public_net_id"));
}
use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.
the class HeatTemplateBuilderTest method buildTestWithExistingNetworkWithoutExistingSubnetAndAssignFloatingIp.
@Test
public void buildTestWithExistingNetworkWithoutExistingSubnetAndAssignFloatingIp() throws Exception {
// GIVEN
boolean existingNetwork = true;
boolean existingSubnet = false;
NeutronNetworkView neutronNetworkView = createNeutronNetworkView(null);
// WHEN
when(openStackUtil.adjustStackNameLength(Mockito.anyString())).thenReturn("t");
ModelContext modelContext = new ModelContext();
modelContext.withExistingNetwork(existingNetwork);
modelContext.withExistingSubnet(existingSubnet);
modelContext.withGroups(groups);
modelContext.withInstanceUserData(image);
modelContext.withLocation(location());
modelContext.withStackName(stackName);
modelContext.withNeutronNetworkView(neutronNetworkView);
modelContext.withTemplateString(heatTemplateBuilder.getTemplate());
String templateString = heatTemplateBuilder.build(modelContext);
// THEN
assertThat(templateString, containsString("name: cb-sec-group_" + 't'));
assertThat(templateString, containsString("app_net_id"));
assertThat(templateString, not(containsString("app_network")));
assertThat(templateString, containsString("subnet_id"));
assertThat(templateString, containsString("app_subnet"));
assertThat(templateString, containsString("network_id"));
assertThat(templateString, not(containsString("public_net_id")));
}
use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.
the class OpenStackSubnetResourceBuilder method build.
@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource) {
try {
NeutronNetworkView neutronView = new NeutronNetworkView(network);
String subnetId = neutronView.isExistingSubnet() ? neutronView.getCustomSubnetId() : context.getParameter(SUBNET_ID, String.class);
if (!neutronView.isExistingSubnet()) {
OSClient<?> osClient = createOSClient(auth);
NeutronNetworkView networkView = new NeutronNetworkView(network);
Subnet subnet = Builders.subnet().name(resource.getName()).networkId(context.getParameter(OpenStackConstants.NETWORK_ID, String.class)).tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)).ipVersion(IPVersionType.V4).cidr(networkView.getSubnetCIDR()).enableDHCP(true).build();
subnetId = osClient.networking().subnet().create(subnet).getId();
}
context.putParameter(SUBNET_ID, subnetId);
return createPersistedResource(resource, subnetId);
} catch (OS4JException ex) {
throw new OpenStackResourceException("Subnet creation failed", resourceType(), resource.getName(), ex);
}
}
use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.
the class OpenStackSubnetResourceBuilder method delete.
@Override
public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) {
try {
NeutronNetworkView neutronView = new NeutronNetworkView(network);
if (!neutronView.isExistingSubnet()) {
OSClient<?> osClient = createOSClient(auth);
ActionResponse response = osClient.networking().subnet().delete(resource.getReference());
return checkDeleteResponse(response, resourceType(), auth, resource, "Subnet deletion failed");
}
return null;
} catch (OS4JException ex) {
throw new OpenStackResourceException("Subnet deletion failed", resourceType(), resource.getName(), ex);
}
}
use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.
the class HeatTemplateBuilder method buildParameters.
public Map<String, String> buildParameters(AuthenticatedContext auth, CloudStack cloudStack, boolean existingNetwork, String existingSubnetCidr) {
KeystoneCredentialView osCredential = new KeystoneCredentialView(auth);
NeutronNetworkView neutronView = new NeutronNetworkView(cloudStack.getNetwork());
Map<String, String> parameters = new HashMap<>();
if (neutronView.isAssignFloatingIp()) {
parameters.put("public_net_id", neutronView.getPublicNetId());
}
parameters.put("image_id", cloudStack.getImage().getImageName());
if (cloudStack.getInstanceAuthentication().getPublicKeyId() != null) {
parameters.put("key_name", cloudStack.getInstanceAuthentication().getPublicKeyId());
} else {
parameters.put("key_name", osCredential.getKeyPairName());
}
if (existingNetwork) {
parameters.put("app_net_id", neutronView.getCustomNetworkId());
if (isNoneEmpty(existingSubnetCidr)) {
parameters.put("subnet_id", neutronView.getCustomSubnetId());
} else {
parameters.put("router_id", neutronView.getCustomRouterId());
}
}
parameters.put("app_net_cidr", isBlank(existingSubnetCidr) ? neutronView.getSubnetCIDR() : existingSubnetCidr);
return parameters;
}
Aggregations