Search in sources :

Example 16 with NeutronNetworkView

use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.

the class OpenStackResourceConnector method downscale.

@Override
public List<CloudResourceStatus> downscale(AuthenticatedContext authenticatedContext, CloudStack cloudStack, List<CloudResource> resources, List<CloudInstance> vms, Object resourcesToRemove) {
    CloudStack stack = removeDeleteRequestedInstances(cloudStack);
    String stackName = utils.getStackName(authenticatedContext);
    NeutronNetworkView neutronNetworkView = new NeutronNetworkView(stack.getNetwork());
    boolean existingNetwork = neutronNetworkView.isExistingNetwork();
    String existingSubnetCidr = getExistingSubnetCidr(authenticatedContext, stack);
    ModelContext modelContext = new ModelContext();
    modelContext.withExistingNetwork(existingNetwork);
    modelContext.withExistingSubnet(existingSubnetCidr != null);
    modelContext.withGroups(stack.getGroups());
    modelContext.withInstanceUserData(stack.getImage());
    modelContext.withLocation(authenticatedContext.getCloudContext().getLocation());
    modelContext.withStackName(stackName);
    modelContext.withNeutronNetworkView(neutronNetworkView);
    modelContext.withTemplateString(stack.getTemplate());
    modelContext.withTags(stack.getTags());
    String heatTemplate = heatTemplateBuilder.build(modelContext);
    Map<String, String> parameters = heatTemplateBuilder.buildParameters(authenticatedContext, stack, existingNetwork, existingSubnetCidr);
    return updateHeatStack(authenticatedContext, resources, heatTemplate, parameters);
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)

Example 17 with NeutronNetworkView

use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.

the class OpenStackResourceConnector method upscale.

@Override
public List<CloudResourceStatus> upscale(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) {
    String stackName = utils.getStackName(authenticatedContext);
    NeutronNetworkView neutronNetworkView = new NeutronNetworkView(stack.getNetwork());
    boolean existingNetwork = neutronNetworkView.isExistingNetwork();
    String existingSubnetCidr = getExistingSubnetCidr(authenticatedContext, stack);
    ModelContext modelContext = new ModelContext();
    modelContext.withExistingNetwork(existingNetwork);
    modelContext.withExistingSubnet(existingSubnetCidr != null);
    modelContext.withGroups(stack.getGroups());
    modelContext.withInstanceUserData(stack.getImage());
    modelContext.withLocation(authenticatedContext.getCloudContext().getLocation());
    modelContext.withStackName(stackName);
    modelContext.withNeutronNetworkView(neutronNetworkView);
    modelContext.withTemplateString(stack.getTemplate());
    modelContext.withTags(stack.getTags());
    String heatTemplate = heatTemplateBuilder.build(modelContext);
    Map<String, String> parameters = heatTemplateBuilder.buildParameters(authenticatedContext, stack, existingNetwork, existingSubnetCidr);
    return updateHeatStack(authenticatedContext, resources, heatTemplate, parameters);
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)

Example 18 with NeutronNetworkView

use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.

the class OpenStackResourceConnector method update.

@Override
public List<CloudResourceStatus> update(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> resources) {
    String stackName = utils.getStackName(authenticatedContext);
    NeutronNetworkView neutronNetworkView = new NeutronNetworkView(stack.getNetwork());
    boolean existingNetwork = neutronNetworkView.isExistingNetwork();
    String existingSubnetCidr = getExistingSubnetCidr(authenticatedContext, stack);
    ModelContext modelContext = new ModelContext();
    modelContext.withExistingNetwork(existingNetwork);
    modelContext.withExistingSubnet(existingSubnetCidr != null);
    modelContext.withGroups(stack.getGroups());
    modelContext.withInstanceUserData(stack.getImage());
    modelContext.withLocation(authenticatedContext.getCloudContext().getLocation());
    modelContext.withStackName(stackName);
    modelContext.withNeutronNetworkView(neutronNetworkView);
    modelContext.withTemplateString(stack.getTemplate());
    modelContext.withTags(stack.getTags());
    String heatTemplate = heatTemplateBuilder.build(modelContext);
    Map<String, String> parameters = heatTemplateBuilder.buildParameters(authenticatedContext, stack, existingNetwork, existingSubnetCidr);
    return updateHeatStack(authenticatedContext, resources, heatTemplate, parameters);
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)

Example 19 with NeutronNetworkView

use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView 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);
}
Also used : HashMap(java.util.HashMap) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Matchers.containsString(org.hamcrest.Matchers.containsString) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)

Example 20 with NeutronNetworkView

use of com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView in project cloudbreak by hortonworks.

the class HeatTemplateBuilderTest method buildTestWithExistingNetworkAndExistingSubnetAndAssignFloatingIpShouldThrowAssertionException.

@Test
@Ignore
public void buildTestWithExistingNetworkAndExistingSubnetAndAssignFloatingIpShouldThrowAssertionException() throws Exception {
    // GIVEN
    boolean existingNetwork = true;
    boolean existingSubnet = true;
    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, not(containsString("name: cb-sec-group_" + 't')));
    assertThat(templateString, not(containsString("app_net_id")));
    assertThat(templateString, containsString("app_network"));
    assertThat(templateString, not(containsString("subnet_id")));
    assertThat(templateString, containsString("app_subnet"));
    assertThat(templateString, not(containsString("network_id")));
    assertThat(templateString, not(containsString("public_net_id")));
}
Also used : ModelContext(com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext) Matchers.containsString(org.hamcrest.Matchers.containsString) NeutronNetworkView(com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

NeutronNetworkView (com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)25 ModelContext (com.sequenceiq.cloudbreak.cloud.openstack.heat.HeatTemplateBuilder.ModelContext)16 Matchers.containsString (org.hamcrest.Matchers.containsString)13 Test (org.junit.Test)12 OpenStackResourceException (com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)7 OS4JException (org.openstack4j.api.exceptions.OS4JException)7 Ignore (org.junit.Ignore)3 ActionResponse (org.openstack4j.model.common.ActionResponse)3 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 HashMap (java.util.HashMap)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)1 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)1 Group (com.sequenceiq.cloudbreak.cloud.model.Group)1 Network (com.sequenceiq.cloudbreak.cloud.model.Network)1 PortDefinition (com.sequenceiq.cloudbreak.cloud.model.PortDefinition)1 Security (com.sequenceiq.cloudbreak.cloud.model.Security)1 SecurityRule (com.sequenceiq.cloudbreak.cloud.model.SecurityRule)1 KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)1 FreeMarkerTemplateUtils.processTemplateIntoString (com.sequenceiq.cloudbreak.util.FreeMarkerTemplateUtils.processTemplateIntoString)1