diff --git a/pkg/apis/compute/dnsrecordsets.go b/pkg/apis/compute/dnsrecordsets.go index 445545ff71..b7afe190e4 100644 --- a/pkg/apis/compute/dnsrecordsets.go +++ b/pkg/apis/compute/dnsrecordsets.go @@ -25,6 +25,7 @@ const ( ) type DnsRecordPolicy struct { + // 平台 Provider string `json:"provider"` PolicyType string `json:"policy_type"` PolicyValue string `json:"policy_value"` @@ -42,9 +43,18 @@ type DnsRecordSetCreateInput struct { TrafficPolicies []DnsRecordPolicy `json:"traffic_policies"` } +type DnsRecordSetUpdateInput struct { + apis.EnabledStatusStandaloneResourceBaseUpdateInput + + SDnsRecordSet + + TrafficPolicies []DnsRecordPolicy +} + type DnsRecordSetDetails struct { apis.EnabledStatusStandaloneResourceDetails SDnsRecordSet + TrafficPolicies []DnsRecordPolicy } diff --git a/pkg/compute/models/dbinstance_accounts.go b/pkg/compute/models/dbinstance_accounts.go index ce19da9862..aaa00b8b45 100644 --- a/pkg/compute/models/dbinstance_accounts.go +++ b/pkg/compute/models/dbinstance_accounts.go @@ -264,6 +264,10 @@ func (manager *SDBInstanceAccountManager) QueryDistinctExtraField(q *sqlchemy.SQ return q, httperrors.ErrNotFound } +func (self *SDBInstanceAccount) GetUniqValues() jsonutils.JSONObject { + return jsonutils.Marshal(map[string]string{"dbinstance_id": self.DBInstanceId}) +} + func (manager *SDBInstanceAccountManager) FetchUniqValues(ctx context.Context, data jsonutils.JSONObject) jsonutils.JSONObject { dbinstanceId, _ := data.GetString("dbinstance_id") return jsonutils.Marshal(map[string]string{"dbinstance_id": dbinstanceId}) diff --git a/pkg/compute/models/dns_recordsets.go b/pkg/compute/models/dns_recordsets.go index 97c2a7a886..fbb75b1b7b 100644 --- a/pkg/compute/models/dns_recordsets.go +++ b/pkg/compute/models/dns_recordsets.go @@ -256,6 +256,14 @@ type sRecordUniqValues struct { DnsValue string } +func (self *SDnsRecordSet) GetUniqValues() jsonutils.JSONObject { + return jsonutils.Marshal(sRecordUniqValues{ + DnsZoneId: self.DnsZoneId, + DnsType: self.DnsType, + DnsValue: self.DnsValue, + }) +} + func (manager *SDnsRecordSetManager) FetchUniqValues(ctx context.Context, data jsonutils.JSONObject) jsonutils.JSONObject { values := &sRecordUniqValues{} data.Unmarshal(values) @@ -335,9 +343,60 @@ func (self *SDnsRecordSet) PreDelete(ctx context.Context, userCred mcclient.Toke dnsZone.DoSyncRecords(ctx, userCred) } +// 更新 +func (self *SDnsRecordSet) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, input api.DnsRecordSetUpdateInput) (api.DnsRecordSetUpdateInput, error) { + var err error + input.EnabledStatusStandaloneResourceBaseUpdateInput, err = self.SEnabledStatusStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, input.EnabledStatusStandaloneResourceBaseUpdateInput) + if err != nil { + return input, err + } + + dnsZone, err := self.GetDnsZone() + if err != nil { + return input, httperrors.NewGeneralError(errors.Wrapf(err, "GetDnsZone")) + } + + for _, policy := range input.TrafficPolicies { + if len(policy.Provider) == 0 { + return input, httperrors.NewGeneralError(fmt.Errorf("missing traffic policy provider")) + } + factory, err := cloudprovider.GetProviderFactory(policy.Provider) + if err != nil { + return input, httperrors.NewGeneralError(errors.Wrapf(err, "invalid provider %s for traffic policy", policy.Provider)) + } + _dnsTypes := factory.GetSupportedDnsTypes() + dnsTypes, _ := _dnsTypes[cloudprovider.TDnsZoneType(dnsZone.ZoneType)] + if ok, _ := utils.InArray(cloudprovider.TDnsType(input.DnsType), dnsTypes); !ok { + return input, httperrors.NewNotSupportedError("%s %s not supported dns type %s", policy.Provider, dnsZone.ZoneType, input.DnsType) + } + _policyTypes := factory.GetSupportedDnsPolicyTypes() + policyTypes, _ := _policyTypes[cloudprovider.TDnsZoneType(dnsZone.ZoneType)] + if ok, _ := utils.InArray(cloudprovider.TDnsPolicyType(policy.PolicyType), policyTypes); !ok { + return input, httperrors.NewNotSupportedError("%s %s not supported policy type %s", policy.Provider, dnsZone.ZoneType, policy.PolicyType) + } + _policyValues := factory.GetSupportedDnsPolicyValues() + policyValues, _ := _policyValues[cloudprovider.TDnsPolicyType(policy.PolicyType)] + if len(policyValues) > 0 { + if len(policy.PolicyValue) == 0 { + return input, httperrors.NewMissingParameterError(fmt.Sprintf("missing %s policy value", policy.Provider)) + } + if isIn, _ := utils.InArray(cloudprovider.TDnsPolicyValue(policy.PolicyValue), policyValues); !isIn { + return input, httperrors.NewNotSupportedError("%s %s %s not support %s", policy.Provider, dnsZone.ZoneType, policy.PolicyType, policy.PolicyValue) + } + } + } + return input, nil +} + func (self *SDnsRecordSet) PostUpdate(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) { self.SEnabledStatusStandaloneResourceBase.PostUpdate(ctx, userCred, query, data) + input := &api.DnsRecordSetUpdateInput{} + data.Unmarshal(input) + for _, policy := range input.TrafficPolicies { + self.setTrafficPolicy(ctx, userCred, policy.Provider, cloudprovider.TDnsPolicyType(policy.PolicyType), cloudprovider.TDnsPolicyValue(policy.PolicyValue), policy.PolicyOptions) + } + dnsZone, err := self.GetDnsZone() if err != nil { return diff --git a/pkg/compute/models/elasticcache_accounts.go b/pkg/compute/models/elasticcache_accounts.go index 5786174a41..c89c1e17ce 100644 --- a/pkg/compute/models/elasticcache_accounts.go +++ b/pkg/compute/models/elasticcache_accounts.go @@ -187,6 +187,10 @@ func (manager *SElasticcacheAccountManager) newFromCloudElasticcacheAccount(ctx return &account, nil } +func (self *SElasticcacheAccount) GetUniqValues() jsonutils.JSONObject { + return jsonutils.Marshal(map[string]string{"elasticcache_id": self.ElasticcacheId}) +} + func (manager *SElasticcacheAccountManager) FetchUniqValues(ctx context.Context, data jsonutils.JSONObject) jsonutils.JSONObject { cacheId := jsonutils.GetAnyString(data, []string{"elasticcache_id", "elasticcache"}) return jsonutils.Marshal(map[string]string{"elasticcache_id": cacheId}) diff --git a/pkg/compute/models/elasticcache_acls.go b/pkg/compute/models/elasticcache_acls.go index 5e946a319d..230e955a8a 100644 --- a/pkg/compute/models/elasticcache_acls.go +++ b/pkg/compute/models/elasticcache_acls.go @@ -167,6 +167,10 @@ func (manager *SElasticcacheAclManager) newFromCloudElasticcacheAcl(ctx context. return &acl, nil } +func (self *SElasticcacheAcl) GetUniqValues() jsonutils.JSONObject { + return jsonutils.Marshal(map[string]string{"elasticcache_id": self.ElasticcacheId}) +} + func (manager *SElasticcacheAclManager) FetchUniqValues(ctx context.Context, data jsonutils.JSONObject) jsonutils.JSONObject { elasticcacheId := jsonutils.GetAnyString(data, []string{"elasticcache_id", "elasticcache"}) return jsonutils.Marshal(map[string]string{"elasticcache_id": elasticcacheId}) diff --git a/pkg/compute/models/elasticcache_backups.go b/pkg/compute/models/elasticcache_backups.go index d4652ff0be..292d4d9c68 100644 --- a/pkg/compute/models/elasticcache_backups.go +++ b/pkg/compute/models/elasticcache_backups.go @@ -195,6 +195,10 @@ func (manager *SElasticcacheBackupManager) newFromCloudElasticcacheBackup(ctx co return &backup, nil } +func (self *SElasticcacheBackup) GetUniqValues() jsonutils.JSONObject { + return jsonutils.Marshal(map[string]string{"elasticcache_id": self.ElasticcacheId}) +} + func (manager *SElasticcacheBackupManager) FetchUniqValues(ctx context.Context, data jsonutils.JSONObject) jsonutils.JSONObject { cacheId := jsonutils.GetAnyString(data, []string{"elasticcache_id", "elasticcache"}) return jsonutils.Marshal(map[string]string{"elasticcache_id": cacheId}) diff --git a/pkg/compute/models/isolated_devices.go b/pkg/compute/models/isolated_devices.go index 5da02b7972..db79d3a3c4 100644 --- a/pkg/compute/models/isolated_devices.go +++ b/pkg/compute/models/isolated_devices.go @@ -780,6 +780,10 @@ func (manager *SIsolatedDeviceManager) GetDevsOnHost(hostId string, model string return devs, nil } +func (self *SIsolatedDevice) GetUniqValues() jsonutils.JSONObject { + return jsonutils.Marshal(map[string]string{"host_id": self.HostId}) +} + func (manager *SIsolatedDeviceManager) FetchUniqValues(ctx context.Context, data jsonutils.JSONObject) jsonutils.JSONObject { hostId, _ := data.GetString("host_id") return jsonutils.Marshal(map[string]string{"host_id": hostId}) diff --git a/pkg/compute/models/reservedips.go b/pkg/compute/models/reservedips.go index 225ca600a2..07aabbe13b 100644 --- a/pkg/compute/models/reservedips.go +++ b/pkg/compute/models/reservedips.go @@ -319,6 +319,10 @@ func (rip *SReservedip) IsExpired() bool { return false } +func (self *SReservedip) GetUniqValues() jsonutils.JSONObject { + return jsonutils.Marshal(map[string]string{"network_id": self.NetworkId}) +} + func (manager *SReservedipManager) FetchUniqValues(ctx context.Context, data jsonutils.JSONObject) jsonutils.JSONObject { networkId, _ := data.GetString("network_id") return jsonutils.Marshal(map[string]string{"network_id": networkId}) diff --git a/pkg/compute/models/scaling_policy.go b/pkg/compute/models/scaling_policy.go index 4f23d222c2..4ed1a47f53 100644 --- a/pkg/compute/models/scaling_policy.go +++ b/pkg/compute/models/scaling_policy.go @@ -116,6 +116,10 @@ func (spm *SScalingPolicyManager) QueryDistinctExtraField(q *sqlchemy.SQuery, fi return spm.SScalingGroupResourceBaseManager.QueryDistinctExtraField(q, field) } +func (sgm *SScalingPolicy) GetUniqValues() jsonutils.JSONObject { + return jsonutils.Marshal(map[string]string{"scaling_group_id": sgm.ScalingGroupId}) +} + func (spm *SScalingPolicyManager) FetchUniqValues(ctx context.Context, data jsonutils.JSONObject) jsonutils.JSONObject { return spm.SScalingGroupResourceBaseManager.FetchUniqValues(ctx, data) }