Ai
77 Star 124 Fork 105

openEuler/PilotGo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
machine.go 2.33 KB
一键复制 编辑 原始数据 按行查看 历史
zhanghan 提交于 2025-08-08 13:26 +08:00 . Plugin client method modification
/*
* Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved.
* PilotGo licensed under the Mulan Permissive Software License, Version 2.
* See LICENSE file for more details.
* Author: zhanghan2021 <zhanghan@kylinos.cn>
* Date: Wed Sep 27 17:35:12 2023 +0800
*/
package client
import (
"encoding/json"
"fmt"
"gitee.com/openeuler/PilotGo/sdk/common"
"gitee.com/openeuler/PilotGo/sdk/plugin/jwt"
"gitee.com/openeuler/PilotGo/sdk/utils/httputils"
)
func (c *Client) MachineList() ([]*common.MachineNode, error) {
serverInfo, err := c.Registry.Get("pilotgo-server")
if err != nil {
return nil, err
}
url := fmt.Sprintf("http://%s:%s/api/v1/pluginapi/machine_list", serverInfo.Address, serverInfo.Port)
r, err := httputils.Get(url, &httputils.Params{
Cookie: map[string]string{
jwt.TokenCookie: c.token,
},
})
if err != nil {
return nil, err
}
result := struct {
Code int `json:"code"`
Data []*common.MachineNode `json:"data"`
}{}
if err := json.Unmarshal(r.Body, &result); err != nil {
return nil, err
}
return result.Data, nil
}
func (c *Client) MachineInfoByUUID(machine_uuid string) (*common.MachineNode, error) {
serverInfo, err := c.Registry.Get("pilotgo-server")
if err != nil {
return &common.MachineNode{}, err
}
url := fmt.Sprintf("http://%s:%s/api/v1/pluginapi/machine_info?machine_uuid=%s", serverInfo.Address, serverInfo.Port, machine_uuid)
r, err := httputils.Get(url, &httputils.Params{
Cookie: map[string]string{
jwt.TokenCookie: c.token,
},
})
if err != nil {
return nil, err
}
result := struct {
Code int `json:"code"`
Data *struct {
ID int `json:"id"`
Departid int `json:"departid"`
Departname string `json:"departname"`
IP string `json:"ip"`
UUID string `json:"uuid"`
CPU string `json:"cpu"`
Runstatus string `json:"runstatus"`
Maintstatus string `json:"maintstatus"`
Systeminfo string `json:"systeminfo"`
} `json:"data"`
}{}
if err := json.Unmarshal(r.Body, &result); err != nil {
return nil, err
}
res := &common.MachineNode{
UUID: machine_uuid,
Department: result.Data.Departname,
IP: result.Data.IP,
CPUArch: result.Data.CPU,
OS: result.Data.Systeminfo,
RunStatus: result.Data.Runstatus,
MaintStatus: result.Data.Maintstatus,
}
return res, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openeuler/PilotGo.git
git@gitee.com:openeuler/PilotGo.git
openeuler
PilotGo
PilotGo
be4573e26691

搜索帮助