mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 19:57:42 +08:00
[REV] update grctl node list Command
This commit is contained in:
parent
940dccdbf7
commit
30884e3574
@ -41,7 +41,7 @@ import (
|
|||||||
|
|
||||||
func handleErr(err *util.APIHandleError) {
|
func handleErr(err *util.APIHandleError) {
|
||||||
if err != nil && err.Err != nil {
|
if err != nil && err.Err != nil {
|
||||||
fmt.Printf("%v\n",err.String())
|
fmt.Printf("%v\n", err.String())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,26 +105,16 @@ func fileExist(path string) bool {
|
|||||||
}
|
}
|
||||||
func handleStatus(serviceTable *termtables.Table, ready bool, v *model.HostNode) {
|
func handleStatus(serviceTable *termtables.Table, ready bool, v *model.HostNode) {
|
||||||
if v.Role.HasRule("compute") && !v.Role.HasRule("manage") {
|
if v.Role.HasRule("compute") && !v.Role.HasRule("manage") {
|
||||||
if ready {
|
serviceTable.AddRow(v.ID, v.InternalIP, v.HostName, v.Role.String(), v.Mode, v.Status, v.Alived, !v.Unschedulable, ready)
|
||||||
// true of false
|
|
||||||
serviceTable.AddRow(v.ID, v.InternalIP, v.HostName, v.Role.String(), v.Mode, v.Alived, !v.Unschedulable, ready)
|
|
||||||
} else {
|
|
||||||
//scheduable==false
|
|
||||||
|
|
||||||
serviceTable.AddRow(v.ID, v.InternalIP, v.HostName, v.Role.String(), v.Mode, v.Alived, false, ready)
|
|
||||||
}
|
|
||||||
} else if v.Role.HasRule("manage") && !v.Role.HasRule("compute") {
|
} else if v.Role.HasRule("manage") && !v.Role.HasRule("compute") {
|
||||||
//scheduable="n/a"
|
//scheduable="n/a"
|
||||||
serviceTable.AddRow(v.ID, v.InternalIP, v.HostName, v.Role.String(), v.Mode, v.Alived, "N/A", ready)
|
serviceTable.AddRow(v.ID, v.InternalIP, v.HostName, v.Role.String(), v.Mode, v.Status, v.Alived, "N/A", ready)
|
||||||
} else if v.Role.HasRule("compute") && v.Role.HasRule("manage") {
|
} else if v.Role.HasRule("compute") && v.Role.HasRule("manage") {
|
||||||
if !ready {
|
serviceTable.AddRow(v.ID, v.InternalIP, v.HostName, v.Role.String(), v.Mode, v.Status, v.Alived, !v.Unschedulable, ready)
|
||||||
//n/a
|
|
||||||
serviceTable.AddRow(v.ID, v.InternalIP, v.HostName, v.Role.String(), v.Mode, v.Alived, "N/A", ready)
|
|
||||||
} else {
|
|
||||||
serviceTable.AddRow(v.ID, v.InternalIP, v.HostName, v.Role.String(), v.Mode, v.Alived, !v.Unschedulable, ready)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//NewCmdNode NewCmdNode
|
||||||
func NewCmdNode() cli.Command {
|
func NewCmdNode() cli.Command {
|
||||||
c := cli.Command{
|
c := cli.Command{
|
||||||
Name: "node",
|
Name: "node",
|
||||||
@ -168,28 +158,20 @@ func NewCmdNode() cli.Command {
|
|||||||
list, err := clients.NodeClient.Nodes().List()
|
list, err := clients.NodeClient.Nodes().List()
|
||||||
handleErr(err)
|
handleErr(err)
|
||||||
serviceTable := termtables.CreateTable()
|
serviceTable := termtables.CreateTable()
|
||||||
serviceTable.AddHeaders("Uid", "IP", "HostName", "NodeRole", "NodeMode", "Alived", "Schedulable", "Ready")
|
serviceTable.AddHeaders("Uid", "IP", "HostName", "NodeRole", "NodeMode", "Status", "Alived", "Schedulable", "Ready")
|
||||||
var rest []*model.HostNode
|
var rest []*model.HostNode
|
||||||
for _, v := range list {
|
for _, v := range list {
|
||||||
var ready bool=false
|
|
||||||
if isNodeReady(v){
|
|
||||||
ready=true
|
|
||||||
}
|
|
||||||
if v.Role.HasRule("manage") {
|
if v.Role.HasRule("manage") {
|
||||||
handleStatus(serviceTable,ready,v)
|
handleStatus(serviceTable, isNodeReady(v), v)
|
||||||
}else{
|
} else {
|
||||||
rest=append(rest,v)
|
rest = append(rest, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(rest) > 0 {
|
if len(rest) > 0 {
|
||||||
serviceTable.AddSeparator()
|
serviceTable.AddSeparator()
|
||||||
}
|
}
|
||||||
for _, v := range rest {
|
for _, v := range rest {
|
||||||
var ready bool = false
|
handleStatus(serviceTable, isNodeReady(v), v)
|
||||||
if v.NodeStatus != nil {
|
|
||||||
ready = true
|
|
||||||
}
|
|
||||||
handleStatus(serviceTable, ready, v)
|
|
||||||
}
|
}
|
||||||
fmt.Println(serviceTable.Render())
|
fmt.Println(serviceTable.Render())
|
||||||
return nil
|
return nil
|
||||||
@ -376,7 +358,7 @@ func NewCmdNode() cli.Command {
|
|||||||
|
|
||||||
var hostNode *model.HostNode
|
var hostNode *model.HostNode
|
||||||
timer := time.NewTimer(15 * time.Second)
|
timer := time.NewTimer(15 * time.Second)
|
||||||
gotNode:=false
|
gotNode := false
|
||||||
for !gotNode {
|
for !gotNode {
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
list, err := clients.NodeClient.Nodes().List()
|
list, err := clients.NodeClient.Nodes().List()
|
||||||
@ -385,7 +367,7 @@ func NewCmdNode() cli.Command {
|
|||||||
if node.InternalIP == v.InternalIP {
|
if node.InternalIP == v.InternalIP {
|
||||||
hostNode = v
|
hostNode = v
|
||||||
timer.Stop()
|
timer.Stop()
|
||||||
gotNode=true
|
gotNode = true
|
||||||
//todo 初始化其它节点失败判定
|
//todo 初始化其它节点失败判定
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -405,13 +387,13 @@ func NewCmdNode() cli.Command {
|
|||||||
default:
|
default:
|
||||||
for _, v := range list {
|
for _, v := range list {
|
||||||
if node.InternalIP == v.InternalIP {
|
if node.InternalIP == v.InternalIP {
|
||||||
hostNode=v
|
hostNode = v
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, val := range hostNode.Conditions {
|
for _, val := range hostNode.Conditions {
|
||||||
fmt.Println("正在判断节点状态,请稍等")
|
fmt.Println("正在判断节点状态,请稍等")
|
||||||
if hostNode.Alived||(val.Type==model.NodeInit&&val.Status==model.ConditionTrue) {
|
if hostNode.Alived || (val.Type == model.NodeInit && val.Status == model.ConditionTrue) {
|
||||||
fmt.Printf("节点 %s 初始化成功", hostNode.ID)
|
fmt.Printf("节点 %s 初始化成功", hostNode.ID)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
header = append(header, string(val.Type))
|
header = append(header, string(val.Type))
|
||||||
|
Loading…
Reference in New Issue
Block a user