public static OSVirtualHardDisk GetCustomServerOSImage(string storageAccountName, string imageName, string diskName = null, string diskLabel = null) { var namer = new RandomAccountName(); return new OSVirtualHardDisk { DiskLabel = diskLabel, DiskName = diskName, MediaLink = String.Format("http://{0}.blob.core.windows.net/vhds/{1}{2}.vhd", storageAccountName, namer.GetNameFromInitString("os"), DateTime.Now.ToString("ddmmyy")), SourceImageName = imageName, HostCaching = HostCaching.ReadWrite, }; }
/// <summary> /// Gets a virtual disk located in blob storage and sets a default size to the disk of 30 GB and a logical unit no. of 0 (drive e:) /// </summary> /// <param name="storageAccountName">The path to blob storage for the disk</param> /// <param name="size">the size of the disk in GB - can be up to 1TB</param> /// <param name="logicalUnitNumber">number between 0 and 15 which is the logical unit of the drive</param> /// <param name="diskName">the name of the disk</param> /// <param name="diskLabel">the label of the disk</param> /// <returns></returns> public static DataVirtualHardDisk GetDefaultDataDisk(string storageAccountName, int size = 30, int logicalUnitNumber = 0, string diskName = null, string diskLabel = null) { var namer = new RandomAccountName(); return new DataVirtualHardDisk { LogicalDiskSizeInGB = size, LogicalUnitNumber = logicalUnitNumber, HostCaching = HostCaching.ReadWrite, DiskLabel = diskLabel, DiskName = diskName, MediaLink = String.Format("http://{0}.blob.core.windows.net/vhds/{1}-{2}.vhd", storageAccountName, namer.GetNameFromInitString("data"), DateTime.Now.ToString("ddmmyy")), }; }
/// <summary> /// This gets the host OS image of Windows Server Data Centre and SQL Server 2012 /// </summary> /// <param name="storageAccountName">The path to the media space in blob storage where the host vhd will be placed</param> /// <param name="diskName">The name of the C: drive </param> /// <param name="diskLabel">The drive volume label for C:</param> /// <returns>An OSVirtualHardDisk instance</returns> public static OSVirtualHardDisk GetSqlServerOSImage(string storageAccountName, string diskName = null, string diskLabel = null) { /*<OSVirtualHardDisk> <MediaLink>http://elastacacheweb.blob.core.windows.net/vhds/elastasql.vhd</MediaLink> <SourceImageName>MSFT__Sql-Server-11EVAL-11.0.2215.0-05152012-en-us-30GB.vhd</SourceImageName> </OSVirtualHardDisk>*/ var namer = new RandomAccountName(); return new OSVirtualHardDisk { DiskLabel = diskLabel, DiskName = diskName, MediaLink = String.Format("http://{0}.blob.core.windows.net/vhds/{1}{2}.vhd", storageAccountName, namer.GetNameFromInitString("os"), DateTime.Now.ToString("ddmmyy")), SourceImageName = "MSFT__Sql-Server-11EVAL-11.0.2215.0-05152012-en-us-30GB.vhd", HostCaching = HostCaching.ReadWrite, }; }
/// <summary> /// Gets the Xml tree for the custom serialiser /// </summary> /// <returns>An XElement </returns> public XElement GetXmlTree() { var namer = new RandomAccountName(); // if the timezone is set to null then set it GMT TimeZone = TimeZone ?? "GMT Standard Time"; var element = new XElement(Namespaces.NsWindowsAzure + "ConfigurationSet", new XElement(Namespaces.NsWindowsAzure + "ConfigurationSetType", ConfigurationSetType.ToString()), new XElement(Namespaces.NsWindowsAzure + "ComputerName", namer.GetPureRandomValue().ToUpper()), new XElement(Namespaces.NsWindowsAzure + "AdminPassword", AdminPassword), new XElement(Namespaces.NsWindowsAzure + "ResetPasswordOnFirstLogon", ResetPasswordOnFirstLogon.ToString(CultureInfo.InvariantCulture).ToLower()), new XElement(Namespaces.NsWindowsAzure + "EnableAutomaticUpdates", EnableAutomaticUpdate.ToString(CultureInfo.InvariantCulture).ToLower()), new XElement(Namespaces.NsWindowsAzure + "TimeZone", TimeZone)); //if (ComputerName != null) // element.Add(new XElement(Namespaces.NsWindowsAzure + "ComputerName", // ComputerName.ToString(CultureInfo.InvariantCulture))); return element; }
/// <summary> /// Gets the Xml tree for the custom serialiser /// </summary> /// <returns>An XElement </returns> public XElement GetXmlTree() { var namer = new RandomAccountName(); var element = new XElement(Namespaces.NsWindowsAzure + "Role", new XElement(Namespaces.NsWindowsAzure + "RoleName", RoleName), new XElement(Namespaces.NsWindowsAzure + "RoleType", RoleType)); var configurationSets = new XElement(Namespaces.NsWindowsAzure + "ConfigurationSets", OperatingSystemConfigurationSet.GetXmlTree(), NetworkConfigurationSet.GetXmlTree()); element.Add(configurationSets); element.Add(HardDisks.GetXmlTree()); element.Add(new XElement(Namespaces.NsWindowsAzure + "Label", Convert.ToBase64String(Encoding.UTF8.GetBytes(RoleName)))); element.Add(OSHardDisk.GetXmlTree()); element.Add(new XElement(Namespaces.NsWindowsAzure + "RoleSize", RoleSize.ToString())); if (AvailabilityNameSet != null) element.Add(AvailabilityNameSet); return element; }
/// <summary> /// Gets the Xml tree for the custom serialiser /// </summary> /// <returns>An XElement </returns> public XElement GetXmlTree() { var namer = new RandomAccountName(); XElement element = null; if (RoleName != null) { element = new XElement(Namespaces.NsWindowsAzure + "Role", new XElement(Namespaces.NsWindowsAzure + "RoleName", RoleName), new XElement(Namespaces.NsWindowsAzure + "RoleType", RoleType)); } else { element = new XElement(Namespaces.NsWindowsAzure + "PersistentVMRole"); } XElement configurationSets = new XElement(Namespaces.NsWindowsAzure + "ConfigurationSets", NetworkConfigurationSet.GetXmlTree()); if (OperatingSystemConfigurationSet != null) configurationSets.Add(OperatingSystemConfigurationSet.GetXmlTree()); element.Add(configurationSets); if (HardDisks != null) element.Add(HardDisks.GetXmlTree()); if (RoleName != null) element.Add(new XElement(Namespaces.NsWindowsAzure + "Label", Convert.ToBase64String(Encoding.UTF8.GetBytes(RoleName)))); if (OSHardDisk != null) element.Add(OSHardDisk.GetXmlTree()); // TODO: Another hack the enum value is always present here so assume if we have no OS hard disk then we don't need a role size if (OSHardDisk != null) element.Add(new XElement(Namespaces.NsWindowsAzure + "RoleSize", RoleSize.ToString())); if (AvailabilityNameSet != null) element.Add(new XElement(Namespaces.NsWindowsAzure + "AvailabilitySetName", AvailabilityNameSet)); return element; }
/// <summary> /// Adds the default template for a Windows Virtual Machine /// </summary> /// <param name="properties"></param> /// <returns></returns> public static PersistentVMRole AddAdhocWindowsRoleTemplate(WindowsVirtualMachineProperties properties) { var namer = new RandomAccountName(); // build the windows configuration set var windows = new WindowsConfigurationSet { AdminUsername = properties.AdministratorUsername ?? "admin", AdminPassword = properties.AdministratorPassword ?? "ElastaPassword101", ComputerName = properties.ComputerName ?? namer.GetPureRandomValue().ToUpper(), ResetPasswordOnFirstLogon = true }; return GetAdHocTemplate(properties, windows); }
/// <summary> /// Used to create a deployment and add any persistent vm role to the deployment /// </summary> /// <param name="role">The PersistentVMRole</param> /// <param name="cloudServiceName">The Name of the cloud service which the role is present in</param> /// <returns>The Deployment that is being used</returns> private static Deployment AddPersistentVMRole(string cloudServiceName, PersistentVMRole role) { var namer = new RandomAccountName(); var deployment = new Deployment { Name = cloudServiceName, // Label = Convert.ToBase64String(Encoding.UTF8.GetBytes(cloudServiceName)) Label = cloudServiceName }; role.RoleName = namer.GetPureRandomValue(); var roleList = new RoleList(); roleList.Roles.Add(role); deployment.RoleList = roleList; return deployment; }
/// <summary> /// This gets the host OS image of Windows Server Data Centre and SQL Server 2012 /// </summary> /// <param name="properties">The path to the media space in blob storage where the host vhd will be placed</param> /// <returns>An OSVirtualHardDisk instance</returns> public static OSVirtualHardDisk GetWindowsOSImageFromTemplate(WindowsVirtualMachineProperties properties) { /*<OSVirtualHardDisk> <MediaLink>http://elastacacheweb.blob.core.windows.net/vhds/elastasql.vhd</MediaLink> <SourceImageName>MSFT__Sql-Server-11EVAL-11.0.2215.0-05152012-en-us-30GB.vhd</SourceImageName> </OSVirtualHardDisk>*/ string templateDetails = null; switch (properties.VirtualMachineType) { case VirtualMachineTemplates.BiztalkServer2012: templateDetails = VmConstants.VmTemplateBiztalk; break; case VirtualMachineTemplates.SqlServer2012: templateDetails = VmConstants.VmTemplateSqlServer2012Eval; break; case VirtualMachineTemplates.WindowsServer2008R2SP1: templateDetails = VmConstants.VmTemplateWin2K8SP1DataCentreServerDecember2012; break; case VirtualMachineTemplates.WindowsServer2012: templateDetails = VmConstants.VmTemplateWin2012DataCentreServerDecember2012; break; } if(templateDetails == null && properties.CustomTemplateName == null) throw new FluentManagementException("no template specified cannot proceed", "CreateWindowsVirtualMachineDeploymentCommand"); var namer = new RandomAccountName(); return new OSVirtualHardDisk { DiskLabel = "OsDisk", DiskName = "OsDisk", MediaLink = String.Format("http://{0}.blob.core.windows.net/vhds/{1}{2}.vhd", properties.StorageAccountName, namer.GetNameFromInitString("os"), DateTime.Now.ToString("ddmmyy")), SourceImageName = templateDetails, HostCaching = HostCaching.ReadWrite, }; }
/// <summary> /// Used to create a deployment and add any persistent vm role to the deployment /// </summary> /// <param name="properties"></param> /// <param name="roles">The PersistentVMRole</param> /// <returns>The Deployment that is being used</returns> private static Deployment AddPersistentVMRole(VirtualMachineProperties properties, IEnumerable<PersistentVMRole> roles) { var namer = new RandomAccountName(); var deployment = new Deployment { // use the first deployment property if it's not the same then fluent doesn't supporting deployment splitting at this level! Name = properties.DeploymentName, // Label = Convert.ToBase64String(Encoding.UTF8.GetBytes(cloudServiceName)) Label = properties.DeploymentName }; if (properties.VirtualNetwork != null) deployment.VirtualNetworkName = properties.VirtualNetwork.VirtualNetworkName; var roleList = new RoleList(); foreach (var role in roles) { role.RoleName = role.RoleName ?? namer.GetPureRandomValue(); roleList.Roles.Add(role); } deployment.RoleList = roleList; return deployment; }
/// <summary> /// Used to create a deployment and add any persistent vm role to the deployment /// </summary> /// <param name="properties"></param> /// <param name="role">The PersistentVMRole</param> /// <returns>The Deployment that is being used</returns> private static Deployment AddPersistentVMRole(WindowsVirtualMachineProperties properties, PersistentVMRole role) { var namer = new RandomAccountName(); var deployment = new Deployment { Name = properties.DeploymentName, // Label = Convert.ToBase64String(Encoding.UTF8.GetBytes(cloudServiceName)) Label = properties.DeploymentName }; role.RoleName = role.RoleName ?? namer.GetPureRandomValue(); var roleList = new RoleList(); roleList.Roles.Add(role); deployment.RoleList = roleList; return deployment; }