Merge pull request #5410 from st1971/api-fixes

APIv2: compatible api fixes
This commit is contained in:
OpenShift Merge Robot
2020-03-06 21:19:55 +01:00
committed by GitHub
14 changed files with 122 additions and 11 deletions

View File

@ -57,6 +57,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
}{
// override any golang type defaults
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
return
@ -85,7 +86,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
var list = make([]*handlers.Container, len(containers))
for i, ctnr := range containers {
api, err := handlers.LibpodToContainer(ctnr, infoData)
api, err := handlers.LibpodToContainer(ctnr, infoData, query.Size)
if err != nil {
utils.InternalServerError(w, err)
return
@ -97,6 +98,17 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
func GetContainer(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value("runtime").(*libpod.Runtime)
decoder := r.Context().Value("decoder").(*schema.Decoder)
query := struct {
Size bool `schema:"size"`
}{
// override any golang type defaults
}
if err := decoder.Decode(&query, r.URL.Query()); err != nil {
utils.Error(w, "Something went wrong.", http.StatusBadRequest, errors.Wrapf(err, "Failed to parse parameters for %s", r.URL.String()))
return
}
name := utils.GetName(r)
ctnr, err := runtime.LookupContainer(name)
@ -104,7 +116,7 @@ func GetContainer(w http.ResponseWriter, r *http.Request) {
utils.ContainerNotFound(w, name, err)
return
}
api, err := handlers.LibpodToContainerJSON(ctnr)
api, err := handlers.LibpodToContainerJSON(ctnr, query.Size)
if err != nil {
utils.InternalServerError(w, err)
return

View File

@ -305,7 +305,7 @@ func GetImages(w http.ResponseWriter, r *http.Request) {
utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Failed get images"))
return
}
var summaries = make([]*handlers.ImageSummary, len(images)+1)
var summaries = make([]*handlers.ImageSummary, len(images))
for j, img := range images {
is, err := handlers.ImageToImageSummary(img)
if err != nil {

View File

@ -347,7 +347,7 @@ func ImageDataToImageInspect(ctx context.Context, l *libpodImage.Image) (*ImageI
}
func LibpodToContainer(l *libpod.Container, infoData []define.InfoData) (*Container, error) {
func LibpodToContainer(l *libpod.Container, infoData []define.InfoData, sz bool) (*Container, error) {
imageId, imageName := l.Image()
var (
@ -360,11 +360,18 @@ func LibpodToContainer(l *libpod.Container, infoData []define.InfoData) (*Contai
if state, err = l.State(); err != nil {
return nil, err
}
if sizeRW, err = l.RWSize(); err != nil {
return nil, err
stateStr := state.String()
if stateStr == "configured" {
stateStr = "created"
}
if sizeRootFs, err = l.RootFsSize(); err != nil {
return nil, err
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{
@ -378,7 +385,7 @@ func LibpodToContainer(l *libpod.Container, infoData []define.InfoData) (*Contai
SizeRw: sizeRW,
SizeRootFs: sizeRootFs,
Labels: l.Labels(),
State: string(state),
State: stateStr,
Status: "",
HostConfig: struct {
NetworkMode string `json:",omitempty"`
@ -391,9 +398,9 @@ func LibpodToContainer(l *libpod.Container, infoData []define.InfoData) (*Contai
}, nil
}
func LibpodToContainerJSON(l *libpod.Container) (*docker.ContainerJSON, error) {
func LibpodToContainerJSON(l *libpod.Container, sz bool) (*docker.ContainerJSON, error) {
_, imageName := l.Image()
inspect, err := l.Inspect(true)
inspect, err := l.Inspect(sz)
if err != nil {
return nil, err
}