Code Monkey home page Code Monkey logo

azure-cli-samples's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-cli-samples's Issues

This repo should also allow addition of python script samples

Some scripts contains logic which is hard to write in sh or bat and most probably users will also be using .py for writing such scripts.

Can we add .py scripts into this repo?

Side Query:
Once a sample .sh is added then where it can be discovered?

how to extract specific key from a service and add it to Azure Key Vault

Using this script, I can list all the account keys for a Cosmos DB database:

az cosmosdb list-keys
--name $accountName
--resource-group $resourceGroupName

  1. How is a specific key (like the primary account key) extracted/selected from the resulting list?
  2. What Azure CLI script will insert the selected key as a new secret in an Azure Key Vault?

Incorrect steps provided for "Azure CLI: Bind a custom TLS/SSL certificate to a web app"

Page "https://github.com/Azure-Samples/azure-cli-samples/blob/master/app-service/configure-ssl-certificate/configure-ssl-certificate-webapp-only.sh" is linked directly from "https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate?tabs=apex#how-can-i-automate-adding-a-bring-your-owncertificate-to-an-app" in the instructions sections for "Azure CLI: Bind a custom TLS/SSL certificate to a web app"

configure-ssl-certificate-webapp-only.sh does not provision the webapp as described, and seems to link to a page (app-service/scripts/cli-configure-ssl-certificate.md) which also doesn't appear to exist.

creating VM-IIS

az vm extension set
--publisher Microsoft.Compute
--version 1.8
--name CustomScriptExtension
--vm-name myVM
--resource-group myResourceGroup
--settings '{"commandToExecute":"powershell.exe Install-WindowsFeature -Name Web-Server"}'

Returns:
Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

How to get Feature Management Keys from Java.

Looking for a solution where I can get Keys and Values with its labels from feature management of app configuration. I do not want to use given Spring libraries. Can anyone please get me to the right direction.

Suggested note on this line....

