Merge pull request #18207 from wanyaoqi/feat/detect-target-image-by-cloudaccount

feat(region,glance): from cloudaccount to enable vmdk target format
This commit is contained in:
Zexi Li
2023-10-07 13:15:55 +08:00
committed by GitHub
4 changed files with 42 additions and 1 deletions
+8
View File
@@ -52,6 +52,7 @@ import (
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/mcclient/modules/image"
"yunion.io/x/onecloud/pkg/util/logclient"
"yunion.io/x/onecloud/pkg/util/stringutils2"
)
@@ -635,6 +636,13 @@ func (self *SCloudaccount) PostCreate(ctx context.Context, userCred mcclient.Tok
} else {
self.SubmitSyncAccountTask(ctx, userCred, nil)
}
if self.Brand == api.CLOUD_PROVIDER_VMWARE {
_, err := image.Images.PerformClassAction(auth.GetAdminSession(ctx, options.Options.Region), "vmware-account-added", nil)
if err != nil {
log.Errorf("failed inform glance vmware account added: %s", err)
}
}
}
func (self *SCloudaccount) savePassword(secret string) error {
+8
View File
@@ -1657,6 +1657,14 @@ func (img *SImage) PerformChangeOwner(ctx context.Context, userCred mcclient.Tok
return ret, nil
}
func (m *SImageManager) PerformVmwareAccountAdded(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input apis.PerformChangeProjectOwnerInput) (jsonutils.JSONObject, error) {
log.Infof("perform vmware account added")
if !utils.IsInStringArray(string(qemuimgfmt.VMDK), options.Options.TargetImageFormats) {
options.Options.TargetImageFormats = append(options.Options.TargetImageFormats, string(qemuimgfmt.VMDK))
}
return nil, nil
}
/*func (image *SImage) getRealPath() string {
diskPath := image.GetPath("")
if !fileutils2.Exists(diskPath) {
+1 -1
View File
@@ -36,7 +36,7 @@ type SImageOptions struct {
EnableTorrentService bool `help:"Enable torrent service" default:"false"`
TargetImageFormats []string `help:"target image formats that the system will automatically convert to" default:"qcow2,vmdk"`
TargetImageFormats []string `help:"target image formats that the system will automatically convert to" default:"qcow2"`
TorrentClientPath string `help:"path to torrent executable" default:"/opt/yunion/bin/torrent"`
+25
View File
@@ -15,6 +15,7 @@
package service
import (
"context"
"fmt"
"os"
"path/filepath"
@@ -22,7 +23,10 @@ import (
"time"
execlient "yunion.io/x/executor/client"
"yunion.io/x/jsonutils"
"yunion.io/x/log"
"yunion.io/x/pkg/util/qemuimgfmt"
"yunion.io/x/pkg/utils"
_ "yunion.io/x/sqlchemy/backends"
api "yunion.io/x/onecloud/pkg/apis/image"
@@ -38,6 +42,8 @@ import (
_ "yunion.io/x/onecloud/pkg/image/policy"
_ "yunion.io/x/onecloud/pkg/image/tasks"
"yunion.io/x/onecloud/pkg/image/torrent"
"yunion.io/x/onecloud/pkg/mcclient/auth"
"yunion.io/x/onecloud/pkg/mcclient/modules/compute"
"yunion.io/x/onecloud/pkg/util/fileutils2"
"yunion.io/x/onecloud/pkg/util/procutils"
)
@@ -94,6 +100,14 @@ func StartService() {
log.Infof("Auth complete!!")
})
if ok, err := hasVmwareAccount(); err != nil {
log.Errorf("failed get vmware cloudaccounts")
} else if ok {
if !utils.IsInStringArray(string(qemuimgfmt.VMDK), options.Options.TargetImageFormats) {
options.Options.TargetImageFormats = append(options.Options.TargetImageFormats, string(qemuimgfmt.VMDK))
}
}
trackers := torrent.GetTrackers()
if len(trackers) == 0 {
log.Errorf("no valid torrent-tracker")
@@ -150,6 +164,17 @@ func StartService() {
})
}
func hasVmwareAccount() (bool, error) {
q := jsonutils.NewDict()
q.Add(jsonutils.NewString("system"), "scope")
q.Add(jsonutils.NewString("brand"), "VMware")
res, err := compute.Cloudaccounts.List(auth.GetAdminSession(context.Background(), options.Options.Region), q)
if err != nil {
return false, err
}
return res.Total > 0, nil
}
func initS3() {
url := options.Options.S3Endpoint
if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") {