use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.
the class HeatTemplateBuilderTest method buildTestWithoutExistingNetworkAndExistingSubnetAndAssignFloatingIp.
@Test
public void buildTestWithoutExistingNetworkAndExistingSubnetAndAssignFloatingIp() throws Exception {
// GIVEN
boolean existingNetwork = false;
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, not(containsString("app_net_id")));
assertThat(templateString, 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 HeatTemplateBuilderTest method buildTestWithAssignFloatingIpWithoutExistingNetworkAndExistingSubnet.
@Test
public void buildTestWithAssignFloatingIpWithoutExistingNetworkAndExistingSubnet() throws Exception {
// GIVEN
boolean existingNetwork = false;
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, not(containsString("app_net_id")));
assertThat(templateString, 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 OpenStackSecurityGroupResourceBuilder method build.
@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Group group, Network network, Security security, CloudResource resource) {
try {
OSClient<?> osClient = createOSClient(auth);
ComputeSecurityGroupService securityGroupService = osClient.compute().securityGroups();
SecGroupExtension securityGroup = securityGroupService.create(resource.getName(), "");
String securityGroupId = securityGroup.getId();
for (SecurityRule rule : security.getRules()) {
IPProtocol osProtocol = getProtocol(rule.getProtocol());
String cidr = rule.getCidr();
for (PortDefinition portStr : rule.getPorts()) {
int from = Integer.parseInt(portStr.getFrom());
int to = Integer.parseInt(portStr.getTo());
securityGroupService.createRule(createRule(securityGroupId, osProtocol, cidr, from, to));
}
}
NeutronNetworkView neutronView = new NeutronNetworkView(network);
String subnetCidr = neutronView.isExistingSubnet() ? utils.getExistingSubnetCidr(auth, neutronView) : network.getSubnet().getCidr();
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.TCP, subnetCidr, MIN_PORT, MAX_PORT));
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.UDP, subnetCidr, MIN_PORT, MAX_PORT));
securityGroupService.createRule(createRule(securityGroupId, IPProtocol.ICMP, "0.0.0.0/0"));
return createPersistedResource(resource, group.getName(), securityGroup.getId());
} catch (OS4JException ex) {
throw new OpenStackResourceException("SecurityGroup creation failed", resourceType(), resource.getName(), ex);
}
}
use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.
the class OpenStackNetworkResourceBuilder method build.
@Override
public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Network network, Security security, CloudResource buildableResource) {
OSClient<?> osClient = createOSClient(auth);
try {
NeutronNetworkView neutronView = new NeutronNetworkView(network);
String networkId = neutronView.isExistingNetwork() ? neutronView.getCustomNetworkId() : context.getParameter(NETWORK_ID, String.class);
if (!neutronView.isExistingNetwork()) {
org.openstack4j.model.network.Network osNetwork = Builders.network().name(buildableResource.getName()).tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)).adminStateUp(true).build();
networkId = osClient.networking().network().create(osNetwork).getId();
}
context.putParameter(NETWORK_ID, networkId);
return createPersistedResource(buildableResource, networkId);
} catch (OS4JException ex) {
throw new OpenStackResourceException("Network creation failed", resourceType(), buildableResource.getName(), ex);
}
}
use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.
the class OpenStackNetworkResourceBuilder method delete.
@Override
public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) {
try {
OSClient<?> osClient = createOSClient(auth);
deAllocateFloatingIps(context, osClient);
NeutronNetworkView neutronView = new NeutronNetworkView(network);
if (!neutronView.isExistingNetwork()) {
ActionResponse response = osClient.networking().network().delete(resource.getReference());
return checkDeleteResponse(response, resourceType(), auth, resource, "Network deletion failed");
}
return null;
} catch (OS4JException ex) {
throw new OpenStackResourceException("Network deletion failed", resourceType(), resource.getName(), ex);
}
}
Aggregations