unexport warnIfSlow func
parent
8a0a210763
commit
038aef6b48
|
@ -234,26 +234,7 @@ func (d *Driver) GetURL() (string, error) {
|
||||||
|
|
||||||
// GetState returns the state that the host is in (running, stopped, etc)
|
// GetState returns the state that the host is in (running, stopped, etc)
|
||||||
func (d *Driver) GetState() (state.State, error) {
|
func (d *Driver) GetState() (state.State, error) {
|
||||||
out, err := oci.WarnIfSlow(d.NodeConfig.OCIBinary, "inspect", "-f", "{{.State.Status}}", d.MachineName)
|
return oci.ContainerStatus(d.OCIBinary, d.MachineName)
|
||||||
if err != nil {
|
|
||||||
return state.Error, err
|
|
||||||
}
|
|
||||||
|
|
||||||
o := strings.TrimSpace(string(out))
|
|
||||||
switch o {
|
|
||||||
case "running":
|
|
||||||
return state.Running, nil
|
|
||||||
case "exited":
|
|
||||||
return state.Stopped, nil
|
|
||||||
case "paused":
|
|
||||||
return state.Paused, nil
|
|
||||||
case "restarting":
|
|
||||||
return state.Starting, nil
|
|
||||||
case "dead":
|
|
||||||
return state.Error, nil
|
|
||||||
default:
|
|
||||||
return state.None, fmt.Errorf("unknown state")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill stops a host forcefully, including any containers that we are managing.
|
// Kill stops a host forcefully, including any containers that we are managing.
|
||||||
|
|
|
@ -232,8 +232,8 @@ func ContainerID(ociBinary string, nameOrID string) (string, error) {
|
||||||
return rr.Stdout.String(), nil
|
return rr.Stdout.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WarnIfSlow runs an oci command, warning about performance issues
|
// warnIfSlow runs an oci command, warning about performance issues
|
||||||
func WarnIfSlow(args ...string) ([]byte, error) {
|
func warnIfSlow(args ...string) ([]byte, error) {
|
||||||
killTime := 19 * time.Second
|
killTime := 19 * time.Second
|
||||||
warnTime := 2 * time.Second
|
warnTime := 2 * time.Second
|
||||||
|
|
||||||
|
@ -268,7 +268,7 @@ func WarnIfSlow(args ...string) ([]byte, error) {
|
||||||
|
|
||||||
// ContainerExists checks if container name exists (either running or exited)
|
// ContainerExists checks if container name exists (either running or exited)
|
||||||
func ContainerExists(ociBin string, name string) (bool, error) {
|
func ContainerExists(ociBin string, name string) (bool, error) {
|
||||||
out, err := WarnIfSlow(ociBin, "ps", "-a", "--format", "{{.Names}}")
|
out, err := warnIfSlow(ociBin, "ps", "-a", "--format", "{{.Names}}")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, errors.Wrapf(err, string(out))
|
return false, errors.Wrapf(err, string(out))
|
||||||
}
|
}
|
||||||
|
@ -431,7 +431,7 @@ func withPortMappings(portMappings []PortMapping) createOpt {
|
||||||
|
|
||||||
// ListContainersByLabel returns all the container names with a specified label
|
// ListContainersByLabel returns all the container names with a specified label
|
||||||
func ListContainersByLabel(ociBinary string, label string) ([]string, error) {
|
func ListContainersByLabel(ociBinary string, label string) ([]string, error) {
|
||||||
stdout, err := WarnIfSlow(ociBinary, "ps", "-a", "--filter", fmt.Sprintf("label=%s", label), "--format", "{{.Names}}")
|
stdout, err := warnIfSlow(ociBinary, "ps", "-a", "--filter", fmt.Sprintf("label=%s", label), "--format", "{{.Names}}")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -466,8 +466,8 @@ func PointToHostDockerDaemon() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContainerStatus returns status of a container running,exited,...
|
// ContainerStatus returns status of a container running,exited,...
|
||||||
func ContainerStatus(ociBin string, name string) (state.State, error) {
|
func ContainerStatus(ociBin string, name string, warnSlow ...bool) (state.State, error) {
|
||||||
out, err := WarnIfSlow(ociBin, "inspect", name, "--format={{.State.Status}}")
|
out, err := warnIfSlow(ociBin, "inspect", name, "--format={{.State.Status}}")
|
||||||
o := strings.TrimSpace(string(out))
|
o := strings.TrimSpace(string(out))
|
||||||
switch o {
|
switch o {
|
||||||
case "running":
|
case "running":
|
||||||
|
|
Loading…
Reference in New Issue