Example #1
0
 public void Execute()
 {
     var properties = new WindowsVirtualMachineProperties()
     {
         AdministratorPassword = _applicationFactory.Password,
         RoleName                = _applicationFactory.RoleName,
         Certificate             = _applicationFactory.ManagementCertificate,
         Location                = LocationConstants.NorthEurope,
         UseExistingCloudService = true,
         SubscriptionId          = _applicationFactory.SubscriptionId,
         CloudServiceName        = _applicationFactory.CloudServiceName,
         PublicEndpoints         = new List <InputEndpoint>(new[] { new InputEndpoint()
                                                                    {
                                                                        EndpointName = "web",
                                                                        LocalPort    = 80,
                                                                        Port         = 80,
                                                                        Protocol     = Protocol.TCP
                                                                    } }),
         VirtualMachineType = VirtualMachineTemplates.BizTalkServer2013Enterprise,
         VmSize             = VmSize.Small,
         StorageAccountName = "elastastorage",
         DataDisks          = new List <DataVirtualHardDisk>()
         {
             new DataVirtualHardDisk()
             {
                 LogicalDiskSizeInGB = 100
             }
         }
     };
     var client    = new WindowsVirtualMachineClient(_applicationFactory.SubscriptionId, _applicationFactory.ManagementCertificate);
     var newClient = client.CreateNewVirtualMachineFromTemplateGallery(properties);
 }
Example #2
0
 /// <summary>
 /// Checks whether the necessary properties are populated
 /// </summary>
 private void EnsureVirtualMachineProperties(WindowsVirtualMachineProperties properties)
 {
     if (properties.Certificate == null || String.IsNullOrEmpty(properties.SubscriptionId) || String.IsNullOrEmpty(properties.CloudServiceName) ||
         String.IsNullOrEmpty(properties.StorageAccountName) || String.IsNullOrEmpty(properties.Location))
     {
         throw new FluentManagementException("Either certificate, subscription id cloud service name or storage account name not present in properties", "CreateWindowsVirtualMachineDeploymentCommand");
     }
 }
Example #3
0
 // GET https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/<deployment-name>/roleinstances/<roleinstance-name>/ModelFile?FileType=RDP
 /// <summary>
 /// Used to construct the command to create a virtual machine deployment including the creation of a role
 /// </summary>
 internal DownloadWindowsRemoteDesktopCommand(WindowsVirtualMachineProperties properties)
 {
     AdditionalHeaders["x-ms-version"] = "2012-03-01";
     OperationId = "hostedservices";
     ServiceType = "services";
     HttpCommand = properties.CloudServiceName + "/deployments/" + properties.DeploymentName + "/roleinstances/" + properties.RoleName + "/ModelFile?FileType=RDP";
     Properties  = properties;
     HttpVerb    = HttpVerbGet;
 }
 // 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 GetWindowsVirtualMachineContextCommand(WindowsVirtualMachineProperties properties)
 {
     AdditionalHeaders["x-ms-version"] = "2012-03-01";
     OperationId = "hostedservices";
     ServiceType = "services";
     HttpCommand = properties.CloudServiceName + "/deploymentslots/Production";
     Properties  = properties;
     HttpVerb    = HttpVerbGet;
 }
Example #5
0
 // DELETE https://management.core.windows.net/<subscription-id>/services/disks/<disk-name>
 /// <summary>
 /// {subscriptionID}/services/hostedservices/{serviceName}/deployments/{deploymentName}/Roles/{roleName}/DataDisks/{lun
 /// Used to construct the command to create a virtual machine deployment including the creation of a role
 /// </summary>
 internal DeleteVirtualMachineDataDiskCommand(WindowsVirtualMachineProperties properties, int lun)
 {
     AdditionalHeaders["x-ms-version"] = "2012-03-01";
     OperationId = "hostedservices";
     ServiceType = "services";
     HttpCommand = String.Format("{0}/deployments/{1}/Roles/{2}/DataDisks/{3}",
                                 properties.CloudServiceName, properties.DeploymentName, properties.RoleName, lun);
     HttpVerb = HttpVerbDelete;
 }
Example #6
0
        /// <summary>
        /// Adds the default template for a Windows Virtual Machine
        /// </summary>
        /// <param name="properties"></param>
        /// <returns></returns>
        public static PersistentVMRole AddAdhocWindowsRoleTemplate(WindowsVirtualMachineProperties properties)
        {
            // build the windows configuration set
            var windows = new WindowsConfigurationSet
            {
                AdminPassword             = properties.AdministratorPassword ?? "ElastaPassword101",
                ResetPasswordOnFirstLogon = true
            };

            return(GetAdHocTemplate(properties, windows));
        }
Example #7
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 CreateWindowsVirtualMachineDeploymentCommand(WindowsVirtualMachineProperties properties)
 {
     AdditionalHeaders["x-ms-version"] = "2012-03-01";
     OperationId        = "hostedservices";
     ServiceType        = "services";
     HttpCommand        = properties.CloudServiceName + "/deployments";
     VirtualMachineType = properties.VirtualMachineType;
     CloudServiceName   = properties.CloudServiceName;
     VhdStorageAccount  = properties.StorageAccountName;
     Size       = properties.VmSize;
     Properties = properties;
 }
Example #8
0
        public void Execute()
        {
            var properties = new WindowsVirtualMachineProperties()
            {
                AdministratorPassword = _applicationFactory.Password,
                RoleName         = _applicationFactory.RoleName,
                Certificate      = _applicationFactory.ManagementCertificate,
                SubscriptionId   = _applicationFactory.SubscriptionId,
                CloudServiceName = _applicationFactory.CloudServiceName,
                DeploymentName   = _applicationFactory.DeploymentName
            };
            var client = new WindowsVirtualMachineClient(properties);
            var vm     = client.VirtualMachine;

            client.DeleteVirtualMachine(true, true);

            System.Console.WriteLine("Deleted virtual machine + disks");
        }
