Is the network configuration set for the vm instance
Inheritance: ConfigurationSet
 private NetworkConfigurationSet GetNetworkConfigurationSet(XElement configurationSet)
 {
     NetworkConfigurationSet networkConfigurationSet = null;
     if (configurationSet.Element(Namespace + "ConfigurationSetType").Value == "NetworkConfiguration")
     {
         networkConfigurationSet = new NetworkConfigurationSet();
         networkConfigurationSet.InputEndpoints= new InputEndpoints();
         var endpoints = configurationSet.Descendants(Namespace + "InputEndpoint");
         foreach (var endpoint in endpoints)
         {
             var inputEndpoint = new InputEndpoint
             {
                 EndpointName = GetStringValue(endpoint.Element(Namespace + "Name")),
                 Port = GetIntValue(endpoint.Element(Namespace + "Port")),
                 LocalPort = GetIntValue(endpoint.Element(Namespace + "LocalPort")),
                 Protocol = GetEnumValue<Protocol>(endpoint.Element(Namespace + "Protocol")),
                 Vip = GetStringValue(endpoint.Element(Namespace + "Vip"))
             };
             networkConfigurationSet.InputEndpoints.AddEndpoint(inputEndpoint);
         }
     }
     return networkConfigurationSet;
 }
 public static PersistentVMRole GetDefaultVMRole(VmSize vmSize, string storageAccount, string password, string computerName, string roleName, InputEndpoints inputEndpoints, string imageName, List<string> subnetNames)
 {
     // add the endpoints collections to a network configuration set
     var network = new NetworkConfigurationSet
     {
         InputEndpoints = inputEndpoints,
         SubnetNames = subnetNames
     };
     // build the windows configuration set
     var windows = new WindowsConfigurationSet
     {
         AdminPassword = password,
         ResetPasswordOnFirstLogon = true,
         ComputerName = computerName
     };
     OSVirtualHardDisk osDisk = OSVirtualHardDisk.GetCustomServerOSImage(storageAccount, imageName);
     DataVirtualHardDisk dataDisk = DataVirtualHardDisk.GetDefaultDataDisk(storageAccount);
     var disks = new DataVirtualHardDisks();
     disks.HardDiskCollection.Add(dataDisk);
     return new PersistentVMRole
     {
         NetworkConfigurationSet = network,
         OperatingSystemConfigurationSet = windows,
         RoleSize = vmSize,
         RoleName = roleName,
         HardDisks = disks,
         OSHardDisk = osDisk
     };
 }
Beispiel #3
0
        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);
        }
 /// <summary>
 /// Used to direct the user to the image for the default Sql Server 2012 image
 /// </summary>
 /// <returns>A persistent VM Role containing the data to execute the image</returns>
 public static PersistentVMRole GetDefaultSqlServer2012VMRole(VmSize vmSize, string storageAccount)
 {
     // build the default endpoints
     var inputEndpoints = new InputEndpoints();
     inputEndpoints.AddEndpoint(InputEndpoint.GetDefaultRemoteDesktopSettings());
     inputEndpoints.AddEndpoint(InputEndpoint.GetDefaultSqlServerSettings());
     // add the endpoints collections to a network configuration set
     var network = new NetworkConfigurationSet
                       {
                           InputEndpoints = inputEndpoints
                       };
     // build the windows configuration set
     var windows = new WindowsConfigurationSet
                       {
                           AdminPassword = "******",
                           ResetPasswordOnFirstLogon = true
                       };
     OSVirtualHardDisk osDisk = OSVirtualHardDisk.GetSqlServerOSImage(storageAccount);
     DataVirtualHardDisk dataDisk = DataVirtualHardDisk.GetDefaultDataDisk(storageAccount);
     var disks = new DataVirtualHardDisks();
     disks.HardDiskCollection.Add(dataDisk);
     return new PersistentVMRole
                {
                    NetworkConfigurationSet = network,
                    OperatingSystemConfigurationSet = windows,
                    RoleSize = vmSize,
                    RoleName = "Elastarole",
                    HardDisks = disks,
                    OSHardDisk = osDisk
                };
 }
        public static PersistentVMRole AddAdhocWindowsRoleTemplate(WindowsVirtualMachineProperties properties)
        {
            // build the default endpoints
            var inputEndpoints = new InputEndpoints();
            if(properties.PublicEndpoints == null)
                properties.PublicEndpoints = new List<InputEndpoint>();

            foreach (var endpoint in properties.PublicEndpoints)
            {
                inputEndpoints.AddEndpoint(endpoint);
            }

            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
            };
            // build the windows configuration set
            var windows = new WindowsConfigurationSet
            {
                AdminPassword = properties.AdministratorPassword ?? "ElastaPassword101",
                ResetPasswordOnFirstLogon = true
            };
            OSVirtualHardDisk osDisk = OSVirtualHardDisk.GetWindowsOSImageFromTemplate(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);
                }
            }
            return new PersistentVMRole
            {
                NetworkConfigurationSet = network,
                OperatingSystemConfigurationSet = windows,
                RoleSize = properties.VmSize,
                RoleName = properties.RoleName,
                HardDisks = disks,
                OSHardDisk = osDisk
            };
        }
        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;
        }
 /// <summary>
 /// Creates a deployment payload for a predefined template 
 /// </summary>
 /// <returns>A string xml representation</returns>
 protected override string CreatePayload()
 {
     var deployment = new NetworkConfigurationSet {InputEndpoints = AllEndpoints};
     var template = new PersistentVMRole {NetworkConfigurationSet = deployment, RoleName = RoleName};
     var document = new XDocument(template.GetXmlTree());
     return document.ToStringFullXmlDeclarationWithReplace();
 }
        public static PersistentVMRole AddAdhocWindowsRoleTemplate(WindowsVirtualMachineProperties properties)
        {
            // build the default endpoints
            var inputEndpoints = new InputEndpoints();
            inputEndpoints.AddEndpoint(InputEndpoint.GetDefaultRemoteDesktopSettings());
            foreach (var endpoint in properties.PublicEndpoints)
            {
                // just in case they've add RDP again
                if (endpoint.Value != 1433)
                {
                    inputEndpoints.AddEndpoint(new InputEndpoint()
                        {
                            EndpointName = endpoint.Key,
                            LocalPort = endpoint.Value,
                            // currently we'll only support TCP
                            Protocol = Protocol.TCP
                        });
                }

            }
            // add the endpoints collections to a network configuration set
            var network = new NetworkConfigurationSet
            {
                InputEndpoints = inputEndpoints
            };
            // build the windows configuration set
            var windows = new WindowsConfigurationSet
            {
                AdminPassword = properties.AdministratorPassword ?? "ElastaPassword101",
                ResetPasswordOnFirstLogon = true
            };
            OSVirtualHardDisk osDisk = OSVirtualHardDisk.GetWindowsOSImageFromTemplate(properties);
            var disks = new DataVirtualHardDisks();
            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);
            }
            return new PersistentVMRole
            {
                NetworkConfigurationSet = network,
                OperatingSystemConfigurationSet = windows,
                RoleSize = properties.VmSize,
                RoleName = properties.RoleName,
                HardDisks = disks,
                OSHardDisk = osDisk
            };
        }