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,6 +42,7 @@ 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
@ -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,7 +109,8 @@ 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;
@ -117,7 +120,8 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
/** /**
* 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"))
@ -126,13 +130,45 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
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
@ -196,6 +234,8 @@ public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
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;
} }
@ -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);
}
} }
} }