コード例 #1
0
        public static async Task <DeploymentExtended> CreateTemplateDeploymentAsync(TokenCredentials credential, string groupName, string vmName, string subscriptionId, string storageName, string VMSize, StreamWriter sr)
        {
            sr.WriteLine("Creating the template deployment...");
            var deployment = new Deployment();


            string tempVhdLocation = "https://armrenderdisks312.blob.core.windows.net/vhds/" + storageName + ".vhd";
            string azureParams     = AzureVMParameters.GetAzureVMTemplateParameters(vmName, groupName, tempVhdLocation, VMSize);
            string azureTemplate   = AzureVMParameters.GetAzureVirtualMachineTemplate();

            //string paramatersVM = "{ \"$schema\": \"http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#\", \"contentVersion\": \"1.0.0.0\", \"parameters\": { \"customVmName\": { \"value\": \"cloneVM2\" }, \"userImageStorageAccountName\": { \"value\": \"armrenderdisks312\" }, \"userImageStorageAccountResourceGroupName\": { \"value\": \"ARMRender\" }, \"adminUsername\": { \"value\": \"MWS\" }, \"adminPassword\": { \"value\": \"Models4Wive$\" }, \"dnsLabelPrefix\": { \"value\": \"idontthinkthismattersvm\" }, \"osType\": { \"value\": \"Windows\" }, \"vmSize\": { \"value\": \"Standard_A2\" }, \"newOrExistingVnet\": { \"value\": \"new\" }, \"newOrExistingVnetName\": { \"value\": \"cloneVM2vnet\" }, \"newOrExistingSubnetName\": { \"value\": \"cloneVM2subnet\" }, \"existingVnetResourceGroupName\": { \"value\": \"TestStrongPW\" } \"tempVHDDiskLocation\": { \"value\": \"TestStrongPW\" } } }";

            deployment.Properties = new DeploymentProperties
            {
                Mode       = DeploymentMode.Incremental,
                Template   = azureTemplate,
                Parameters = azureParams
            };
            var resourceManagementClient = new ResourceManagementClient(credential)
            {
                SubscriptionId = subscriptionId
            };

            return(await resourceManagementClient.Deployments.CreateOrUpdateAsync(groupName, vmName, deployment));
        }
コード例 #2
0
        public static async Task <DeploymentExtended> CreateTemplateDeployment(TokenCredentials credential, string groupName, string vmName, string subscriptionId, string storageName, string VMSize)
        {
            var deployment = new Deployment();

            //string tempVhdLocation = "https://midweststreamsdevdisks.blob.core.windows.net/vhds/" + storageName + ".vhd";
            string tempVhdLocation = "https://armrenderdisks312.blob.core.windows.net/vhds/" + storageName + ".vhd";
            string azureParams     = AzureVMParameters.GetAzureVMTemplateParameters(vmName, groupName, tempVhdLocation, VMSize);
            string azureTemplate   = AzureVMParameters.GetAzureVirtualMachineTemplate();

            //string paramatersVM = "{ \"$schema\": \"http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#\", \"contentVersion\": \"1.0.0.0\", \"parameters\": { \"customVmName\": { \"value\": \"cloneVM2\" }, \"userImageStorageAccountName\": { \"value\": \"armrenderdisks312\" }, \"userImageStorageAccountResourceGroupName\": { \"value\": \"ARMRender\" }, \"adminUsername\": { \"value\": \"MWS\" }, \"adminPassword\": { \"value\": \"Models4Wive$\" }, \"dnsLabelPrefix\": { \"value\": \"idontthinkthismattersvm\" }, \"osType\": { \"value\": \"Windows\" }, \"vmSize\": { \"value\": \"Standard_A2\" }, \"newOrExistingVnet\": { \"value\": \"new\" }, \"newOrExistingVnetName\": { \"value\": \"cloneVM2vnet\" }, \"newOrExistingSubnetName\": { \"value\": \"cloneVM2subnet\" }, \"existingVnetResourceGroupName\": { \"value\": \"TestStrongPW\" } \"tempVHDDiskLocation\": { \"value\": \"TestStrongPW\" } } }";

            deployment.Properties = new DeploymentProperties
            {
                Mode       = DeploymentMode.Incremental,
                Template   = azureTemplate,
                Parameters = azureParams
            };
            var resourceManagementClient = new ResourceManagementClient(credential)
            {
                SubscriptionId = subscriptionId
            };
            var result = await resourceManagementClient.Deployments.CreateOrUpdateAsync(groupName, vmName, deployment);

            string BatchFilePath = ConfigurationManager.AppSettings["logFilePath"];
            var    sr            = new StreamWriter(BatchFilePath + "templateDeployLog.txt");

            sr.WriteLine("Deployed Azure VM");
            sr.WriteLine("Template");
            if (result != null)
            {
                if (result.Properties != null)
                {
                    if (result.Properties.Template != null)
                    {
                        sr.WriteLine(result.Properties.Template.ToString());
                    }
                    else
                    {
                        sr.WriteLine("deploy result properties template is null");
                        sr.WriteLine("Properties:");
                        sr.WriteLine(result.Properties.ToString());
                    }
                }
                else
                {
                    sr.WriteLine("Deploy Result Properties is null");
                }
            }
            else
            {
                sr.WriteLine("Deploy Result is null");
            }
            sr.Close();
            return(result);
        }