Skip to content

Commit

Permalink
Correct minor issues with the generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
jachinte committed Oct 21, 2019
1 parent fc2102e commit 41b40fa
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CamTemplates {
}
],
"template_input_params": [
«FOR input : specification.resources.filter[it.specifier.equals("variable")]»
«FOR input : specification.resources.filter[it.specifier.equals("variable")] SEPARATOR ",\n"»
{
"name": "«input.name»",
"type": "«input.attr("type"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,56 @@ public Map<String, String> variableValues() {
public Specification specification() {
// TODO Create issue when VM no longer exists in vmware
// (CAM deployment must be removed too)
// Add resources associated with the provider
// - var allow_unverified_ssl
final Resource unverified = HclFactory.eINSTANCE.createResource();
final Dictionary attrs = HclFactory.eINSTANCE.createDictionary();
unverified.setSpecifier("variable");
unverified.setName("allow_unverified_ssl");
unverified.setValue(attrs);
final NameValuePair description = HclFactory.eINSTANCE.createNameValuePair();
description.setName("description");
final Text desctext = HclFactory.eINSTANCE.createText();
desctext.setValue("Communication with vsphere server with self signed certificate");
description.setValue(desctext);
final NameValuePair value = HclFactory.eINSTANCE.createNameValuePair();
value.setName("default");
final Text valuetext = HclFactory.eINSTANCE.createText();
valuetext.setValue("true");
value.setValue(valuetext);
attrs.getElements().add(description);
attrs.getElements().add(value);
this.spec.getResources().add(unverified);
// - provider vsphere
final Resource vsphere = HclFactory.eINSTANCE.createResource();
final Dictionary vattrs = HclFactory.eINSTANCE.createDictionary();
vsphere.setSpecifier("provider");
vsphere.setName("vsphere");
vsphere.setValue(vattrs);
final NameValuePair ssl = HclFactory.eINSTANCE.createNameValuePair();
ssl.setName("allow_unverified_ssl");
ssl.setValue(this.reference("var", "allow_unverified_ssl"));
final NameValuePair version = HclFactory.eINSTANCE.createNameValuePair();
version.setName("version");
final Text versiontext = HclFactory.eINSTANCE.createText();
versiontext.setValue("~> 1.3");
version.setValue(versiontext);
vattrs.getElements().add(version);
vattrs.getElements().add(ssl);
this.spec.getResources().add(vsphere);
// - provider camc
final Resource camc = HclFactory.eINSTANCE.createResource();
final Dictionary cattrs = HclFactory.eINSTANCE.createDictionary();
camc.setSpecifier("provider");
camc.setName("camc");
camc.setValue(cattrs);
final NameValuePair camversion = HclFactory.eINSTANCE.createNameValuePair();
camversion.setName("version");
final Text versionattr = HclFactory.eINSTANCE.createText();
versionattr.setValue("~> 0.2");
camversion.setValue(versionattr);
cattrs.getElements().add(camversion);
this.spec.getResources().add(camc);
this.data.get("getVcenterVm").forEach(this::handleVm);
return this.spec;
}
Expand All @@ -126,7 +176,7 @@ private void handleVm(final JsonNode node) {
"name",
"string"
);
this.values.put(name.getName(), node.get("vm").asText());
this.values.put(name.getName(), node.get("name").asText());
// - Folder
final Resource folder = this.variable(
attributes,
Expand All @@ -143,23 +193,23 @@ private void handleVm(final JsonNode node) {
attributes,
String.format("%s_number_of_cpus", resource.getName()),
"num_cpus",
"integer"
"string"
);
this.values.put(cpus.getName(), node.get("cpu").get("count").asText());
// - Cores per Socket
final Resource cores = this.variable(
attributes,
String.format("%s_num_cores_per_socket", resource.getName()),
"num_cores_per_socket",
"integer"
"string"
);
this.values.put(cores.getName(), node.get("cpu").get("cores_per_socket").asText());
// - Memory
final Resource memory = this.variable(
attributes,
String.format("%s_memory", resource.getName()),
"memory",
"integer"
"string"
);
this.values.put(memory.getName(), node.get("memory").get("size_MiB").asText());
// - Resource pool
Expand Down Expand Up @@ -269,7 +319,7 @@ private void handleDisk(final String vmname, final String datacenter,
dictionary,
String.format("%s_unit_number", diskn),
"unit_number",
"integer"
"string"
);
this.values.put(unit.getName(), value.get("scsi").get("unit").asText());
// - Label and Datastore
Expand Down Expand Up @@ -324,7 +374,11 @@ private void handleNic(final String vmname, final String datacenter,
"adapter_type",
"string"
);
this.values.put(type.getName(), value.get("type").asText());
this.values.put(
type.getName(),
value.get("type").asText()
.toLowerCase(Locale.getDefault())
);
// Network id: data + variable resources
final String netname = value.get("backing").get("network_name").asText();
final Resource netdata;
Expand Down

0 comments on commit 41b40fa

Please sign in to comment.