mirror of
https://github.com/containers/podman.git
synced 2025-06-22 01:48:54 +08:00
Embed runtime struct in super localRuntime
We clean up the code by eliminating stuttering references when we embed the runtime struct into localRuntime. Makes for less change in the future as well. ++ jhonce Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
@ -71,7 +71,7 @@ func imageExistsCmd(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
defer runtime.Runtime.Shutdown(false)
|
||||
defer runtime.Shutdown(false)
|
||||
if _, err := runtime.NewImageFromLocal(args[0]); err != nil {
|
||||
//TODO we need to ask about having varlink defined errors exposed
|
||||
//so we can reuse them
|
||||
@ -92,8 +92,8 @@ func containerExistsCmd(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
defer runtime.Runtime.Shutdown(false)
|
||||
if _, err := runtime.Runtime.LookupContainer(args[0]); err != nil {
|
||||
defer runtime.Shutdown(false)
|
||||
if _, err := runtime.LookupContainer(args[0]); err != nil {
|
||||
if errors.Cause(err) == libpod.ErrNoSuchCtr || err.Error() == "io.podman.ContainerNotFound" {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/containers/libpod/libpod/adapter"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/formats"
|
||||
"github.com/containers/libpod/libpod/adapter"
|
||||
"github.com/containers/libpod/libpod/image"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/pkg/errors"
|
||||
@ -76,7 +76,7 @@ func historyCmd(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
defer runtime.Runtime.Shutdown(false)
|
||||
defer runtime.Shutdown(false)
|
||||
|
||||
format := genHistoryFormat(c.String("format"), c.Bool("quiet"))
|
||||
|
||||
|
@ -8,10 +8,9 @@ import (
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/formats"
|
||||
"github.com/containers/libpod/cmd/podman/imagefilters"
|
||||
"github.com/containers/libpod/libpod/adapter"
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/formats"
|
||||
"github.com/containers/libpod/libpod/image"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/opencontainers/go-digest"
|
||||
@ -157,7 +156,7 @@ func imagesCmd(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Could not get runtime")
|
||||
}
|
||||
defer runtime.Runtime.Shutdown(false)
|
||||
defer runtime.Shutdown(false)
|
||||
if len(c.Args()) == 1 {
|
||||
newImage, err = runtime.NewImageFromLocal(c.Args().Get(0))
|
||||
if err != nil {
|
||||
|
@ -1,11 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/containers/libpod/libpod/adapter"
|
||||
"runtime"
|
||||
|
||||
"github.com/containers/libpod/cmd/podman/formats"
|
||||
"github.com/containers/libpod/libpod"
|
||||
"github.com/containers/libpod/libpod/adapter"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
@ -43,9 +43,9 @@ func infoCmd(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
defer runtime.Runtime.Shutdown(false)
|
||||
defer runtime.Shutdown(false)
|
||||
|
||||
infoArr, err := runtime.Runtime.Info()
|
||||
infoArr, err := runtime.Info()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error getting info")
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/containers/libpod/libpod/adapter"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
@ -10,6 +9,7 @@ import (
|
||||
dockerarchive "github.com/containers/image/docker/archive"
|
||||
"github.com/containers/image/transports/alltransports"
|
||||
"github.com/containers/image/types"
|
||||
"github.com/containers/libpod/libpod/adapter"
|
||||
image2 "github.com/containers/libpod/libpod/image"
|
||||
"github.com/containers/libpod/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
@ -68,7 +68,7 @@ func pullCmd(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
defer runtime.Runtime.Shutdown(false)
|
||||
defer runtime.Shutdown(false)
|
||||
|
||||
args := c.Args()
|
||||
if len(args) == 0 {
|
||||
|
@ -61,7 +61,7 @@ func rmiCmd(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not get runtime")
|
||||
}
|
||||
defer runtime.Runtime.Shutdown(false)
|
||||
defer runtime.Shutdown(false)
|
||||
|
||||
args := c.Args()
|
||||
if len(args) == 0 && !removeAll {
|
||||
|
@ -27,7 +27,7 @@ func tagCmd(c *cli.Context) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create runtime")
|
||||
}
|
||||
defer runtime.Runtime.Shutdown(false)
|
||||
defer runtime.Shutdown(false)
|
||||
|
||||
newImage, err := runtime.NewImageFromLocal(args[0])
|
||||
if err != nil {
|
||||
|
@ -15,8 +15,8 @@ import (
|
||||
|
||||
// LocalRuntime describes a typical libpod runtime
|
||||
type LocalRuntime struct {
|
||||
Runtime *libpod.Runtime
|
||||
Remote bool
|
||||
*libpod.Runtime
|
||||
Remote bool
|
||||
}
|
||||
|
||||
// ContainerImage ...
|
||||
|
@ -22,17 +22,13 @@ type RemoteImageRuntime struct{}
|
||||
|
||||
// RemoteRuntime describes a wrapper runtime struct
|
||||
type RemoteRuntime struct {
|
||||
Conn *varlink.Connection
|
||||
Conn *varlink.Connection
|
||||
Remote bool
|
||||
}
|
||||
|
||||
//func (r *LocalRuntime) LookupContainer(idOrName string) (*Container, error) {
|
||||
// if _, err := runtime.Runtime.LookupContainer(args[0]); err != nil {
|
||||
|
||||
// LocalRuntime describes a typical libpod runtime
|
||||
type LocalRuntime struct {
|
||||
Runtime *RemoteRuntime
|
||||
Remote bool
|
||||
Conn *varlink.Connection
|
||||
*RemoteRuntime
|
||||
}
|
||||
|
||||
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
|
||||
@ -42,12 +38,14 @@ func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
runtime.Conn = conn
|
||||
return &LocalRuntime{
|
||||
Runtime: &runtime,
|
||||
Remote: true,
|
||||
Conn: conn,
|
||||
}, nil
|
||||
rr := RemoteRuntime{
|
||||
Conn: conn,
|
||||
Remote: true,
|
||||
}
|
||||
foo := LocalRuntime{
|
||||
&rr,
|
||||
}
|
||||
return &foo, nil
|
||||
}
|
||||
|
||||
// Shutdown is a bogus wrapper for compat with the libpod runtime
|
||||
@ -272,18 +270,14 @@ func (ci *ContainerImage) History(ctx context.Context) ([]*image.History, error)
|
||||
return imageHistories, nil
|
||||
}
|
||||
|
||||
// LookupContainer ...
|
||||
// LookupContainer gets basic information about container over a varlink
|
||||
// connection and then translates it to a *Container
|
||||
func (r *RemoteRuntime) LookupContainer(idOrName string) (*Container, error) {
|
||||
container, err := iopodman.GetContainer().Call(r.Conn, idOrName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctr, err := listContainerDataToContainer(container)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ctr, nil
|
||||
return listContainerDataToContainer(container)
|
||||
}
|
||||
|
||||
// listContainerDataToContainer takes a varlink listcontainerData struct and makes
|
||||
@ -294,6 +288,8 @@ func listContainerDataToContainer(listData iopodman.ListContainerData) (*Contain
|
||||
return nil, err
|
||||
}
|
||||
rc := remoteContainer{
|
||||
// TODO commented out attributes will be populated when podman-remote ps
|
||||
// is implemented. They are not needed yet for basic container operations.
|
||||
ID: listData.Id,
|
||||
Image: listData.Image,
|
||||
ImageID: listData.Imageid,
|
||||
@ -301,13 +297,13 @@ func listContainerDataToContainer(listData iopodman.ListContainerData) (*Contain
|
||||
Created: created,
|
||||
RunningFor: listData.Runningfor,
|
||||
Status: listData.Status,
|
||||
//ports: //map[ocicni.portmapping]
|
||||
//ports:
|
||||
RootFsSize: listData.Rootfssize,
|
||||
RWSize: listData.Rwsize,
|
||||
Names: listData.Names,
|
||||
//Labels:
|
||||
//Mounts
|
||||
//ContainerRunning: listData.r
|
||||
//ContainerRunning:
|
||||
//namespaces:
|
||||
}
|
||||
return &Container{rc}, nil
|
||||
|
Reference in New Issue
Block a user