github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/varlinkapi/system.go (about) 1 // +build varlink 2 3 package varlinkapi 4 5 import ( 6 "context" 7 "fmt" 8 "os" 9 goruntime "runtime" 10 "strconv" 11 "time" 12 13 "github.com/containers/image/v5/pkg/sysregistriesv2" 14 "github.com/containers/podman/v2/libpod/define" 15 iopodman "github.com/containers/podman/v2/pkg/varlink" 16 "github.com/sirupsen/logrus" 17 ) 18 19 // GetVersion ... 20 func (i *VarlinkAPI) GetVersion(call iopodman.VarlinkCall) error { 21 versionInfo, err := define.GetVersion() 22 if err != nil { 23 return call.ReplyErrorOccurred(err.Error()) 24 } 25 26 int64APIVersion, err := strconv.ParseInt(versionInfo.APIVersion, 10, 64) 27 if err != nil { 28 return call.ReplyErrorOccurred(err.Error()) 29 } 30 31 return call.ReplyGetVersion( 32 versionInfo.Version, 33 versionInfo.GoVersion, 34 versionInfo.GitCommit, 35 time.Unix(versionInfo.Built, 0).Format(time.RFC3339), 36 versionInfo.OsArch, 37 int64APIVersion, 38 ) 39 } 40 41 // GetInfo returns details about the podman host and its stores 42 func (i *VarlinkAPI) GetInfo(call iopodman.VarlinkCall) error { 43 versionInfo, err := define.GetVersion() 44 if err != nil { 45 return err 46 } 47 podmanInfo := iopodman.PodmanInfo{} 48 info, err := i.Runtime.Info() 49 if err != nil { 50 return call.ReplyErrorOccurred(err.Error()) 51 } 52 53 distribution := iopodman.InfoDistribution{ 54 Distribution: info.Host.Distribution.Distribution, 55 Version: info.Host.Distribution.Version, 56 } 57 infoHost := iopodman.InfoHost{ 58 Buildah_version: info.Host.BuildahVersion, 59 Distribution: distribution, 60 Mem_free: info.Host.MemFree, 61 Mem_total: info.Host.MemTotal, 62 Swap_free: info.Host.SwapFree, 63 Swap_total: info.Host.SwapTotal, 64 Arch: info.Host.Arch, 65 Cpus: int64(info.Host.CPUs), 66 Hostname: info.Host.Hostname, 67 Kernel: info.Host.Kernel, 68 Os: info.Host.OS, 69 Uptime: info.Host.Uptime, 70 Eventlogger: info.Host.EventLogger, 71 } 72 podmanInfo.Host = infoHost 73 pmaninfo := iopodman.InfoPodmanBinary{ 74 Compiler: goruntime.Compiler, 75 Go_version: goruntime.Version(), 76 Podman_version: versionInfo.Version, 77 Git_commit: versionInfo.GitCommit, 78 } 79 80 graphStatus := iopodman.InfoGraphStatus{ 81 Backing_filesystem: info.Store.GraphStatus["Backing Filesystem"], 82 Native_overlay_diff: info.Store.GraphStatus["Native Overlay Diff"], 83 Supports_d_type: info.Store.GraphStatus["Supports d_type"], 84 } 85 infoStore := iopodman.InfoStore{ 86 Graph_driver_name: info.Store.GraphDriverName, 87 Containers: int64(info.Store.ContainerStore.Number), 88 Images: int64(info.Store.ImageStore.Number), 89 Run_root: info.Store.RunRoot, 90 Graph_root: info.Store.GraphRoot, 91 Graph_driver_options: fmt.Sprintf("%v", info.Store.GraphOptions), 92 Graph_status: graphStatus, 93 } 94 95 // Registry information if any is stored as the second list item 96 for key, val := range info.Registries { 97 if key == "search" { 98 podmanInfo.Registries.Search = val.([]string) 99 continue 100 } 101 regData := val.(sysregistriesv2.Registry) 102 if regData.Insecure { 103 podmanInfo.Registries.Insecure = append(podmanInfo.Registries.Insecure, key) 104 } 105 if regData.Blocked { 106 podmanInfo.Registries.Blocked = append(podmanInfo.Registries.Blocked, key) 107 } 108 } 109 podmanInfo.Store = infoStore 110 podmanInfo.Podman = pmaninfo 111 return call.ReplyGetInfo(podmanInfo) 112 } 113 114 // GetVersion ... 115 func (i *VarlinkAPI) Reset(call iopodman.VarlinkCall) error { 116 if err := i.Runtime.Reset(context.TODO()); err != nil { 117 logrus.Errorf("Reset Failed: %v", err) 118 if err := call.ReplyErrorOccurred(err.Error()); err != nil { 119 logrus.Errorf("Failed to send ReplyErrorOccurred: %v", err) 120 } 121 os.Exit(define.ExecErrorCodeGeneric) 122 } 123 if err := call.ReplyReset(); err != nil { 124 logrus.Errorf("Failed to send ReplyReset: %v", err) 125 os.Exit(define.ExecErrorCodeGeneric) 126 } 127 os.Exit(0) 128 return nil 129 }