From ba430bfe5ef65d5aa5ffa1fef0087da76aafcc35 Mon Sep 17 00:00:00 2001
From: Brent Baude <bbaude@redhat.com>
Date: Thu, 16 Apr 2020 08:39:34 -0500
Subject: podman v2 remove bloat v2

rid ourseleves of libpod references in v2 client

Signed-off-by: Brent Baude <bbaude@redhat.com>
---
 pkg/api/handlers/compat/containers.go        | 197 ++++++++++++++++++++++++++-
 pkg/api/handlers/compat/swagger.go           |   4 +-
 pkg/api/handlers/compat/unsupported.go       |   4 +-
 pkg/api/handlers/libpod/containers_create.go |   4 +-
 pkg/api/handlers/libpod/pods.go              |   3 +-
 pkg/api/handlers/swagger.go                  | 158 ---------------------
 pkg/api/handlers/swagger/swagger.go          | 159 +++++++++++++++++++++
 pkg/api/handlers/types.go                    | 196 --------------------------
 pkg/api/handlers/utils/containers.go         |  14 +-
 pkg/api/handlers/utils/errors.go             |  26 +---
 pkg/api/server/swagger.go                    |  27 ++--
 11 files changed, 382 insertions(+), 410 deletions(-)
 delete mode 100644 pkg/api/handlers/swagger.go
 create mode 100644 pkg/api/handlers/swagger/swagger.go

(limited to 'pkg/api')

diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go
index 3f6aca502..239e41af4 100644
--- a/pkg/api/handlers/compat/containers.go
+++ b/pkg/api/handlers/compat/containers.go
@@ -2,6 +2,7 @@ package compat
 
 import (
 	"encoding/binary"
+	"encoding/json"
 	"fmt"
 	"net/http"
 	"strconv"
@@ -16,6 +17,9 @@ import (
 	"github.com/containers/libpod/pkg/api/handlers/utils"
 	"github.com/containers/libpod/pkg/signal"
 	"github.com/containers/libpod/pkg/util"
+	"github.com/docker/docker/api/types"
+	"github.com/docker/docker/api/types/container"
+	"github.com/docker/go-connections/nat"
 	"github.com/gorilla/schema"
 	"github.com/pkg/errors"
 	log "github.com/sirupsen/logrus"
@@ -96,7 +100,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
 	// TODO filters still need to be applied
 	var list = make([]*handlers.Container, len(containers))
 	for i, ctnr := range containers {
-		api, err := handlers.LibpodToContainer(ctnr, query.Size)
+		api, err := LibpodToContainer(ctnr, query.Size)
 		if err != nil {
 			utils.InternalServerError(w, err)
 			return
@@ -126,7 +130,7 @@ func GetContainer(w http.ResponseWriter, r *http.Request) {
 		utils.ContainerNotFound(w, name, err)
 		return
 	}
-	api, err := handlers.LibpodToContainerJSON(ctnr, query.Size)
+	api, err := LibpodToContainerJSON(ctnr, query.Size)
 	if err != nil {
 		utils.InternalServerError(w, err)
 		return
@@ -341,3 +345,192 @@ func LogsFromContainer(w http.ResponseWriter, r *http.Request) {
 		}
 	}
 }
+
+func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error) {
+	imageId, imageName := l.Image()
+
+	var (
+		err        error
+		sizeRootFs int64
+		sizeRW     int64
+		state      define.ContainerStatus
+	)
+
+	if state, err = l.State(); err != nil {
+		return nil, err
+	}
+	stateStr := state.String()
+	if stateStr == "configured" {
+		stateStr = "created"
+	}
+
+	if sz {
+		if sizeRW, err = l.RWSize(); err != nil {
+			return nil, err
+		}
+		if sizeRootFs, err = l.RootFsSize(); err != nil {
+			return nil, err
+		}
+	}
+
+	return &handlers.Container{Container: types.Container{
+		ID:         l.ID(),
+		Names:      []string{fmt.Sprintf("/%s", l.Name())},
+		Image:      imageName,
+		ImageID:    imageId,
+		Command:    strings.Join(l.Command(), " "),
+		Created:    l.CreatedTime().Unix(),
+		Ports:      nil,
+		SizeRw:     sizeRW,
+		SizeRootFs: sizeRootFs,
+		Labels:     l.Labels(),
+		State:      stateStr,
+		Status:     "",
+		HostConfig: struct {
+			NetworkMode string `json:",omitempty"`
+		}{
+			"host"},
+		NetworkSettings: nil,
+		Mounts:          nil,
+	},
+		ContainerCreateConfig: types.ContainerCreateConfig{},
+	}, nil
+}
+
+func LibpodToContainerJSON(l *libpod.Container, sz bool) (*types.ContainerJSON, error) {
+	_, imageName := l.Image()
+	inspect, err := l.Inspect(sz)
+	if err != nil {
+		return nil, err
+	}
+	i, err := json.Marshal(inspect.State)
+	if err != nil {
+		return nil, err
+	}
+	state := types.ContainerState{}
+	if err := json.Unmarshal(i, &state); err != nil {
+		return nil, err
+	}
+
+	// docker considers paused to be running
+	if state.Paused {
+		state.Running = true
+	}
+
+	h, err := json.Marshal(inspect.HostConfig)
+	if err != nil {
+		return nil, err
+	}
+	hc := container.HostConfig{}
+	if err := json.Unmarshal(h, &hc); err != nil {
+		return nil, err
+	}
+	g, err := json.Marshal(inspect.GraphDriver)
+	if err != nil {
+		return nil, err
+	}
+	graphDriver := types.GraphDriverData{}
+	if err := json.Unmarshal(g, &graphDriver); err != nil {
+		return nil, err
+	}
+
+	cb := types.ContainerJSONBase{
+		ID:              l.ID(),
+		Created:         l.CreatedTime().String(),
+		Path:            "",
+		Args:            nil,
+		State:           &state,
+		Image:           imageName,
+		ResolvConfPath:  inspect.ResolvConfPath,
+		HostnamePath:    inspect.HostnamePath,
+		HostsPath:       inspect.HostsPath,
+		LogPath:         l.LogPath(),
+		Node:            nil,
+		Name:            fmt.Sprintf("/%s", l.Name()),
+		RestartCount:    0,
+		Driver:          inspect.Driver,
+		Platform:        "linux",
+		MountLabel:      inspect.MountLabel,
+		ProcessLabel:    inspect.ProcessLabel,
+		AppArmorProfile: inspect.AppArmorProfile,
+		ExecIDs:         inspect.ExecIDs,
+		HostConfig:      &hc,
+		GraphDriver:     graphDriver,
+		SizeRw:          inspect.SizeRw,
+		SizeRootFs:      &inspect.SizeRootFs,
+	}
+
+	stopTimeout := int(l.StopTimeout())
+
+	ports := make(nat.PortSet)
+	for p := range inspect.HostConfig.PortBindings {
+		splitp := strings.Split(p, "/")
+		port, err := nat.NewPort(splitp[0], splitp[1])
+		if err != nil {
+			return nil, err
+		}
+		ports[port] = struct{}{}
+	}
+
+	config := container.Config{
+		Hostname:        l.Hostname(),
+		Domainname:      inspect.Config.DomainName,
+		User:            l.User(),
+		AttachStdin:     inspect.Config.AttachStdin,
+		AttachStdout:    inspect.Config.AttachStdout,
+		AttachStderr:    inspect.Config.AttachStderr,
+		ExposedPorts:    ports,
+		Tty:             inspect.Config.Tty,
+		OpenStdin:       inspect.Config.OpenStdin,
+		StdinOnce:       inspect.Config.StdinOnce,
+		Env:             inspect.Config.Env,
+		Cmd:             inspect.Config.Cmd,
+		Healthcheck:     nil,
+		ArgsEscaped:     false,
+		Image:           imageName,
+		Volumes:         nil,
+		WorkingDir:      l.WorkingDir(),
+		Entrypoint:      l.Entrypoint(),
+		NetworkDisabled: false,
+		MacAddress:      "",
+		OnBuild:         nil,
+		Labels:          l.Labels(),
+		StopSignal:      string(l.StopSignal()),
+		StopTimeout:     &stopTimeout,
+		Shell:           nil,
+	}
+
+	m, err := json.Marshal(inspect.Mounts)
+	if err != nil {
+		return nil, err
+	}
+	mounts := []types.MountPoint{}
+	if err := json.Unmarshal(m, &mounts); err != nil {
+		return nil, err
+	}
+
+	networkSettingsDefault := types.DefaultNetworkSettings{
+		EndpointID:          "",
+		Gateway:             "",
+		GlobalIPv6Address:   "",
+		GlobalIPv6PrefixLen: 0,
+		IPAddress:           "",
+		IPPrefixLen:         0,
+		IPv6Gateway:         "",
+		MacAddress:          l.Config().StaticMAC.String(),
+	}
+
+	networkSettings := types.NetworkSettings{
+		NetworkSettingsBase:    types.NetworkSettingsBase{},
+		DefaultNetworkSettings: networkSettingsDefault,
+		Networks:               nil,
+	}
+
+	c := types.ContainerJSON{
+		ContainerJSONBase: &cb,
+		Mounts:            mounts,
+		Config:            &config,
+		NetworkSettings:   &networkSettings,
+	}
+	return &c, nil
+}
diff --git a/pkg/api/handlers/compat/swagger.go b/pkg/api/handlers/compat/swagger.go
index f1aabf987..ce83aa32f 100644
--- a/pkg/api/handlers/compat/swagger.go
+++ b/pkg/api/handlers/compat/swagger.go
@@ -1,7 +1,7 @@
 package compat
 
 import (
-	"github.com/containers/libpod/pkg/api/handlers/utils"
+	"github.com/containers/libpod/pkg/domain/entities"
 	"github.com/containers/storage/pkg/archive"
 )
 
@@ -10,7 +10,7 @@ import (
 type swagCtrCreateResponse struct {
 	// in:body
 	Body struct {
-		utils.ContainerCreateResponse
+		entities.ContainerCreateResponse
 	}
 }
 
diff --git a/pkg/api/handlers/compat/unsupported.go b/pkg/api/handlers/compat/unsupported.go
index d9c3c3f49..55660882f 100644
--- a/pkg/api/handlers/compat/unsupported.go
+++ b/pkg/api/handlers/compat/unsupported.go
@@ -4,6 +4,8 @@ import (
 	"fmt"
 	"net/http"
 
+	"github.com/containers/libpod/pkg/domain/entities"
+
 	"github.com/containers/libpod/pkg/api/handlers/utils"
 	log "github.com/sirupsen/logrus"
 )
@@ -13,5 +15,5 @@ func UnsupportedHandler(w http.ResponseWriter, r *http.Request) {
 	log.Infof("Request Failed: %s", msg)
 
 	utils.WriteJSON(w, http.StatusInternalServerError,
-		utils.ErrorModel{Message: msg})
+		entities.ErrorModel{Message: msg})
 }
diff --git a/pkg/api/handlers/libpod/containers_create.go b/pkg/api/handlers/libpod/containers_create.go
index 38a341a89..f64132d55 100644
--- a/pkg/api/handlers/libpod/containers_create.go
+++ b/pkg/api/handlers/libpod/containers_create.go
@@ -4,6 +4,8 @@ import (
 	"encoding/json"
 	"net/http"
 
+	"github.com/containers/libpod/pkg/domain/entities"
+
 	"github.com/containers/libpod/libpod"
 	"github.com/containers/libpod/pkg/api/handlers/utils"
 	"github.com/containers/libpod/pkg/specgen"
@@ -29,6 +31,6 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
 		utils.InternalServerError(w, err)
 		return
 	}
-	response := utils.ContainerCreateResponse{ID: ctr.ID()}
+	response := entities.ContainerCreateResponse{ID: ctr.ID()}
 	utils.WriteJSON(w, http.StatusCreated, response)
 }
diff --git a/pkg/api/handlers/libpod/pods.go b/pkg/api/handlers/libpod/pods.go
index 81cab1ede..92556bb61 100644
--- a/pkg/api/handlers/libpod/pods.go
+++ b/pkg/api/handlers/libpod/pods.go
@@ -74,8 +74,9 @@ func PodInspect(w http.ResponseWriter, r *http.Request) {
 		utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
 		return
 	}
+
 	report := entities.PodInspectReport{
-		PodInspect: podData,
+		InspectPodData: podData,
 	}
 	utils.WriteResponse(w, http.StatusOK, report)
 }
