github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/pkg/domain/entities/pods.go (about) 1 package entities 2 3 import ( 4 "errors" 5 "strings" 6 "time" 7 8 "github.com/containers/podman/v2/libpod/define" 9 "github.com/containers/podman/v2/pkg/specgen" 10 ) 11 12 type PodKillOptions struct { 13 All bool 14 Latest bool 15 Signal string 16 } 17 18 type PodKillReport struct { 19 Errs []error 20 Id string //nolint 21 } 22 23 type ListPodsReport struct { 24 Cgroup string 25 Containers []*ListPodContainer 26 Created time.Time 27 Id string //nolint 28 InfraId string //nolint 29 Name string 30 Namespace string 31 Status string 32 Labels map[string]string 33 } 34 35 type ListPodContainer struct { 36 Id string //nolint 37 Names string 38 Status string 39 } 40 41 type PodPauseOptions struct { 42 All bool 43 Latest bool 44 } 45 46 type PodPauseReport struct { 47 Errs []error 48 Id string //nolint 49 } 50 51 type PodunpauseOptions struct { 52 All bool 53 Latest bool 54 } 55 56 type PodUnpauseReport struct { 57 Errs []error 58 Id string //nolint 59 } 60 61 type PodStopOptions struct { 62 All bool 63 Ignore bool 64 Latest bool 65 Timeout int 66 } 67 68 type PodStopReport struct { 69 Errs []error 70 Id string //nolint 71 } 72 73 type PodRestartOptions struct { 74 All bool 75 Latest bool 76 } 77 78 type PodRestartReport struct { 79 Errs []error 80 Id string //nolint 81 } 82 83 type PodStartOptions struct { 84 All bool 85 Latest bool 86 } 87 88 type PodStartReport struct { 89 Errs []error 90 Id string //nolint 91 } 92 93 type PodRmOptions struct { 94 All bool 95 Force bool 96 Ignore bool 97 Latest bool 98 } 99 100 type PodRmReport struct { 101 Err error 102 Id string //nolint 103 } 104 105 type PodCreateOptions struct { 106 CGroupParent string 107 CreateCommand []string 108 Hostname string 109 Infra bool 110 InfraImage string 111 InfraCommand string 112 InfraConmonPidFile string 113 Labels map[string]string 114 Name string 115 Net *NetOptions 116 Share []string 117 } 118 119 type PodCreateReport struct { 120 Id string //nolint 121 } 122 123 func (p PodCreateOptions) ToPodSpecGen(s *specgen.PodSpecGenerator) { 124 // Basic Config 125 s.Name = p.Name 126 s.Hostname = p.Hostname 127 s.Labels = p.Labels 128 s.NoInfra = !p.Infra 129 if len(p.InfraCommand) > 0 { 130 s.InfraCommand = strings.Split(p.InfraCommand, " ") 131 } 132 if len(p.InfraConmonPidFile) > 0 { 133 s.InfraConmonPidFile = p.InfraConmonPidFile 134 } 135 s.InfraImage = p.InfraImage 136 s.SharedNamespaces = p.Share 137 s.PodCreateCommand = p.CreateCommand 138 139 // Networking config 140 s.NetNS = p.Net.Network 141 s.StaticIP = p.Net.StaticIP 142 s.StaticMAC = p.Net.StaticMAC 143 s.PortMappings = p.Net.PublishPorts 144 s.CNINetworks = p.Net.CNINetworks 145 s.NetworkOptions = p.Net.NetworkOptions 146 if p.Net.UseImageResolvConf { 147 s.NoManageResolvConf = true 148 } 149 s.DNSServer = p.Net.DNSServers 150 s.DNSSearch = p.Net.DNSSearch 151 s.DNSOption = p.Net.DNSOptions 152 s.NoManageHosts = p.Net.NoHosts 153 s.HostAdd = p.Net.AddHosts 154 155 // Cgroup 156 s.CgroupParent = p.CGroupParent 157 } 158 159 type PodPruneOptions struct { 160 Force bool `json:"force" schema:"force"` 161 } 162 163 type PodPruneReport struct { 164 Err error 165 Id string //nolint 166 } 167 168 type PodTopOptions struct { 169 // CLI flags. 170 ListDescriptors bool 171 Latest bool 172 173 // Options for the API. 174 Descriptors []string 175 NameOrID string 176 } 177 178 type PodPSOptions struct { 179 CtrNames bool 180 CtrIds bool 181 CtrStatus bool 182 Filters map[string][]string 183 Format string 184 Latest bool 185 Namespace bool 186 Quiet bool 187 Sort string 188 } 189 190 type PodInspectOptions struct { 191 Latest bool 192 193 // Options for the API. 194 NameOrID string 195 196 Format string 197 } 198 199 type PodInspectReport struct { 200 *define.InspectPodData 201 } 202 203 // PodStatsOptions are options for the pod stats command. 204 type PodStatsOptions struct { 205 // All - provide stats for all running pods. 206 All bool 207 // Latest - provide stats for the latest pod. 208 Latest bool 209 } 210 211 // PodStatsReport includes pod-resource statistics data. 212 type PodStatsReport struct { 213 CPU string 214 MemUsage string 215 Mem string 216 NetIO string 217 BlockIO string 218 PIDS string 219 Pod string 220 CID string 221 Name string 222 } 223 224 // ValidatePodStatsOptions validates the specified slice and options. Allows 225 // for sharing code in the front- and the back-end. 226 func ValidatePodStatsOptions(args []string, options *PodStatsOptions) error { 227 num := 0 228 if len(args) > 0 { 229 num++ 230 } 231 if options.All { 232 num++ 233 } 234 if options.Latest { 235 num++ 236 } 237 switch num { 238 case 0: 239 // Podman v1 compat: if nothing's specified get all running 240 // pods. 241 options.All = true 242 return nil 243 case 1: 244 return nil 245 default: 246 return errors.New("--all, --latest and arguments cannot be used together") 247 } 248 }