8 "git.curoverse.com/arvados.git/sdk/go/config"
12 Clusters map[string]Cluster
15 // GetConfig returns the current system config, loading it from
17 func GetConfig() (*Config, error) {
19 err := config.LoadFile(&cfg, "/etc/arvados/config.yml")
23 // GetCluster returns the cluster ID and config for the given
24 // cluster, or the default/only configured cluster if clusterID is "".
25 func (sc *Config) GetCluster(clusterID string) (*Cluster, error) {
27 if len(sc.Clusters) == 0 {
28 return nil, fmt.Errorf("no clusters configured")
29 } else if len(sc.Clusters) > 1 {
30 return nil, fmt.Errorf("multiple clusters configured, cannot choose")
32 for id, cc := range sc.Clusters {
38 if cc, ok := sc.Clusters[clusterID]; !ok {
39 return nil, fmt.Errorf("cluster %q is not configured", clusterID)
41 cc.ClusterID = clusterID
47 ClusterID string `json:"-"`
48 ManagementToken string
49 SystemNodes map[string]SystemNode
52 // GetThisSystemNodeConfig returns a SystemNode for the node we're
53 // running on right now.
54 func (cc *Cluster) GetThisSystemNode() (*SystemNode, error) {
55 hostname, err := os.Hostname()
59 return cc.GetSystemNode(hostname)
62 // GetSystemNodeConfig returns a NodeConfig for the given node. An
63 // error is returned if the appropriate configuration can't be
64 // determined (e.g., this does not appear to be a system node).
65 func (cc *Cluster) GetSystemNode(node string) (*SystemNode, error) {
66 // Generally node is "a.b.ca", use the first of {"a.b.ca",
67 // "a.b", "a"} that has an entry in SystemNodes.
68 labels := strings.Split(node, ".")
69 for j := len(labels); j > 0; j-- {
70 hostpart := strings.Join(labels[:j], ".")
71 if cfg, ok := cc.SystemNodes[hostpart]; ok {
75 // If node is not listed, but "*" gives a default system node
76 // config, use the default config.
77 if cfg, ok := cc.SystemNodes["*"]; ok {
80 return nil, fmt.Errorf("config does not provision host %q as a system node", node)
83 type SystemNode struct {
92 type Keepstore struct {