diff --git a/pkg/api/handlers/swagger.go b/pkg/api/handlers/swagger.go
deleted file mode 100644
index 33a9fdd58..000000000
--- a/pkg/api/handlers/swagger.go
+++ /dev/null
@@ -1,158 +0,0 @@
-package handlers
-
-import (
-	"github.com/containers/libpod/libpod"
-	"github.com/containers/libpod/libpod/define"
-	"github.com/containers/libpod/libpod/image"
-	"github.com/containers/libpod/pkg/domain/entities"
-	"github.com/containers/libpod/pkg/inspect"
-	"github.com/docker/docker/api/types"
-)
-
-// History response
-// swagger:response DocsHistory
-type swagHistory struct {
-	// in:body
-	Body struct {
-		HistoryResponse
-	}
-}
-
-// Inspect response
-// swagger:response DocsImageInspect
-type swagImageInspect struct {
-	// in:body
-	Body struct {
-		ImageInspect
-	}
-}
-
-// Load response
-// swagger:response DocsLibpodImagesLoadResponse
-type swagLibpodImagesLoadResponse struct {
-	// in:body
-	Body entities.ImageLoadReport
-}
-
-// Import response
-// swagger:response DocsLibpodImagesImportResponse
-type swagLibpodImagesImportResponse struct {
-	// in:body
-	Body entities.ImageImportReport
-}
-
-// Pull response
-// swagger:response DocsLibpodImagesPullResponse
-type swagLibpodImagesPullResponse struct {
-	// in:body
-	Body LibpodImagesPullReport
-}
-
-// Delete response
-// swagger:response DocsImageDeleteResponse
-type swagImageDeleteResponse struct {
-	// in:body
-	Body []image.ImageDeleteResponse
-}
-
-// Search results
-// swagger:response DocsSearchResponse
-type swagSearchResponse struct {
-	// in:body
-	Body struct {
-		image.SearchResult
-	}
-}
-
-// Inspect image
-// swagger:response DocsLibpodInspectImageResponse
-type swagLibpodInspectImageResponse struct {
-	// in:body
-	Body struct {
-		inspect.ImageData
-	}
-}
-
-// Prune containers
-// swagger:response DocsContainerPruneReport
-type swagContainerPruneReport struct {
-	// in: body
-	Body []ContainersPruneReport
-}
-
-// Prune containers
-// swagger:response DocsLibpodPruneResponse
-type swagLibpodContainerPruneReport struct {
-	// in: body
-	Body []LibpodContainersPruneReport
-}
-
-// Inspect container
-// swagger:response DocsContainerInspectResponse
-type swagContainerInspectResponse struct {
-	// in:body
-	Body struct {
-		types.ContainerJSON
-	}
-}
-
-// List processes in container
-// swagger:response DocsContainerTopResponse
-type swagContainerTopResponse struct {
-	// in:body
-	Body struct {
-		ContainerTopOKBody
-	}
-}
-
-// List processes in pod
-// swagger:response DocsPodTopResponse
-type swagPodTopResponse struct {
-	// in:body
-	Body struct {
-		PodTopOKBody
-	}
-}
-
-// Inspect container
-// swagger:response LibpodInspectContainerResponse
-type swagLibpodInspectContainerResponse struct {
-	// in:body
-	Body struct {
-		define.InspectContainerData
-	}
-}
-
-// List pods
-// swagger:response ListPodsResponse
-type swagListPodsResponse struct {
-	// in:body
-	Body []entities.ListPodsReport
-}
-
-// Inspect pod
-// swagger:response InspectPodResponse
-type swagInspectPodResponse struct {
-	// in:body
-	Body struct {
-		libpod.PodInspect
-	}
-}
-
-// Inspect volume
-// swagger:response InspectVolumeResponse
-type swagInspectVolumeResponse struct {
-	// in:body
-	Body struct {
-		libpod.InspectVolumeData
-	}
-}
-
-// Image tree response
-// swagger:response LibpodImageTreeResponse
-type swagImageTreeResponse struct {
-	// in:body
-	Body struct {
-		ImageTreeResponse
-	}
-}
diff --git a/pkg/api/handlers/swagger/swagger.go b/pkg/api/handlers/swagger/swagger.go
new file mode 100644
index 000000000..ba97a4755
--- /dev/null
+++ b/pkg/api/handlers/swagger/swagger.go
@@ -0,0 +1,159 @@
+package swagger
+
+import (
+	"github.com/containers/libpod/libpod"
+	"github.com/containers/libpod/libpod/define"
+	"github.com/containers/libpod/libpod/image"
+	"github.com/containers/libpod/pkg/api/handlers"
+	"github.com/containers/libpod/pkg/domain/entities"
+	"github.com/containers/libpod/pkg/inspect"
+	"github.com/docker/docker/api/types"
+)
+
+// History response
+// swagger:response DocsHistory
+type swagHistory struct {
+	// in:body
+	Body struct {
+		handlers.HistoryResponse
+	}
+}
+
+// Inspect response
+// swagger:response DocsImageInspect
+type swagImageInspect struct {
+	// in:body
+	Body struct {
+		handlers.ImageInspect
+	}
+}
+
+// Load response
+// swagger:response DocsLibpodImagesLoadResponse
+type swagLibpodImagesLoadResponse struct {
+	// in:body
+	Body entities.ImageLoadReport
+}
+
+// Import response
+// swagger:response DocsLibpodImagesImportResponse
+type swagLibpodImagesImportResponse struct {
+	// in:body
+	Body entities.ImageImportReport
+}
+
+// Pull response
+// swagger:response DocsLibpodImagesPullResponse
+type swagLibpodImagesPullResponse struct {
+	// in:body
+	Body handlers.LibpodImagesPullReport
+}
+
+// Delete response
+// swagger:response DocsImageDeleteResponse
+type swagImageDeleteResponse struct {
+	// in:body
+	Body []image.ImageDeleteResponse
+}
+
+// Search results
+// swagger:response DocsSearchResponse
+type swagSearchResponse struct {
+	// in:body
+	Body struct {
+		image.SearchResult
+	}
+}
+
+// Inspect image
+// swagger:response DocsLibpodInspectImageResponse
+type swagLibpodInspectImageResponse struct {
+	// in:body
+	Body struct {
+		inspect.ImageData
+	}
+}
+
+// Prune containers
+// swagger:response DocsContainerPruneReport
+type swagContainerPruneReport struct {
+	// in: body
+	Body []handlers.ContainersPruneReport
+}
+
+// Prune containers
+// swagger:response DocsLibpodPruneResponse
+type swagLibpodContainerPruneReport struct {
+	// in: body
+	Body []handlers.LibpodContainersPruneReport
+}
+
+// Inspect container
+// swagger:response DocsContainerInspectResponse
+type swagContainerInspectResponse struct {
+	// in:body
+	Body struct {
+		types.ContainerJSON
+	}
+}
+
+// List processes in container
+// swagger:response DocsContainerTopResponse
+type swagContainerTopResponse struct {
+	// in:body
+	Body struct {
+		handlers.ContainerTopOKBody
+	}
+}
+
+// List processes in pod
+// swagger:response DocsPodTopResponse
+type swagPodTopResponse struct {
+	// in:body
+	Body struct {
+		handlers.PodTopOKBody
+	}
+}
+
+// Inspect container
+// swagger:response LibpodInspectContainerResponse
+type swagLibpodInspectContainerResponse struct {
+	// in:body
+	Body struct {
+		define.InspectContainerData
+	}
+}
+
+// List pods
+// swagger:response ListPodsResponse
+type swagListPodsResponse struct {
+	// in:body
+	Body []entities.ListPodsReport
+}
+
+// Inspect pod
+// swagger:response InspectPodResponse
+type swagInspectPodResponse struct {
+	// in:body
+	Body struct {
+		libpod.PodInspect
+	}
+}
+
+// Inspect volume
+// swagger:response InspectVolumeResponse
+type swagInspectVolumeResponse struct {
+	// in:body
+	Body struct {
+		libpod.InspectVolumeData
+	}
+}
+
+// Image tree response
+// swagger:response LibpodImageTreeResponse
+type swagImageTreeResponse struct {
+	// in:body
+	Body struct {
+		handlers.ImageTreeResponse
+	}
+}
diff --git a/pkg/api/handlers/types.go b/pkg/api/handlers/types.go
index 0fe6ae6a7..f402da064 100644
--- a/pkg/api/handlers/types.go
+++ b/pkg/api/handlers/types.go
@@ -5,12 +5,9 @@ import (
 	"encoding/json"
 	"fmt"
 	"strconv"
-	"strings"
 	"time"
 
 	"github.com/containers/image/v5/manifest"
-	"github.com/containers/libpod/libpod"
-	"github.com/containers/libpod/libpod/define"
 	"github.com/containers/libpod/libpod/events"
 	libpodImage "github.com/containers/libpod/libpod/image"
 	"github.com/containers/libpod/pkg/domain/entities"
@@ -146,10 +143,6 @@ type PodCreateConfig struct {
 	Share        string   `json:"share"`
 }
 
-type ErrorModel struct {
-	Message string `json:"message"`
-}
-
 type Event struct {
 	dockerEvents.Message
 }
@@ -378,195 +371,6 @@ func ImageDataToImageInspect(ctx context.Context, l *libpodImage.Image) (*ImageI
 
 }
 
-func LibpodToContainer(l *libpod.Container, sz bool) (*Container, error) {
-	imageId, imageName := l.Image()
-
-	var (
-		err        error
-		sizeRootFs int64
-		sizeRW     int64
-		state      define.ContainerStatus
-	)
-
-	if state, err = l.State(); err != nil {
-		return nil, err
-	}
-	stateStr := state.String()
-	if stateStr == "configured" {
-		stateStr = "created"
-	}
-
-	if sz {
-		if sizeRW, err = l.RWSize(); err != nil {
-			return nil, err
-		}
-		if sizeRootFs, err = l.RootFsSize(); err != nil {
-			return nil, err
-		}
-	}
-
-	return &Container{docker.Container{
-		ID:         l.ID(),
-		Names:      []string{fmt.Sprintf("/%s", l.Name())},
-		Image:      imageName,
-		ImageID:    imageId,
-		Command:    strings.Join(l.Command(), " "),
-		Created:    l.CreatedTime().Unix(),
-		Ports:      nil,
-		SizeRw:     sizeRW,
-		SizeRootFs: sizeRootFs,
-		Labels:     l.Labels(),
-		State:      stateStr,
-		Status:     "",
-		HostConfig: struct {
-			NetworkMode string `json:",omitempty"`
-		}{
-			"host"},
-		NetworkSettings: nil,
-		Mounts:          nil,
-	},
-		docker.ContainerCreateConfig{},
-	}, nil
-}
-
-func LibpodToContainerJSON(l *libpod.Container, sz bool) (*docker.ContainerJSON, error) {
-	_, imageName := l.Image()
-	inspect, err := l.Inspect(sz)
-	if err != nil {
-		return nil, err
-	}
-	i, err := json.Marshal(inspect.State)
-	if err != nil {
-		return nil, err
-	}
-	state := docker.ContainerState{}
-	if err := json.Unmarshal(i, &state); err != nil {
-		return nil, err
-	}
-
-	// docker considers paused to be running
-	if state.Paused {
-		state.Running = true
-	}
-
-	h, err := json.Marshal(inspect.HostConfig)
-	if err != nil {
-		return nil, err
-	}
-	hc := dockerContainer.HostConfig{}
-	if err := json.Unmarshal(h, &hc); err != nil {
-		return nil, err
-	}
-	g, err := json.Marshal(inspect.GraphDriver)
-	if err != nil {
-		return nil, err
-	}
-	graphDriver := docker.GraphDriverData{}
-	if err := json.Unmarshal(g, &graphDriver); err != nil {
-		return nil, err
-	}
-
-	cb := docker.ContainerJSONBase{
-		ID:              l.ID(),
-		Created:         l.CreatedTime().String(),
-		Path:            "",
-		Args:            nil,
-		State:           &state,
-		Image:           imageName,
-		ResolvConfPath:  inspect.ResolvConfPath,
-		HostnamePath:    inspect.HostnamePath,
-		HostsPath:       inspect.HostsPath,
-		LogPath:         l.LogPath(),
-		Node:            nil,
-		Name:            fmt.Sprintf("/%s", l.Name()),
-		RestartCount:    0,
-		Driver:          inspect.Driver,
-		Platform:        "linux",
-		MountLabel:      inspect.MountLabel,
-		ProcessLabel:    inspect.ProcessLabel,
-		AppArmorProfile: inspect.AppArmorProfile,
-		ExecIDs:         inspect.ExecIDs,
-		HostConfig:      &hc,
-		GraphDriver:     graphDriver,
-		SizeRw:          inspect.SizeRw,
-		SizeRootFs:      &inspect.SizeRootFs,
-	}
-
-	stopTimeout := int(l.StopTimeout())
-
-	ports := make(nat.PortSet)
-	for p := range inspect.HostConfig.PortBindings {
-		splitp := strings.Split(p, "/")
-		port, err := nat.NewPort(splitp[0], splitp[1])
-		if err != nil {
-			return nil, err
-		}
-		ports[port] = struct{}{}
-	}
-
-	config := dockerContainer.Config{
-		Hostname:        l.Hostname(),
-		Domainname:      inspect.Config.DomainName,
-		User:            l.User(),
-		AttachStdin:     inspect.Config.AttachStdin,
-		AttachStdout:    inspect.Config.AttachStdout,
-		AttachStderr:    inspect.Config.AttachStderr,
-		ExposedPorts:    ports,
-		Tty:             inspect.Config.Tty,
-		OpenStdin:       inspect.Config.OpenStdin,
-		StdinOnce:       inspect.Config.StdinOnce,
-		Env:             inspect.Config.Env,
-		Cmd:             inspect.Config.Cmd,
-		Healthcheck:     nil,
-		ArgsEscaped:     false,
-		Image:           imageName,
-		Volumes:         nil,
-		WorkingDir:      l.WorkingDir(),
-		Entrypoint:      l.Entrypoint(),
-		NetworkDisabled: false,
-		MacAddress:      "",
-		OnBuild:         nil,
-		Labels:          l.Labels(),
-		StopSignal:      string(l.StopSignal()),
-		StopTimeout:     &stopTimeout,
-		Shell:           nil,
-	}
-
-	m, err := json.Marshal(inspect.Mounts)
-	if err != nil {
-		return nil, err
-	}
-	mounts := []docker.MountPoint{}
-	if err := json.Unmarshal(m, &mounts); err != nil {
-		return nil, err
-	}
-
-	networkSettingsDefault := docker.DefaultNetworkSettings{
-		EndpointID:          "",
-		Gateway:             "",
-		GlobalIPv6Address:   "",
-		GlobalIPv6PrefixLen: 0,
-		IPAddress:           "",
-		IPPrefixLen:         0,
-		IPv6Gateway:         "",
-		MacAddress:          l.Config().StaticMAC.String(),
-	}
-
-	networkSettings := docker.NetworkSettings{
-		NetworkSettingsBase:    docker.NetworkSettingsBase{},
-		DefaultNetworkSettings: networkSettingsDefault,
-		Networks:               nil,
-	}
-
-	c := docker.ContainerJSON{
-		ContainerJSONBase: &cb,
-		Mounts:            mounts,
-		Config:            &config,
-		NetworkSettings:   &networkSettings,
-	}
-	return &c, nil
-}
-
 // portsToPortSet converts libpods exposed ports to dockers structs
 func portsToPortSet(input map[string]struct{}) (nat.PortSet, error) {
 	ports := make(nat.PortSet)
diff --git a/pkg/api/handlers/utils/containers.go b/pkg/api/handlers/utils/containers.go
index d1107f67c..bc247c4ae 100644
--- a/pkg/api/handlers/utils/containers.go
+++ b/pkg/api/handlers/utils/containers.go
@@ -6,22 +6,14 @@ import (
 	"time"
 
 	"github.com/containers/libpod/cmd/podman/shared"
-	createconfig "github.com/containers/libpod/pkg/spec"
-
 	"github.com/containers/libpod/libpod"
 	"github.com/containers/libpod/libpod/define"
+	"github.com/containers/libpod/pkg/domain/entities"
+	createconfig "github.com/containers/libpod/pkg/spec"
 	"github.com/gorilla/schema"
 	"github.com/pkg/errors"
 )
 
-// ContainerCreateResponse is the response struct for creating a container
-type ContainerCreateResponse struct {
-	// ID of the container created
-	ID string `json:"Id"`
-	// Warnings during container creation
-	Warnings []string `json:"Warnings"`
-}
-
 func WaitContainer(w http.ResponseWriter, r *http.Request) (int32, error) {
 	var (
 		err      error
@@ -77,7 +69,7 @@ func CreateContainer(ctx context.Context, w http.ResponseWriter, runtime *libpod
 		return
 	}
 
-	response := ContainerCreateResponse{
+	response := entities.ContainerCreateResponse{
 		ID:       ctr.ID(),
 		Warnings: []string{}}
 
diff --git a/pkg/api/handlers/utils/errors.go b/pkg/api/handlers/utils/errors.go
index 8d499f40b..aafc64353 100644
--- a/pkg/api/handlers/utils/errors.go
+++ b/pkg/api/handlers/utils/errors.go
@@ -5,6 +5,7 @@ import (
 	"net/http"
 
 	"github.com/containers/libpod/libpod/define"
+	"github.com/containers/libpod/pkg/domain/entities"
 	"github.com/pkg/errors"
 	log "github.com/sirupsen/logrus"
 )
@@ -20,7 +21,7 @@ var (
 func Error(w http.ResponseWriter, apiMessage string, code int, err error) {
 	// Log detailed message of what happened to machine running podman service
 	log.Infof("Request Failed(%s): %s", http.StatusText(code), err.Error())
-	em := ErrorModel{
+	em := entities.ErrorModel{
 		Because:      (errors.Cause(err)).Error(),
 		Message:      err.Error(),
 		ResponseCode: code,
@@ -73,29 +74,6 @@ func BadRequest(w http.ResponseWriter, key string, value string, err error) {
 	Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest, e)
 }
 
-type ErrorModel struct {
-	// API root cause formatted for automated parsing
-	// example: API root cause
-	Because string `json:"cause"`
-	// human error message, formatted for a human to read
-	// example: human error message
-	Message string `json:"message"`
-	// http response code
-	ResponseCode int `json:"response"`
-}
-
-func (e ErrorModel) Error() string {
-	return e.Message
-}
-
-func (e ErrorModel) Cause() error {
-	return errors.New(e.Because)
-}
-
-func (e ErrorModel) Code() int {
-	return e.ResponseCode
-}
-
 // UnsupportedParameter logs a given param by its string name as not supported.
 func UnSupportedParameter(param string) {
 	log.Infof("API parameter %q: not supported", param)
diff --git a/pkg/api/server/swagger.go b/pkg/api/server/swagger.go
index 2433a6a05..75dcc71a6 100644
--- a/pkg/api/server/swagger.go
+++ b/pkg/api/server/swagger.go
@@ -3,7 +3,6 @@ package server
 import (
 	"github.com/containers/libpod/libpod"
 	"github.com/containers/libpod/libpod/define"
-	"github.com/containers/libpod/pkg/api/handlers/utils"
 	"github.com/containers/libpod/pkg/domain/entities"
 )
 
@@ -12,7 +11,7 @@ import (
 type swagErrNoSuchImage struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -21,7 +20,7 @@ type swagErrNoSuchImage struct {
 type swagErrNoSuchContainer struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -30,7 +29,7 @@ type swagErrNoSuchContainer struct {
 type swagErrNoSuchExecInstance struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -39,7 +38,7 @@ type swagErrNoSuchExecInstance struct {
 type swagErrNoSuchVolume struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -48,7 +47,7 @@ type swagErrNoSuchVolume struct {
 type swagErrNoSuchPod struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -57,7 +56,7 @@ type swagErrNoSuchPod struct {
 type swagErrNoSuchManifest struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -66,7 +65,7 @@ type swagErrNoSuchManifest struct {
 type swagInternalError struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -75,7 +74,7 @@ type swagInternalError struct {
 type swagConflictError struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -84,7 +83,7 @@ type swagConflictError struct {
 type swagBadParamError struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -93,7 +92,7 @@ type swagBadParamError struct {
 type swagContainerAlreadyStartedError struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -102,7 +101,7 @@ type swagContainerAlreadyStartedError struct {
 type swagContainerAlreadyStopped struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -111,7 +110,7 @@ type swagContainerAlreadyStopped struct {
 type swagPodAlreadyStartedError struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
@@ -120,7 +119,7 @@ type swagPodAlreadyStartedError struct {
 type swagPodAlreadyStopped struct {
 	// in:body
 	Body struct {
-		utils.ErrorModel
+		entities.ErrorModel
 	}
 }
 
-- 
cgit v1.2.3-54-g00ecf