serverApplicationSecret=$(az ad sp credential reset \

FYI it seems valid to point out that user should either use a small string in --credential-description or make use of the suggested az rest call until we wait for az ad sp credential reset to accept bigger pwds or limit the amount of chars in that param with a friendlier error.

FYI here is the az rest suggestion:

Azure/azure-cli#10234 (comment)

Copy snapshots to storage account script - not working

Opening the issue here although this may be an Azure CLI bug.

Background

We have a snapshot "SS-1" that resides in Resource Group "RG-1" which lives in Subscription "A-1". The idea was to use the Azure CLI to copy that snapshot into Storage Account "SA-1", inside Container "C-1", as VHD "SS-1.vhd" under the Subscription "A-2". I used the example script here as a template, and received the errors mentioned below.

After trying a few things with the CLI, I decided to try the same operation with the Powershell Azure Module. For that I followed this script here, and that worked as expected.

I was under the impression these operations were similar and should work the same. Am I missing something, or is this a bug with the CLI?

Errors

azure.multiapi.storage.v2018_11_09.common.storageclient : Client-Request-ID=26db9db0-3a8b-11eb-bd33-d0abd52dec12 Retry policy did not allow for a retry: Server-Timestamp=Thu, 10 Dec 2020 01:58:10 GMT, Server-Request-ID=0603f00d-201e-0048-4197-ce479b000000, HTTP status code=403, Exception=Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. ErrorCode: CannotVerifyCopySource<?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.RequestId:0603f00d-201e-0048-4197-ce479b000000Time:2020-12-10T01:58:11.1978438Z</Message></Error>.
azure.cli.core.util.handle_exception is called with an exception:
Traceback (most recent call last):
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-2huwp6jm\knack\cli.py", line 215, in invoke
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\commands\__init__.py", line 654, in execute
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\commands\__init__.py", line 717, in _run_jobs_serially
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\commands\__init__.py", line 709, in _run_job
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-_skkczbr\azure\cli\command_modules\storage\__init__.py", line 342, in new_handler
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\commands\__init__.py", line 688, in _run_job
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\commands\__init__.py", line 325, in __call__
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-0ydpnxq9\azure\cli\core\__init__.py", line 784, in default_command_handler
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\blob\blockblobservice.py", line 1018, in copy_blob
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\blob\baseblobservice.py", line 3261, in _copy_blob
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\common\storageclient.py", line 430, in _perform_request
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\common\storageclient.py", line 358, in _perform_request
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\common\storageclient.py", line 344, in _perform_request
  File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-unpacked-wheel-35ikgud1\azure\multiapi\storage\v2018_11_09\common\_error.py", line 115, in _http_error_handler
azure.common.AzureHttpError: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. ErrorCode: CannotVerifyCopySource
<?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:0603f00d-201e-0048-4197-ce479b000000
Time:2020-12-10T01:58:11.1978438Z</Message></Error>

Additional Debug output

Command arguments: ['storage', 'blob', 'copy', 'start', '--debug', '--destination-blob', '<redacted>', '--destination-container', '<redacted>', '--account-name', '<redacted>', '--account-key', '<redacted>', '--source-uri', 'https://<redacted>.blob.core.windows.net/<redacted>/<redacted>?sv=2018-03-28']
Event: Cli.PreExecute []
Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x02B1CA08>, <function OutputProducer.on_global_arguments at 0x02CAAE88>, <function CLIQuery.on_global_arguments at 0x02CCFE88>]
Event: CommandInvoker.OnPreCommandTableCreate []
Modules found from index for 'storage': ['azure.cli.command_modules.storage']
Loading command modules:
Name                  Load Time    Groups  Commands
storage                   0.091        52       238
Total (1)                 0.091        52       238
Loaded 52 groups, 238 commands.
Found a match in the command table.
Raw command  : storage blob copy start
Command table: storage blob copy start
Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x02F37E88>]
az_command_data_logger : command args: storage blob copy start --debug --destination-blob {} --destination-container {} --account-name {} --account-key {} --source-uri {}
Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x02F8FA50>, <function register_global_query_examples_argument.<locals>.register_query_examples at 0x02F991E0>]
Event: CommandInvoker.OnPostArgumentLoad []
Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x02F99228>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x02F992B8>]
Event: CommandInvoker.OnCommandTableLoaded []
Event: CommandInvoker.OnPreParseArgs []
Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x02CAAED0>, <function CLIQuery.handle_query_parameter at 0x02CCFED0>, <function register_global_query_examples_argument.<locals>.handle_example_parameter at 0x02F8FBB8>, 
<function register_ids_argument.<locals>.parse_ids_arguments at 0x02F99270>]
Getting data service client service_type=BlockBlobService
azure.multiapi.storage.v2018_11_09.common._auth : String_to_sign=PUT











