/// <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);
        }
Beispiel #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;
 }
 // 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;
 }
Beispiel #4
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;
 }
Beispiel #5
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;
 }
        /// <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,
            });
        }
 internal VirtualMachineManager(string subscriptionId)
 {
     Properties = new VirtualMachineProperties {
         SubscriptionId = subscriptionId
     };
 }
Beispiel #8
0
        private async void treeARM_AfterSelect(object sender, TreeViewEventArgs e)
        {
            LogProvider.WriteLog("treeARM_AfterSelect", "Start");
            _SourceArmNode = e.Node;

            _PropertyPanel.Clear();
            _PropertyPanel.ResourceText = String.Empty;
            if (e.Node.Tag != null)
            {
                if (e.Node.Tag.GetType() == typeof(TreeNode))
                {
                    TreeNode asmTreeNode = (TreeNode)e.Node.Tag;

                    if (asmTreeNode.Tag != null)
                    {
                        _PropertyPanel.ResourceText = e.Node.Text;

                        if (asmTreeNode.Tag.GetType() == typeof(Azure.Asm.VirtualNetwork) || asmTreeNode.Tag.GetType() == typeof(Azure.Arm.VirtualNetwork))
                        {
                            this._PropertyPanel.ResourceImage = imageList1.Images["VirtualNetwork"];

                            VirtualNetworkProperties properties = new VirtualNetworkProperties();
                            properties.PropertyChanged += Properties_PropertyChanged;
                            properties.Bind(e.Node);
                            _PropertyPanel.PropertyDetailControl = properties;
                        }
                        else if (asmTreeNode.Tag.GetType() == typeof(Azure.Asm.StorageAccount) || asmTreeNode.Tag.GetType() == typeof(Azure.Arm.StorageAccount))
                        {
                            this._PropertyPanel.ResourceImage = imageList1.Images["StorageAccount"];

                            StorageAccountProperties properties = new StorageAccountProperties();
                            properties.PropertyChanged += Properties_PropertyChanged;
                            properties.Bind(this._AzureContextTargetARM, e.Node);
                            _PropertyPanel.PropertyDetailControl = properties;
                        }
                        else if (asmTreeNode.Tag.GetType() == typeof(Azure.Asm.VirtualMachine) || asmTreeNode.Tag.GetType() == typeof(Azure.Arm.VirtualMachine))
                        {
                            this._PropertyPanel.ResourceImage = imageList1.Images["VirtualMachine"];

                            VirtualMachineProperties properties = new VirtualMachineProperties();
                            properties.LogProvider       = LogProvider;
                            properties.AllowManangedDisk = (await _AzureContextSourceASM.AzureRetriever.GetAzureARMManagedDisks() != null);
                            properties.PropertyChanged  += Properties_PropertyChanged;
                            await properties.Bind(e.Node, this);

                            _PropertyPanel.PropertyDetailControl = properties;
                        }
                        else if (asmTreeNode.Tag.GetType() == typeof(Azure.Asm.NetworkSecurityGroup) || asmTreeNode.Tag.GetType() == typeof(Azure.Arm.NetworkSecurityGroup))
                        {
                            this._PropertyPanel.ResourceImage = imageList1.Images["NetworkSecurityGroup"];

                            NetworkSecurityGroupProperties properties = new NetworkSecurityGroupProperties();
                            properties.PropertyChanged += Properties_PropertyChanged;
                            properties.Bind(e.Node, this);
                            _PropertyPanel.PropertyDetailControl = properties;
                        }
                    }
                }
                if (e.Node.Tag.GetType() == typeof(Azure.Asm.Subnet) || e.Node.Tag.GetType() == typeof(Azure.Arm.Subnet))
                {
                    this._PropertyPanel.ResourceImage = imageList1.Images["VirtualNetwork"];

                    SubnetProperties properties = new SubnetProperties();
                    properties.PropertyChanged += Properties_PropertyChanged;
                    properties.Bind(e.Node);
                    _PropertyPanel.PropertyDetailControl = properties;
                }
                else if (e.Node.Tag.GetType() == typeof(Azure.Asm.Disk) || e.Node.Tag.GetType() == typeof(Azure.Arm.Disk))
                {
                    Azure.Asm.Disk asmDisk = (Azure.Asm.Disk)e.Node.Tag;

                    this._PropertyPanel.ResourceImage = imageList1.Images["Disk"];

                    DiskProperties properties = new DiskProperties();
                    properties.LogProvider       = this.LogProvider;
                    properties.AllowManangedDisk = (await _AzureContextSourceASM.AzureRetriever.GetAzureARMManagedDisks() != null);
                    properties.PropertyChanged  += Properties_PropertyChanged;
                    properties.Bind(this, e.Node);
                    _PropertyPanel.PropertyDetailControl = properties;
                }
                else if (e.Node.Tag.GetType() == typeof(Azure.Asm.AvailabilitySet))
                {
                    this._PropertyPanel.ResourceImage = imageList1.Images["AvailabilitySet"];

                    AvailabilitySetProperties properties = new AvailabilitySetProperties();
                    properties.PropertyChanged += Properties_PropertyChanged;
                    properties.Bind(e.Node);
                    _PropertyPanel.PropertyDetailControl = properties;
                }
                else if (e.Node.Tag.GetType() == typeof(ResourceGroup))
                {
                    this._PropertyPanel.ResourceImage = imageList1.Images["ResourceGroup"];

                    ResourceGroupProperties properties = new ResourceGroupProperties();
                    properties.PropertyChanged += Properties_PropertyChanged;
                    await properties.Bind(this, e.Node);

                    _PropertyPanel.PropertyDetailControl = properties;
                }
            }

            _SourceArmNode = null;
            LogProvider.WriteLog("treeARM_AfterSelect", "End");
            StatusProvider.UpdateStatus("Ready");
        }
