org.openstack4j.api.OSClient Java Examples
The following examples show how to use
org.openstack4j.api.OSClient.
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: OpenStackFloatingIPBuilder.java From cloudbreak with Apache License 2.0 | 7 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 { String publicNetId = context.getStringParameter(OpenStackConstants.PUBLIC_NET_ID); if (publicNetId != null) { OSClient<?> osClient = createOSClient(auth); List<CloudResource> computeResources = context.getComputeResources(privateId); CloudResource instance = getInstance(computeResources); FloatingIP unusedIp = osClient.compute().floatingIps().allocateIP(publicNetId); ActionResponse response = osClient.compute().floatingIps().addFloatingIP(instance.getParameter(OpenStackConstants.SERVER, Server.class), unusedIp.getFloatingIpAddress()); if (!response.isSuccess()) { throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(), auth.getCloudContext().getId(), response.getFault()); } return Collections.singletonList(createPersistedResource(resource, group.getName(), unusedIp.getId())); } return Collections.emptyList(); } catch (OS4JException ex) { throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(), ex); } }
Example #2
Source File: OpenStackPlatformResourcesTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void testVirtualMachinesWhenTypesEmpty() { CloudCredential cloudCredential = new CloudCredential("crn", "name"); OSClient osClient = mock(OSClient.class); String regionName = "region1"; Set<String> regionsFromOpenStack = Sets.newHashSet(regionName); List<AvailabilityZone> availabilityZones = newArrayList(new AvailabilityZone("zone1")); when(openStackClient.createOSClient(cloudCredential)).thenReturn(osClient); when(openStackClient.getRegion(cloudCredential)).thenReturn(regionsFromOpenStack); when(openStackClient.getFlavors(osClient)).thenReturn(emptyList()); when(openStackAvailabilityZoneProvider.getAvailabilityZones(openStackClient, osClient, regionName, cloudCredential)) .thenReturn(availabilityZones); CloudVmTypes actual = underTest.virtualMachines(cloudCredential, null, null); verify(openStackClient, times(1)).getFlavors(osClient); Assert.assertEquals(0L, actual.getCloudVmResponses().get("zone1").size()); Assert.assertNull(actual.getDefaultCloudVmResponses().get(regionName)); }
Example #3
Source File: OpenStackResourceConnector.java From cloudbreak with Apache License 2.0 | 6 votes |
private void createKeyPair(AuthenticatedContext authenticatedContext, CloudStack stack, OSClient<?> client) { KeystoneCredentialView keystoneCredential = openStackClient.createKeystoneCredential(authenticatedContext); String keyPairName = keystoneCredential.getKeyPairName(); if (client.compute().keypairs().get(keyPairName) == null) { try { Keypair keyPair = client.compute().keypairs().create(keyPairName, stack.getInstanceAuthentication().getPublicKey()); LOGGER.debug("Keypair has been created: {}", keyPair); } catch (Exception e) { LOGGER.warn("Failed to create keypair", e); throw new CloudConnectorException(e.getMessage(), e); } } else { LOGGER.debug("Keypair already exists: {}", keyPairName); } }
Example #4
Source File: OpenStackResourceConnector.java From cloudbreak with Apache License 2.0 | 6 votes |
private void terminateHeatStack(AuthenticatedContext authenticatedContext, CloudStack cloudStack, CloudResource resource) { String heatStackId = resource.getName(); String stackName = utils.getStackName(authenticatedContext); LOGGER.debug("Terminate stack: {}", stackName); OSClient<?> client = openStackClient.createOSClient(authenticatedContext); try { retryService.testWith2SecDelayMax5Times(() -> { boolean exists = client.heat().stacks().getStackByName(resource.getName()) != null; if (!exists) { throw new ActionFailedException("Stack not exists"); } return true; }); client.heat().stacks().delete(stackName, heatStackId); LOGGER.debug("Heat stack has been deleted"); if (cloudStack.getInstanceAuthentication().getPublicKeyId() == null) { deleteKeyPair(authenticatedContext, client); } } catch (ActionFailedException ignored) { LOGGER.debug("Stack not found with name: {}", resource.getName()); } }
Example #5
Source File: DefaultOpenstackNodeHandler.java From onos with Apache License 2.0 | 6 votes |
/** * Checks the validity of the given endpoint. * * @param osNode gateway node * @return validity result */ private boolean checkEndpoint(OpenstackNode osNode) { if (osNode == null) { log.warn("Keystone auth info has not been configured. " + "Please specify auth info via network-cfg.json."); return false; } OSClient client = getConnectedClient(osNode); if (client == null) { return false; } else { return client.getSupportedServices().size() != 0; } }
Example #6
Source File: OpenStackAttachedDiskResourceBuilder.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override protected boolean checkStatus(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) { CloudContext cloudContext = auth.getCloudContext(); OSClient<?> osClient = createOSClient(auth); Volume osVolume = osClient.blockStorage().volumes().get(resource.getReference()); if (osVolume != null && context.isBuild()) { Status volumeStatus = osVolume.getStatus(); if (Status.ERROR == volumeStatus || Status.ERROR_DELETING == volumeStatus || Status.ERROR_RESTORING == osVolume.getStatus()) { throw new OpenStackResourceException("Volume in failed state", resource.getType(), resource.getName(), cloudContext.getId(), volumeStatus.name()); } return volumeStatus == Status.AVAILABLE; } else { return osVolume == null && !context.isBuild(); } }
Example #7
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 #8
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 #9
Source File: SwiftStorageService.java From front50 with Apache License 2.0 | 6 votes |
public SwiftStorageService( String containerName, String identityEndpoint, String username, String password, String projectName, String domainName) { OSClient.OSClientV3 os = OSFactory.builderV3() .endpoint(identityEndpoint) .credentials(username, password, Identifier.byName(domainName)) .scopeToProject(Identifier.byName(projectName), Identifier.byName(domainName)) .authenticate(); this.token = os.getToken(); this.swift = os.objectStorage(); this.containerName = containerName; }
Example #10
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 #11
Source File: OpenStackRouterResourceBuilder.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) { try { OSClient<?> osClient = createOSClient(auth); NeutronNetworkView networkView = new NeutronNetworkView(network); if (!networkView.isExistingSubnet()) { String subnetId = context.getStringParameter(OpenStackConstants.SUBNET_ID); osClient.networking().router().detachInterface(resource.getReference(), subnetId, null); } if (!networkView.isExistingNetwork()) { ActionResponse response = osClient.networking().router().delete(resource.getReference()); return checkDeleteResponse(response, resourceType(), auth, resource, "Router deletion failed"); } return null; } catch (OS4JException ex) { throw new OpenStackResourceException("Router deletion failed", resourceType(), resource.getName(), ex); } }
Example #12
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 #13
Source File: OpenStackNetworkResourceBuilder.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override protected boolean checkStatus(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) { CloudContext cloudContext = auth.getCloudContext(); OSClient<?> osClient = createOSClient(auth); org.openstack4j.model.network.Network osNetwork = osClient.networking().network().get(resource.getReference()); if (osNetwork != null && context.isBuild()) { State networkStatus = osNetwork.getStatus(); if (State.ERROR == networkStatus) { throw new OpenStackResourceException("Network in failed state", resource.getType(), resource.getName(), cloudContext.getId(), networkStatus.name()); } return networkStatus == State.ACTIVE; } else { return osNetwork == null && !context.isBuild(); } }
Example #14
Source File: OpenStackPlatformResourcesTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void testVirtualMachines() { CloudCredential cloudCredential = new CloudCredential("crn", "name"); OSClient osClient = mock(OSClient.class); String regionName = "region1"; Set<String> regionsFromOpenStack = Sets.newHashSet(regionName); List<AvailabilityZone> availabilityZones = newArrayList(new AvailabilityZone("zone1")); when(flavor.getRam()).thenReturn(8192); when(openStackClient.createOSClient(cloudCredential)).thenReturn(osClient); when(openStackClient.getRegion(cloudCredential)).thenReturn(regionsFromOpenStack); when(openStackClient.getFlavors(osClient)).thenReturn((List) Collections.singletonList(flavor)); when(openStackAvailabilityZoneProvider.getAvailabilityZones(openStackClient, osClient, regionName, cloudCredential)) .thenReturn(availabilityZones); CloudVmTypes actual = underTest.virtualMachines(cloudCredential, null, null); Assert.assertEquals(1L, actual.getCloudVmResponses().get("zone1").size()); Assert.assertEquals(1L, actual.getDefaultCloudVmResponses().size()); Assert.assertEquals("8.0", actual.getCloudVmResponses().get("zone1").iterator().next().getMetaData().getProperties().get("Memory")); Assert.assertNotNull(actual.getDefaultCloudVmResponses().get(regionName)); }
Example #15
Source File: OpenStackClientTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void testGetZones() { OSClient<?> osClient = mock(OSClient.class); ComputeService computeService = mock(ComputeService.class); ZoneService zoneService = mock(ZoneService.class); when(availabilityZone.getZoneName()).thenReturn("zone1"); when(osClient.compute()).thenReturn(computeService); when(computeService.zones()).thenReturn(zoneService); List availabilityZones = Collections.singletonList(availabilityZone); when(zoneService.list()).thenReturn(availabilityZones); List<AvailabilityZone> actual = underTest.getZones(osClient, "region"); Assert.assertEquals(1L, actual.size()); Assert.assertEquals("zone1", actual.get(0).value()); }
Example #16
Source File: OpenStackImageVerifier.java From cloudbreak with Apache License 2.0 | 6 votes |
private Optional<ImageStatus> handleImageNotFound(OSClient<?> osClient, String name) { LOGGER.error("OpenStack image: {} not found", name); List<? extends BasicResource> allImages; try { allImages = osClient.imagesV2().list(); } catch (ProcessingException e) { LOGGER.debug("Exception occured during listing openstack images on V2 API. Falling back to V1 API.", e); allImages = osClient.images().list(); } if (allImages != null) { for (BasicResource image : allImages) { LOGGER.debug("Available images: {}, entry: {}", image.getName(), image); } } LOGGER.debug("OpenStack image: {} not found", name); return Optional.empty(); }
Example #17
Source File: OpenStackSetup.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public ImageStatusResult checkImageStatus(AuthenticatedContext authenticatedContext, CloudStack stack, com.sequenceiq.cloudbreak.cloud.model.Image image) { String imageName = image.getImageName(); OSClient osClient = openStackClient.createOSClient(authenticatedContext); Optional<Image.ImageStatus> optionalImageStatus = openStackImageVerifier.getStatus(osClient, imageName); ImageStatusResult imageStatusResult = optionalImageStatus.map(imageStatus -> { switch (imageStatus) { case ACTIVE: return new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED); case QUEUED: case SAVING: return new ImageStatusResult(ImageStatus.IN_PROGRESS, ImageStatusResult.HALF); default: return new ImageStatusResult(ImageStatus.CREATE_FAILED, ImageStatusResult.COMPLETED); } }).orElse( new ImageStatusResult(ImageStatus.CREATE_FAILED, ImageStatusResult.COMPLETED) ); LOGGER.debug("OpenStack image result. name: {}, imageStatus: {}, imageStatusResult: {}", imageName, optionalImageStatus.orElse(null), imageStatusResult); return imageStatusResult; }
Example #18
Source File: OpenStackPlatformResources.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public CloudIpPools publicIpPool(CloudCredential cloudCredential, Region region, Map<String, String> filters) { OSClient<?> osClient = openStackClient.createOSClient(cloudCredential); Map<String, Set<CloudIpPool>> cloudIpPools = new HashMap<>(); CloudRegions regions = regions(cloudCredential, region, filters, true); for (Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) { Set<CloudIpPool> cloudGateWays = new HashSet<>(); List<? extends Network> networks = getNetworks(osClient); List<? extends Network> networksWithExternalRouter = networks.stream().filter(Network::isRouterExternal).collect(Collectors.toList()); for (Network network : networksWithExternalRouter) { CloudIpPool cloudIpPool = new CloudIpPool(); cloudIpPool.setId(network.getId()); cloudIpPool.setName(network.getName()); cloudGateWays.add(cloudIpPool); } for (AvailabilityZone availabilityZone : regionListEntry.getValue()) { cloudIpPools.put(availabilityZone.value(), cloudGateWays); } } LOGGER.debug("Openstack public ip pool result: {}", cloudIpPools); return new CloudIpPools(cloudIpPools); }
Example #19
Source File: OpenStackPlatformResources.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override @Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()") public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) { OSClient<?> osClient = openStackClient.createOSClient(cloudCredential); Map<String, Set<VmType>> cloudVmResponses = new HashMap<>(); Map<String, VmType> defaultCloudVmResponses = new HashMap<>(); CloudRegions regions = regions(cloudCredential, region, filters, true); regions.getCloudRegions().forEach((cloudRegion, availabilityZones) -> { Set<VmType> types = collectVmTypes(osClient); convertVmSizeToGB(types); availabilityZones.forEach(availabilityZone -> cloudVmResponses.put(availabilityZone.value(), types)); defaultCloudVmResponses.put(cloudRegion.value(), types.isEmpty() ? null : (VmType) types.toArray()[0]); }); CloudVmTypes cloudVmTypes = new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses); LOGGER.debug("Openstack virtual machine types: {}", cloudVmTypes); return cloudVmTypes; }
Example #20
Source File: OpenStackPlatformResources.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public CloudSecurityGroups securityGroups(CloudCredential cloudCredential, Region region, Map<String, String> filters) { OSClient<?> osClient = openStackClient.createOSClient(cloudCredential); KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential); Set<CloudSecurityGroup> cloudSecurityGroups = new HashSet<>(); List<? extends SecGroupExtension> osSecurityGroups = osClient.compute().securityGroups().list(); LOGGER.debug("Security groups from openstack: {}", osSecurityGroups); for (SecGroupExtension secGroup : osSecurityGroups) { Map<String, Object> properties = new HashMap<>(); properties.put("tenantId", secGroup.getTenantId()); properties.put("rules", secGroup.getRules()); CloudSecurityGroup cloudSecurityGroup = new CloudSecurityGroup(secGroup.getName(), secGroup.getId(), properties); cloudSecurityGroups.add(cloudSecurityGroup); } Map<String, Set<CloudSecurityGroup>> result = new HashMap<>(); result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudSecurityGroups); LOGGER.debug("Openstack security groups result: {}", result); return new CloudSecurityGroups(result); }
Example #21
Source File: OpenStackPlatformResources.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public CloudSshKeys sshKeys(CloudCredential cloudCredential, Region region, Map<String, String> filters) { OSClient<?> osClient = openStackClient.createOSClient(cloudCredential); KeystoneCredentialView osCredential = openStackClient.createKeystoneCredential(cloudCredential); Set<CloudSshKey> cloudSshKeys = new HashSet<>(); for (Keypair keypair : osClient.compute().keypairs().list()) { Map<String, Object> properties = new HashMap<>(); properties.put("fingerprint", keypair.getFingerprint()); properties.put("id", keypair.getId()); properties.put("publicKey", keypair.getPublicKey()); properties.put("createdAt", keypair.getCreatedAt()); CloudSshKey cloudSshKey = new CloudSshKey(); cloudSshKey.setName(keypair.getName()); cloudSshKey.setProperties(properties); cloudSshKeys.add(cloudSshKey); } Map<String, Set<CloudSshKey>> result = new HashMap<>(); result.put(region.value() == null ? osCredential.getTenantName() : region.value(), cloudSshKeys); LOGGER.debug("Openstack cloud ssh keys result: {}", result); return new CloudSshKeys(result); }
Example #22
Source File: OpenStackRouterResourceBuilder.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override protected boolean checkStatus(OpenStackContext context, AuthenticatedContext auth, CloudResource resource) { CloudContext cloudContext = auth.getCloudContext(); OSClient<?> osClient = createOSClient(auth); Router osRouter = osClient.networking().router().get(resource.getReference()); if (osRouter != null && context.isBuild()) { State routerStatus = osRouter.getStatus(); if (State.ERROR == routerStatus) { throw new OpenStackResourceException("Router in failed state", resource.getType(), utils.getStackName(auth), cloudContext.getId(), resource.getName()); } return routerStatus == State.ACTIVE; } else { return osRouter == null && !context.isBuild(); } }
Example #23
Source File: OpenStackNativeMetaDataCollector.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms, List<CloudInstance> knownInstances) { List<InstanceTemplate> templates = Lists.transform(vms, CloudInstance::getTemplate); Map<String, InstanceTemplate> templateMap = Maps.uniqueIndex(templates, from -> utils.getPrivateInstanceId(from.getGroupName(), Long.toString(from.getPrivateId()))); OSClient<?> client = openStackClient.createOSClient(authenticatedContext); List<CloudVmMetaDataStatus> results = new ArrayList<>(); for (CloudResource resource : resources) { if (resource.getType() == ResourceType.OPENSTACK_INSTANCE) { String instanceUUID = resource.getReference(); Server server = client.compute().servers().get(instanceUUID); if (server != null) { Map<String, String> metadata = server.getMetadata(); String privateInstanceId = utils.getPrivateInstanceId(metadata); InstanceTemplate template = templateMap.get(privateInstanceId); if (template != null) { CloudInstanceMetaData md = cloudInstanceMetaDataExtractor.extractMetadata(client, server, instanceUUID); CloudInstance cloudInstance = new CloudInstance(instanceUUID, template, null); CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED); results.add(new CloudVmMetaDataStatus(status, md)); } } } } return results; }
Example #24
Source File: OpenStackResourceConnector.java From cloudbreak with Apache License 2.0 | 5 votes |
private CloudResourceStatus checkByResourceType(AuthenticatedContext authenticatedContext, OSClient<?> client, String stackName, Collection<CloudResource> list, CloudResource resource) { CloudResourceStatus result = null; switch (resource.getType()) { case HEAT_STACK: String heatStackId = resource.getName(); LOGGER.debug("Checking OpenStack Heat stack status of: {}", stackName); Stack heatStack = Optional.ofNullable(client.heat().stacks().getDetails(stackName, heatStackId)) .orElseThrow(() -> new CloudConnectorException("Stack not found on provider by id: " + heatStackId)); result = utils.heatStatus(resource, heatStack); break; case OPENSTACK_NETWORK: result = checkResourceStatus(authenticatedContext, stackName, list, resource, ResourceType.OPENSTACK_NETWORK); break; case OPENSTACK_SUBNET: result = checkResourceStatus(authenticatedContext, stackName, list, resource, ResourceType.OPENSTACK_SUBNET); break; case OPENSTACK_ROUTER: case OPENSTACK_INSTANCE: case OPENSTACK_PORT: case OPENSTACK_ATTACHED_DISK: case OPENSTACK_SECURITY_GROUP: case OPENSTACK_FLOATING_IP: break; default: throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType())); } return result; }
Example #25
Source File: OpenStackPlatformResources.java From cloudbreak with Apache License 2.0 | 5 votes |
private Set<VmType> collectVmTypes(OSClient<?> osClient) { Set<VmType> types = new HashSet<>(); for (Flavor flavor : openStackClient.getFlavors(osClient)) { VmTypeMetaBuilder builder = VmTypeMetaBuilder.builder() .withCpuAndMemory(flavor.getVcpus(), flavor.getRam()); for (VolumeParameterType volumeParameterType : values()) { switch (volumeParameterType) { case MAGNETIC: builder.withMagneticConfig(volumeParameterConfig(MAGNETIC)); break; case SSD: builder.withSsdConfig(null); break; case EPHEMERAL: builder.withEphemeralConfig(null); break; case ST1: builder.withSt1Config(null); break; case AUTO_ATTACHED: builder.withAutoAttachedConfig(null); break; default: break; } } VmType vmType = VmType.vmTypeWithMeta(flavor.getName(), builder.create(), true); types.add(vmType); } LOGGER.debug("Openstack collect vm types result: {}", types); return types; }
Example #26
Source File: OpenStackSubnetResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@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); } }
Example #27
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 #28
Source File: OpenStackNativeInstanceConnector.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) { List<CloudVmInstanceStatus> statuses = new ArrayList<>(); OSClient<?> osClient = openStackClient.createOSClient(ac); for (CloudInstance vm : vms) { Server server = osClient.compute().servers().get(vm.getInstanceId()); if (server == null) { statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED)); } else { statuses.add(new CloudVmInstanceStatus(vm, NovaInstanceStatus.get(server))); } } return statuses; }
Example #29
Source File: OpenStackSecurityGroupResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public CloudResource delete(OpenStackContext context, AuthenticatedContext auth, CloudResource resource, Network network) { try { OSClient<?> osClient = createOSClient(auth); ActionResponse response = osClient.compute().securityGroups().delete(resource.getReference()); return checkDeleteResponse(response, resourceType(), auth, resource, "SecurityGroup deletion failed"); } catch (OS4JException ex) { throw new OpenStackResourceException("SecurityGroup deletion failed", resourceType(), resource.getName(), ex); } }
Example #30
Source File: OpenStackSecurityGroupResourceBuilder.java From cloudbreak with Apache License 2.0 | 5 votes |
@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); } }