Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New MAAS (Metal as a Service) infrastructure. #38

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import org.apache.log4j.Logger;
import org.json.JSONObject;

import com.google.common.collect.Lists;


public class ConnectorIaasController {

Expand Down Expand Up @@ -100,6 +102,25 @@ public String createAzureInfrastructure(String infrastructureId, String clientId
return infrastructureId;
}

public String createMaasInfrastructure(String infrastructureId, String apiToken, String endpoint,
boolean ignoreCertificateCheck, boolean destroyOnShutdown) {

String infrastructureJson = ConnectorIaasJSONTransformer.getMaasInfrastructureJSON(infrastructureId,
infrastructureType,
apiToken,
endpoint,
ignoreCertificateCheck,
destroyOnShutdown);

logger.info("Creating MAAS infrastructure : " + infrastructureJson);

connectorIaasClient.createInfrastructure(infrastructureId, infrastructureJson);

logger.info("MAAS infrastructure created");

return infrastructureId;
}

public Set<String> createInstances(String infrastructureId, String instanceTag, String image, int numberOfInstances,
int cores, int ram) {

Expand Down Expand Up @@ -135,6 +156,20 @@ public Set<String> createAzureInstances(String infrastructureId, String instance
return createInstance(infrastructureId, instanceTag, instanceJson);
}

public Set<String> createMaasInstances(String infrastructureId, String instanceTag, String image,
int numberOfInstances, String systemId, String minCpu, String minMem, List<String> scripts) {

String instanceJson = ConnectorIaasJSONTransformer.getMaasInstanceJSON(instanceTag,
image,
"" + numberOfInstances,
systemId,
minCpu,
minMem,
scripts);

return createInstance(infrastructureId, instanceTag, instanceJson);
}

public Set<String> createInstancesWithOptions(String infrastructureId, String instanceTag, String image,
int numberOfInstances, int cores, int ram, String spotPrice, String securityGroupNames, String subnetId,
String macAddresses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.json.JSONArray;
import org.json.JSONObject;

import com.google.common.collect.Lists;


public class ConnectorIaasJSONTransformer {

Expand Down Expand Up @@ -85,6 +87,18 @@ public static String getAzureInfrastructureJSON(String infrastructureId, String
return infrastructure.toString();
}

public static String getMaasInfrastructureJSON(String infrastructureId, String type, String apiToken,
String endpoint, boolean ignoreCertificateCheck, boolean toBeRemovedOnShutdown) {
JSONObject credentials = new JSONObject().put("password", apiToken).put("allowSelfSignedSSLCertificate",
ignoreCertificateCheck);
JSONObject infrastructure = new JSONObject().put("id", infrastructureId).put("type", type).put("credentials",
credentials);
infrastructure.put("endpoint", endpoint);
infrastructure.put("toBeRemovedOnShutdown", toBeRemovedOnShutdown);

return infrastructure.toString();
}

public static String getInstanceJSON(String tag, String image, String number, String cpu, String ram,
String spotPrice, String securityGroupNames, String subnetId, String macAddresses) {
JSONObject hardware = new JSONObject();
Expand Down Expand Up @@ -165,6 +179,31 @@ public static String getAzureInstanceJSON(String instanceTag, String image, Stri
return instance.toString();
}

public static String getMaasInstanceJSON(String instanceTag, String image, String number, String systemId,
String minCpu, String minMem, List<String> scripts) {
JSONObject hardware = new JSONObject();
if (minMem != null && !minMem.isEmpty()) {
hardware.put("minRam", minMem);
}
if (minCpu != null && !minCpu.isEmpty()) {
hardware.put("minCores", minCpu);
}
JSONObject script = new JSONObject();
script.put("scripts", new JSONArray(scripts));
JSONObject instance = new JSONObject().put("tag", instanceTag).put("image", image).put("number", number);
if (systemId != null && !systemId.isEmpty()) {
instance.put("id", systemId);
}
if (hardware.length() > 0) {
instance.put("hardware", hardware);
}
if (script.length() > 0) {
instance.put("initScript", script);
}

return instance.toString();
}

public static String getInstanceJSONWithPublicKeyAndScripts(String tag, String image, String number,
String publicKeyName, String type, List<String> scripts) {
JSONObject credentials = new JSONObject();
Expand Down
46 changes: 46 additions & 0 deletions infrastructures/infrastructure-maas/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'

shadowJar {

}

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7


dependencies {
compile project(':infrastructures:infrastructure-common')
compile "org.ow2.proactive:rm-server:${rmVersion}"
compile "org.objectweb.proactive:programming-core:${programmingVersion}"

testCompile files("${System.properties['java.home']}/../lib/tools.jar")
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-junit:2.0.0.0'
testCompile 'org.mockito:mockito-core:1.10.19'

}

configurations {
shadowJar

runtime.extendsFrom = [compile]
runtime.exclude module: 'rm-server'
runtime.exclude module: 'programming-core'
runtime.exclude module: 'guava'
runtime.exclude module: 'log4j'

testRuntime.extendsFrom = [testCompile]
}


jar {
manifest {
attributes("Implementation-Title": "ProActive",
"Implementation-Version": version,
"Specification-Version": version,
"Implementation-Vendor": "Activeeon - OASIS - INRIA Sophia Antipolis",
"Implementation-URL": "http://proactive.inria.fr"
)
}
}
Loading