MCPcopy Create free account
hub / github.com/OpenSN-Library/OpenSN-Library / GetInstanceList

Function GetInstanceList

daemon/pkg/synchronizer/instance.go:45–69  ·  view source on GitHub ↗
(nodeIndex int)

Source from the content-addressed store, hash-verified

43}
44
45func GetInstanceList(nodeIndex int) ([]*model.Instance, error) {
46 var instanceList []*model.Instance
47 instanceInfoKeyBase := fmt.Sprintf(key.NodeInstanceListKeyTemplate, nodeIndex)
48 nodeListEtcd, err := utils.EtcdClient.Get(
49 context.Background(),
50 instanceInfoKeyBase,
51 clientv3.WithPrefix(),
52 )
53 if err != nil {
54 err := fmt.Errorf("get instance list from etcd error:%s", err.Error())
55 return nil, err
56 }
57
58 for _, v := range nodeListEtcd.Kvs {
59 instanceInfo := new(model.Instance)
60 err = json.Unmarshal(v.Value, instanceInfo)
61 if err != nil {
62 errMsg := fmt.Sprintf("Unable to parse instance info from etcd value %s, Error:%s", string(v.Value), err.Error())
63 logrus.Error(errMsg)
64 continue
65 }
66 instanceList = append(instanceList, instanceInfo)
67 }
68 return instanceList, nil
69}
70
71func AddInstanceInfo(nodeIndex int, instanceInfo *model.Instance) error {
72 instanceInfoKeyBase := fmt.Sprintf(key.NodeInstanceListKeyTemplate, nodeIndex)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected