【问题标题】:See if Azure Virtual Machine is down using python使用 python 查看 Azure 虚拟机是否已关闭
【发布时间】:2019-03-19 20:24:18
【问题描述】:

我正在尝试编写一个 python 程序,它会在 VM 关闭时提醒我。我知道 PowerShell 可能更好,但更喜欢 python。

【问题讨论】:

    标签: python azure virtual-machine


    【解决方案1】:

    为什么您认为使用 PowerShell 会更好:)。 Python 规则 ;)

    如果您想要更具反应性的编程,您应该首先查看 EventGrid + LogicApp + WebApp/Function。就像 Azure 的 IFTTT,EventGrid 将触发一个事件,而 LogicApp 将能够使用此事件并将其发送到 WebApp 或 Function(您可以用 Python 编写)。 例子: https://docs.microsoft.com/en-us/azure/event-grid/monitor-virtual-machine-changes-event-grid-logic-app

    如果您想要更多“我拉每一分钟”的体验,只需使用 azure-mgmt-compute 包: https://pypi.org/project/azure-mgmt-compute/

    基本示例: https://github.com/Azure-Samples/virtual-machines-python-manage

    您将需要 VM 的实例视图,以获取电源状态,使用 instance_view

    希望这会有所帮助!

    (我在 MS 的 Azure SDK for Python 团队工作)

    编辑:

    EventGrid 似乎还不支持从 VM 电源状态触发,您仍然可以将 LogicApp 与解决方案 1 的轮询计划一起使用:https://docs.microsoft.com/en-us/azure/connectors/connectors-native-recurrence

    【讨论】:

      猜你喜欢
      • 2016-08-18
      • 1970-01-01
      • 2021-06-28
      • 1970-01-01
      • 1970-01-01
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多