public static PersistentVMRole GetAdHocTemplate(VirtualMachineProperties properties, ConfigurationSet operatingSystemConfigurationSet) { // build the default endpoints var inputEndpoints = new InputEndpoints(); if (properties.PublicEndpoints == null) { properties.PublicEndpoints = new List <InputEndpoint>(); } // add all of the endpoints foreach (var endpoint in properties.PublicEndpoints) { inputEndpoints.AddEndpoint(endpoint); } if (operatingSystemConfigurationSet.ConfigurationSetType == ConfigurationSetType.WindowsProvisioningConfiguration) { if (properties.PublicEndpoints.All(endpoint => endpoint.Port != 3389)) { inputEndpoints.AddEndpoint(InputEndpoint.GetDefaultRemoteDesktopSettings()); } } // add the endpoints collections to a network configuration set var network = new NetworkConfigurationSet { InputEndpoints = inputEndpoints }; if (properties.EndpointAclRules != null) { network.EndpointAcl = new EndpointAcl(new EndpointAclRules(properties.EndpointAclRules)); } if (properties.VirtualNetwork != null) { network.SubnetName = properties.VirtualNetwork.SubnetName; } OSVirtualHardDisk osDisk = OSVirtualHardDisk.GetOSImageFromTemplate(properties); var disks = new DataVirtualHardDisks(); if (properties.DataDisks != null) { for (int i = 0; i < properties.DataDisks.Count; i++) { var label = properties.DataDisks[i].DiskLabel ?? "DataDisk" + i; var name = properties.DataDisks[i].DiskName ?? "DataDisk" + i; var size = properties.DataDisks[i].LogicalDiskSizeInGB < 30 ? 30 : properties.DataDisks[i].LogicalDiskSizeInGB; var disk = DataVirtualHardDisk.GetDefaultDataDisk(properties.StorageAccountName, size, i, name, label); disks.HardDiskCollection.Add(disk); } } var pvm = new PersistentVMRole { NetworkConfigurationSet = network, OperatingSystemConfigurationSet = operatingSystemConfigurationSet, RoleSize = properties.VmSize, RoleName = properties.RoleName, HardDisks = disks, OSHardDisk = osDisk }; if (properties.AvailabilitySet != null) { pvm.AvailabilityNameSet = properties.AvailabilitySet; } return(pvm); }
public static PersistentVMRole GetAdHocTemplate(VirtualMachineProperties properties, ConfigurationSet operatingSystemConfigurationSet) { // build the default endpoints var inputEndpoints = new InputEndpoints(); if (properties.PublicEndpoints == null) properties.PublicEndpoints = new List<InputEndpoint>(); // add all of the endpoints foreach (var endpoint in properties.PublicEndpoints) { inputEndpoints.AddEndpoint(endpoint); } if (operatingSystemConfigurationSet.ConfigurationSetType == ConfigurationSetType.WindowsProvisioningConfiguration) { if (properties.PublicEndpoints.All(endpoint => endpoint.Port != 3389)) inputEndpoints.AddEndpoint(InputEndpoint.GetDefaultRemoteDesktopSettings()); } // add the endpoints collections to a network configuration set var network = new NetworkConfigurationSet { InputEndpoints = inputEndpoints }; if (properties.EndpointAclRules != null) { network.EndpointAcl = new EndpointAcl(new EndpointAclRules(properties.EndpointAclRules)); } if (properties.VirtualNetwork != null) { network.SubnetName = properties.VirtualNetwork.SubnetName; } OSVirtualHardDisk osDisk = OSVirtualHardDisk.GetOSImageFromTemplate(properties); var disks = new DataVirtualHardDisks(); if (properties.DataDisks != null) { for (int i = 0; i < properties.DataDisks.Count; i++) { var label = properties.DataDisks[i].DiskLabel ?? "DataDisk" + i; var name = properties.DataDisks[i].DiskName ?? "DataDisk" + i; var size = properties.DataDisks[i].LogicalDiskSizeInGB < 30 ? 30 : properties.DataDisks[i].LogicalDiskSizeInGB; var disk = DataVirtualHardDisk.GetDefaultDataDisk(properties.StorageAccountName, size, i, name, label); disks.HardDiskCollection.Add(disk); } } var pvm = new PersistentVMRole { NetworkConfigurationSet = network, OperatingSystemConfigurationSet = operatingSystemConfigurationSet, RoleSize = properties.VmSize, RoleName = properties.RoleName, HardDisks = disks, OSHardDisk = osDisk }; if (properties.AvailabilitySet != null) { pvm.AvailabilityNameSet = properties.AvailabilitySet; } return pvm; }