Show remote host info and proper progress
parent
39218369c0
commit
d51443bee1
|
@ -851,7 +851,7 @@ func validateUser(drvName string) {
|
|||
|
||||
// memoryLimits returns the amount of memory allocated to the system and hypervisor, the return value is in MiB
|
||||
func memoryLimits(drvName string) (int, int, error) {
|
||||
info, cpuErr, memErr, diskErr := machine.CachedHostInfo()
|
||||
info, cpuErr, memErr, diskErr := machine.LocalHostInfo()
|
||||
if cpuErr != nil {
|
||||
klog.Warningf("could not get system cpu info while verifying memory limits, which might be okay: %v", cpuErr)
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ package machine
|
|||
import (
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/machine/libmachine/provision"
|
||||
"github.com/shirou/gopsutil/cpu"
|
||||
|
@ -39,8 +41,8 @@ type HostInfo struct {
|
|||
DiskSize int64
|
||||
}
|
||||
|
||||
// CachedHostInfo returns system information such as memory,CPU, DiskSize
|
||||
func CachedHostInfo() (*HostInfo, error, error, error) {
|
||||
// LocalHostInfo returns system information such as memory,CPU, DiskSize
|
||||
func LocalHostInfo() (*HostInfo, error, error, error) {
|
||||
var cpuErr, memErr, diskErr error
|
||||
i, cpuErr := cachedCPUInfo()
|
||||
if cpuErr != nil {
|
||||
|
@ -63,6 +65,43 @@ func CachedHostInfo() (*HostInfo, error, error, error) {
|
|||
return &info, cpuErr, memErr, diskErr
|
||||
}
|
||||
|
||||
// RemoteHostInfo returns system information such as memory,CPU, DiskSize
|
||||
func RemoteHostInfo(r command.Runner) (*HostInfo, error, error, error) {
|
||||
rr, cpuErr := r.RunCmd(exec.Command("nproc"))
|
||||
if cpuErr != nil {
|
||||
klog.Warningf("Unable to get CPU info: %v", cpuErr)
|
||||
}
|
||||
nproc := rr.Stdout.String()
|
||||
ncpus, err := strconv.Atoi(strings.TrimSpace(nproc))
|
||||
if err != nil {
|
||||
klog.Warningf("Failed to parse CPU info: %v", err)
|
||||
}
|
||||
rr, memErr := r.RunCmd(exec.Command("free", "-m"))
|
||||
if memErr != nil {
|
||||
klog.Warningf("Unable to get mem info: %v", memErr)
|
||||
}
|
||||
free := rr.Stdout.String()
|
||||
memory, err := parseMemFree(free)
|
||||
if err != nil {
|
||||
klog.Warningf("Unable to parse mem info: %v", err)
|
||||
}
|
||||
rr, diskErr := r.RunCmd(exec.Command("df", "-m"))
|
||||
if diskErr != nil {
|
||||
klog.Warningf("Unable to get disk info: %v", diskErr)
|
||||
}
|
||||
df := rr.Stdout.String()
|
||||
disksize, err := parseDiskFree(df)
|
||||
if err != nil {
|
||||
klog.Warningf("Unable to parse disk info: %v", err)
|
||||
}
|
||||
|
||||
var info HostInfo
|
||||
info.CPUs = ncpus
|
||||
info.Memory = memory
|
||||
info.DiskSize = disksize
|
||||
return &info, cpuErr, memErr, diskErr
|
||||
}
|
||||
|
||||
// showLocalOsRelease shows systemd information about the current linux distribution, on the local host
|
||||
func showLocalOsRelease() {
|
||||
osReleaseOut, err := ioutil.ReadFile("/etc/os-release")
|
||||
|
@ -150,3 +189,44 @@ func cachedCPUInfo() ([]cpu.InfoStat, error) {
|
|||
}
|
||||
return *cachedCPU, *cachedCPUErr
|
||||
}
|
||||
|
||||
// ParseMemFree parses the output of the `free -m` command
|
||||
func parseMemFree(out string) (int64, error) {
|
||||
// total used free shared buff/cache available
|
||||
//Mem: 1987 706 194 1 1086 1173
|
||||
//Swap: 0 0 0
|
||||
outlines := strings.Split(out, "\n")
|
||||
l := len(outlines)
|
||||
for _, line := range outlines[1 : l-1] {
|
||||
parsedLine := strings.Fields(line)
|
||||
t, err := strconv.ParseInt(parsedLine[1], 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
m := strings.Trim(parsedLine[0], ":")
|
||||
if m == "Mem" {
|
||||
return t, nil
|
||||
}
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// ParseDiskFree parses the output of the `df -m` command
|
||||
func parseDiskFree(out string) (int64, error) {
|
||||
// Filesystem 1M-blocks Used Available Use% Mounted on
|
||||
// /dev/sda1 39643 3705 35922 10% /
|
||||
outlines := strings.Split(out, "\n")
|
||||
l := len(outlines)
|
||||
for _, line := range outlines[1 : l-1] {
|
||||
parsedLine := strings.Fields(line)
|
||||
t, err := strconv.ParseInt(parsedLine[1], 10, 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
m := parsedLine[5]
|
||||
if m == "/" {
|
||||
return t, nil
|
||||
}
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
|
|
@ -129,7 +129,10 @@ func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) (
|
|||
klog.Infof("duration metric: createHost completed in %s", time.Since(start))
|
||||
}()
|
||||
|
||||
showHostInfo(*cfg)
|
||||
if cfg.Driver != driver.Generic {
|
||||
showHostInfo(nil, *cfg)
|
||||
}
|
||||
|
||||
def := registry.Driver(cfg.Driver)
|
||||
if def.Empty() {
|
||||
return nil, fmt.Errorf("unsupported/missing driver: %s", cfg.Driver)
|
||||
|
@ -163,6 +166,9 @@ func createHost(api libmachine.API, cfg *config.ClusterConfig, n *config.Node) (
|
|||
return nil, errors.Wrap(err, "creating host")
|
||||
}
|
||||
klog.Infof("duration metric: libmachine.API.Create for %q took %s", cfg.Name, time.Since(cstart))
|
||||
if cfg.Driver == driver.Generic {
|
||||
showHostInfo(h, *cfg)
|
||||
}
|
||||
|
||||
if err := postStartSetup(h, *cfg); err != nil {
|
||||
return h, errors.Wrap(err, "post-start")
|
||||
|
@ -320,16 +326,29 @@ func acquireMachinesLock(name string, drv string) (mutex.Releaser, error) {
|
|||
}
|
||||
|
||||
// showHostInfo shows host information
|
||||
func showHostInfo(cfg config.ClusterConfig) {
|
||||
func showHostInfo(h *host.Host, cfg config.ClusterConfig) {
|
||||
machineType := driver.MachineType(cfg.Driver)
|
||||
if driver.BareMetal(cfg.Driver) {
|
||||
info, cpuErr, memErr, DiskErr := CachedHostInfo()
|
||||
info, cpuErr, memErr, DiskErr := LocalHostInfo()
|
||||
if cpuErr == nil && memErr == nil && DiskErr == nil {
|
||||
register.Reg.SetStep(register.RunningLocalhost)
|
||||
out.Step(style.StartingNone, "Running on localhost (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize})
|
||||
}
|
||||
return
|
||||
}
|
||||
if cfg.Driver == driver.Generic {
|
||||
r, err := CommandRunner(h)
|
||||
if err != nil {
|
||||
klog.Warningf("error getting command runner: %v", err)
|
||||
return
|
||||
}
|
||||
info, cpuErr, memErr, DiskErr := RemoteHostInfo(r)
|
||||
if cpuErr == nil && memErr == nil && DiskErr == nil {
|
||||
register.Reg.SetStep(register.RunningRemotely)
|
||||
out.Step(style.StartingGeneric, "Running remotely (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB, Disk={{.disk_size}}MB) ...", out.V{"number_of_cpus": info.CPUs, "memory_size": info.Memory, "disk_size": info.DiskSize})
|
||||
}
|
||||
return
|
||||
}
|
||||
if driver.IsKIC(cfg.Driver) { // TODO:medyagh add free disk space on docker machine
|
||||
register.Reg.SetStep(register.CreatingContainer)
|
||||
out.Step(style.StartingVM, "Creating {{.driver_name}} {{.machine_type}} (CPUs={{.number_of_cpus}}, Memory={{.memory_size}}MB) ...", out.V{"driver_name": cfg.Driver, "number_of_cpus": cfg.CPUs, "memory_size": cfg.Memory, "machine_type": machineType})
|
||||
|
|
|
@ -32,6 +32,7 @@ const (
|
|||
StartingNode RegStep = "Starting Node"
|
||||
PullingBaseImage RegStep = "Pulling Base Image"
|
||||
RunningLocalhost RegStep = "Running on Localhost"
|
||||
RunningRemotely RegStep = "Running Remotely"
|
||||
LocalOSRelease RegStep = "Local OS Release"
|
||||
CreatingContainer RegStep = "Creating Container"
|
||||
CreatingVM RegStep = "Creating VM"
|
||||
|
@ -79,6 +80,7 @@ func init() {
|
|||
LocalOSRelease,
|
||||
CreatingContainer,
|
||||
CreatingVM,
|
||||
RunningRemotely,
|
||||
PreparingKubernetes,
|
||||
PreparingKubernetesCerts,
|
||||
PreparingKubernetesControlPlane,
|
||||
|
|
|
@ -126,6 +126,7 @@ var Config = map[Enum]Options{
|
|||
Resetting: {Prefix: "🔄 "},
|
||||
Shutdown: {Prefix: "🛑 "},
|
||||
StartingNone: {Prefix: "🤹 "},
|
||||
StartingGeneric: {Prefix: "🔗 "},
|
||||
StartingVM: {Prefix: "🔥 ", OmitNewline: true, Spinner: true},
|
||||
SubStep: {Prefix: " ▪ ", LowPrefix: LowIndent, OmitNewline: true, Spinner: true}, // Indented bullet
|
||||
Tip: {Prefix: "💡 "},
|
||||
|
|
|
@ -81,6 +81,7 @@ const (
|
|||
Shutdown
|
||||
Sparkle
|
||||
StartingNone
|
||||
StartingGeneric
|
||||
StartingVM
|
||||
Stopped
|
||||
Stopping
|
||||
|
|
Loading…
Reference in New Issue