Generate ImageDeleteResponse from swagger spec.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
b462c93edb
commit
5988b84e4f
10 changed files with 48 additions and 38 deletions
|
@ -25,7 +25,7 @@ type containerBackend interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type imageBackend interface {
|
type imageBackend interface {
|
||||||
ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error)
|
ImageDelete(imageRef string, force, prune bool) ([]types.ImageDeleteResponseItem, error)
|
||||||
ImageHistory(imageName string) ([]*image.HistoryResponseItem, error)
|
ImageHistory(imageName string) ([]*image.HistoryResponseItem, error)
|
||||||
Images(imageFilters filters.Args, all bool, withExtraAttrs bool) ([]*types.ImageSummary, error)
|
Images(imageFilters filters.Args, all bool, withExtraAttrs bool) ([]*types.ImageSummary, error)
|
||||||
LookupImage(name string) (*types.ImageInspect, error)
|
LookupImage(name string) (*types.ImageInspect, error)
|
||||||
|
|
|
@ -2337,7 +2337,7 @@ definitions:
|
||||||
-
|
-
|
||||||
NetworkID: "4qvuz4ko70xaltuqbt8956gd1"
|
NetworkID: "4qvuz4ko70xaltuqbt8956gd1"
|
||||||
Addr: "10.255.0.3/16"
|
Addr: "10.255.0.3/16"
|
||||||
ImageDeleteResponse:
|
ImageDeleteResponseItem:
|
||||||
type: "object"
|
type: "object"
|
||||||
properties:
|
properties:
|
||||||
Untagged:
|
Untagged:
|
||||||
|
@ -4780,19 +4780,20 @@ paths:
|
||||||
delete:
|
delete:
|
||||||
summary: "Remove an image"
|
summary: "Remove an image"
|
||||||
description: |
|
description: |
|
||||||
Remove an image, along with any untagged parent images that were referenced by that image.
|
Remove an image, along with any untagged parent images that were
|
||||||
|
referenced by that image.
|
||||||
|
|
||||||
Images can't be removed if they have descendant images, are being used by a running container or are being used by a build.
|
Images can't be removed if they have descendant images, are being
|
||||||
|
used by a running container or are being used by a build.
|
||||||
operationId: "ImageDelete"
|
operationId: "ImageDelete"
|
||||||
produces:
|
produces: ["application/json"]
|
||||||
- "application/json"
|
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: "No error"
|
description: "The image was deleted successfully"
|
||||||
schema:
|
schema:
|
||||||
type: "array"
|
type: "array"
|
||||||
items:
|
items:
|
||||||
$ref: "#/definitions/ImageDeleteResponse"
|
$ref: "#/definitions/ImageDeleteResponseItem"
|
||||||
examples:
|
examples:
|
||||||
application/json:
|
application/json:
|
||||||
- Untagged: "3e2f21a89f"
|
- Untagged: "3e2f21a89f"
|
||||||
|
@ -4920,7 +4921,7 @@ paths:
|
||||||
description: "Images that were deleted"
|
description: "Images that were deleted"
|
||||||
type: "array"
|
type: "array"
|
||||||
items:
|
items:
|
||||||
$ref: "#/definitions/ImageDeleteResponse"
|
$ref: "#/definitions/ImageDeleteResponseItem"
|
||||||
SpaceReclaimed:
|
SpaceReclaimed:
|
||||||
description: "Disk space reclaimed in bytes"
|
description: "Disk space reclaimed in bytes"
|
||||||
type: "integer"
|
type: "integer"
|
||||||
|
|
15
api/types/image_delete_response_item.go
Normal file
15
api/types/image_delete_response_item.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package types
|
||||||
|
|
||||||
|
// This file was generated by the swagger tool.
|
||||||
|
// Editing this file might prove futile when you re-run the swagger generate command
|
||||||
|
|
||||||
|
// ImageDeleteResponseItem image delete response item
|
||||||
|
// swagger:model ImageDeleteResponseItem
|
||||||
|
type ImageDeleteResponseItem struct {
|
||||||
|
|
||||||
|
// The image ID of an image that was deleted
|
||||||
|
Deleted string `json:"Deleted,omitempty"`
|
||||||
|
|
||||||
|
// The image ID of an image that was untagged
|
||||||
|
Untagged string `json:"Untagged,omitempty"`
|
||||||
|
}
|
|
@ -17,13 +17,6 @@ import (
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImageDelete contains response of Engine API:
|
|
||||||
// DELETE "/images/{name:.*}"
|
|
||||||
type ImageDelete struct {
|
|
||||||
Untagged string `json:",omitempty"`
|
|
||||||
Deleted string `json:",omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GraphDriverData returns Image's graph driver config info
|
// GraphDriverData returns Image's graph driver config info
|
||||||
// when calling inspect command
|
// when calling inspect command
|
||||||
type GraphDriverData struct {
|
type GraphDriverData struct {
|
||||||
|
@ -508,7 +501,7 @@ type VolumesPruneReport struct {
|
||||||
// ImagesPruneReport contains the response for Engine API:
|
// ImagesPruneReport contains the response for Engine API:
|
||||||
// POST "/images/prune"
|
// POST "/images/prune"
|
||||||
type ImagesPruneReport struct {
|
type ImagesPruneReport struct {
|
||||||
ImagesDeleted []ImageDelete
|
ImagesDeleted []ImageDeleteResponseItem
|
||||||
SpaceReclaimed uint64
|
SpaceReclaimed uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImageRemove removes an image from the docker host.
|
// ImageRemove removes an image from the docker host.
|
||||||
func (cli *Client) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDelete, error) {
|
func (cli *Client) ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
|
||||||
query := url.Values{}
|
query := url.Values{}
|
||||||
|
|
||||||
if options.Force {
|
if options.Force {
|
||||||
|
@ -24,7 +24,7 @@ func (cli *Client) ImageRemove(ctx context.Context, imageID string, options type
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var dels []types.ImageDelete
|
var dels []types.ImageDeleteResponseItem
|
||||||
err = json.NewDecoder(resp.body).Decode(&dels)
|
err = json.NewDecoder(resp.body).Decode(&dels)
|
||||||
ensureReaderClosed(resp)
|
ensureReaderClosed(resp)
|
||||||
return dels, err
|
return dels, err
|
||||||
|
|
|
@ -63,7 +63,7 @@ func TestImageRemove(t *testing.T) {
|
||||||
return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual)
|
return nil, fmt.Errorf("%s not set in URL query properly. Expected '%s', got %s", key, expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b, err := json.Marshal([]types.ImageDelete{
|
b, err := json.Marshal([]types.ImageDeleteResponseItem{
|
||||||
{
|
{
|
||||||
Untagged: "image_id1",
|
Untagged: "image_id1",
|
||||||
},
|
},
|
||||||
|
|
|
@ -79,7 +79,7 @@ type ImageAPIClient interface {
|
||||||
ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)
|
ImageLoad(ctx context.Context, input io.Reader, quiet bool) (types.ImageLoadResponse, error)
|
||||||
ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error)
|
ImagePull(ctx context.Context, ref string, options types.ImagePullOptions) (io.ReadCloser, error)
|
||||||
ImagePush(ctx context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error)
|
ImagePush(ctx context.Context, ref string, options types.ImagePushOptions) (io.ReadCloser, error)
|
||||||
ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]types.ImageDelete, error)
|
ImageRemove(ctx context.Context, image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
|
||||||
ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error)
|
ImageSearch(ctx context.Context, term string, options types.ImageSearchOptions) ([]registry.SearchResult, error)
|
||||||
ImageSave(ctx context.Context, images []string) (io.ReadCloser, error)
|
ImageSave(ctx context.Context, images []string) (io.ReadCloser, error)
|
||||||
ImageTag(ctx context.Context, image, ref string) error
|
ImageTag(ctx context.Context, image, ref string) error
|
||||||
|
|
|
@ -61,9 +61,9 @@ const (
|
||||||
// FIXME: remove ImageDelete's dependency on Daemon, then move to the graph
|
// FIXME: remove ImageDelete's dependency on Daemon, then move to the graph
|
||||||
// package. This would require that we no longer need the daemon to determine
|
// package. This would require that we no longer need the daemon to determine
|
||||||
// whether images are being used by a stopped or running container.
|
// whether images are being used by a stopped or running container.
|
||||||
func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.ImageDelete, error) {
|
func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.ImageDeleteResponseItem, error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
records := []types.ImageDelete{}
|
records := []types.ImageDeleteResponseItem{}
|
||||||
|
|
||||||
imgID, err := daemon.GetImageID(imageRef)
|
imgID, err := daemon.GetImageID(imageRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -99,7 +99,7 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
untaggedRecord := types.ImageDelete{Untagged: parsedRef.String()}
|
untaggedRecord := types.ImageDeleteResponseItem{Untagged: parsedRef.String()}
|
||||||
|
|
||||||
daemon.LogImageEvent(imgID.String(), imgID.String(), "untag")
|
daemon.LogImageEvent(imgID.String(), imgID.String(), "untag")
|
||||||
records = append(records, untaggedRecord)
|
records = append(records, untaggedRecord)
|
||||||
|
@ -126,7 +126,7 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I
|
||||||
return records, err
|
return records, err
|
||||||
}
|
}
|
||||||
|
|
||||||
untaggedRecord := types.ImageDelete{Untagged: repoRef.String()}
|
untaggedRecord := types.ImageDeleteResponseItem{Untagged: repoRef.String()}
|
||||||
records = append(records, untaggedRecord)
|
records = append(records, untaggedRecord)
|
||||||
} else {
|
} else {
|
||||||
remainingRefs = append(remainingRefs, repoRef)
|
remainingRefs = append(remainingRefs, repoRef)
|
||||||
|
@ -162,7 +162,7 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
untaggedRecord := types.ImageDelete{Untagged: parsedRef.String()}
|
untaggedRecord := types.ImageDeleteResponseItem{Untagged: parsedRef.String()}
|
||||||
|
|
||||||
daemon.LogImageEvent(imgID.String(), imgID.String(), "untag")
|
daemon.LogImageEvent(imgID.String(), imgID.String(), "untag")
|
||||||
records = append(records, untaggedRecord)
|
records = append(records, untaggedRecord)
|
||||||
|
@ -244,9 +244,9 @@ func (daemon *Daemon) removeImageRef(ref reference.Named) (reference.Named, erro
|
||||||
// removeAllReferencesToImageID attempts to remove every reference to the given
|
// removeAllReferencesToImageID attempts to remove every reference to the given
|
||||||
// imgID from this daemon's store of repository tag/digest references. Returns
|
// imgID from this daemon's store of repository tag/digest references. Returns
|
||||||
// on the first encountered error. Removed references are logged to this
|
// on the first encountered error. Removed references are logged to this
|
||||||
// daemon's event service. An "Untagged" types.ImageDelete is added to the
|
// daemon's event service. An "Untagged" types.ImageDeleteResponseItem is added to the
|
||||||
// given list of records.
|
// given list of records.
|
||||||
func (daemon *Daemon) removeAllReferencesToImageID(imgID image.ID, records *[]types.ImageDelete) error {
|
func (daemon *Daemon) removeAllReferencesToImageID(imgID image.ID, records *[]types.ImageDeleteResponseItem) error {
|
||||||
imageRefs := daemon.referenceStore.References(imgID.Digest())
|
imageRefs := daemon.referenceStore.References(imgID.Digest())
|
||||||
|
|
||||||
for _, imageRef := range imageRefs {
|
for _, imageRef := range imageRefs {
|
||||||
|
@ -255,7 +255,7 @@ func (daemon *Daemon) removeAllReferencesToImageID(imgID image.ID, records *[]ty
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
untaggedRecord := types.ImageDelete{Untagged: parsedRef.String()}
|
untaggedRecord := types.ImageDeleteResponseItem{Untagged: parsedRef.String()}
|
||||||
|
|
||||||
daemon.LogImageEvent(imgID.String(), imgID.String(), "untag")
|
daemon.LogImageEvent(imgID.String(), imgID.String(), "untag")
|
||||||
*records = append(*records, untaggedRecord)
|
*records = append(*records, untaggedRecord)
|
||||||
|
@ -295,7 +295,7 @@ func (idc *imageDeleteConflict) Error() string {
|
||||||
// conflict is encountered, it will be returned immediately without deleting
|
// conflict is encountered, it will be returned immediately without deleting
|
||||||
// the image. If quiet is true, any encountered conflicts will be ignored and
|
// the image. If quiet is true, any encountered conflicts will be ignored and
|
||||||
// the function will return nil immediately without deleting the image.
|
// the function will return nil immediately without deleting the image.
|
||||||
func (daemon *Daemon) imageDeleteHelper(imgID image.ID, records *[]types.ImageDelete, force, prune, quiet bool) error {
|
func (daemon *Daemon) imageDeleteHelper(imgID image.ID, records *[]types.ImageDeleteResponseItem, force, prune, quiet bool) error {
|
||||||
// First, determine if this image has any conflicts. Ignore soft conflicts
|
// First, determine if this image has any conflicts. Ignore soft conflicts
|
||||||
// if force is true.
|
// if force is true.
|
||||||
c := conflictHard
|
c := conflictHard
|
||||||
|
@ -331,9 +331,9 @@ func (daemon *Daemon) imageDeleteHelper(imgID image.ID, records *[]types.ImageDe
|
||||||
}
|
}
|
||||||
|
|
||||||
daemon.LogImageEvent(imgID.String(), imgID.String(), "delete")
|
daemon.LogImageEvent(imgID.String(), imgID.String(), "delete")
|
||||||
*records = append(*records, types.ImageDelete{Deleted: imgID.String()})
|
*records = append(*records, types.ImageDeleteResponseItem{Deleted: imgID.String()})
|
||||||
for _, removedLayer := range removedLayers {
|
for _, removedLayer := range removedLayers {
|
||||||
*records = append(*records, types.ImageDelete{Deleted: removedLayer.ChainID.String()})
|
*records = append(*records, types.ImageDeleteResponseItem{Deleted: removedLayer.ChainID.String()})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !prune || parent == "" {
|
if !prune || parent == "" {
|
||||||
|
|
|
@ -114,7 +114,7 @@ func (daemon *Daemon) ImagesPrune(pruneFilters filters.Args) (*types.ImagesPrune
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
deletedImages := []types.ImageDelete{}
|
deletedImages := []types.ImageDeleteResponseItem{}
|
||||||
refs := daemon.referenceStore.References(dgst)
|
refs := daemon.referenceStore.References(dgst)
|
||||||
if len(refs) > 0 {
|
if len(refs) > 0 {
|
||||||
if danglingOnly {
|
if danglingOnly {
|
||||||
|
|
|
@ -3,13 +3,14 @@ set -eu
|
||||||
|
|
||||||
swagger generate model -f api/swagger.yaml \
|
swagger generate model -f api/swagger.yaml \
|
||||||
-t api -m types --skip-validator -C api/swagger-gen.yaml \
|
-t api -m types --skip-validator -C api/swagger-gen.yaml \
|
||||||
-n Volume \
|
|
||||||
-n Port \
|
|
||||||
-n ImageSummary \
|
|
||||||
-n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \
|
|
||||||
-n ErrorResponse \
|
-n ErrorResponse \
|
||||||
-n IdResponse \
|
-n IdResponse \
|
||||||
-n ServiceUpdateResponse
|
-n ImageDeleteResponseItem \
|
||||||
|
-n ImageSummary \
|
||||||
|
-n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \
|
||||||
|
-n Port \
|
||||||
|
-n ServiceUpdateResponse \
|
||||||
|
-n Volume
|
||||||
|
|
||||||
swagger generate operation -f api/swagger.yaml \
|
swagger generate operation -f api/swagger.yaml \
|
||||||
-t api -a types -m types -C api/swagger-gen.yaml \
|
-t api -a types -m types -C api/swagger-gen.yaml \
|
||||||
|
|
Loading…
Reference in a new issue