mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(region): show pretty cdrom info for server (#20776)
This commit is contained in:
@@ -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{})
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user