mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
fix(glance): sync service options after vmware detected (#20607)
This commit is contained in:
@@ -29,7 +29,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules/identity"
|
||||
)
|
||||
|
||||
func getServiceIdByType(s *mcclient.ClientSession, typeStr string, verStr string) (string, error) {
|
||||
func GetServiceIdByType(s *mcclient.ClientSession, typeStr string, verStr string) (string, error) {
|
||||
params := jsonutils.NewDict()
|
||||
if len(verStr) > 0 {
|
||||
typeStr += "_" + verStr
|
||||
@@ -47,7 +47,7 @@ func getServiceIdByType(s *mcclient.ClientSession, typeStr string, verStr string
|
||||
return result.Data[0].GetString("id")
|
||||
}
|
||||
|
||||
func getServiceConfig(s *mcclient.ClientSession, serviceId string) (jsonutils.JSONObject, error) {
|
||||
func GetServiceConfig(s *mcclient.ClientSession, serviceId string) (jsonutils.JSONObject, error) {
|
||||
conf, err := identity.ServicesV3.GetSpecific(s, serviceId, "config", nil)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "modules.ServicesV3.GetSpecific config")
|
||||
@@ -81,11 +81,11 @@ func (s *mcclientServiceConfigSession) Merge(opts interface{}, serviceType strin
|
||||
// epType, _ := s.config.GetString("session_endpoint_type")
|
||||
s.session = auth.GetAdminSession(context.Background(), region)
|
||||
if len(serviceType) > 0 {
|
||||
s.serviceId, _ = getServiceIdByType(s.session, serviceType, serviceVersion)
|
||||
s.serviceId, _ = GetServiceIdByType(s.session, serviceType, serviceVersion)
|
||||
if len(s.serviceId) > 0 {
|
||||
serviceConf, err := getServiceConfig(s.session, s.serviceId)
|
||||
serviceConf, err := GetServiceConfig(s.session, s.serviceId)
|
||||
if err != nil {
|
||||
log.Errorf("getServiceConfig for %s failed: %s", serviceType, err)
|
||||
log.Errorf("GetServiceConfig for %s failed: %s", serviceType, err)
|
||||
} else if serviceConf != nil {
|
||||
s.config.Update(serviceConf)
|
||||
merged = true
|
||||
@@ -95,11 +95,11 @@ func (s *mcclientServiceConfigSession) Merge(opts interface{}, serviceType strin
|
||||
}
|
||||
}
|
||||
}
|
||||
s.commonServiceId, _ = getServiceIdByType(s.session, consts.COMMON_SERVICE, "")
|
||||
s.commonServiceId, _ = GetServiceIdByType(s.session, consts.COMMON_SERVICE, "")
|
||||
if len(s.commonServiceId) > 0 {
|
||||
commonConf, err := getServiceConfig(s.session, s.commonServiceId)
|
||||
commonConf, err := GetServiceConfig(s.session, s.commonServiceId)
|
||||
if err != nil {
|
||||
log.Errorf("getServiceConfig for %s failed: %s", consts.COMMON_SERVICE, err)
|
||||
log.Errorf("GetServiceConfig for %s failed: %s", consts.COMMON_SERVICE, err)
|
||||
} else if commonConf != nil {
|
||||
s.config.Update(commonConf)
|
||||
merged = true
|
||||
|
||||
@@ -48,6 +48,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/notifyclient"
|
||||
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
|
||||
deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
|
||||
"yunion.io/x/onecloud/pkg/hostman/hostdeployer/deployclient"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -1659,10 +1660,45 @@ func (img *SImage) PerformChangeOwner(ctx context.Context, userCred mcclient.Tok
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func UpdateImageConfigTargetImageFormats(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
s := auth.GetSession(ctx, userCred, options.Options.Region)
|
||||
serviceId, err := common_options.GetServiceIdByType(s, api.SERVICE_TYPE, "")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get service id")
|
||||
}
|
||||
|
||||
defConf, err := common_options.GetServiceConfig(s, serviceId)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "GetServiceConfig")
|
||||
}
|
||||
targetFormats := make([]string, 0)
|
||||
err = defConf.Unmarshal(&targetFormats, "target_image_formats")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "get target_image_formats")
|
||||
}
|
||||
if !utils.IsInStringArray(string(qemuimgfmt.VMDK), targetFormats) {
|
||||
targetFormats = append(targetFormats, string(qemuimgfmt.VMDK))
|
||||
}
|
||||
defConfDict := defConf.(*jsonutils.JSONDict)
|
||||
defConfDict.Set("target_image_formats", jsonutils.NewStringArray(targetFormats))
|
||||
nconf := jsonutils.NewDict()
|
||||
nconf.Add(defConfDict, "config", "default")
|
||||
_, err = identity_modules.ServicesV3.PerformAction(s, serviceId, "config", nconf)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "fail to save config")
|
||||
}
|
||||
return 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))
|
||||
if err := UpdateImageConfigTargetImageFormats(ctx, userCred); err != nil {
|
||||
log.Errorf("failed update target_image_formats %s", err)
|
||||
} else {
|
||||
options.Options.TargetImageFormats = append(options.Options.TargetImageFormats, string(qemuimgfmt.VMDK))
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -107,7 +107,11 @@ func StartService() {
|
||||
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))
|
||||
if err = models.UpdateImageConfigTargetImageFormats(context.Background(), auth.AdminCredential()); err != nil {
|
||||
log.Errorf("failed update target_image_formats %s", err)
|
||||
} else {
|
||||
options.Options.TargetImageFormats = append(options.Options.TargetImageFormats, string(qemuimgfmt.VMDK))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user