2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-11-30 19:49:58 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-03-24 17:58:03 +00:00
|
|
|
"net/http"
|
2021-11-30 19:49:58 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Sys) HAStatus() (*HAStatusResponse, error) {
|
2022-03-23 21:47:43 +00:00
|
|
|
return c.HAStatusWithContext(context.Background())
|
|
|
|
}
|
2021-11-30 19:49:58 +00:00
|
|
|
|
2022-03-23 21:47:43 +00:00
|
|
|
func (c *Sys) HAStatusWithContext(ctx context.Context) (*HAStatusResponse, error) {
|
|
|
|
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
|
2021-11-30 19:49:58 +00:00
|
|
|
defer cancelFunc()
|
2022-03-23 21:47:43 +00:00
|
|
|
|
2022-03-24 17:58:03 +00:00
|
|
|
r := c.c.NewRequest(http.MethodGet, "/v1/sys/ha-status")
|
2022-03-23 21:47:43 +00:00
|
|
|
|
|
|
|
resp, err := c.c.rawRequestWithContext(ctx, r)
|
2021-11-30 19:49:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var result HAStatusResponse
|
|
|
|
err = resp.DecodeJSON(&result)
|
|
|
|
return &result, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type HAStatusResponse struct {
|
|
|
|
Nodes []HANode
|
|
|
|
}
|
|
|
|
|
|
|
|
type HANode struct {
|
|
|
|
Hostname string `json:"hostname"`
|
|
|
|
APIAddress string `json:"api_address"`
|
|
|
|
ClusterAddress string `json:"cluster_address"`
|
|
|
|
ActiveNode bool `json:"active_node"`
|
|
|
|
LastEcho *time.Time `json:"last_echo"`
|
2022-05-20 20:49:11 +00:00
|
|
|
Version string `json:"version"`
|
|
|
|
UpgradeVersion string `json:"upgrade_version,omitempty"`
|
|
|
|
RedundancyZone string `json:"redundancy_zone,omitempty"`
|
2021-11-30 19:49:58 +00:00
|
|
|
}
|