我想启动一个 Azure Linux 实例,处理一些数据,然后让实例自动进入停止(解除分配)状态,以避免进一步计费。
是否可以做到这一点,理想情况下是在作业完成后简单地在实例上运行一个命令?
编辑:在下面的评论帮助搜索相关命令之后,我尝试在实例上运行以下命令,但出现错误:
[server]$ az vm deallocate --resource-group MyResources --name VMName
导致错误
getattr(): attribute name must be string
Traceback (most recent call last):
File "/anaconda/envs/py35/lib/python3.5/site-packages/azure/cli/main.py", line 36, in main
cmd_result = APPLICATION.execute(args)
File "/anaconda/envs/py35/lib/python3.5/site-packages/azure/cli/core/application.py", line 177, in execute
self.configuration.load_params(command)
File "/anaconda/envs/py35/lib/python3.5/site-packages/azure/cli/core/application.py", line 50, in load_params
commands.load_params(command)
File "/anaconda/envs/py35/lib/python3.5/site-packages/azure/cli/core/commands/__init__.py", line 408, in load_params
import_module(module_to_load).load_params(command)
File "/anaconda/envs/py35/lib/python3.5/site-packages/azure/cli/command_modules/vm/__init__.py", line 10, in load_params
import azure.cli.command_modules.vm._params # pylint: disable=redefined-outer-name, unused-variable
File "/anaconda/envs/py35/lib/python3.5/site-packages/azure/cli/command_modules/vm/_params.py", line 78, in <module>
c.register_cli_argument('vm', 'zone', zone_type)
File "/anaconda/envs/py35/lib/python3.5/site-packages/azure/cli/core/commands/__init__.py", line 62, in register_cli_argument
if (isinstance(is_supported, tuple) and getattr(is_supported, self._operation_group)) or is_supported:
TypeError: getattr(): attribute name must be string
答案1
取消分配实例需要针对 Azure API 运行命令以使其关闭 VM,如果您已关闭 Windows,则不会取消分配。您可以做的是在您的 VM 上安装 Azure PowerShell cmdlet,然后让脚本末尾调用 stop-azurermvm 命令来关闭自身。
话虽如此,您是否也考虑过查看 Azure Functions?这将为您完成所有这些工作/