华为云Astro轻应用-对接IEF实现边缘节点管理功能:在脚本中调用连接器
时间:2025-02-12 14:58:40
在脚本中调用连接器
在脚本中,调用连接器实现调用IEF的接口。
- 参考开发一个简单脚本实例中操作,创建一个空白脚本。
图5 新建空白脚本
- 在脚本编辑器中,输入如下代码。
import { Decimal } from 'decimal';import { Error } from 'error';import * as ief from 'ief';export class Input { @action.param({ type: "String", required: true, description: "type" }) project_id: string; // @action.param({ type: "String", required: true, description: "the operation value 2" }) // node_id: string;}export class Output { @action.param({ type: "Object", required: true }) result: Object;}export class Calculator { @action.method({ input: "Input", output: "Output", description: "do a operation" }) run(input: Input): Output { let output = new Output(); let cli = ief.newClient("ief_test"); output.result = cli.getProjectNode(input.project_id); //console.log(output.result); return output; }}
其中,ief.newClient("ief_test")中的“ief_test”为连接器的名称。
- 单击脚本编辑器页面上方的
,保存脚本。
- 保存成功后,单击
,运行脚本。
- 在输入参数页签,输入请求参数的项目ID,单击测试窗口右上角的
。
{ "project_id":"XXXXXXXXXXX"}
在输出参数页签,显示出边缘节点列表,表示执行脚本成功。
- 单击脚本编辑器页面上方的
,启用脚本。
support.huaweicloud.com/usermanual-astrozero/astrozero_05_0096.html