Я пытаюсь выполнить удаленный скрипт на Python с аргументами командной строки.Скрипт python разработан с использованием argparse.Как мы знаем, argparse принимает входные данные с -/--
в качестве имени параметра.Передача этого значения в --parameters
из az cli приводит к странным ошибкам.
Вопрос Как передать параметры типа python argparse для сценария python, используя az run-command invoke
Некоторые примеры попыток и вывод
Try - 1
az vm run-command invoke --resource-group MDC_VME_DEV_EUS \
--name ubuntumemsql002 --command-id RunShellScript \
--scripts /mnt/workspace/scripts/test.py \
--parameters "-i /mnt/workspace/data/indata" "-o /mnt/workspace/data/outdata" "--input_compressed_data" "--output_compressed_data" "-a 600" "-p 0.1" "-b 600 1200 1800" "-s 1543275000"
az vm run-command invoke: ' /mnt/workspace/data/outdata' is not a valid value for '--output'. See 'az vm run-command invoke --help'.
Try - 2
bash-4.4# az vm run-command invoke \
--resource-group MDC_VME_DEV_EUS \
--name ubuntumemsql002 \
--command-id RunShellScript \
--scripts /mnt/workspace/scripts/test.py \
--parameters "-i /mnt/workspace/data/indata -o /mnt/workspace/data/outdata --input_compressed_data --output_compressed_data -a 600 -p 0.1 -b 600 1200 1800 -s 1543275000"
Deployment failed. Correlation ID: 36317037-4cfb-429e-b113-f8995d3419fb. VM has reported a failure when processing extension 'RunCommandLinux'.
Error message: "Enable failed: failed to execute command: command terminated with exit status=2
[stdout]
[stderr]
/var/lib/waagent/run-command/download/7/script.sh: 1: export: /mnt/workspace/data/indata: bad variable name
".
Попробуйте - 3
bash-4.4# az vm run-command invoke \
--resource-group MDC_VME_DEV_EUS \
--name ubuntumemsql002 \
--command-id RunShellScript \
--scripts /mnt/workspace/scripts/test.py \
--parameters "-i /mnt/workspace/data/indata -o /mnt/workspace/data/outdata --input_compressed_data --output_compressed_data -a 600 -p 0.1 -b 600 1200 1800 -s 1543275000" --verbose
Deployment failed. Correlation ID: 9efaf01c-3d7b-473a-90c8-802d63b6ccf0. VM has reported a failure when processing extension 'RunCommandLinux'.
Error message: "Enable failed: failed to execute command: command terminated with exit status=2
[stdout]
[stderr]
/var/lib/waagent/run-command/download/8/script.sh: 1: export: /mnt/workspace/data/indata: bad variable name
".
Попробуйте - 4
bash-4.4# az vm run-command invoke \
> --resource-group MDC_VME_DEV_EUS \
> --name ubuntumemsql002 \
> --command-id RunShellScript \
> --scripts /mnt/workspace/scripts/test.py \
> --parameters -i /mnt/workspace/data/indata -o /mnt/workspace/data/outdata --input_compressed_data --output_compressed_data -a 600 -p 0.1 -b 600 1200 1800 -s 1543275000
az vm run-command invoke: error: argument --parameters: expected at least one argument
usage: az vm run-command invoke [-h] [--verbose] [--debug]
[--output {json,jsonc,table,tsv,yaml}]
[--query JMESPATH]
[--resource-group RESOURCE_GROUP_NAME]
[--name NAME] --command-id COMMAND_ID
[--scripts SCRIPTS [SCRIPTS ...]]
[--parameters PARAMETERS [PARAMETERS ...]]
[--subscription _SUBSCRIPTION]
[--ids ID [ID ...]]
Попробуйте - 5
bash-4.4# az vm run-command invoke \
> --resource-group MDC_VME_DEV_EUS \
> --name ubuntumemsql002 \
> --command-id RunShellScript \
> --scripts /mnt/workspace/scripts/test.py \
> --parameters \-i /mnt/workspace/data/indata \-o /mnt/workspace/data/outdata --input_compressed_data --output_compressed_data \-a 600 \-p 0.1 \-b 600 1200 1800 \-s 1543275000
az vm run-command invoke: error: argument --parameters: expected at least one argument
usage: az vm run-command invoke [-h] [--verbose] [--debug]
[--output {json,jsonc,table,tsv,yaml}]
[--query JMESPATH]
[--resource-group RESOURCE_GROUP_NAME]
[--name NAME] --command-id COMMAND_ID
[--scripts SCRIPTS [SCRIPTS ...]]
[--parameters PARAMETERS [PARAMETERS ...]]
[--subscription _SUBSCRIPTION]
[--ids ID [ID ...]]
bash-4.4#
Direct VM CLI Try
И, просто для подтверждения, эта же команда отлично выполняется, когда я запускаю их в CLI
/mnt/workspace/scripts/test.py -i /mnt/workspace/data/indata -o /mnt/workspace/data/outdata --input_compressed_data --output_compressed_data -a 600 -p 0.1 -b 600 1200 1800 -s 1543275000
ReportInfo( input_file_name='/mnt/workspace/data/indata/s22k-1543290398518-VV5X13.gz'output_file_name='/mnt/workspace/data/outdata/s22k-1543290398518-VV5X13-data-1543275000.gz'result='Success' )
ReportInfo( input_file_name='/mnt/workspace/data/indata/s22k-1543290398518-VV5X11.gz'output_file_name='/mnt/workspace/data/outdata/s22k-1543290398518-VV5X11-data-1543275000.gz'result='Success' )
ReportInfo( input_file_name='/mnt/workspace/data/indata/s22k-1543290398518-VV5X12.gz'output_file_name='/mnt/workspace/data/outdata/s22k-1543290398518-VV5X12-data-1543275000.gz'result='Success' )
ReportInfo( input_file_name='/mnt/workspace/data/indata/s22k-1543290398518-VV5X15.gz'output_file_name='/mnt/workspace/data/outdata/s22k-1543290398518-VV5X15-data-1543275000.gz'result='Success' )
ReportInfo( input_file_name='/mnt/workspace/data/indata/s22k-1543290398518-VV5X14.gz'output_file_name='/mnt/workspace/data/outdata/s22k-1543290398518-VV5X14-data-1543275000.gz'result='Success' )
Некоторые примеры (как предлагается в комментариях)
Выполнить - 1
bash-4.4# az vm run-command invoke \
> --resource-group MDC_VME_DEV_EUS \
> --name ubuntumemsql002 \
> --command-id RunShellScript \
> --scripts /mnt/workspace/scripts/test.py \
> --parameters "\-i" "/mnt/workspace/data/indata" "\-o" "/mnt/workspace/data/outdata" "\--input_compressed_data" "\--output_compressed_data" "\-a" "600" "\-p" "0.1" "\-b" "600 1200 1800" "\-s" "1543275000"
Deployment failed. Correlation ID: 70f7646e-fa94-4104-8067-e42b92470803. VM has reported a failure when processing extension 'RunCommandLinux'. Error message: "Enable failed: failed to execute command: command terminated with exit status=2
[stdout]
[stderr]
/var/lib/waagent/run-command/download/9/script.sh: 1: export: 1200: bad variable name
Выполнить - 2
bash-4.4# az vm run-command invoke \
> --resource-group MDC_VME_DEV_EUS \
> --name ubuntumemsql002 \
> --command-id RunShellScript \
> --scripts /mnt/workspace/scripts/prepare_data_for_memsql_ingest.py \
> --parameters "\-i" "/mnt/workspace/data/indata" "\-o" "/mnt/workspace/data/outdata" "\--input_compressed_data" "\--output_compressed_data" "\-a" "600" "\-p" "0.1" "\-b" "600" "1200" "1800" "\-s" "1543275000"
Deployment failed. Correlation ID: e460bfa4-286e-43c3-8a60-6f74b78c7e85. VM has reported a failure when processing extension 'RunCommandLinux'. Error message: "Enable failed: failed to execute command: command terminated with exit status=2
[stdout]
[stderr]
usage: PROG [-h] -i INPUT_DIR -o OUT_DIR
(--input_compressed_data | --input_uncompressed_data)
(--output_compressed_data | --output_uncompressed_data) -a
AGGREGATE_INTERVAL -p {<__main__.Range object at 0x7fd86f8c49d0>}
-b BACKDATE_INTERVAL_LIST [BACKDATE_INTERVAL_LIST ...] -s
START_EPOCH
PROG: error: argument -i/--input_dir is required
".