mirror of
https://github.com/containers/podman.git
synced 2025-06-22 18:08:11 +08:00
Collaberative podman-remote container exists
Began frameout of container super structs for adapted methods. This allows for the use of container exists. Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
@ -88,13 +88,13 @@ func containerExistsCmd(c *cli.Context) error {
|
|||||||
if len(args) > 1 || len(args) < 1 {
|
if len(args) > 1 || len(args) < 1 {
|
||||||
return errors.New("you may only check for the existence of one container at a time")
|
return errors.New("you may only check for the existence of one container at a time")
|
||||||
}
|
}
|
||||||
runtime, err := libpodruntime.GetRuntime(c)
|
runtime, err := adapter.GetRuntime(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "could not get runtime")
|
return errors.Wrapf(err, "could not get runtime")
|
||||||
}
|
}
|
||||||
defer runtime.Shutdown(false)
|
defer runtime.Runtime.Shutdown(false)
|
||||||
if _, err := runtime.LookupContainer(args[0]); err != nil {
|
if _, err := runtime.Runtime.LookupContainer(args[0]); err != nil {
|
||||||
if errors.Cause(err) == libpod.ErrNoSuchCtr {
|
if errors.Cause(err) == libpod.ErrNoSuchCtr || err.Error() == "io.podman.ContainerNotFound" {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -2,14 +2,15 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/containers/libpod/cmd/podman/imagefilters"
|
|
||||||
"github.com/containers/libpod/libpod/adapter"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/cmd/podman/imagefilters"
|
||||||
|
"github.com/containers/libpod/libpod/adapter"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/formats"
|
"github.com/containers/libpod/cmd/podman/formats"
|
||||||
"github.com/containers/libpod/libpod/image"
|
"github.com/containers/libpod/libpod/image"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
|
@ -61,7 +61,7 @@ type ImageSearch (
|
|||||||
star_count: int
|
star_count: int
|
||||||
)
|
)
|
||||||
|
|
||||||
# ListContainer is the returned struct for an individual container
|
# ListContainerData is the returned struct for an individual container
|
||||||
type ListContainerData (
|
type ListContainerData (
|
||||||
id: string,
|
id: string,
|
||||||
image: string,
|
image: string,
|
||||||
|
@ -24,6 +24,11 @@ type ContainerImage struct {
|
|||||||
*image.Image
|
*image.Image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Container ...
|
||||||
|
type Container struct {
|
||||||
|
*libpod.Container
|
||||||
|
}
|
||||||
|
|
||||||
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
|
// GetRuntime returns a LocalRuntime struct with the actual runtime embedded in it
|
||||||
func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
|
func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
|
||||||
runtime, err := libpodruntime.GetRuntime(c)
|
runtime, err := libpodruntime.GetRuntime(c)
|
||||||
@ -85,3 +90,12 @@ func (r *LocalRuntime) New(ctx context.Context, name, signaturePolicyPath, authf
|
|||||||
func (r *LocalRuntime) RemoveImage(ctx context.Context, img *ContainerImage, force bool) (string, error) {
|
func (r *LocalRuntime) RemoveImage(ctx context.Context, img *ContainerImage, force bool) (string, error) {
|
||||||
return r.Runtime.RemoveImage(ctx, img.Image, force)
|
return r.Runtime.RemoveImage(ctx, img.Image, force)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LookupContainer ...
|
||||||
|
func (r *LocalRuntime) LookupContainer(idOrName string) (*Container, error) {
|
||||||
|
ctr, err := r.Runtime.LookupContainer(idOrName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &Container{ctr}, nil
|
||||||
|
}
|
||||||
|
@ -22,8 +22,12 @@ type RemoteImageRuntime struct{}
|
|||||||
|
|
||||||
// RemoteRuntime describes a wrapper runtime struct
|
// RemoteRuntime describes a wrapper runtime struct
|
||||||
type RemoteRuntime struct {
|
type RemoteRuntime struct {
|
||||||
|
Conn *varlink.Connection
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//func (r *LocalRuntime) LookupContainer(idOrName string) (*Container, error) {
|
||||||
|
// if _, err := runtime.Runtime.LookupContainer(args[0]); err != nil {
|
||||||
|
|
||||||
// LocalRuntime describes a typical libpod runtime
|
// LocalRuntime describes a typical libpod runtime
|
||||||
type LocalRuntime struct {
|
type LocalRuntime struct {
|
||||||
Runtime *RemoteRuntime
|
Runtime *RemoteRuntime
|
||||||
@ -38,6 +42,7 @@ func GetRuntime(c *cli.Context) (*LocalRuntime, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
runtime.Conn = conn
|
||||||
return &LocalRuntime{
|
return &LocalRuntime{
|
||||||
Runtime: &runtime,
|
Runtime: &runtime,
|
||||||
Remote: true,
|
Remote: true,
|
||||||
@ -70,6 +75,30 @@ type remoteImage struct {
|
|||||||
Runtime *LocalRuntime
|
Runtime *LocalRuntime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Container ...
|
||||||
|
type Container struct {
|
||||||
|
remoteContainer
|
||||||
|
}
|
||||||
|
|
||||||
|
// remoteContainer ....
|
||||||
|
type remoteContainer struct {
|
||||||
|
ID string
|
||||||
|
Image string
|
||||||
|
ImageID string
|
||||||
|
Command []string
|
||||||
|
Created time.Time
|
||||||
|
RunningFor string
|
||||||
|
Status string
|
||||||
|
//Ports []ocicni.PortMapping
|
||||||
|
RootFsSize int64
|
||||||
|
RWSize int64
|
||||||
|
Names string
|
||||||
|
Labels []map[string]string
|
||||||
|
// Mounts []string
|
||||||
|
// ContainerRunning bool
|
||||||
|
//Namespaces []LinuxNameSpace
|
||||||
|
}
|
||||||
|
|
||||||
// GetImages returns a slice of containerimages over a varlink connection
|
// GetImages returns a slice of containerimages over a varlink connection
|
||||||
func (r *LocalRuntime) GetImages() ([]*ContainerImage, error) {
|
func (r *LocalRuntime) GetImages() ([]*ContainerImage, error) {
|
||||||
var newImages []*ContainerImage
|
var newImages []*ContainerImage
|
||||||
@ -213,10 +242,6 @@ func (ci *ContainerImage) TagImage(tag string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r RemoteRuntime) RemoveImage(force bool) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveImage calls varlink to remove an image
|
// RemoveImage calls varlink to remove an image
|
||||||
func (r *LocalRuntime) RemoveImage(ctx context.Context, img *ContainerImage, force bool) (string, error) {
|
func (r *LocalRuntime) RemoveImage(ctx context.Context, img *ContainerImage, force bool) (string, error) {
|
||||||
return iopodman.RemoveImage().Call(r.Conn, img.InputName, force)
|
return iopodman.RemoveImage().Call(r.Conn, img.InputName, force)
|
||||||
@ -246,3 +271,44 @@ func (ci *ContainerImage) History(ctx context.Context) ([]*image.History, error)
|
|||||||
}
|
}
|
||||||
return imageHistories, nil
|
return imageHistories, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LookupContainer ...
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// listContainerDataToContainer takes a varlink listcontainerData struct and makes
|
||||||
|
// an "adapted" Container
|
||||||
|
func listContainerDataToContainer(listData iopodman.ListContainerData) (*Container, error) {
|
||||||
|
created, err := splitStringDate(listData.Createdat)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
rc := remoteContainer{
|
||||||
|
ID: listData.Id,
|
||||||
|
Image: listData.Image,
|
||||||
|
ImageID: listData.Imageid,
|
||||||
|
Command: listData.Command,
|
||||||
|
Created: created,
|
||||||
|
RunningFor: listData.Runningfor,
|
||||||
|
Status: listData.Status,
|
||||||
|
//ports: //map[ocicni.portmapping]
|
||||||
|
RootFsSize: listData.Rootfssize,
|
||||||
|
RWSize: listData.Rwsize,
|
||||||
|
Names: listData.Names,
|
||||||
|
//Labels:
|
||||||
|
//Mounts
|
||||||
|
//ContainerRunning: listData.r
|
||||||
|
//namespaces:
|
||||||
|
}
|
||||||
|
return &Container{rc}, nil
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user