Пример #1
0
func Status() (v1.DockerStatus, error) {
	client, err := Client()
	if err != nil {
		return v1.DockerStatus{}, fmt.Errorf("unable to communicate with docker daemon: %v", err)
	}
	dockerInfo, err := client.Info(context.Background())
	if err != nil {
		return v1.DockerStatus{}, err
	}

	out := v1.DockerStatus{}
	out.Version = VersionString()
	out.KernelVersion = machine.KernelVersion()
	out.OS = dockerInfo.OperatingSystem
	out.Hostname = dockerInfo.Name
	out.RootDir = dockerInfo.DockerRootDir
	out.Driver = dockerInfo.Driver
	out.ExecDriver = dockerInfo.ExecutionDriver
	out.NumImages = dockerInfo.Images
	out.NumContainers = dockerInfo.Containers
	out.DriverStatus = make(map[string]string, len(dockerInfo.DriverStatus))
	for _, v := range dockerInfo.DriverStatus {
		out.DriverStatus[v[0]] = v[1]
	}
	return out, nil
}
Пример #2
0
func (m *manager) HyperInfo() (info.DockerStatus, error) {
	hyperClient := hyper.NewHyperClient()
	hyperInfo, err := hyperClient.Info()
	if err != nil {
		return info.DockerStatus{}, err
	}

	hyperVersion, err := hyperClient.Version()
	if err != nil {
		return info.DockerStatus{}, err
	}

	out := info.DockerStatus{
		Version:      hyperVersion,
		DriverStatus: make(map[string]string),
	}
	if val, ok := hyperInfo["KernelVersion"]; ok {
		out.KernelVersion = val.(string)
	}
	if val, ok := hyperInfo["OperatingSystem"]; ok {
		out.OS = val.(string)
	}
	if val, ok := hyperInfo["Name"]; ok {
		out.Hostname = val.(string)
	}
	if val, ok := hyperInfo["DockerRootDir"]; ok {
		out.RootDir = val.(string)
	}
	if val, ok := hyperInfo["Driver"]; ok {
		out.Driver = val.(string)
	}
	if val, ok := hyperInfo["ExecutionDriver"]; ok {
		out.ExecDriver = val.(string)
	}
	if val, ok := hyperInfo["Images"]; ok {
		out.NumImages = int(val.(float64))
	}
	if val, ok := hyperInfo["Containers"]; ok {
		out.NumContainers = int(val.(float64))
	}
	if val, ok := hyperInfo["DriverStatus"]; ok {
		for _, value := range val.([]interface{}) {
			v := value.([]interface{})
			out.DriverStatus[v[0].(string)] = v[1].(string)
		}
	}
	return out, nil
}