From 143120dad9c768d2f00e3af6646fd89ffd7d9d9c Mon Sep 17 00:00:00 2001 From: "Smokowski, Steven" Date: Tue, 25 Feb 2020 14:31:12 -0500 Subject: enhance openstack library Add new methods to NovaClient Issue-ID: SO-2680 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I13fdfcb7052f12ece409a19fbd33abc3f101e2d9 --- .../onap/so/openstack/utils/NovaClientImpl.java | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'adapters') diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java index 7f0f6e4a8b..4dc139f37d 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java @@ -26,14 +26,20 @@ import org.onap.so.openstack.exceptions.MsoException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.woorea.openstack.base.client.Entity; +import com.woorea.openstack.base.client.HttpMethod; import com.woorea.openstack.base.client.OpenStackRequest; import com.woorea.openstack.nova.Nova; import com.woorea.openstack.nova.model.Flavor; import com.woorea.openstack.nova.model.Flavors; import com.woorea.openstack.nova.model.HostAggregate; import com.woorea.openstack.nova.model.HostAggregates; +import com.woorea.openstack.nova.model.Hypervisors; import com.woorea.openstack.nova.model.QuotaSet; import com.woorea.openstack.nova.model.Server; +import com.woorea.openstack.nova.model.VolumeAttachment; @Component @@ -216,4 +222,61 @@ public class NovaClientImpl extends MsoCommonUtils { throw new NovaClientException("Error building Nova Client", e); } } + + public void postActionToServer(String cloudSiteId, String tenantId, String id, String request) + throws NovaClientException { + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode actualObj = mapper.readTree(request); + Entity openstackEntity = new Entity<>(actualObj, "application/json"); + CharSequence actionPath = "/servers/" + id + "/action"; + Nova novaClient = getNovaClient(cloudSiteId, tenantId); + OpenStackRequest OSRequest = + new OpenStackRequest<>(novaClient, HttpMethod.POST, actionPath, openstackEntity, Void.class); + executeAndRecordOpenstackRequest(OSRequest, false); + } catch (Exception e) { + logger.error("Error building Nova Client", e); + throw new NovaClientException("Error building Nova Client", e); + } + } + + public void attachVolume(String cloudSiteId, String tenantId, String serverId, VolumeAttachment volumeAttachment) + throws NovaClientException { + Nova novaClient; + try { + novaClient = getNovaClient(cloudSiteId, tenantId); + OpenStackRequest request = novaClient.servers().attachVolume(serverId, volumeAttachment.getVolumeId(), + volumeAttachment.getDevice()); + executeAndRecordOpenstackRequest(request, false); + } catch (MsoException e) { + logger.error("Error building Nova Client", e); + throw new NovaClientException("Error building Nova Client", e); + } + } + + public void detachVolume(String cloudSiteId, String tenantId, String serverId, String volumeId) + throws NovaClientException { + Nova novaClient; + try { + novaClient = getNovaClient(cloudSiteId, tenantId); + OpenStackRequest request = novaClient.servers().detachVolume(serverId, volumeId); + executeAndRecordOpenstackRequest(request, false); + } catch (MsoException e) { + logger.error("Error building Nova Client", e); + throw new NovaClientException("Error building Nova Client", e); + } + } + + public Hypervisors getHypervisorDetails(String cloudSiteId, String tenantId) throws NovaClientException { + Nova novaClient; + try { + novaClient = getNovaClient(cloudSiteId, tenantId); + OpenStackRequest request = novaClient.hypervisors().listDetail(); + return executeAndRecordOpenstackRequest(request, false); + } catch (MsoException e) { + logger.error("Error building Nova Client", e); + throw new NovaClientException("Error building Nova Client", e); + } + } + } -- cgit 1.2.3-korg