x-ms-client-request-id:<redacted>
x-ms-copy-source:https://<redacted>.blob.core.windows.net/<redacted>/<redacted>?sv=2018-03-28
x-ms-date:Thu, 10 Dec 2020 01:58:09 GMT
x-ms-version:2018-11-09
/<redacted>/<redacted>/<redacted>
azure.multiapi.storage.v2018_11_09.common.storageclient : Client-Request-ID=<redacted> Outgoing request: Method=PUT, Path=/images/our_test.vhd, Query={'timeout': None}, Headers={'x-ms-copy-source': 'https://<redacted>.blob.core.windows.net/<redacted>/<redacted>?sv=2018-03-28', 'x-ms-source-if-modified-since': None, 'x-ms-source-if-unmodified-since': None, 'x-ms-source-if-match': None, 'x-ms-source-if-none-match': None, 'If-Modified-Since': None, 'If-Unmodified-Since': None, 'If-Match': None, 'If-None-Match': None, 'x-ms-lease-id': None, 'x-ms-source-lease-id': None, 'x-ms-access-tier': None, 'x-ms-requires-sync': None, 'x-ms-version': '2018-11-09', 'User-Agent': 'Azure-Storage/2.0.0-2.0.1 (Python CPython 3.6.8; Windows 10) AZURECLI/2.16.0 (MSI)', 'x-ms-client-request-id': '<redacted>', 'x-ms-date': 'Thu, 10 Dec 2020 01:58:09 GMT', 'Authorization': 'REDACTED'}.
urllib3.connectionpool : Starting new HTTPS connection (1): <redacted>.blob.core.windows.net:443
urllib3.connectionpool : https://<redacted>.blob.core.windows.net:443 "PUT /<redacted>/<redacted> HTTP/1.1" 403 322
azure.multiapi.storage.v2018_11_09.common.storageclient : Client-Request-ID=<redacted> Receiving Response: Server-Timestamp=Thu, 10 Dec 2020 01:58:10 GMT, Server-Request-ID=0603f00d-201e-0048-4197-ce479b000000, HTTP Status Code=403, Message=Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature., Headers={'content-length': '322', 'content-type': 'application/xml', 'server': 'Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0', 'x-ms-request-id': '0603f00d-201e-0048-4197-ce479b000000', 'x-ms-version': '2018-11-09', 'x-ms-error-code': 'CannotVerifyCopySource', 'date': 'Thu, 10 Dec 2020 01:58:10 GMT'}.
azure.multiapi.storage.v2018_11_09.common.storageclient : Client-Request-ID=<redacted> Operation failed: checking if the operation should be retried. Current retry count=0, Server-Timestamp=Thu, 10 Dec 2020 01:58:10 GMT, Server-Request-ID=0603f00d-201e-0048-4197-ce479b000000, HTTP status code=403, Exception=Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. ErrorCode: CannotVerifyCopySource<?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.RequestId:0603f00d-201e-0048-4197-ce479b000000Time:2020-12-10T01:58:11.1978438Z</Message></Error>.

Code (Redacted)

Working (Azure Powershell Module)

$sourceSubscriptionId = '<redacted>'

$sourceResourceGroupName = '<redacted>'

$snapshotName = '<redacted>'

$sasExpiryDuration = "3600"

$targetStorageAccountName = "<redacted>"

$targetStorageContainerName = "<redacted>"

$targetStorageAccountKey = "<redacted>"

$targetVHDFileName = "<redacted>"

Select-AzSubscription -SubscriptionId $sourceSubscriptionId

$sas = Grant-AzSnapshotAccess -ResourceGroupName $sourceResourceGroupName -SnapshotName $snapshotName -DurationInSecond $sasExpiryDuration -Access Read

$destinationContext = New-AzStorageContext -StorageAccountName $targetStorageAccountName -StorageAccountKey $targetStorageAccountKey

Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer $targetStorageContainerName -DestContext $destinationContext -DestBlob $targetVHDFileName

Not Working (CLI)

$sourceSubscriptionId = '<redacted>'

$sourceResourceGroupName = '<redacted>'

$snapshotName = '<redacted>'

$sasExpiryDuration = '3600'

$targetStorageAccountName = "<redacted>"

$targetStorageContainerName = "<redacted>"

$targetStorageAccountKey = "<redacted>"

$targetVHDFileName = "<redacted>"

az account set --subscription $sourceSubscriptionId

$sas = az snapshot grant-access --resource-group $sourceResourceGroupName --name $snapshotName --duration-in-seconds $sasExpiryDuration --access-level "Read" --query [accessSas] -o tsv

az storage blob copy start --debug --destination-blob $targetVHDFileName --destination-container $targetStorageContainerName --account-name $targetStorageAccountName --account-key $targetStorageAccountKey --source-uri $sas

VMSS with load balancer not going through

I tried to to create a VN scale set as indicated in create-vmss.sh but with a load balancer and not application gateway. I created Vnet, Subnet, public IP addr, loadbalancer with the public IP, http rule then the VMSS. When I try to access the IP , I get

The connection has timed out
The server at 20.199.112.60 is taking too long to respond.

