zoukankan      html  css  js  c++  java
  • azure cli and powershell

    Azure CLI

    export RESOURCE_GROUP=learn-123
    export AZURE_REGION=westus2
    export AZURE_APP_PLAN=popupappplan-$RANDOM
    export AZURE_WEB_APP=popupwebapp-$RANDOM
    
    # 前面漏了一个resource group的生成语句
    az group list --output table
    az group list --query "[?name == '$RESOURCE_GROUP']"
    
    # webapp要用到appservice
    az appservice plan create --name $AZURE_APP_PLAN --resource-group $RESOURCE_GROUP --location $AZURE_REGION --sku FREE
    az appservice plan list --output table
    
    # 生成webapp
    az webapp create --name $AZURE_WEB_APP --resource-group $RESOURCE_GROUP --plan $AZURE_APP_PLAN
    az webapp list --output table
    
    # 从github部署webapp
    az webapp deployment source config --name $AZURE_WEB_APP --resource-group $RESOURCE_GROUP --repo-url "https://github.com/Azure-Samples/php-docs-hello-world" --branch master --manual-integration
    

    Azure PowerShell

    默认情况下PowerShell是不包含Azure模块的,所以需要import相关模块。

    Install-Module -Name Az -AllowClobber -SkipPublisherCheck
    Import-Module Az
    Connect-AzAccount / Select-AzSubscription -SubscriptionId '{scriptid}'
    Get-AzResourceGroup / Get-AzResource
    Get-AzResource -ResourceType Microsoft.Compute/virtualMachines
    
    New-AzVm -ResourceGroupName learn-123 -Name "testvm-eus-01" -Credential (Get-Credential) -Location "East US" -Image UbuntuLTS -OpenPorts 22
    
    $vm = (Get-AzVM -Name "testvm-eus-01" -ResourceGroupName learn-8a9c4aca-2d74-4915-8aa3-919f875366ad)
    #可以通过这样的方式显示vm中的值
    $vm.StorageProfile.OsDisk
    $vm | Get-AzPublicIpAddress
    
    
    Stop-AzVM -Name $vm.Name -ResourceGroup $vm.ResourceGroupName
    Remove-AzVM -Name $vm.Name -ResourceGroup $vm.ResourceGroupName
    Get-AzResource -ResourceGroupName $vm.ResourceGroupName | ft
    $vm | Remove-AzNetworkInterface –Force
    
    Get-AzDisk -ResourceGroupName $vm.ResourceGroupName -DiskName $vm.StorageProfile.OSDisk.Name | Remove-AzDisk -Force
    Get-AzVirtualNetwork -ResourceGroup $vm.ResourceGroupName | Remove-AzVirtualNetwork -Force
    Get-AzNetworkSecurityGroup -ResourceGroup $vm.ResourceGroupName | Remove-AzNetworkSecurityGroup -Force
    Get-AzPublicIpAddress -ResourceGroup $vm.ResourceGroupName | Remove-AzPublicIpAddress -Force
    

    使用ps脚本文件(ConferenceDailyReset.ps1)。

    param([string]$resourceGroup)
    
    $adminCredential = Get-Credential -Message "Enter a username and password for the VM administrator."
    For ($i = 1; $i -le 3; $i++)
    {
      $vmName = "ConferenceDemo" + $i
      Write-Host "Creating VM: " $vmName
      New-AzVm -ResourceGroupName $resourceGroup -Name $vmName -Credential $adminCredential -Image UbuntuLTS
    }
    

    运行
    ./ConferenceDailyReset.ps1 {resource group name}

    Azure CLI需要配合OS的Shell脚本运行,而Azure PowerShell配合PowerShell运行。
    相对于Azure CLI,Azure PowerShell适用于已有PowerShell经验的人。

    --------------------------- 知道的更多,不知道的也更多 ---------------------------
  • 相关阅读:
    POJ 3710 Christmas Game#经典图SG博弈
    POJ 2599 A funny game#树形SG(DFS实现)
    POJ 2425 A Chess Game#树形SG
    LeetCode Array Easy 122. Best Time to Buy and Sell Stock II
    LeetCode Array Easy121. Best Time to Buy and Sell Stock
    LeetCode Array Easy 119. Pascal's Triangle II
    LeetCode Array Easy 118. Pascal's Triangle
    LeetCode Array Easy 88. Merge Sorted Array
    ASP.NET MVC 学习笔记之 MVC + EF中的EO DTO ViewModel
    ASP.NET MVC 学习笔记之面向切面编程与过滤器
  • 原文地址:https://www.cnblogs.com/mryux/p/15315200.html
Copyright © 2011-2022 走看看