Example #9
0
        /// <summary>
        /// Executes the query performing the underlying operation
        /// </summary>
        /// <typeparam name="T">The type used to define the query - CloudService or StorageAccount</typeparam>
        /// <param name="inputs">The Authentication inputs needed to fulfil the operation</param>
        /// <returns>An IQueryable interface</returns>
        public IQueryable <T> Execute <T>(LinqToAzureInputs inputs)
        {
            if (typeof(T) != GetValidType())
            {
                throw new InvalidQueryException("Mismatch between generic types StorageAccount type expected");
            }

            // Get the place name(s) to query the Web service with.
            var    sf = new VirtualMachineFinder(_expression != null ? _expression.Body : null);
            string cloudServiceName = sf.CloudServiceName;

            if (String.IsNullOrEmpty(cloudServiceName))
            {
                throw new InvalidQueryException("You must specify a single cloud service in your query");
            }

            // Call the Web service and get the results.
            if (_roles == null)
            {
                // get the cert in the form of an x509v3
                var certificate = PublishSettingsExtractor.FromStore(inputs.ManagementCertificateThumbprint);
                try
                {
                    var properties = new WindowsVirtualMachineProperties()
                    {
                        CloudServiceName = cloudServiceName
                    };
                    var command = new GetVirtualMachineContextCommand(properties)
                    {
                        SubscriptionId = inputs.SubscriptionId,
                        Certificate    = certificate
                    };
                    command.Execute();
                    _roles = command.PersistentVm;
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Unable to query Windows Azure", ex);
                }
            }
            //return _roles.AsQueryable();
            return((IQueryable <T>)_roles.AsQueryable());
        }
Example #10
0
        /// <summary>
        /// Creates a new virtual machine from a gallery template
        /// </summary>
        /// <param name="properties">Can be any gallery template</param>
        public IVirtualMachineClient CreateNewVirtualMachineFromTemplateGallery(WindowsVirtualMachineProperties properties)
        {
            // for the time being we're going to adopt the default powershell cmdlet behaviour and always create a new cloud services
            EnsureVirtualMachineProperties(properties);
            if (!properties.UseExistingCloudService)
            {
                var cloudServiceCommand = new CreateCloudServiceCommand(properties.CloudServiceName, "Created by Fluent Management", properties.Location)
                {
                    SubscriptionId = properties.SubscriptionId,
                    Certificate    = properties.Certificate
                };
                cloudServiceCommand.Execute();
            }
            // continue to the create the virtual machine in the cloud service
            var command = new CreateWindowsVirtualMachineDeploymentCommand(properties)
            {
                SubscriptionId = properties.SubscriptionId,
                Certificate    = properties.Certificate
            };

            command.Execute();
            // start the role up -- this could take a while the previous two operations are fairly lightweight
            // and the provisioning doesn't occur until the role starts not when it is created
            var startCommand = new StartVirtualMachineCommand(properties)
            {
                SubscriptionId = properties.SubscriptionId,
                Certificate    = properties.Certificate
            };

            startCommand.Execute();
            // important here to force a refresh - just in case someone to conduct an operation on the VM in a single step
            Properties = properties;
            var vm = VirtualMachine;

            // create a new client and return this so that properties can be populated automatically
            return(new WindowsVirtualMachineClient(properties));
        }
Example #11
0
        public void Execute()
        {
            var properties = new WindowsVirtualMachineProperties()
            {
                AdministratorPassword = _applicationFactory.Password,
                RoleName         = _applicationFactory.RoleName,
                Certificate      = _applicationFactory.ManagementCertificate,
                SubscriptionId   = _applicationFactory.SubscriptionId,
                CloudServiceName = _applicationFactory.CloudServiceName,
                DeploymentName   = _applicationFactory.DeploymentName
            };
            var client = new WindowsVirtualMachineClient(properties);
            var vm     = client.VirtualMachine;

            System.Console.WriteLine("Virtual machine client");
            System.Console.WriteLine("======================");
            System.Console.WriteLine("Role name: {0}", vm.RoleName);
            System.Console.WriteLine("Role size: {0}", vm.RoleSize.ToString());

            string rdpFile = Path.Combine(_applicationFactory.PublishSettingsRoot, "vm.rdp");

            client.SaveRemoteDesktopFile(rdpFile);
            System.Console.WriteLine("RDP file saved to: {0}", rdpFile);
        }
Example #12
0
 /// <summary>
 /// Constructs a VirtualMachinenClient
 /// </summary>
 /// <param name="properties">A valid VirtualMachineProperties object</param>
 public WindowsVirtualMachineClient(WindowsVirtualMachineProperties properties)
 {
     Properties = properties;
 }
Example #13
0
 /// <summary>
 /// Gets an ad-hoc deployment for a Windows templated VM instance
 /// </summary>
 /// <param name="properties">The VM properties touse for the deployment</param>
 /// <returns>A valid deployment for the command</returns>
 public static Deployment GetAdHocWindowsTemplateDeployment(WindowsVirtualMachineProperties properties)
 {
     return(AddPersistentVMRole(properties, new [] { PersistentVMRole.AddAdhocWindowsRoleTemplate(properties) }));
 }
 internal VirtualMachineManager(string subscriptionId)
 {
     Properties = new WindowsVirtualMachineProperties {
         SubscriptionId = subscriptionId
     };
 }