1
0
mirror of https://github.com/gluster/glusterd2.git synced 2026-02-05 12:45:38 +01:00
Files
glusterd2/pkg/api/brickutils.go
2018-10-26 09:31:33 +05:30

44 lines
1.0 KiB
Go

package api
import (
"fmt"
"github.com/pborman/uuid"
)
// Nodes extracts the list of nodes from Volume Create request
func (req *VolCreateReq) Nodes() ([]uuid.UUID, error) {
var nodesMap = make(map[string]bool)
var nodes []uuid.UUID
for _, subvol := range req.Subvols {
for _, brick := range subvol.Bricks {
if _, ok := nodesMap[brick.PeerID]; !ok {
nodesMap[brick.PeerID] = true
u := uuid.Parse(brick.PeerID)
if u == nil {
return nil, fmt.Errorf("failed to parse peer ID: %s", brick.PeerID)
}
nodes = append(nodes, u)
}
}
}
return nodes, nil
}
// Nodes extracts list of Peer IDs from Volume Expand request
func (req *VolExpandReq) Nodes() ([]uuid.UUID, error) {
var nodesMap = make(map[string]bool)
var nodes []uuid.UUID
for _, brick := range req.Bricks {
if _, ok := nodesMap[brick.PeerID]; !ok {
nodesMap[brick.PeerID] = true
u := uuid.Parse(brick.PeerID)
if u == nil {
return nil, fmt.Errorf("failed to parse peer ID: %s", brick.PeerID)
}
nodes = append(nodes, u)
}
}
return nodes, nil
}