Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/pmk/checkNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func CheckNode(ctx objects.Config, allClients client.Client, auth keystone.Keyst
//If hostID is empty then host could be connected to other DU
var connected bool
if len(id) != 0 {
connected = allClients.Resmgr.HostSatus(auth.Token, id[0])
connected = allClients.Resmgr.HostStatus(auth.Token, id[0])
} else {
zap.S().Fatalf("Hostagent is installed on this host, but this host is not part of the DU %s specified in the config", ctx.Fqdn)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/pmk/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func Bootstrap(ctx objects.Config, c client.Client, req qbert.ClusterCreateReque

LoopVariable := 1
for LoopVariable <= util.MaxLoopValue {
hostStatus := c.Resmgr.HostSatus(token, nodeID)
hostStatus := c.Resmgr.HostStatus(token, nodeID)
if !hostStatus {
zap.S().Debugf("Host is Down...Trying again")
} else {
Expand Down Expand Up @@ -150,7 +150,7 @@ func Bootstrap(ctx objects.Config, c client.Client, req qbert.ClusterCreateReque
return nil
}

//Checks Prerequisites for Bootstrap Command
// Checks Prerequisites for Bootstrap Command
func PreReqBootstrap(executor cmdexec.Executor) (bool, bool, error) {

os, err := ValidatePlatform(executor)
Expand Down Expand Up @@ -183,7 +183,7 @@ func PreReqBootstrap(executor cmdexec.Executor) (bool, bool, error) {
return val, val1, nil
}

//Deleting the cluster if the node is not attached to the cluster
// Deleting the cluster if the node is not attached to the cluster
func DeleteClusterBootstrap(clusterID string, c client.Client, keystoneAuth keystone.KeystoneAuth, token string) {
err := c.Qbert.DeleteCluster(clusterID, keystoneAuth.ProjectID, token)

Expand Down
6 changes: 6 additions & 0 deletions pkg/pmk/decomissionNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ func DecommissionNode(cfg *objects.Config, nc objects.NodeConfig, removePf9 bool
fmt.Printf("Node is connected to %s cluster\n", nodeInfo.ClusterName)
fmt.Println("Detaching node from cluster...")
err = c.Qbert.DetachNode(nodeInfo.ClusterUuid, auth.ProjectID, auth.Token, hostID[0])
for {
nodeInfo := c.Resmgr.GetHostInfo(auth.Token, hostID[0])
if nodeInfo.Extensions.Pf9KubeStatus.Data.Pf9ClusterID == "" {
break
}
}
if err != nil {
zap.S().Fatalf("Failed to detach host from cluster")
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkg/qbert/qbert.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func (c QbertImpl) CheckClusterExistsWithUuid(uuid, projectID, token string) (st
return "", fmt.Errorf("error finding cluster with uuid %s", uuid)
}

//Function to Check status of attach-node API
// Function to Check status of attach-node API
func Attach_Status(attachEndpoint string, token string, byt []byte) (*http.Response, error) {
client := http.Client{}
req, err := http.NewRequest("POST", attachEndpoint, strings.NewReader(string(byt)))
Expand All @@ -513,7 +513,7 @@ func Attach_Status(attachEndpoint string, token string, byt []byte) (*http.Respo
return resp, nil
}

//There are two different payload structures based on pmk version
// There are two different payload structures based on pmk version
func updatePayload(p string) string {
var monitoringDetails string
var tagDetails string
Expand Down
56 changes: 54 additions & 2 deletions pkg/resmgr/resmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (
type Resmgr interface {
AuthorizeHost(hostID, token string) error
GetHostId(token string, hostIP []string) []string
HostSatus(token string, hostID string) bool
HostStatus(token string, hostID string) bool
GetHostInfo(token string, hostID string) Info
}

type ResmgrImpl struct {
Expand All @@ -38,6 +39,30 @@ type hostInfo []struct {
ID string `json:"id,omitempty"`
}

type Info struct {
Extensions struct {
Pf9KubeStatus struct {
//Status string `json:"status"`
Data struct {
/*Pf9KubeServiceState string `json:"pf9_kube_service_state"`
Pf9KubeNodeState string `json:"pf9_kube_node_state"`
Pf9KubeStartAttempt int `json:"pf9_kube_start_attempt"`*/
Pf9ClusterID string `json:"pf9_cluster_id,omitempty"`
/*Pf9ClusterRole string `json:"pf9_cluster_role"`
AllStatusChecks []string `json:"all_status_checks"`
AllTasks []string `json:"all_tasks"`
CompletedTasks []string `json:"completed_tasks"`
CurrentStatusCheck string `json:"current_status_check"`
CurrentTask string `json:"current_task"`
LastFailedStatusCheck string `json:"last_failed_status_check"`
LastFailedStatusTime int `json:"last_failed_status_time"`
LastFailedTask string `json:"last_failed_task"`
StatusCheckTimestamp int `json:"status_check_timestamp"`*/
} `json:"data,omitempty"`
} `json:"pf9_kube_status,omitempty"`
} `json:"extensions,omitempty"`
}

func NewResmgr(fqdn string, maxHttpRetry int, minWait, maxWait time.Duration, allowInsecure bool) Resmgr {

return &ResmgrImpl{fqdn, minWait, maxWait, maxHttpRetry, allowInsecure}
Expand Down Expand Up @@ -121,7 +146,7 @@ func (c *ResmgrImpl) GetHostId(token string, hostIPs []string) []string {
return hostUUIDs
}

func (c *ResmgrImpl) HostSatus(token string, hostID string) bool {
func (c *ResmgrImpl) HostStatus(token string, hostID string) bool {
url := fmt.Sprintf("%s/resmgr/v1/hosts/%s", c.fqdn, hostID)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
Expand Down Expand Up @@ -151,3 +176,30 @@ func (c *ResmgrImpl) HostSatus(token string, hostID string) bool {
}
return host.Info.Responding
}

func (c *ResmgrImpl) GetHostInfo(token string, hostID string) Info {
url := fmt.Sprintf("%s/resmgr/v1/hosts/%s", c.fqdn, hostID)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
zap.S().Infof("Unable to create a new request: %w", err)
}
req.Header.Set("X-Auth-Token", token)
client := http.Client{}
resp, err := client.Do(req)
if err != nil {
zap.S().Infof("Client is unable to send the request: %w", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
zap.S().Infof("Unable to read resp body: %w", err)
}

nodeInfo := Info{}
err = json.Unmarshal(body, &nodeInfo)
if err != nil {
zap.S().Debugf("Unable to unmarshal resp body to struct: %w", err)
}

return nodeInfo
}