summaryrefslogtreecommitdiff
path: root/pkg/domain/entities
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2020-03-12 10:49:03 -0700
committerJhon Honce <jhonce@redhat.com>2020-03-18 16:41:12 -0700
commitfbe743501e2a3ea28fe446754b9b12988b4e7a0e (patch)
tree7582c99d828bcbc83b6bb312e253f006ac637734 /pkg/domain/entities
parentbd9386ddac4ef6730fbe6ce4104e80f56a48fe43 (diff)
downloadpodman-fbe743501e2a3ea28fe446754b9b12988b4e7a0e.tar.gz
podman-fbe743501e2a3ea28fe446754b9b12988b4e7a0e.tar.bz2
podman-fbe743501e2a3ea28fe446754b9b12988b4e7a0e.zip
V2 podman command
Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'pkg/domain/entities')
-rw-r--r--pkg/domain/entities/containers.go1
-rw-r--r--pkg/domain/entities/engine.go97
-rw-r--r--pkg/domain/entities/engine_container.go26
-rw-r--r--pkg/domain/entities/engine_image.go12
-rw-r--r--pkg/domain/entities/filters.go150
-rw-r--r--pkg/domain/entities/images.go151
-rw-r--r--pkg/domain/entities/types.go25
7 files changed, 462 insertions, 0 deletions
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go
new file mode 100644
index 000000000..1899b98f7
--- /dev/null
+++ b/pkg/domain/entities/containers.go
@@ -0,0 +1 @@
+package entities
diff --git a/pkg/domain/entities/engine.go b/pkg/domain/entities/engine.go
new file mode 100644
index 000000000..a1096f1f1
--- /dev/null
+++ b/pkg/domain/entities/engine.go
@@ -0,0 +1,97 @@
+package entities
+
+import (
+ "net/url"
+ "os/user"
+ "path/filepath"
+
+ "github.com/containers/libpod/libpod/define"
+ "github.com/spf13/pflag"
+)
+
+type EngineMode string
+
+const (
+ ABIMode = EngineMode("abi")
+ TunnelMode = EngineMode("tunnel")
+)
+
+func (m EngineMode) String() string {
+ return string(m)
+}
+
+type EngineOptions struct {
+ Uri *url.URL
+ Identities []string
+ FlagSet pflag.FlagSet
+ Flags EngineFlags
+}
+
+type EngineFlags struct {
+ CGroupManager string
+ CniConfigDir string
+ ConmonPath string
+ DefaultMountsFile string
+ EventsBackend string
+ HooksDir []string
+ MaxWorks int
+ Namespace string
+ Root string
+ Runroot string
+ Runtime string
+ StorageDriver string
+ StorageOpts []string
+ Syslog bool
+ Trace bool
+ NetworkCmdPath string
+
+ Config string
+ CpuProfile string
+ LogLevel string
+ TmpDir string
+
+ RemoteUserName string
+ RemoteHost string
+ VarlinkAddress string
+ ConnectionName string
+ RemoteConfigFilePath string
+ Port int
+ IdentityFile string
+ IgnoreHosts bool
+
+ EngineMode EngineMode
+}
+
+func NewEngineOptions() (EngineFlags, error) {
+ u, _ := user.Current()
+ return EngineFlags{
+ CGroupManager: define.SystemdCgroupsManager,
+ CniConfigDir: "",
+ Config: "",
+ ConmonPath: filepath.Join("usr", "bin", "conmon"),
+ ConnectionName: "",
+ CpuProfile: "",
+ DefaultMountsFile: "",
+ EventsBackend: "",
+ HooksDir: nil,
+ IdentityFile: "",
+ IgnoreHosts: false,
+ LogLevel: "",
+ MaxWorks: 0,
+ Namespace: "",
+ NetworkCmdPath: "",
+ Port: 0,
+ RemoteConfigFilePath: "",
+ RemoteHost: "",
+ RemoteUserName: "",
+ Root: "",
+ Runroot: filepath.Join("run", "user", u.Uid),
+ Runtime: "",
+ StorageDriver: "overlayfs",
+ StorageOpts: nil,
+ Syslog: false,
+ TmpDir: filepath.Join("run", "user", u.Uid, "libpod", "tmp"),
+ Trace: false,
+ VarlinkAddress: "",
+ }, nil
+}
diff --git a/pkg/domain/entities/engine_container.go b/pkg/domain/entities/engine_container.go
new file mode 100644
index 000000000..d08f37d44
--- /dev/null
+++ b/pkg/domain/entities/engine_container.go
@@ -0,0 +1,26 @@
+package entities
+
+import (
+ "context"
+)
+
+type ContainerEngine interface {
+ ContainerRuntime
+ PodRuntime
+ VolumeRuntime
+}
+
+type ContainerRuntime interface {
+ ContainerDelete(ctx context.Context, opts ContainerDeleteOptions) (*ContainerDeleteReport, error)
+ ContainerPrune(ctx context.Context) (*ContainerPruneReport, error)
+}
+
+type PodRuntime interface {
+ PodDelete(ctx context.Context, opts PodPruneOptions) (*PodDeleteReport, error)
+ PodPrune(ctx context.Context) (*PodPruneReport, error)
+}
+
+type VolumeRuntime interface {
+ VolumeDelete(ctx context.Context, opts VolumeDeleteOptions) (*VolumeDeleteReport, error)
+ VolumePrune(ctx context.Context) (*VolumePruneReport, error)
+}
diff --git a/pkg/domain/entities/engine_image.go b/pkg/domain/entities/engine_image.go
new file mode 100644
index 000000000..27676d781
--- /dev/null
+++ b/pkg/domain/entities/engine_image.go
@@ -0,0 +1,12 @@
+package entities
+
+import (
+ "context"
+)
+
+type ImageEngine interface {
+ Delete(ctx context.Context, nameOrId string, opts ImageDeleteOptions) (*ImageDeleteReport, error)
+ History(ctx context.Context, nameOrId string, opts ImageHistoryOptions) (*ImageHistoryReport, error)
+ List(ctx context.Context, opts ImageListOptions) (*ImageListReport, error)
+ Prune(ctx context.Context, opts ImagePruneOptions) (*ImagePruneReport, error)
+}
diff --git a/pkg/domain/entities/filters.go b/pkg/domain/entities/filters.go
new file mode 100644
index 000000000..c7e227244
--- /dev/null
+++ b/pkg/domain/entities/filters.go
@@ -0,0 +1,150 @@
+package entities
+
+import (
+ "net/url"
+ "strings"
+)
+
+// Identifier interface allows filters to access ID() of object
+type Identifier interface {
+ Id() string
+}
+
+// Named interface allows filters to access Name() of object
+type Named interface {
+ Name() string
+}
+
+// Named interface allows filters to access Name() of object
+type Names interface {
+ Names() []string
+}
+
+// IdOrName interface allows filters to access ID() or Name() of object
+type IdOrNamed interface {
+ Identifier
+ Named
+}
+
+// IdOrName interface allows filters to access ID() or Names() of object
+type IdOrNames interface {
+ Identifier
+ Names
+}
+
+type ImageFilter func(Image) bool
+type VolumeFilter func(Volume) bool
+type ContainerFilter func(Container) bool
+
+func CompileImageFilters(filters url.Values) ImageFilter {
+ var fns []interface{}
+
+ for name, targets := range filters {
+ switch name {
+ case "id":
+ fns = append(fns, FilterIdFn(targets))
+ case "name":
+ fns = append(fns, FilterNamesFn(targets))
+ case "idOrName":
+ fns = append(fns, FilterIdOrNameFn(targets))
+ }
+ }
+
+ return func(image Image) bool {
+ for _, fn := range fns {
+ if !fn.(ImageFilter)(image) {
+ return false
+ }
+ }
+ return true
+ }
+}
+
+func CompileContainerFilters(filters url.Values) ContainerFilter {
+ var fns []interface{}
+
+ for name, targets := range filters {
+ switch name {
+ case "id":
+ fns = append(fns, FilterIdFn(targets))
+ case "name":
+ fns = append(fns, FilterNameFn(targets))
+ case "idOrName":
+ fns = append(fns, FilterIdOrNameFn(targets))
+ }
+ }
+
+ return func(ctnr Container) bool {
+ for _, fn := range fns {
+ if !fn.(ContainerFilter)(ctnr) {
+ return false
+ }
+ }
+ return true
+ }
+}
+
+func CompileVolumeFilters(filters url.Values) VolumeFilter {
+ var fns []interface{}
+
+ for name, targets := range filters {
+ if name == "id" {
+ fns = append(fns, FilterIdFn(targets))
+ }
+ }
+
+ return func(volume Volume) bool {
+ for _, fn := range fns {
+ if !fn.(VolumeFilter)(volume) {
+ return false
+ }
+ }
+ return true
+ }
+}
+
+func FilterIdFn(id []string) func(Identifier) bool {
+ return func(obj Identifier) bool {
+ for _, v := range id {
+ if strings.Contains(obj.Id(), v) {
+ return true
+ }
+ }
+ return false
+ }
+}
+
+func FilterNameFn(name []string) func(Named) bool {
+ return func(obj Named) bool {
+ for _, v := range name {
+ if strings.Contains(obj.Name(), v) {
+ return true
+ }
+ }
+ return false
+ }
+}
+
+func FilterNamesFn(name []string) func(Names) bool {
+ return func(obj Names) bool {
+ for _, v := range name {
+ for _, n := range obj.Names() {
+ if strings.Contains(n, v) {
+ return true
+ }
+ }
+ }
+ return false
+ }
+}
+
+func FilterIdOrNameFn(id []string) func(IdOrNamed) bool {
+ return func(obj IdOrNamed) bool {
+ for _, v := range id {
+ if strings.Contains(obj.Id(), v) || strings.Contains(obj.Name(), v) {
+ return true
+ }
+ }
+ return false
+ }
+}
diff --git a/pkg/domain/entities/images.go b/pkg/domain/entities/images.go
new file mode 100644
index 000000000..c84ed5351
--- /dev/null
+++ b/pkg/domain/entities/images.go
@@ -0,0 +1,151 @@
+package entities
+
+import (
+ "net/url"
+
+ "github.com/containers/image/v5/manifest"
+ docker "github.com/docker/docker/api/types"
+ "github.com/docker/docker/api/types/container"
+ "github.com/opencontainers/go-digest"
+ v1 "github.com/opencontainers/image-spec/specs-go/v1"
+)
+
+type Image struct {
+ IdOrNamed
+ ID string `json:"Id"`
+ RepoTags []string `json:",omitempty"`
+ RepoDigests []string `json:",omitempty"`
+ Parent string `json:",omitempty"`
+ Comment string `json:",omitempty"`
+ Created string `json:",omitempty"`
+ Container string `json:",omitempty"`
+ ContainerConfig *container.Config `json:",omitempty"`
+ DockerVersion string `json:",omitempty"`
+ Author string `json:",omitempty"`
+ Config *container.Config `json:",omitempty"`
+ Architecture string `json:",omitempty"`
+ Variant string `json:",omitempty"`
+ Os string `json:",omitempty"`
+ OsVersion string `json:",omitempty"`
+ Size int64 `json:",omitempty"`
+ VirtualSize int64 `json:",omitempty"`
+ GraphDriver docker.GraphDriverData `json:",omitempty"`
+ RootFS docker.RootFS `json:",omitempty"`
+ Metadata docker.ImageMetadata `json:",omitempty"`
+
+ // Podman extensions
+ Digest digest.Digest `json:",omitempty"`
+ PodmanVersion string `json:",omitempty"`
+ ManifestType string `json:",omitempty"`
+ User string `json:",omitempty"`
+ History []v1.History `json:",omitempty"`
+ NamesHistory []string `json:",omitempty"`
+ HealthCheck *manifest.Schema2HealthConfig `json:",omitempty"`
+}
+
+func (i *Image) Id() string {
+ return i.ID
+}
+
+type ImageSummary struct {
+ Identifier
+ ID string `json:"Id"`
+ ParentId string `json:",omitempty"`
+ RepoTags []string `json:",omitempty"`
+ Created int `json:",omitempty"`
+ Size int `json:",omitempty"`
+ SharedSize int `json:",omitempty"`
+ VirtualSize int `json:",omitempty"`
+ Labels string `json:",omitempty"`
+ Containers int `json:",omitempty"`
+ ReadOnly bool `json:",omitempty"`
+ Dangling bool `json:",omitempty"`
+
+ // Podman extensions
+ Digest digest.Digest `json:",omitempty"`
+ ConfigDigest digest.Digest `json:",omitempty"`
+}
+
+func (i *ImageSummary) Id() string {
+ return i.ID
+}
+
+func (i *ImageSummary) IsReadOnly() bool {
+ return i.ReadOnly
+}
+
+func (i *ImageSummary) IsDangling() bool {
+ return i.Dangling
+}
+
+type ImageOptions struct {
+ All bool
+ Digests bool
+ Filter []string
+ Format string
+ Noheading bool
+ NoTrunc bool
+ Quiet bool
+ Sort string
+ History bool
+}
+
+type ImageDeleteOptions struct {
+ Force bool
+}
+
+// ImageDeleteResponse is the response for removing an image from storage and containers
+// what was untagged vs actually removed
+type ImageDeleteReport struct {
+ Untagged []string `json:"untagged"`
+ Deleted string `json:"deleted"`
+}
+
+type ImageHistoryOptions struct{}
+
+type ImageHistoryLayer struct {
+ ID string `json:"Id"`
+ Created int64 `json:"Created,omitempty"`
+ CreatedBy string `json:",omitempty"`
+ Tags []string `json:",omitempty"`
+ Size int64 `json:",omitempty"`
+ Comment string `json:",omitempty"`
+}
+
+type ImageHistoryReport struct {
+ Layers []ImageHistoryLayer
+}
+
+type ImageInspectOptions struct {
+ TypeObject string `json:",omitempty"`
+ Format string `json:",omitempty"`
+ Size bool `json:",omitempty"`
+ Latest bool `json:",omitempty"`
+}
+
+type ImageListOptions struct {
+ All bool `json:"all" schema:"all"`
+ Digests bool `json:"digests" schema:"digests"`
+ Filter []string `json:",omitempty"`
+ Filters url.Values `json:"filters" schema:"filters"`
+ Format string `json:",omitempty"`
+ History bool `json:",omitempty"`
+ Noheading bool `json:",omitempty"`
+ NoTrunc bool `json:",omitempty"`
+ Quiet bool `json:",omitempty"`
+ Sort string `json:",omitempty"`
+}
+
+type ImageListReport struct {
+ Images []ImageSummary
+}
+
+type ImagePruneOptions struct {
+ All bool
+ Filter ImageFilter
+}
+
+type ImagePruneReport struct {
+ Report Report
+ Size int64
+}
diff --git a/pkg/domain/entities/types.go b/pkg/domain/entities/types.go
new file mode 100644
index 000000000..6f947dc4d
--- /dev/null
+++ b/pkg/domain/entities/types.go
@@ -0,0 +1,25 @@
+package entities
+
+type Container struct {
+ IdOrNamed
+}
+
+type Volume struct {
+ Identifier
+}
+
+type Report struct {
+ Id []string
+ Err map[string]error
+}
+
+type ContainerDeleteOptions struct{}
+type ContainerDeleteReport struct{ Report }
+type ContainerPruneReport struct{ Report }
+
+type PodDeleteReport struct{ Report }
+type PodPruneOptions struct{}
+type PodPruneReport struct{ Report }
+type VolumeDeleteOptions struct{}
+type VolumeDeleteReport struct{ Report }
+type VolumePruneReport struct{ Report }