Issue 695: Added DNS Settings element to create virtual machine request

This commit is contained in:
Jason King 2011-12-21 12:00:58 +00:00
parent 2cb4c4ac76
commit 4e5b1e96cd
2 changed files with 26 additions and 10 deletions

View File

@ -24,9 +24,7 @@ import org.jclouds.rest.Binder;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSetting;
import org.jclouds.tmrk.enterprisecloud.domain.network.WindowsCustomization;
import org.jclouds.tmrk.enterprisecloud.domain.network.*;
import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine;
import javax.inject.Inject;
@ -135,14 +133,17 @@ public class BindCreateVirtualMachineKeyToXmlPayload implements Binder {
in = in.e("LinuxCustomization")
.e("NetworkSettings")
.e("NetworkAdapterSettings");
for(NetworkAdapterSetting setting:linuxCustomization.getNetworkSettings().getNetworkAdapterSettings().getNetworkAdapterSettings()) {
in = networkAdapterSetting(in,setting);
}
//TODO DNS Settings
in = in.up();
in = dnsSettings(in, linuxCustomization.getNetworkSettings().getDnsSettings());
String href = linuxCustomization.getSshKey().getHref().toString();
String type = linuxCustomization.getSshKey().getType();
return in.up().up().e("SshKey").a("href",href).a("type",type).up().up();
return in.up().e("SshKey").a("href",href).a("type",type).up().up();
}
private XMLBuilder networkAdapterSetting(XMLBuilder builder, NetworkAdapterSetting setting) {
@ -155,6 +156,18 @@ public class BindCreateVirtualMachineKeyToXmlPayload implements Binder {
return builder;
}
private XMLBuilder dnsSettings(XMLBuilder in, DnsSettings dnsSettings) {
if(dnsSettings==null)return in;
final String primary = dnsSettings.getPrimaryDns();
final String secondary = dnsSettings.getSecondaryDns();
in = in.e("DnsSettings").e("PrimaryDns").t(primary).up();
if(secondary!=null && !secondary.isEmpty()) {
in = in.e("SecondaryDns").t(secondary).up();
}
return in.up();
}
private XMLBuilder windowsCustomization(XMLBuilder builder, CreateVirtualMachine vmData) {
WindowsCustomization windowsCustomization = vmData.getWindowsCustomization();
if(windowsCustomization==null) return builder;

View File

@ -26,10 +26,7 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.tmrk.enterprisecloud.domain.NamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import org.jclouds.tmrk.enterprisecloud.domain.layout.LayoutRequest;
import org.jclouds.tmrk.enterprisecloud.domain.network.LinuxCustomization;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSetting;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkAdapterSettings;
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkSettings;
import org.jclouds.tmrk.enterprisecloud.domain.network.*;
import org.jclouds.tmrk.enterprisecloud.domain.vm.CreateVirtualMachine;
import org.testng.annotations.Test;
@ -67,6 +64,10 @@ public class BindCreateVirtualMachineKeyToXmlPayloadTest {
"<IpAddress>10.146.204.68</IpAddress>" +
"</NetworkAdapter>" +
"</NetworkAdapterSettings>" +
"<DnsSettings>" +
"<PrimaryDns>1.2.3.4</PrimaryDns>" +
"<SecondaryDns>5.6.7.8</SecondaryDns>" +
"</DnsSettings>" +
"</NetworkSettings>" +
"<SshKey href='/cloudapi/ecloud/admin/sshkeys/77' type='application/vnd.tmrk.cloud.admin.sshKey'/>" +
"</LinuxCustomization>" +
@ -102,7 +103,9 @@ public class BindCreateVirtualMachineKeyToXmlPayloadTest {
NetworkAdapterSettings adapterSettings = NetworkAdapterSettings.builder()
.addNetworkAdapterSetting(adapterSetting).build();
NetworkSettings networkSettings = NetworkSettings.builder().networkAdapterSettings(adapterSettings).build();
NetworkSettings networkSettings = NetworkSettings.builder().networkAdapterSettings(adapterSettings)
.dnsSettings(DnsSettings.builder().primaryDns("1.2.3.4").secondaryDns("5.6.7.8").build())
.build();
LinuxCustomization linuxCustomization = LinuxCustomization.builder()
.sshKey(sshKey)