Beispiel #9
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);
        }
Beispiel #10
0
        private async void treeARM_AfterSelect(object sender, TreeViewEventArgs e)
        {
            ClearAzureResourceManagerProperties();

            lblAzureObjectName.Text = String.Empty;

            if (e.Node.Tag != null)
            {
                if (e.Node.Tag.GetType() == typeof(TreeNode))
                {
                    TreeNode asmTreeNode = (TreeNode)e.Node.Tag;

                    if (asmTreeNode.Tag != null)
                    {
                        lblAzureObjectName.Text = e.Node.Text;

                        if (asmTreeNode.Tag.GetType() == typeof(AsmVirtualNetwork))
                        {
                            pictureBox1.Image = imageList1.Images["VirtualNetwork"];

                            VirtualNetworkProperties properties = new VirtualNetworkProperties();
                            properties.Bind(e.Node);
                            panel1.Controls.Add(properties);
                        }
                        else if (asmTreeNode.Tag.GetType() == typeof(AsmStorageAccount))
                        {
                            pictureBox1.Image = imageList1.Images["StorageAccount"];

                            AsmStorageAccount storageAccount = (AsmStorageAccount)asmTreeNode.Tag;
                            lblAzureObjectName.Text = storageAccount.Name;

                            StorageAccountProperties properties = new StorageAccountProperties();
                            properties.Bind(this._AzureContextTargetARM, e.Node);
                            panel1.Controls.Add(properties);
                        }
                        else if (asmTreeNode.Tag.GetType() == typeof(AsmVirtualMachine))
                        {
                            pictureBox1.Image = imageList1.Images["VirtualMachine"];

                            VirtualMachineProperties properties = new VirtualMachineProperties();
                            properties.Bind(e.Node, this);
                            panel1.Controls.Add(properties);
                        }
                        else if (asmTreeNode.Tag.GetType() == typeof(AsmNetworkSecurityGroup))
                        {
                            pictureBox1.Image = imageList1.Images["NetworkSecurityGroup"];

                            NetworkSecurityGroupProperties properties = new NetworkSecurityGroupProperties();
                            properties.Bind(e.Node, this);
                            panel1.Controls.Add(properties);
                        }
                    }
                }
                if (e.Node.Tag.GetType() == typeof(AsmSubnet))
                {
                    pictureBox1.Image = imageList1.Images["VirtualNetwork"];

                    AsmSubnet asmSubnet = (AsmSubnet)e.Node.Tag;

                    SubnetProperties properties = new SubnetProperties();
                    properties.Bind(e.Node);
                    panel1.Controls.Add(properties);
                }
                else if (e.Node.Tag.GetType() == typeof(AsmDisk))
                {
                    AsmDisk asmDisk = (AsmDisk)e.Node.Tag;

                    pictureBox1.Image = imageList1.Images["Disk"];

                    DiskProperties properties = new DiskProperties();
                    properties.Bind(this, e.Node);
                    panel1.Controls.Add(properties);
                }
                else if (e.Node.Tag.GetType() == typeof(ArmAvailabilitySet))
                {
                    pictureBox1.Image = imageList1.Images["AvailabilitySet"];

                    AvailabilitySetProperties properties = new AvailabilitySetProperties();
                    properties.Bind(e.Node);
                    panel1.Controls.Add(properties);
                }
                else if (e.Node.Tag.GetType() == typeof(ArmResourceGroup))
                {
                    pictureBox1.Image = imageList1.Images["ResourceGroup"];

                    ResourceGroupProperties properties = new ResourceGroupProperties();
                    await properties.Bind(this, e.Node);

                    panel1.Controls.Add(properties);
                }
            }

            _statusProvider.UpdateStatus("Ready");
        }