public class BindDeploymentParamsToXmlPayload implements Binder {
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
DeploymentParams params = DeploymentParams.class.cast(input);
try {
XMLBuilder builder = XMLBuilder.create("Deployment").a("xmlns", "http://schemas.microsoft.com/windowsazure")
.e("Name").t(params.getName()).up()
.e("DeploymentSlot").t("Production").up()
.e("Label").t(params.getName()).up()
.e("RoleList")
.e("Role")
.e("RoleName").t(params.getName()).up()
.e("RoleType").t("PersistentVMRole").up()
.e("ConfigurationSets");
if (params.getOsType() == OSType.WINDOWS){
XMLBuilder configBuilder = builder.e("ConfigurationSet"); // Windows
configBuilder.e("ConfigurationSetType").t("WindowsProvisioningConfiguration").up()
.e("ComputerName").t(params.getUsername()).up()
.e("AdminPassword").t(params.getPassword()).up()
.e("ResetPasswordOnFirstLogon").t("false").up()
.e("EnableAutomaticUpdate").t("false").up()
.e("DomainJoin")
.e("Credentials")
.e("Domain").t(params.getName()).up()
.e("Username").t(params.getUsername()).up()
.e("Password").t(params.getPassword()).up()
.up()//Credentials
.e("JoinDomain").t(params.getName()).up()
.up()// Domain Join
.e("StoredCertificateSettings").up()
.up();//Windows ConfigurationSet
}else if (params.getOsType() == OSType.LINUX){
XMLBuilder configBuilder = builder.e("ConfigurationSet"); // Linux
configBuilder.e("ConfigurationSetType").t("LinuxProvisioningConfiguration").up()
.e("HostName").t(params.getName()).up()
.e("UserName").t(params.getUsername()).up()
.e("UserPassword").t(params.getPassword()).up()
.e("DisableSshPasswordAuthentication").t("false").up()
.e("SSH").up()
.up();//Linux ConfigurationSet
}
XMLBuilder configBuilder = builder.e("ConfigurationSet"); // Network
configBuilder.e("ConfigurationSetType").t("NetworkConfiguration").up();
XMLBuilder inputEndpoints = configBuilder.e("InputEndpoints");
for (InputEndpoint endpoint : params.getEndpoints()){
XMLBuilder inputBuilder = inputEndpoints.e("InputEndpoint");
inputBuilder.e("LocalPort").t(endpoint.getLocalPort().toString()).up()
.e("Name").t(endpoint.getName()).up()
.e("Port").t(endpoint.getExternalPort().toString()).up()
.e("Protocol").t(endpoint.getProtocol().name()).up()
.up();//InputEndpoint
}
inputEndpoints.up();
configBuilder.e("SubnetNames").up()
.up();
builder.up()//ConfigurationSets
.e("DataVirtualHardDisks").up()
.e("OSVirtualHardDisk")
.e("HostCaching").t("ReadWrite").up()
.e("MediaLink").t("http://"+params.getStorageAccount()+".blob.core.windows.net/disks/"+params.getName()+"/"+params.getSourceImageName()).up()
.e("SourceImageName").t(params.getSourceImageName()).up()
.e("OS").t("Linux").up()
.up()//OSVirtualHardDisk
.e("RoleSize").t(params.getSize().value()).up()
.up()//Role
.up();//RoleList
// builder.e("ConfigurationSet") // Network