Skip to content

Commit

Permalink
add cluster join config
Browse files Browse the repository at this point in the history
  • Loading branch information
sp-yduck committed Oct 21, 2023
1 parent aef985f commit 80a0440
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
39 changes: 39 additions & 0 deletions api/cluster_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package api

type ClusterJoinConfig struct {
ConfigDigest string `json:"config_digest"`
NodeList []ClusterNodeConfig `json:"nodelist"`
PreferredNode string `json:"preferred_node"`
Totem Totem `json:"totem"`
}

type ClusterNodeConfig struct {
Name string `json:"name"`
NodeID string `json:"nodeid"`
PVEAddr string `json:"pve_addr"`
PVEFP string `json:"pve_fp"`
QuorumVotes string `json:"quorum_votes"`
Ring0Addr string `json:"ring0_addr"`
}

type Totem struct {
ClusterName string `json:"cluster_name"`
ConfigVersion string `json:"config_version"`
Interface interface{} `json:"interface"`
IPVersion string `json:"ip_version"`
LinkMode string `json:"link_mode"`
SecAuth string `json:"secauth"`
Version string `json:"version"`
}

type CorosyncLink struct {
Link0 string `json:"link0"`
Link1 string `json:"link1"`
Link2 string `json:"link2"`
Link3 string `json:"link3"`
Link4 string `json:"link4"`
Link5 string `json:"link5"`
Link6 string `json:"link6"`
Link7 string `json:"link7"`
Link8 string `json:"link8"`
}
15 changes: 15 additions & 0 deletions proxmox/cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package proxmox

import (
"context"

"github.com/sp-yduck/proxmox-go/api"
)

func (s *Service) NextID(ctx context.Context) (int, error) {
return s.restclient.GetNextID(ctx)
}

func (s *Service) JoinConfig(ctx context.Context) (*api.ClusterJoinConfig, error) {
return s.restclient.GetJoinConfig(ctx)
}
10 changes: 10 additions & 0 deletions rest/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package rest
import (
"context"
"encoding/json"

"github.com/sp-yduck/proxmox-go/api"
)

func (c *RESTClient) GetNextID(ctx context.Context) (int, error) {
Expand All @@ -16,3 +18,11 @@ func (c *RESTClient) GetNextID(ctx context.Context) (int, error) {
}
return int(nextid), nil
}

func (c *RESTClient) GetJoinConfig(ctx context.Context) (*api.ClusterJoinConfig, error) {
var config *api.ClusterJoinConfig
if err := c.Get(ctx, "/cluster/config/join", &config); err != nil {
return nil, err
}
return config, nil
}
8 changes: 8 additions & 0 deletions rest/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ func (s *TestSuite) TestGetNextID() {
}
s.T().Logf("get nextID: %d", nextid)
}

func (s *TestSuite) TestGetJoinConfig() {
c, err := s.restclient.GetJoinConfig(context.Background())
if err != nil {
s.T().Errorf("failed to get join config: %v", err)
}
s.T().Logf("get join config: %v", c)
}

0 comments on commit 80a0440

Please sign in to comment.