aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-03-20 14:28:22 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-03-20 17:37:00 -0400
commit13f102e42fc4f7d874ccd7af5400a7b1e240e4c8 (patch)
tree2dd0718887ad93cb19f58813157f20735750f434 /adapters/mso-adapter-utils/src
parent353782a4d50f3764f71916385dc062401aa7456d (diff)
Adjust audit to use device_id to find nova server
Adjust audit to use device_id to find nova server Change-Id: If060b68ba480b0750e66a7fe26a6fa72382dcdd5 Issue-ID: SO-1677 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java69
1 files changed, 57 insertions, 12 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java
index 22ce6d9781..93460ff119 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java
@@ -23,21 +23,11 @@
package org.onap.so.openstack.utils;
-import com.woorea.openstack.base.client.OpenStackBaseException;
-import com.woorea.openstack.base.client.OpenStackConnectException;
-import com.woorea.openstack.base.client.OpenStackRequest;
-import com.woorea.openstack.base.client.OpenStackResponseException;
-import com.woorea.openstack.keystone.Keystone;
-import com.woorea.openstack.keystone.model.Access;
-import com.woorea.openstack.keystone.model.Authentication;
-import com.woorea.openstack.keystone.utils.KeystoneUtils;
-import com.woorea.openstack.quantum.Quantum;
-import com.woorea.openstack.quantum.model.Network;
-import com.woorea.openstack.quantum.model.Networks;
-import com.woorea.openstack.quantum.model.Segment;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
+import java.util.Optional;
+
import org.onap.so.cloud.CloudConfig;
import org.onap.so.cloud.authentication.AuthenticationMethodFactory;
import org.onap.so.cloud.authentication.KeystoneAuthHolder;
@@ -62,6 +52,20 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import com.woorea.openstack.base.client.OpenStackBaseException;
+import com.woorea.openstack.base.client.OpenStackConnectException;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.base.client.OpenStackResponseException;
+import com.woorea.openstack.keystone.Keystone;
+import com.woorea.openstack.keystone.model.Access;
+import com.woorea.openstack.keystone.model.Authentication;
+import com.woorea.openstack.keystone.utils.KeystoneUtils;
+import com.woorea.openstack.quantum.Quantum;
+import com.woorea.openstack.quantum.model.Network;
+import com.woorea.openstack.quantum.model.Networks;
+import com.woorea.openstack.quantum.model.Port;
+import com.woorea.openstack.quantum.model.Segment;
+
@Component
public class MsoNeutronUtils extends MsoCommonUtils
{
@@ -211,6 +215,24 @@ public class MsoNeutronUtils extends MsoCommonUtils
throw me;
}
}
+
+ public Optional<Port> getNeutronPort(String neutronPortId, String tenantId, String cloudSiteId)
+ {
+ try {
+ CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow(
+ () -> new MsoCloudSiteNotFound(cloudSiteId));
+ Quantum neutronClient = getNeutronClient (cloudSite, tenantId);
+ Port port = findPortById (neutronClient, neutronPortId);
+ if (port == null) {
+ return Optional.empty();
+ }
+ return Optional.of(port);
+ }
+ catch (RuntimeException | MsoException e) {
+ logger.error("Error retrieving neutron port", e);
+ return Optional.empty();
+ }
+ }
/**
* Delete the specified Network (by ID) in the given cloud.
@@ -488,6 +510,29 @@ public class MsoNeutronUtils extends MsoCommonUtils
}
}
}
+
+
+ private Port findPortById (Quantum neutronClient, String neutronPortId)
+ {
+ if (neutronPortId == null) {
+ return null;
+ }
+
+ try {
+ OpenStackRequest<Port> request = neutronClient.ports().show(neutronPortId);
+ Port port = executeAndRecordOpenstackRequest(request);
+ return port;
+ }
+ catch (OpenStackResponseException e) {
+ if (e.getStatus() == 404) {
+ return null;
+ } else {
+ logger.error("{} {} Openstack Error, GET Neutron Port By ID ({}): ", MessageEnum.RA_CONNECTION_EXCEPTION,
+ ErrorCode.DataError.getValue(), neutronPortId, e);
+ throw e;
+ }
+ }
+ }
/*
* Find a network (or query its existence) by its Name. This method avoids an