diff --git a/cmd/climc/shell/compute/cachedimages.go b/cmd/climc/shell/compute/cachedimages.go index 7d05739957..899e94d67f 100644 --- a/cmd/climc/shell/compute/cachedimages.go +++ b/cmd/climc/shell/compute/cachedimages.go @@ -15,62 +15,17 @@ package compute import ( - "yunion.io/x/onecloud/pkg/mcclient" + "yunion.io/x/onecloud/cmd/climc/shell" modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute" - "yunion.io/x/onecloud/pkg/mcclient/options" + opts "yunion.io/x/onecloud/pkg/mcclient/options" + options "yunion.io/x/onecloud/pkg/mcclient/options/compute" ) func init() { - type CachedImageListOptions struct { - options.BaseListOptions - ImageType string `help:"image type" choices:"system|customized|shared|market"` - - Region string `help:"show images cached at cloud region"` - Zone string `help:"show images cached at zone"` - - HostSchedtagId string `help:"filter cached image with host schedtag"` - Valid *bool `help:"valid cachedimage"` - } - R(&CachedImageListOptions{}, "cached-image-list", "List cached images", func(s *mcclient.ClientSession, args *CachedImageListOptions) error { - params, err := options.ListStructToParams(args) - if err != nil { - return err - } - result, err := modules.Cachedimages.List(s, params) - if err != nil { - return err - } - printList(result, modules.Cachedimages.GetColumns(s)) - return nil - }) - - type CachedImageShowOptions struct { - ID string `help:"ID or Name of the cached image to show"` - } - R(&CachedImageShowOptions{}, "cached-image-show", "Show cached image details", func(s *mcclient.ClientSession, args *CachedImageShowOptions) error { - result, err := modules.Cachedimages.Get(s, args.ID, nil) - if err != nil { - return err - } - printObject(result) - return nil - }) - - R(&CachedImageShowOptions{}, "cached-image-refresh", "Refresh cached image details", func(s *mcclient.ClientSession, args *CachedImageShowOptions) error { - result, err := modules.Cachedimages.PerformAction(s, args.ID, "refresh", nil) - if err != nil { - return err - } - printObject(result) - return nil - }) - - type CachedImageDeleteOptions struct { - ID []string `help:"ID or Name of the cached image to show"` - } - R(&CachedImageDeleteOptions{}, "cached-image-delete", "Remove cached image information", func(s *mcclient.ClientSession, args *CachedImageDeleteOptions) error { - results := modules.Cachedimages.BatchDelete(s, args.ID, nil) - printBatchResults(results, modules.Cachedimages.GetColumns(s)) - return nil - }) + cmd := shell.NewResourceCmd(&modules.Cachedimages).WithKeyword("cached-image") + cmd.List(&options.CachedImageListOptions{}) + cmd.Show(&opts.BaseIdOptions{}) + cmd.PerformClass("cache-image", &options.CachedImageCacheImageOptions{}) + cmd.Perform("refresh", &opts.BaseIdOptions{}) + cmd.BatchDelete(&opts.BaseIdsOptions{}) } diff --git a/pkg/apis/compute/guests.go b/pkg/apis/compute/guests.go index 98d7f9a997..a71c48ea82 100644 --- a/pkg/apis/compute/guests.go +++ b/pkg/apis/compute/guests.go @@ -283,6 +283,7 @@ type Floppy struct { type Cdrom struct { Ordinal int `json:"ordinal"` Detail string `json:"detail"` + Name string `json:"name"` BootIndex int8 `json:"boot_index"` } diff --git a/pkg/compute/models/guest_queries.go b/pkg/compute/models/guest_queries.go index 2526441b10..9c4511d945 100644 --- a/pkg/compute/models/guest_queries.go +++ b/pkg/compute/models/guest_queries.go @@ -249,7 +249,7 @@ func (manager *SGuestManager) FetchCustomizeColumns( for i := range rows { for _, gcd := range gcds[guestIds[i]] { if details := gcd.GetDetails(); len(details) > 0 { - t := api.Cdrom{Ordinal: gcd.Ordinal, Detail: details, BootIndex: gcd.BootIndex} + t := api.Cdrom{Ordinal: gcd.Ordinal, Detail: details, BootIndex: gcd.BootIndex, Name: gcd.Name} rows[i].Cdrom = append(rows[i].Cdrom, t) } } @@ -724,7 +724,19 @@ func fetchGuestIsolatedDevices(guestIds []string) map[string][]api.SIsolatedDevi } func fetchGuestCdroms(guestIds []string) map[string][]SGuestcdrom { - q := GuestcdromManager.Query().In("id", guestIds) + sq := GuestcdromManager.Query().In("id", guestIds).SubQuery() + image := CachedimageManager.Query().SubQuery() + + q := sq.Query( + sq.Field("id"), + sq.Field("path"), + sq.Field("boot_index"), + sq.Field("image_id"), + image.Field("size"), + image.Field("name"), + ) + q = q.LeftJoin(image, sqlchemy.Equals(sq.Field("image_id"), image.Field("id"))) + gcds := make([]SGuestcdrom, 0) err := q.All(&gcds) if err != nil { diff --git a/pkg/mcclient/options/compute/cachedimage.go b/pkg/mcclient/options/compute/cachedimage.go new file mode 100644 index 0000000000..9704d03938 --- /dev/null +++ b/pkg/mcclient/options/compute/cachedimage.go @@ -0,0 +1,44 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package compute + +import ( + "yunion.io/x/jsonutils" + + "yunion.io/x/onecloud/pkg/mcclient/options" +) + +type CachedImageListOptions struct { + options.BaseListOptions + ImageType string `help:"image type" choices:"system|customized|shared|market"` + + Region string `help:"show images cached at cloud region"` + Zone string `help:"show images cached at zone"` + + HostSchedtagId string `help:"filter cached image with host schedtag"` + Valid *bool `help:"valid cachedimage"` +} + +func (opts *CachedImageListOptions) Params() (jsonutils.JSONObject, error) { + return options.ListStructToParams(opts) +} + +type CachedImageCacheImageOptions struct { + ID string +} + +func (opts *CachedImageCacheImageOptions) Params() (jsonutils.JSONObject, error) { + return jsonutils.Marshal(map[string]string{"image_id": opts.ID}), nil +}