-
Notifications
You must be signed in to change notification settings - Fork 47
/
mcis.go
57 lines (43 loc) · 1.34 KB
/
mcis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package proc
import (
"encoding/json"
"fmt"
gc "github.com/cloud-barista/cb-tumblebug/src/api/grpc/common"
tb_api "github.com/cloud-barista/cb-tumblebug/src/api/grpc/request"
)
// ===== [ Constants and Variables ] =====
// VMListInfo - VM 목록 구조 정의
type VMListInfo struct {
Id string `yaml:"id" json:"id"`
Name string `yaml:"name" json:"name"`
Vm []string `yaml:"vm" json:"vm"`
}
// ===== [ Implementations ] =====
// ===== [ Private Functions ] =====
// ===== [ Public Functions ] =====
// ListMcisVM - VM 목록
func ListMcisVM(mcis *tb_api.MCISApi, nameSpaceID string, mcisID string) (string, error) {
holdType, _ := mcis.GetOutType()
mcis.SetOutType("json")
defer mcis.SetOutType(holdType)
result, err := mcis.GetMcisInfoByParam(nameSpaceID, mcisID)
if err != nil {
return "", err
}
jsonMap := make(map[string]interface{})
err = json.Unmarshal([]byte(result), &jsonMap)
if err != nil {
return "", err
}
vmList := []string{}
for _, m := range jsonMap["vm"].([]interface{}) {
item := m.(map[string]interface{})
vmList = append(vmList, fmt.Sprintf("%v", item["id"]))
}
vmListInfo := VMListInfo{}
vmListInfo.Id = fmt.Sprintf("%v", jsonMap["id"])
vmListInfo.Name = fmt.Sprintf("%v", jsonMap["name"])
vmListInfo.Vm = vmList
outType, _ := mcis.GetOutType()
return gc.ConvertToOutput(outType, &vmListInfo)
}