Merge pull request #4442 from wanyaoqi/feature/wyq/image-batch-update

feature: image batch update
This commit is contained in:
yunion-ci-robot
2019-12-31 18:45:36 +08:00
committed by GitHub
2 changed files with 30 additions and 8 deletions
+5 -8
View File
@@ -221,9 +221,9 @@ func init() {
})
type ImageUpdateOptions struct {
ID string `help:"ID or Name of Image"`
Name string `help:"New name of the image"`
Description string `help:"Description of image"`
ID []string `help:"ID or Name of Image"`
Name string `help:"New name of the image"`
Description string `help:"Description of image"`
ImageOptionalOptions
}
@@ -239,11 +239,8 @@ func init() {
if err != nil {
return err
}
img, err := modules.Images.Update(s, args.ID, params)
if err != nil {
return err
}
printObject(img)
result := modules.Images.BatchUpdate(s, args.ID, params)
printBatchResults(result, modules.Images.GetColumns(s))
return nil
})
+25
View File
@@ -540,6 +540,31 @@ func (this *ImageManager) _update(s *mcclient.ClientSession, id string, params j
return json.Get("image")
}
func (this *ImageManager) BatchUpdate(
session *mcclient.ClientSession, idlist []string, params jsonutils.JSONObject,
) []modulebase.SubmitResult {
return modulebase.BatchDo(idlist, func(id string) (jsonutils.JSONObject, error) {
var curParams = params.(*jsonutils.JSONDict).Copy()
img, err := this.Get(session, id, nil)
if err != nil {
return nil, err
}
properties, _ := img.Get("properties")
if properties != nil {
propDict := properties.(*jsonutils.JSONDict)
propMap, _ := propDict.GetMap()
if propMap != nil {
for k, val := range propMap {
if !curParams.Contains("properties", k) {
curParams.Add(val, "properties", k)
}
}
}
}
return this._update(session, id, curParams, nil)
})
}
func (this *ImageManager) Download(s *mcclient.ClientSession, id string, format string, torrent bool) (jsonutils.JSONObject, io.Reader, int64, error) {
query := jsonutils.NewDict()
if len(format) > 0 {