image mgmt: restructure cli and add images delete

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2016-09-18 11:32:48 +02:00
parent b22c85068c
commit e9cb1b1868
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
2 changed files with 46 additions and 6 deletions

View file

@ -234,8 +234,7 @@ func main() {
podSandboxCommand,
containerCommand,
runtimeVersionCommand,
pullImageCommand,
listImagesCommand,
imagesCommand,
}
app.Flags = []cli.Flag{
@ -252,8 +251,44 @@ func main() {
}
}
var imagesCommand = cli.Command{
Name: "images",
Subcommands: []cli.Command{
pullImageCommand,
removeImageCommand,
listImagesCommand,
},
}
var removeImageCommand = cli.Command{
Name: "delete",
Usage: "delete an image",
Action: func(context *cli.Context) error {
// Set up a connection to the server.
conn, err := getClientConnection()
if err != nil {
return fmt.Errorf("failed to connect: %v", err)
}
defer conn.Close()
client := pb.NewImageServiceClient(conn)
if err := RemoveImage(client, context.Args().Get(0)); err != nil {
return err
}
return nil
},
}
func RemoveImage(client pb.ImageServiceClient, image string) error {
_, err := client.RemoveImage(context.Background(), &pb.RemoveImageRequest{Image: &pb.ImageSpec{Image: &image}})
if err != nil {
return err
}
return nil
}
var listImagesCommand = cli.Command{
Name: "listimages",
Name: "list",
Usage: "list images",
Action: func(context *cli.Context) error {
// Set up a connection to the server.
@ -292,7 +327,7 @@ func PullImage(client pb.ImageServiceClient, image string) error {
// try this with ./ocic pullimage docker://busybox
var pullImageCommand = cli.Command{
Name: "pullimage",
Name: "pull",
Usage: "pull an image",
Action: func(context *cli.Context) error {
// Set up a connection to the server.

View file

@ -2,6 +2,7 @@ package server
import (
"errors"
"fmt"
ic "github.com/containers/image/copy"
"github.com/containers/image/signature"
@ -56,7 +57,11 @@ func (s *Server) PullImage(ctx context.Context, req *pb.PullImageRequest) (*pb.P
return nil, err
}
dr, err := transports.ParseImageName(storage.Transport.Name() + ":" + sr.StringWithinTransport())
if sr.Transport().Name() != "docker" {
return nil, fmt.Errorf("can only pull docker images, got %s", sr.Transport().Name())
}
dr, err := transports.ParseImageName(storage.Transport.Name() + ":" + sr.DockerReference().String())
if err != nil {
return nil, err
}
@ -82,5 +87,5 @@ func (s *Server) PullImage(ctx context.Context, req *pb.PullImageRequest) (*pb.P
// RemoveImage removes the image.
func (s *Server) RemoveImage(ctx context.Context, req *pb.RemoveImageRequest) (*pb.RemoveImageResponse, error) {
_, err := s.storage.DeleteImage(*(req.Image.Image), true)
return nil, err
return &pb.RemoveImageResponse{}, err
}