Commit d7fea37e authored by Ali Fahs's avatar Ali Fahs
Browse files

OpenStack retrieve Linux NC

parent fc7b5d0a
Pipeline #16470 passed with stage
in 1 minute and 6 seconds
......@@ -10,10 +10,8 @@ import org.json.JSONObject;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
......@@ -257,26 +255,47 @@ public class NodeCandidateUtils {
//TODO: (Optimization) An images per region map structure <region,[image1,image2]> could be the best here.
// It can reduce the getNodeCandidates calls to PA.
List<String> entries = new LinkedList<>();
List<String> openstackOsList = Arrays.asList("Ubuntu","Fedora","Centos","Debian");
consolidatedImages.forEach(image -> {
String region = image.optString("location");
String imageReq;
String os = (String) ((JSONObject) image.get("operatingSystem")).get("family");
os = os.substring(0, 1).toUpperCase() + os.substring(1);
String pair =os+":"+region;
switch (paCloud.getCloudProviderName()) {
case "aws-ec2":
imageReq = "Linux";
break;
case "openstack":
imageReq = "linux";
imageReq = os;
break;
default:
throw new IllegalArgumentException("The infrastructure " + paCloud.getCloudProviderName() + " is not handled yet.");
}
JSONArray nodeCandidates = connectorIaasGateway.getNodeCandidates(paCloud.getDummyInfrastructureName(),
region, imageReq);
nodeCandidates.forEach(nc -> {
JSONObject nodeCandidate = (JSONObject) nc;
EntityManagerHelper.persist(createLocation(nodeCandidate, paCloud));
EntityManagerHelper.persist(createNodeCandidate(nodeCandidate, image, paCloud));
});
if (paCloud.getCloudProviderName().equals("openstack")){
if((!entries.contains(pair)) && openstackOsList.contains(os)) {
entries.add(pair);
JSONArray nodeCandidates = connectorIaasGateway.getNodeCandidates(paCloud.getDummyInfrastructureName(),
region, imageReq);
nodeCandidates.forEach(nc -> {
JSONObject nodeCandidate = (JSONObject) nc;
EntityManagerHelper.persist(createLocation(nodeCandidate, paCloud));
EntityManagerHelper.persist(createNodeCandidate(nodeCandidate, image, paCloud));
});
}
}
else {
JSONArray nodeCandidates = connectorIaasGateway.getNodeCandidates(paCloud.getDummyInfrastructureName(),
region, imageReq);
nodeCandidates.forEach(nc -> {
JSONObject nodeCandidate = (JSONObject) nc;
EntityManagerHelper.persist(createLocation(nodeCandidate, paCloud));
EntityManagerHelper.persist(createNodeCandidate(nodeCandidate, image, paCloud));
});
}
});
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment