From 80a04403aab7956a6a8581d7b3e7171185311494 Mon Sep 17 00:00:00 2001 From: sp-yduck Date: Sat, 21 Oct 2023 14:11:48 +0900 Subject: [PATCH] add cluster join config --- api/cluster_type.go | 39 +++++++++++++++++++++++++++++++++++++++ proxmox/cluster.go | 15 +++++++++++++++ rest/cluster.go | 10 ++++++++++ rest/cluster_test.go | 8 ++++++++ 4 files changed, 72 insertions(+) create mode 100644 api/cluster_type.go create mode 100644 proxmox/cluster.go diff --git a/api/cluster_type.go b/api/cluster_type.go new file mode 100644 index 0000000..e8f7f11 --- /dev/null +++ b/api/cluster_type.go @@ -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"` +} diff --git a/proxmox/cluster.go b/proxmox/cluster.go new file mode 100644 index 0000000..077586c --- /dev/null +++ b/proxmox/cluster.go @@ -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) +} diff --git a/rest/cluster.go b/rest/cluster.go index c868601..da8a872 100644 --- a/rest/cluster.go +++ b/rest/cluster.go @@ -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) { @@ -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 +} diff --git a/rest/cluster_test.go b/rest/cluster_test.go index 247777c..a0bc135 100644 --- a/rest/cluster_test.go +++ b/rest/cluster_test.go @@ -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) +}