コード例 #1
0
        /// <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 GetOSImageFromTemplate(VirtualMachineProperties 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;

            string vmType = properties.VirtualMachineType.ToString();
            if (String.IsNullOrEmpty(properties.CustomTemplateName))
            {
                AddVmTemplatesToDictionary();
                if (VmTemplates.ContainsKey(vmType))
                {
                    templateDetails = VmTemplates[vmType];
                }
            }

            if(templateDetails == null && properties.CustomTemplateName == null)
                throw new FluentManagementException("no template specified cannot proceed", "GetOSImageFromTemplate");

            if (properties.CustomTemplateName != null)
                templateDetails = properties.CustomTemplateName;

            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("ddMMyyhhmmss-ffffff")),

                SourceImageName = templateDetails,
                HostCaching = HostCaching.ReadWrite,
            };
        }
コード例 #2
0
 // https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/
 /// <summary>
 /// Used to construct the command to create a virtual machine deployment including the creation of a role
 /// </summary>
 internal StopVirtualMachineCommand(VirtualMachineProperties properties)
 {
     AdditionalHeaders["x-ms-version"] = "2013-06-01";
     OperationId = "hostedservices";
     ServiceType = "services";
     HttpCommand = string.Format("{0}/deployments/{1}/roleinstances/{2}/Operations", properties.CloudServiceName, properties.DeploymentName, properties.RoleName);
     Properties = properties;
 }
コード例 #3
0
 // GET https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deploymentslots/Production
 /// <summary>
 /// Used to construct the command to create a virtual machine deployment including the creation of a role
 /// </summary>
 internal GetVirtualMachineContextCommand(VirtualMachineProperties properties)
 {
     AdditionalHeaders["x-ms-version"] = "2012-03-01";
     OperationId = "hostedservices";
     ServiceType = "services";
     HttpCommand = properties.CloudServiceName + "/deploymentslots/Production";
     Properties = properties;
     HttpVerb = HttpVerbGet;
 }
コード例 #4
0
 // https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/
 /// <summary>
 /// Used to construct the command to create a virtual machine deployment including the creation of a role
 /// </summary>
 internal RestartVirtualMachineCommand(VirtualMachineProperties properties)
 {
     AdditionalHeaders["x-ms-version"] = "2012-03-01";
     OperationId = "hostedservices";
     ServiceType = "services";
     //https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/<deployment-name>/roles/<role-name>/Operations
     HttpCommand = string.Format("{0}/deployments/{1}/roleinstances/{2}/Operations", properties.CloudServiceName, properties.DeploymentName, properties.RoleName);
     Properties = properties;
 }
コード例 #5
0
 // DELETE https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/<deployment-name>/roles/<role-name>
 /// <summary>
 /// Used to construct the command to create a virtual machine deployment including the creation of a role
 /// </summary>
 internal DeleteVirtualMachineCommand(VirtualMachineProperties properties)
 {
     AdditionalHeaders["x-ms-version"] = "2012-03-01";
     OperationId = "hostedservices";
     ServiceType = "services";
     HttpCommand = String.Format("{0}/deployments/{1}/roles/{2}", properties.CloudServiceName, properties.DeploymentName, properties.RoleName);
     HttpVerb = HttpVerbDelete;
     Properties = properties;
 }
コード例 #6
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;
        }
コード例 #7
0
 internal VirtualMachineManager(string subscriptionId)
 {
     Properties = new VirtualMachineProperties {SubscriptionId = subscriptionId};
 }
コード例 #8
0
        /// <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;
        }