JCLOUDS-1282: Add back support for Azure ARM custom data

This commit is contained in:
Vikas Rangarajan 2017-05-26 16:16:35 -05:00 committed by Ignasi Barrera
parent b0abfa4b9a
commit 7d3b1bebd5
2 changed files with 93 additions and 41 deletions

View File

@ -99,6 +99,7 @@ import com.google.common.base.Function;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -381,7 +382,7 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
OSProfile.Builder builder = OSProfile.builder().adminUsername(adminUsername).adminPassword(adminPassword) OSProfile.Builder builder = OSProfile.builder().adminUsername(adminUsername).adminPassword(adminPassword)
.computerName(computerName); .computerName(computerName);
if (template.getOptions().getPublicKey() != null if (!Strings.isNullOrEmpty(template.getOptions().getPublicKey())
&& OsFamily.WINDOWS != template.getImage().getOperatingSystem().getFamily()) { && OsFamily.WINDOWS != template.getImage().getOperatingSystem().getFamily()) {
OSProfile.LinuxConfiguration linuxConfiguration = OSProfile.LinuxConfiguration.create("true", OSProfile.LinuxConfiguration linuxConfiguration = OSProfile.LinuxConfiguration.create("true",
OSProfile.LinuxConfiguration.SSH.create(of( OSProfile.LinuxConfiguration.SSH.create(of(
@ -391,7 +392,6 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
builder.linuxConfiguration(linuxConfiguration); builder.linuxConfiguration(linuxConfiguration);
} }
AzureTemplateOptions azureTemplateOptions = template.getOptions().as(AzureTemplateOptions.class); AzureTemplateOptions azureTemplateOptions = template.getOptions().as(AzureTemplateOptions.class);
if (azureTemplateOptions.getWindowsConfiguration() != null) { if (azureTemplateOptions.getWindowsConfiguration() != null) {
@ -402,6 +402,10 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<Virtual
builder.secrets(azureTemplateOptions.getSecrets()); builder.secrets(azureTemplateOptions.getSecrets());
} }
if (!Strings.isNullOrEmpty(azureTemplateOptions.getCustomData())) {
builder.customData(azureTemplateOptions.getCustomData());
}
return builder.build(); return builder.build();
} }

View File

@ -42,7 +42,8 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
private List<IpOptions> ipOptions = ImmutableList.of(); private List<IpOptions> ipOptions = ImmutableList.of();
private WindowsConfiguration windowsConfiguration; private WindowsConfiguration windowsConfiguration;
private List<Secrets> secrets = ImmutableList.of(); private List<Secrets> secrets = ImmutableList.of();
private String customData;
/** /**
* Sets the availability set where the nodes will be configured. If it does * Sets the availability set where the nodes will be configured. If it does
* not exist jclouds will create a new one with the given configuration. * not exist jclouds will create a new one with the given configuration.
@ -60,7 +61,7 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
this.availabilitySetName = availabilitySetName; this.availabilitySetName = availabilitySetName;
return this; return this;
} }
/** /**
* The resource group where the new resources will be created. * The resource group where the new resources will be created.
*/ */
@ -79,7 +80,7 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
public AzureTemplateOptions dataDisks(DataDisk... dataDisks) { public AzureTemplateOptions dataDisks(DataDisk... dataDisks) {
return dataDisks(ImmutableList.copyOf(checkNotNull(dataDisks, "dataDisks"))); return dataDisks(ImmutableList.copyOf(checkNotNull(dataDisks, "dataDisks")));
} }
/** /**
* Configure the NICs that will be attached to the created nodes. * Configure the NICs that will be attached to the created nodes.
* <p> * <p>
@ -99,6 +100,7 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
/** /**
* @see {@link AzureTemplateOptions#ipOptions(Iterable) * @see {@link AzureTemplateOptions#ipOptions(Iterable)
*/ */
public AzureTemplateOptions ipOptions(IpOptions... ipOptions) { public AzureTemplateOptions ipOptions(IpOptions... ipOptions) {
return ipOptions(ImmutableList.copyOf(checkNotNull(ipOptions, "ipOptions"))); return ipOptions(ImmutableList.copyOf(checkNotNull(ipOptions, "ipOptions")));
@ -107,32 +109,66 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
/** /**
* Windows configuration parameters * Windows configuration parameters
* *
* @see <a href="https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#bk_windowsconfig5">docs</a> * @see <a
* href="https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#bk_windowsconfig5">docs</a>
*/ */
public AzureTemplateOptions windowsConfiguration(WindowsConfiguration windowsConfiguration) { public AzureTemplateOptions windowsConfiguration(WindowsConfiguration windowsConfiguration) {
this.windowsConfiguration = windowsConfiguration; this.windowsConfiguration = windowsConfiguration;
return this; return this;
} }
/** /**
* Import certificates in the Windows Certificate Store * Import certificates in the Windows Certificate Store
* *
* @see <a href="https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#bk_srcvault">docs</a> * @see <a
* href="https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#bk_srcvault">docs</a>
*/ */
public AzureTemplateOptions secrets(Iterable<? extends Secrets> secrets) { public AzureTemplateOptions secrets(Iterable<? extends Secrets> secrets) {
for (Secrets secret : checkNotNull(secrets, "secrets")) for (Secrets secret : checkNotNull(secrets, "secrets"))
checkNotNull(secret, "secrets can not be empty"); checkNotNull(secret, "secrets can not be empty");
this.secrets = ImmutableList.copyOf(secrets); this.secrets = ImmutableList.copyOf(secrets);
return this; return this;
} }
public AvailabilitySet getAvailabilitySet() { return availabilitySet; } /**
public String getAvailabilitySetName() { return availabilitySetName; } * Custom data (for cloud-init) for the Azure ARM API
public List<DataDisk> getDataDisks() { return dataDisks; } */
public String getResourceGroup() { return resourceGroup; } public AzureTemplateOptions customData(String customData) {
public List<IpOptions> getIpOptions() { return ipOptions; } this.customData = customData;
public WindowsConfiguration getWindowsConfiguration() { return windowsConfiguration; } return this;
public List<Secrets> getSecrets() { return secrets; } }
public AvailabilitySet getAvailabilitySet() {
return availabilitySet;
}
public String getAvailabilitySetName() {
return availabilitySetName;
}
public List<DataDisk> getDataDisks() {
return dataDisks;
}
public String getResourceGroup() {
return resourceGroup;
}
public List<IpOptions> getIpOptions() {
return ipOptions;
}
public WindowsConfiguration getWindowsConfiguration() {
return windowsConfiguration;
}
public List<Secrets> getSecrets() {
return secrets;
}
public String getCustomData() {
return customData;
}
@Override @Override
public AzureTemplateOptions clone() { public AzureTemplateOptions clone() {
@ -153,30 +189,32 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
eTo.ipOptions(ipOptions); eTo.ipOptions(ipOptions);
eTo.windowsConfiguration(windowsConfiguration); eTo.windowsConfiguration(windowsConfiguration);
eTo.secrets(secrets); eTo.secrets(secrets);
eTo.customData(customData);
} }
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o)
if (!(o instanceof AzureTemplateOptions)) return false; return true;
if (!super.equals(o)) return false; if (!(o instanceof AzureTemplateOptions))
return false;
if (!super.equals(o))
return false;
AzureTemplateOptions that = (AzureTemplateOptions) o; AzureTemplateOptions that = (AzureTemplateOptions) o;
return Objects.equal(availabilitySetName, that.availabilitySetName) && return Objects.equal(availabilitySetName, that.availabilitySetName)
Objects.equal(resourceGroup, that.resourceGroup) && && Objects.equal(resourceGroup, that.resourceGroup) && Objects.equal(availabilitySet, that.availabilitySet)
Objects.equal(availabilitySet, that.availabilitySet) && && Objects.equal(dataDisks, that.dataDisks) && Objects.equal(ipOptions, that.ipOptions)
Objects.equal(dataDisks, that.dataDisks) && && Objects.equal(windowsConfiguration, that.windowsConfiguration) && Objects.equal(secrets, that.secrets)
Objects.equal(ipOptions, that.ipOptions) && && Objects.equal(this.customData, that.customData);
Objects.equal(windowsConfiguration, that.windowsConfiguration) &&
Objects.equal(secrets, that.secrets);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hashCode(availabilitySet, availabilitySetName, dataDisks, return Objects.hashCode(super.hashCode(), availabilitySet, availabilitySetName, dataDisks, resourceGroup,
resourceGroup, ipOptions); ipOptions, customData);
} }
@Override @Override
@ -193,14 +231,16 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
if (!ipOptions.isEmpty()) if (!ipOptions.isEmpty())
toString.add("ipOptions", ipOptions); toString.add("ipOptions", ipOptions);
if (windowsConfiguration != null) if (windowsConfiguration != null)
toString.add("windowsConfiguration", windowsConfiguration); toString.add("windowsConfiguration", windowsConfiguration);
if (!secrets.isEmpty()) if (!secrets.isEmpty())
toString.add("secrets", secrets); toString.add("secrets", secrets);
if (customData != null)
toString.add("customData", customData);
return toString; return toString;
} }
public static class Builder { public static class Builder {
/** /**
* @see AzureTemplateOptions#availabilitySet(AvailabilitySet) * @see AzureTemplateOptions#availabilitySet(AvailabilitySet)
*/ */
@ -208,7 +248,7 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
AzureTemplateOptions options = new AzureTemplateOptions(); AzureTemplateOptions options = new AzureTemplateOptions();
return options.availabilitySet(availabilitySet); return options.availabilitySet(availabilitySet);
} }
/** /**
* @see AzureTemplateOptions#availabilitySet(String) * @see AzureTemplateOptions#availabilitySet(String)
*/ */
@ -232,7 +272,7 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
AzureTemplateOptions options = new AzureTemplateOptions(); AzureTemplateOptions options = new AzureTemplateOptions();
return options.dataDisks(dataDisks); return options.dataDisks(dataDisks);
} }
/** /**
* @see AzureTemplateOptions#resourceGroup(String) * @see AzureTemplateOptions#resourceGroup(String)
*/ */
@ -240,7 +280,7 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
AzureTemplateOptions options = new AzureTemplateOptions(); AzureTemplateOptions options = new AzureTemplateOptions();
return options.resourceGroup(resourceGroup); return options.resourceGroup(resourceGroup);
} }
/** /**
* @see AzureTemplateOptions#ipOptions(IpOptions...) * @see AzureTemplateOptions#ipOptions(IpOptions...)
*/ */
@ -272,5 +312,13 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
AzureTemplateOptions options = new AzureTemplateOptions(); AzureTemplateOptions options = new AzureTemplateOptions();
return options.secrets(secrets); return options.secrets(secrets);
} }
/**
* @see AzureTemplateOptions#customData
*/
public static AzureTemplateOptions customData(String customData) {
AzureTemplateOptions options = new AzureTemplateOptions();
return options.customData(customData);
}
} }
} }