Here are the steps I followed

1 - az network vnet create \
    --name vnet-myrg \
    --resource-group myrg \
    --address-prefix 10.0.0.0/16 \
    --subnet-name subnet-myrg \
    --subnet-prefixes 10.0.0.0/24

2 - az network vnet subnet create \
  --name Subnet-vnet-myrg \
  --resource-group myrg \
  --vnet-name vnet-myrg \
  --address-prefix 10.0.2.0/24

3 - az network public-ip create \
  --resource-group myrg \
  --name myrgPubIPAddr \
  --sku Standard

4 - az network lb create \
    --resource-group myrg \
    --name myrgLB \
    --sku Standard \
    --public-ip-address myrgPubIPAddr \
    --frontend-ip-name myFrontEnd \
    --backend-pool-name myBackEndPool

5 - az network lb probe create \
    --resource-group myrg \
    --lb-name myrgLB \
    --name myHealthProbe \
    --protocol tcp \
    --port 80

6 - az network lb rule create \
    --resource-group myrg \
    --lb-name myrgLB \
    --name myHTTPRule \
    --protocol tcp \
    --frontend-port 80 \
    --backend-port 80 \
    --frontend-ip-name myFrontEnd \
    --backend-pool-name myBackEndPool \
    --probe-name myHealthProbe \
    --disable-outbound-snat true \
    --idle-timeout 15 \
    --enable-tcp-reset true

7 - az vmss create \
  --name myrg \
  --resource-group myrg \
  --image Ubuntu2204 \
  --admin-username azureuser \
  --admin-password Azure123456! \
  --instance-count 2 \
  --vnet-name vnet-myrg \
  --subnet Subnet-vnet-myrg \
  --vm-sku Standard_DS1_v2 \
  --upgrade-policy-mode Automatic \
  --lb myrgLB \
  --backend-pool-name myBackEndPool \
  --custom-data cloud-init.txt

What might be wrong in this config? Is there a sample here for using load balancer instead of application gateway?

script doesn't run as is

https://github.com/Azure-Samples/azure-cli-samples/tree/master/redis-cache

The scripts in this folder needed to checked and rerun.

  1. These don't run 'as-is"
  2. Even if they ran, they would basically create a resource and delete a resource without anything being illustrated. There are no pauses, for example, but that is hard to do when they don't run in the first place because the variables section fails.
  3. I suggest that there be a create cache/resource group script and delete cache /resource group script.

Create a resource group

echo "Creating $resourceGroup in "$location"..."
az group create --name $resourceGroup --location "$location" --tags $tag

shoud be:

az group create --resourcegroup $resourceGroup --location "$location" --tags $tag

like all the others

Create a Basic C0 (256 MB) Redis Cache

echo "Creating $cache"
az redis create --name $cache --resource-group $resourceGroup --location "$location" --sku $sku --vm-size $size

Get details of an Azure Cache for Redis

echo "Showing details of $cache"
az redis show --name $cache --resource-group $resourceGroup

Retrieve the hostname and ports for an Azure Redis Cache instance

redis=($(az redis show --name $cache --resource-group $resourceGroup --query [hostName,enableNonSslPort,port,sslPort] --output tsv))

Retrieve the keys for an Azure Redis Cache instance

keys=($(az redis list-keys --name $cache --resource-group $resourceGroup --query [primaryKey,secondaryKey] --output tsv))

Display the retrieved hostname, keys, and ports

echo "Hostname:" ${redis[0]}
echo "Non SSL Port:" ${redis[2]}
echo "Non SSL Port Enabled:" ${redis[1]}
echo "SSL Port:" ${redis[3]}
echo "Primary Key:" ${keys[0]}
echo "Secondary Key:" ${keys[1]}

Delete a redis cache

echo "Deleting $cache"
az redis delete --name $resourceGroup --resource-group $resourceGroup -y

should be

az redis delete --name $name --resource-group $resourceGroup -y

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.