mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 14:19:49 +08:00
fix(region): public cloud user data
This commit is contained in:
@@ -368,6 +368,7 @@ type ServerCreateInput struct {
|
||||
VcpuCount int `json:"vcpu_count"`
|
||||
|
||||
// 用户自定义启动脚本
|
||||
// 公有云私有云只支持 #cloud-config yaml 格式, 且只有linux系统生效
|
||||
// required: false
|
||||
UserData string `json:"user_data"`
|
||||
|
||||
|
||||
@@ -176,9 +176,6 @@ func ParseDiskConfig(diskStr string, idx int) (*compute.DiskConfig, error) {
|
||||
case "mountpoint":
|
||||
diskConfig.Mountpoint = str
|
||||
case "storage_type", "backend":
|
||||
if !utils.IsInStringArray(str, compute.STORAGE_ALL_TYPES) {
|
||||
return nil, errors.Errorf("invalid disk storage type %s, allow choices: %s", str, compute.STORAGE_ALL_TYPES)
|
||||
}
|
||||
diskConfig.Backend = str
|
||||
case "snapshot", "snapshot_id":
|
||||
diskConfig.SnapshotId = str
|
||||
|
||||
@@ -170,9 +170,7 @@ func (vmConfig *SManagedVMCreateConfig) GetConfig(config *jsonutils.JSONDict) er
|
||||
if strings.ToLower(vmConfig.OsType) == strings.ToLower(osprofile.OS_TYPE_LINUX) {
|
||||
adminPublicKey, _ := config.GetString("admin_public_key")
|
||||
projectPublicKey, _ := config.GetString("project_public_key")
|
||||
oUserData, _ := config.GetString("user_data")
|
||||
|
||||
vmConfig.UserData = generateUserData(adminPublicKey, projectPublicKey, oUserData)
|
||||
vmConfig.UserData = generateUserData(adminPublicKey, projectPublicKey, vmConfig.UserData)
|
||||
}
|
||||
|
||||
resetPassword := jsonutils.QueryBoolean(config, "reset_password", false)
|
||||
|
||||
@@ -66,6 +66,7 @@ func (self *SManagedVirtualizedGuestDriver) GetJsonDescAtHost(ctx context.Contex
|
||||
config.Hostname = guest.Hostname
|
||||
config.Cpu = int(guest.VcpuCount)
|
||||
config.MemoryMB = guest.VmemSize
|
||||
config.UserData = guest.GetUserData(ctx, userCred)
|
||||
config.Description = guest.Description
|
||||
if params != nil {
|
||||
params.Unmarshal(&config.SPublicIpInfo)
|
||||
@@ -220,6 +221,12 @@ func (self *SManagedVirtualizedGuestDriver) ValidateCreateData(ctx context.Conte
|
||||
if input.Cdrom != "" {
|
||||
return nil, httperrors.NewInputParameterError("%s not support cdrom params", input.Hypervisor)
|
||||
}
|
||||
if len(input.UserData) > 0 {
|
||||
_, err := cloudinit.ParseUserData(input.UserData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3178,6 +3178,15 @@ func (self *SGuest) setUserData(ctx context.Context, userCred mcclient.TokenCred
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SGuest) GetUserData(ctx context.Context, userCred mcclient.TokenCredential) string {
|
||||
userData := self.GetMetadata(ctx, "user_data", userCred)
|
||||
if len(userData) == 0 {
|
||||
return userData
|
||||
}
|
||||
decodeData, _ := userdata.Decode(userData)
|
||||
return decodeData
|
||||
}
|
||||
|
||||
func (self *SGuest) PerformUserData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.ServerUserDataInput) (jsonutils.JSONObject, error) {
|
||||
if len(input.UserData) == 0 {
|
||||
return nil, httperrors.NewMissingParameterError("user_data")
|
||||
|
||||
Reference in New Issue
Block a user