org.openstack4j.api.Builders Java Examples
The following examples show how to use
org.openstack4j.api.Builders.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenStackPortBuilder.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResource, CloudStack cloudStack) { CloudResource resource = buildableResource.get(0); try { OSClient<?> osClient = createOSClient(auth); Port port = Builders.port() .tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)) .networkId(context.getStringParameter(OpenStackConstants.NETWORK_ID)) .fixedIp(null, context.getStringParameter(OpenStackConstants.SUBNET_ID)) .securityGroup(context.getGroupResources(group.getName()).get(0).getReference()) .build(); port = osClient.networking().port().create(port); return Collections.singletonList(createPersistedResource(resource, group.getName(), port.getId(), Collections.singletonMap( OpenStackConstants.PORT_ID, port.getId()))); } catch (OS4JException ex) { throw new OpenStackResourceException("Port creation failed", resourceType(), resource.getName(), ex); } }
Example #2
Source File: OpenStackNetworkResourceBuilder.java From cloudbreak with Apache License 2.0 | 6 votes |
@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); } }
Example #3
Source File: OpenStackRouterResourceBuilder.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public CloudResource build(OpenStackContext context, AuthenticatedContext auth, Network network, Security security, CloudResource resource) { try { OSClient<?> osClient = createOSClient(auth); NeutronNetworkView networkView = new NeutronNetworkView(network); String routerId = networkView.getCustomRouterId(); if (!networkView.isExistingNetwork()) { Router router = Builders.router() .name(resource.getName()) .adminStateUp(true) .tenantId(context.getStringParameter(OpenStackConstants.TENANT_ID)) .externalGateway(networkView.getPublicNetId()).build(); Router newRouter = osClient.networking().router().create(router); if (newRouter == null) { throw new OpenStackResourceException("Router creation failed, maybe network does not exists", resourceType(), resource.getName()); } routerId = newRouter.getId(); } if (!networkView.isExistingSubnet()) { osClient.networking().router().attachInterface(routerId, AttachInterfaceType.SUBNET, context.getStringParameter(OpenStackConstants.SUBNET_ID)); } return createPersistedResource(resource, routerId); } catch (OS4JException ex) { throw new OpenStackResourceException("Router creation failed", resourceType(), resource.getName(), ex); } }
Example #4
Source File: OpenStackSubnetResourceBuilder.java From cloudbreak with Apache License 2.0 | 6 votes |
@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); } }
Example #5
Source File: OpenStackResourceConnector.java From cloudbreak with Apache License 2.0 | 5 votes |
private List<CloudResourceStatus> updateHeatStack(AuthenticatedContext authenticatedContext, List<CloudResource> resources, String heatTemplate, Map<String, String> parameters) { CloudResource resource = utils.getHeatResource(resources); String stackName = utils.getStackName(authenticatedContext); String heatStackId = resource.getName(); OSClient<?> client = openStackClient.createOSClient(authenticatedContext); StackUpdate updateRequest = Builders.stackUpdate().template(heatTemplate) .parameters(parameters).timeoutMins(OPERATION_TIMEOUT).build(); client.heat().stacks().update(stackName, heatStackId, updateRequest); LOGGER.debug("Heat stack update request sent with stack name: '{}' for Heat stack: '{}'", stackName, heatStackId); return check(authenticatedContext, resources); }
Example #6
Source File: OpenStackAttachedDiskResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, List<CloudResource> buildableResource, CloudStack cloudStack) throws Exception { List<CloudResource> resources = new ArrayList<>(); List<CloudResource> syncedResources = Collections.synchronizedList(resources); Collection<Future<Void>> futures = new ArrayList<>(); for (CloudResource cloudResource : buildableResource) { Future<Void> submit = intermediateBuilderExecutor.submit(() -> { CinderVolumeView volumeView = cloudResource.getParameter(VOLUME_VIEW, CinderVolumeView.class); Volume osVolume = Builders.volume().name(cloudResource.getName()) .size(volumeView.getSize()).build(); try { OSClient<?> osClient = createOSClient(auth); osVolume = osClient.blockStorage().volumes().create(osVolume); CloudResource newRes = createPersistedResource(cloudResource, group.getName(), osVolume.getId()); newRes.putParameter(OpenStackConstants.VOLUME_MOUNT_POINT, volumeView.getDevice()); syncedResources.add(newRes); } catch (OS4JException ex) { throw new OpenStackResourceException("Volume creation failed", resourceType(), cloudResource.getName(), ex); } return null; }); futures.add(submit); } for (Future<Void> future : futures) { future.get(); } return resources; }
Example #7
Source File: OpenStackSecurityGroupResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
private Rule createRule(String securityGroupId, IPProtocol protocol, String cidr, int fromPort, int toPort) { return Builders.secGroupRule() .parentGroupId(securityGroupId) .protocol(protocol) .cidr(cidr) .range(fromPort, toPort) .build(); }
Example #8
Source File: OpenStackSecurityGroupResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
private Rule createRule(String securityGroupId, IPProtocol protocol, String cidr) { return Builders.secGroupRule() .parentGroupId(securityGroupId) .protocol(protocol) .cidr(cidr) .build(); }
Example #9
Source File: OpenStackImageImporter.java From cloudbreak with Apache License 2.0 | 5 votes |
public void importImage(OSClient osClient, String name) { String importLocation = openStackImageImportTaskParameters.getImportLocation(name); LOGGER.debug("Import OpenStack image from: {}", importLocation); if (!urlAccessValidationService.isAccessible(importLocation)) { throw new CloudConnectorException(String.format("OpenStack image '%s' is not accessible, therefore it cannot be imported automatically", importLocation)); } Map<String, Object> input = openStackImageImportTaskParameters.buildInput(name); LOGGER.debug("Executing of the following import Task: {}", input); Task task = osClient.imagesV2().tasks().create(Builders.taskBuilder().type("import").input(input).build()); evaluateTaskStatus(task, name); LOGGER.debug("Task of importing {} image, returned with {}", name, task.getStatus()); }
Example #10
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
private Network createNetwork() { return Builders.network().name("name").tenantId("tenantID").networkType(NetworkType.LOCAL).build(); }
Example #11
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
private Project createProject() { return Builders.project().domainId("domain").description("desc").name("project Name").parentId("parent").build(); }
Example #12
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
private Image createImage() { return Builders.image().name("Image Name").diskFormat(DiskFormat.ISO).containerFormat(ContainerFormat.BARE).checksum("checksum").minDisk(10L).minRam(5L) .owner("owner").build(); }
Example #13
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
private Volume createTestVolume() { VolumeBuilder builder = Builders.volume().name("name").description("description").imageRef("ref").size(20).volumeType("type"); return builder.build(); }