Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #972 from galasa-dev/iss1956
Browse files Browse the repository at this point in the history
Iss1956 - Fix Openstack Manager choosing the first external network it finds in the response to `/networks`
  • Loading branch information
jadecarino authored Aug 6, 2024
2 parents abc2a12 + 7a2abe2 commit 3be2723
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,7 @@ public Port retrievePort(@NotNull String deviceId) throws OpenstackManagerExcept
PortsResponse portsResponse = this.gson.fromJson(entity, PortsResponse.class);
if (portsResponse != null && portsResponse.ports != null) {
for (Port port : portsResponse.ports) {
logger.debug("Available port - ID: " + port.id + " Device ID: " + port.device_id);
if (deviceId.equals(port.device_id)) {
logger.debug("Port selected that matches our device ID: " + port.id);
return port;
}
}
Expand Down Expand Up @@ -616,8 +614,6 @@ public Floatingip allocateFloatingip(Port port, Network network) throws Openstac
try {
checkToken();

logger.debug("Attempting to allocate a floating ID with port ID: " + port.id + " and network ID: " + network.id);

Floatingip fip = new Floatingip();
fip.port_id = port.id;
fip.floating_network_id = network.id;
Expand All @@ -636,8 +632,6 @@ public Floatingip allocateFloatingip(Port port, Network network) throws Openstac
StatusLine status = response.getStatusLine();
String entity = EntityUtils.toString(response.getEntity());

logger.debug("Response body: " + entity);

if (status.getStatusCode() != HttpStatus.SC_CREATED) {
throw new OpenstackManagerException("OpenStack create floating ip failed - " + status);
}
Expand All @@ -657,8 +651,6 @@ public Floatingip allocateFloatingip(Port port, Network network) throws Openstac

public Network findExternalNetwork(String externalNetwork) throws OpenstackManagerException {

logger.debug("External network name from the CPS: " + externalNetwork);

try {
checkToken();

Expand All @@ -678,15 +670,8 @@ public Network findExternalNetwork(String externalNetwork) throws OpenstackManag
Networks networks = this.gson.fromJson(entity, Networks.class);
if (networks != null && networks.networks != null) {
for (Network network : networks.networks) {
logger.debug("Available network - ID: " + network.id + " Name: " + network.name + " External? " + network.route_external);
if (externalNetwork != null && externalNetwork.equals(network.name)) {
logger.debug("Selected network: " + network.id);
return network;
} else {
if (network.route_external) {
logger.debug("External network name was not provided in CPS or no match was found. Selected network: " + network.id);
return network;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,10 @@ protected void createServer(ServerRequest serverRequest) throws OpenstackManager

// *** Locate the external network
String networkName = OpenStackNetworkName.get();
if (networkName == null) {
throw new OpenstackManagerException("The external network name to allocate a floatingip on was not provided in the CPS");
}
Network network = this.openstackHttpClient.findExternalNetwork(networkName);

if (network == null) {
throw new OpenstackManagerException("Unable to select an external network to allocate a floatingip on");
}
Expand Down

0 comments on commit 3be2723

Please sign in to comment.