• VMware Orchestrator API调用Workflow 示例


    1、获取Workflow信息

    1.1 workflow id

    1.2 workflow input

    1.3 workflow output

    2、Python示例代码

    import requests
    import time
    from django.conf import settings
    
    
    def get_result(result_url, headers, user, password):
        """
        执行Workflow执行结果查询
        """
        result_response = requests.get(url=result_url, headers=headers, auth=(user, password))
        return result_response.json()
    
    
    def get_vm_owner(user, password, workflow_id, vm_name):
        """
        通过VM名称获取VM Owner
        """
        submit_url = "https://vro-server-ip/vco/api/workflows/{}/executions".format(workflow_id)
        headers = {
            "Content-Type": "Application/Json"
        }
    
        request_body = {
            "parameters": [
                {
                    "type": "string",  # input参数类型
                    "name": "vm_name",  # input参数名称 
                    "value": {
                        "string": {
                            "value": vm_name  # input参数值
                        }
                    }
                }
            ]
        }
        response = requests.post(url=submit_url, headers=headers, json=request_body, auth=(user, password))  # 执行Workflow API异步调用
        if response.status_code == 202:
            result_url = response.headers.get("Location")  # 获取Workflow执行结果的URL
            time.sleep(10)  # 等待Workflow查询执行完成
    
            try_number = 3  # 尝试3次
            while try_number:
                result_json = get_result(result_url, headers, user, password)  # 查询Workflow执行结果
                if result_json.get("state") == "running":  # 如果Workflow还在执行中,继续循环
                    try_number = try_number - 1
                    time.sleep(3)
             continue
    if result_json.get("state") == "completed":  # 如果Workflow执行完成,获取output值 return result_json.get("output-parameters")[0]["value"]["string"]["value"] if result_json.get("state") in ["failed", "canceled"]: return None

    if __name__ == '__main__':
    owner = get_vm_owner("vro_user", "vro_password", "workflow_id", "vm_name")
    print(owner)
  • 相关阅读:
    互操作
    Rx基础
    数据流块基础
    C# 一个帮您理解回调函数的例子(新手必看)
    C# 多线程之通过Timer开启线程的例子
    C# 利用委托事件进行窗体间的传值(新手必看)
    C#XML文件操作随笔
    C# 委托学习笔记
    c# 关于抓取网页源码后中文显示乱码的原因分析和解决方法
    c# 异步编程 使用回调函数例子
  • 原文地址:https://www.cnblogs.com/vincenshen/p/12536757.html
Copyright © 2020-2023  润新知