diff --git a/pkg/apis/compute/dnsrecordsets.go b/pkg/apis/compute/dnsrecordsets.go index 0027780af8..222b651005 100644 --- a/pkg/apis/compute/dnsrecordsets.go +++ b/pkg/apis/compute/dnsrecordsets.go @@ -15,9 +15,14 @@ package compute import ( + "regexp" + "yunion.io/x/jsonutils" + "yunion.io/x/pkg/util/regutils" "yunion.io/x/onecloud/pkg/apis" + "yunion.io/x/onecloud/pkg/cloudprovider" + "yunion.io/x/onecloud/pkg/httperrors" ) const ( @@ -47,7 +52,10 @@ type DnsRecordSetCreateInput struct { type DnsRecordSetUpdateInput struct { apis.EnabledStatusStandaloneResourceBaseUpdateInput - SDnsRecordSet + DnsType string `json:"dns_type"` + DnsValue string `json:"dns_value"` + TTL *int64 `json:"ttl"` + MxPriority *int64 `json:"mx_priority"` TrafficPolicies []DnsRecordPolicy } @@ -76,3 +84,29 @@ type DnsRecordDisableInput struct { type DnsRecordSetTrafficPoliciesInput struct { TrafficPolicies []DnsRecordPolicy `json:"traffic_policies"` } + +func (recordset *SDnsRecordSet) ValidateDnsrecordValue() error { + domainReg := regexp.MustCompile(`^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\.([a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\.[a-zA-Z]{2,3})$`) + switch cloudprovider.TDnsType(recordset.DnsType) { + case cloudprovider.DnsTypeMX: + if recordset.MxPriority < 1 || recordset.MxPriority > 50 { + return httperrors.NewOutOfRangeError("mx_priority range limited to [1,50]") + } + if !domainReg.MatchString(recordset.DnsValue) { + return httperrors.NewInputParameterError("invalid domain %s for MX record", recordset.DnsValue) + } + case cloudprovider.DnsTypeA: + if !regutils.MatchIP4Addr(recordset.DnsValue) { + return httperrors.NewInputParameterError("invalid ipv4 %s for A record", recordset.DnsValue) + } + case cloudprovider.DnsTypeAAAA: + if !regutils.MatchIP6Addr(recordset.DnsValue) { + return httperrors.NewInputParameterError("invalid ipv6 %s for AAAA record", recordset.DnsValue) + } + case cloudprovider.DnsTypeCNAME: + if !domainReg.MatchString(recordset.DnsValue) { + return httperrors.NewInputParameterError("invalid domain %s for CNAME record", recordset.DnsValue) + } + } + return nil +} diff --git a/pkg/cloudprovider/dnszone.go b/pkg/cloudprovider/dnszone.go index b287639ecf..201fd3f978 100644 --- a/pkg/cloudprovider/dnszone.go +++ b/pkg/cloudprovider/dnszone.go @@ -16,6 +16,7 @@ package cloudprovider import ( "fmt" + "strings" "yunion.io/x/jsonutils" "yunion.io/x/pkg/utils" @@ -601,7 +602,7 @@ func (r DnsRecordSet) GetMxPriority() int64 { } func (record DnsRecordSet) Equals(r DnsRecordSet) bool { - if record.DnsName != r.DnsName { + if strings.ToLower(record.DnsName) != strings.ToLower(r.DnsName) { return false } if record.DnsType != r.DnsType { diff --git a/pkg/compute/models/dns_recordsets.go b/pkg/compute/models/dns_recordsets.go index 833be5d1dc..4eb90e6e88 100644 --- a/pkg/compute/models/dns_recordsets.go +++ b/pkg/compute/models/dns_recordsets.go @@ -18,13 +18,11 @@ import ( "context" "database/sql" "fmt" - "regexp" "strings" "yunion.io/x/jsonutils" "yunion.io/x/pkg/errors" "yunion.io/x/pkg/tristate" - "yunion.io/x/pkg/util/regutils" "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" @@ -75,6 +73,44 @@ func (manager *SDnsRecordSetManager) EnableGenerateName() bool { return false } +type SDnsRecordSetValidateInfo struct { + api.SDnsRecordSet + TrafficPolicies []api.DnsRecordPolicy +} + +func validateDnsrecordPolicy(dnsType string, dnsZone *SDnsZone, trafficPolicies []api.DnsRecordPolicy) error { + for _, policy := range trafficPolicies { + if len(policy.Provider) == 0 { + return httperrors.NewGeneralError(fmt.Errorf("missing traffic policy provider")) + } + factory, err := cloudprovider.GetProviderFactory(policy.Provider) + if err != nil { + return 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(dnsType), dnsTypes); !ok { + return httperrors.NewNotSupportedError("%s %s not supported dns type %s", policy.Provider, dnsZone.ZoneType, dnsType) + } + _policyTypes := factory.GetSupportedDnsPolicyTypes() + policyTypes, _ := _policyTypes[cloudprovider.TDnsZoneType(dnsZone.ZoneType)] + if ok, _ := utils.InArray(cloudprovider.TDnsPolicyType(policy.PolicyType), policyTypes); !ok { + return 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 httperrors.NewMissingParameterError(fmt.Sprintf("missing %s policy value", policy.Provider)) + } + if isIn, _ := utils.InArray(cloudprovider.TDnsPolicyValue(policy.PolicyValue), policyValues); !isIn { + return httperrors.NewNotSupportedError("%s %s %s not support %s", policy.Provider, dnsZone.ZoneType, policy.PolicyType, policy.PolicyValue) + } + } + } + return nil +} + // 创建 func (manager *SDnsRecordSetManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, input api.DnsRecordSetCreateInput) (api.DnsRecordSetCreateInput, error) { var err error @@ -93,69 +129,36 @@ func (manager *SDnsRecordSetManager) ValidateCreateData(ctx context.Context, use } return input, httperrors.NewGeneralError(err) } - domainReg := regexp.MustCompile(`^(([a-zA-Z]{1})|([a-zA-Z]{1}[a-zA-Z]{1})|([a-zA-Z]{1}[0-9]{1})|([0-9]{1}[a-zA-Z]{1})|([a-zA-Z0-9][a-zA-Z0-9-_]{1,61}[a-zA-Z0-9]))\.([a-zA-Z]{2,6}|[a-zA-Z0-9-]{2,30}\.[a-zA-Z]{2,3})$`) - switch cloudprovider.TDnsType(input.DnsType) { - case cloudprovider.DnsTypeMX: - if input.MxPriority < 1 || input.MxPriority > 50 { - return input, httperrors.NewOutOfRangeError("mx_priority range limited to [1,50]") - } - if !domainReg.MatchString(input.DnsValue) { - return input, httperrors.NewInputParameterError("invalid domain %s for MX record", input.DnsValue) - } - case cloudprovider.DnsTypeA: - if !regutils.MatchIP4Addr(input.DnsValue) { - return input, httperrors.NewInputParameterError("invalid ipv4 %s for A record", input.DnsValue) - } - case cloudprovider.DnsTypeAAAA: - if !regutils.MatchIP6Addr(input.DnsValue) { - return input, httperrors.NewInputParameterError("invalid ipv6 %s for AAAA record", input.DnsValue) - } - case cloudprovider.DnsTypeCNAME: - if !domainReg.MatchString(input.DnsValue) { - return input, httperrors.NewInputParameterError("invalid domain %s for CNAME record", input.DnsValue) - } - default: - input.MxPriority = 0 + dnsZone := _dnsZone.(*SDnsZone) + + validateInfo := &SDnsRecordSetValidateInfo{} + + validateInfo.TrafficPolicies = input.TrafficPolicies + + recordset := api.SDnsRecordSet{} + recordset.DnsZoneId = input.DnsZoneId + recordset.DnsType = input.DnsType + recordset.DnsValue = input.DnsValue + recordset.TTL = input.TTL + recordset.MxPriority = input.MxPriority + + err = recordset.ValidateDnsrecordValue() + if err != nil { + return input, err + } + err = validateDnsrecordPolicy(input.DnsType, dnsZone, input.TrafficPolicies) + if err != nil { + return input, err } - dnsZone := _dnsZone.(*SDnsZone) - 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) - } - } - } // 处理重复的记录 dupedRecordsets := make([]SDnsRecordSet, 0) err = DnsRecordSetManager.Query().Equals("dns_zone_id", input.DnsZoneId).Equals("name", input.Name).Equals("dns_type", input.DnsType).All(&dupedRecordsets) if err != nil && errors.Cause(err) != sql.ErrNoRows { return input, httperrors.NewGeneralError(err) } - // 检查dnsrecord 是否通过为policy重复 - // simple 不能重复,不能和其他policy重复 + // 检查dnsrecord 是否通过policy重复 + // simple类型不能重复,不能和其他policy重复 // 不同类型policy不能重复 // 同类型policy的dnsrecord重复时,需要通过policyvalue区别 for i := range dupedRecordsets { @@ -167,28 +170,25 @@ func (manager *SDnsRecordSetManager) ValidateCreateData(ctx context.Context, use return input, httperrors.NewGeneralError(errors.Wrap(err, "db.FetchModelObjects")) } if len(policies) < 1 || len(input.TrafficPolicies) < 1 { - return input, httperrors.NewNotSupportedError("duplicated dnsrecord not support") + return input, httperrors.NewNotSupportedError("duplicated dnsrecord with simple policy not support") } for j := range policies { for k := range input.TrafficPolicies { - if strings.Contains(policies[j].Name, "MultiValueAnswer") && - input.TrafficPolicies[k].PolicyType == "MultiValueAnswer" { - if dupedRecordsets[i].DnsValue == input.DnsValue { - return input, httperrors.NewNotSupportedError("MultiValueAnswer policy not support duplicated recordset value") - } + if policies[j].Provider != input.TrafficPolicies[k].Provider { continue } if strings.Contains(policies[j].Name, "Simple") || strings.Contains(input.TrafficPolicies[k].PolicyType, "Simple") || - policies[j].Name != fmt.Sprintf("%s-%s", input.TrafficPolicies[k].Provider, input.TrafficPolicies[k].PolicyType) { - return input, httperrors.NewNotSupportedError("duplicated dnsrecord not support") + policies[j].PolicyType != input.TrafficPolicies[k].PolicyType { + return input, httperrors.NewNotSupportedError("duplicated dnsrecord with different policyType not support") } if policies[j].PolicyValue == input.TrafficPolicies[k].PolicyValue { - return input, httperrors.NewNotSupportedError("duplicated dnsrecord not support") + return input, httperrors.NewNotSupportedError("duplicated dnsrecord with same policyValue not support") } } } } + input.Status = api.DNS_RECORDSET_STATUS_AVAILABLE input.DnsZoneId = dnsZone.Id return input, nil @@ -324,12 +324,14 @@ func (self *SDnsRecordSet) Delete(ctx context.Context, userCred mcclient.TokenCr type sRecordUniqValues struct { DnsZoneId string DnsType string + DnsName string DnsValue string } func (self *SDnsRecordSet) GetUniqValues() jsonutils.JSONObject { return jsonutils.Marshal(sRecordUniqValues{ DnsZoneId: self.DnsZoneId, + DnsName: self.Name, DnsType: self.DnsType, DnsValue: self.DnsValue, }) @@ -347,12 +349,19 @@ func (manager *SDnsRecordSetManager) FilterByUniqValues(q *sqlchemy.SQuery, valu if len(uniq.DnsZoneId) > 0 { q = q.Equals("dns_zone_id", uniq.DnsZoneId) } + if len(uniq.DnsName) > 0 { + q = q.Equals("name", uniq.DnsName) + } + if uniq.DnsType == "CNAME" { + return q + } if len(uniq.DnsType) > 0 { q = q.Equals("dns_type", uniq.DnsType) } if len(uniq.DnsValue) > 0 { q = q.Equals("dns_value", uniq.DnsValue) } + return q } @@ -427,32 +436,90 @@ func (self *SDnsRecordSet) ValidateUpdateData(ctx context.Context, userCred mccl 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) + recordset := api.SDnsRecordSet{} + recordset.DnsType = input.DnsType + recordset.DnsValue = input.DnsValue + if len(recordset.DnsType) == 0 { + recordset.DnsType = self.DnsType + } + if len(recordset.DnsValue) == 0 { + recordset.DnsValue = self.DnsValue + } + if input.TTL != nil { + recordset.TTL = *input.TTL + } else { + recordset.TTL = self.TTL + } + if input.MxPriority != nil { + recordset.MxPriority = *input.MxPriority + } else { + recordset.MxPriority = self.MxPriority + } + + err = recordset.ValidateDnsrecordValue() + if err != nil { + return input, err + } + err = validateDnsrecordPolicy(input.DnsType, dnsZone, input.TrafficPolicies) + if err != nil { + return input, err + } + + // 处理重复的记录 + dupedRecordsets := make([]SDnsRecordSet, 0) + q := DnsRecordSetManager.Query().Equals("dns_zone_id", dnsZone.Id).Equals("name", input.Name).Equals("dns_type", input.DnsType).NotEquals("id", self.Id) + err = q.All(&dupedRecordsets) + if err != nil && errors.Cause(err) != sql.ErrNoRows { + return input, httperrors.NewGeneralError(err) + } + // 检查dnsrecord 是否通过policy重复 + // simple类型不能重复,不能和其他policy重复 + // 不同类型policy不能重复 + // 同类型policy的dnsrecord重复时,需要通过policyvalue区别 + + oldPolicies, err := self.GetDnsTrafficPolicies() + if err != nil { + return input, httperrors.NewGeneralError(err) + } + for i := range dupedRecordsets { + sq := DnsRecordSetTrafficPolicyManager.Query("dns_traffic_policy_id").Equals("dns_recordset_id", dupedRecordsets[i].Id) + q := DnsTrafficPolicyManager.Query().In("id", sq.SubQuery()) + policies := []SDnsTrafficPolicy{} + err := db.FetchModelObjects(DnsTrafficPolicyManager, q, &policies) if err != nil { - return input, httperrors.NewGeneralError(errors.Wrapf(err, "invalid provider %s for traffic policy", policy.Provider)) + return input, httperrors.NewGeneralError(errors.Wrap(err, "db.FetchModelObjects")) } - _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) + if len(policies) < 1 || (len(input.TrafficPolicies) < 1 && len(oldPolicies) < 1) { + return input, httperrors.NewNotSupportedError("duplicated dnsrecord with simple policy not support") } - _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)) + for j := range policies { + for k := range input.TrafficPolicies { + if policies[j].Provider != input.TrafficPolicies[k].Provider { + continue + } + if strings.Contains(policies[j].Name, "Simple") || + strings.Contains(input.TrafficPolicies[k].PolicyType, "Simple") || + policies[j].PolicyType != input.TrafficPolicies[k].PolicyType { + return input, httperrors.NewNotSupportedError("duplicated dnsrecord with different policyType not support") + } + if policies[j].PolicyValue == input.TrafficPolicies[k].PolicyValue { + return input, httperrors.NewNotSupportedError("duplicated dnsrecord with same policyValue not support") + } } - 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) + if len(input.TrafficPolicies) < 1 { + for k := range oldPolicies { + if policies[j].Provider != input.TrafficPolicies[k].Provider { + continue + } + if strings.Contains(policies[j].Name, "Simple") || + strings.Contains(oldPolicies[k].PolicyType, "Simple") || + policies[j].PolicyType != oldPolicies[k].PolicyType { + return input, httperrors.NewNotSupportedError("duplicated dnsrecord with different policyType not support") + } + if policies[j].PolicyValue == oldPolicies[k].PolicyValue { + return input, httperrors.NewNotSupportedError("duplicated dnsrecord with same policyValue not support") + } + } } } } diff --git a/pkg/compute/models/dns_zones.go b/pkg/compute/models/dns_zones.go index 772744cf54..8d493c3b90 100644 --- a/pkg/compute/models/dns_zones.go +++ b/pkg/compute/models/dns_zones.go @@ -34,6 +34,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/db/lockman" "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas" "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" + "yunion.io/x/onecloud/pkg/cloudcommon/policy" "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/httperrors" "yunion.io/x/onecloud/pkg/mcclient" @@ -245,12 +246,35 @@ func (manager *SDnsZoneManager) FetchCustomizeColumns( return rows } + ownedVpcs := []SVpc{} + q := VpcManager.Query() + ownerId, queryScope, err := db.FetchCheckQueryOwnerScope(ctx, userCred, query, VpcManager, policy.PolicyActionList, true) + if err != nil { + log.Errorf("FetchCheckQueryOwnerScope error: %v", err) + return rows + } + q = VpcManager.FilterByOwner(q, ownerId, queryScope) + err = db.FetchModelObjects(VpcManager, q, &ownedVpcs) + if err != nil { + log.Errorf("db.FetchModelObjects error: %v", err) + return rows + } + ownedVpcIds := map[string]bool{} + for i := range ownedVpcs { + ownedVpcIds[ownedVpcs[i].Id] = true + } + for i := range rows { records, _ := recordMaps[dnsZoneIds[i]] rows[i].DnsRecordsetCount = len(records) vpcs, _ := vpcMaps[dnsZoneIds[i]] - rows[i].VpcCount = len(vpcs) + rows[i].VpcCount = 0 + for j := range vpcs { + if _, ok := ownedVpcIds[vpcs[j]]; ok { + rows[i].VpcCount++ + } + } } return rows } diff --git a/pkg/mcclient/options/dnszone_recordsets.go b/pkg/mcclient/options/dnszone_recordsets.go index 2a1824ac3d..5500127d0b 100644 --- a/pkg/mcclient/options/dnszone_recordsets.go +++ b/pkg/mcclient/options/dnszone_recordsets.go @@ -78,14 +78,37 @@ func (opts *DnsRecordSetIdOptions) Params() (jsonutils.JSONObject, error) { type DnsRecordSetUpdateOptions struct { BaseUpdateOptions - DnsType string `choices:"A|AAAA|CAA|CNAME|MX|NS|SRV|SOA|TXT|PRT|DS|DNSKEY|IPSECKEY|NAPTR|SPF|SSHFP|TLSA|REDIRECT_URL|FORWARD_URL"` - DnsValue string - Ttl int64 + DnsType string `choices:"A|AAAA|CAA|CNAME|MX|NS|SRV|SOA|TXT|PRT|DS|DNSKEY|IPSECKEY|NAPTR|SPF|SSHFP|TLSA|REDIRECT_URL|FORWARD_URL"` + DnsValue string + Ttl int64 + MxPriority int64 `help:"dns mx type mxpriority"` + Provider string `help:"Dns triffic policy provider" choices:"Aws|Qcloud|Aliyun"` + PolicyType string `choices:"Simple|ByCarrier|ByGeoLocation|BySearchEngine|IpRange|Weighted|Failover|MultiValueAnswer|Latency"` + PolicyValue string `help:"Dns Traffic policy value"` + PolicyOptions string } func (opts *DnsRecordSetUpdateOptions) Params() (jsonutils.JSONObject, error) { params := jsonutils.Marshal(opts).(*jsonutils.JSONDict) params.Remove("id") + params.Remove("policy_type") + params.Remove("policy_options") + if len(opts.PolicyType) > 0 && len(opts.Provider) > 0 { + policies := jsonutils.NewArray() + policy := jsonutils.NewDict() + policy.Add(jsonutils.NewString(opts.PolicyType), "policy_type") + policy.Add(jsonutils.NewString(opts.Provider), "provider") + policy.Add(jsonutils.NewString(opts.PolicyValue), "policy_value") + if len(opts.PolicyOptions) > 0 { + policyParams, err := jsonutils.Parse([]byte(opts.PolicyOptions)) + if err != nil { + return nil, errors.Wrapf(err, "jsonutils.Parse(%s)", opts.PolicyOptions) + } + policy.Add(policyParams, "policy_options") + } + policies.Add(policy) + params.Add(policies, "traffic_policies") + } return params, nil } diff --git a/pkg/multicloud/aliyun/dns_domain_record.go b/pkg/multicloud/aliyun/dns_domain_record.go index 5b53d6b06d..f479dad7a6 100644 --- a/pkg/multicloud/aliyun/dns_domain_record.go +++ b/pkg/multicloud/aliyun/dns_domain_record.go @@ -212,7 +212,7 @@ func (self *SDomainRecord) GetDnsName() string { } func (self *SDomainRecord) GetStatus() string { - return api.DNS_ZONE_STATUS_AVAILABLE + return api.DNS_RECORDSET_STATUS_AVAILABLE } func (self *SDomainRecord) GetEnabled() bool { diff --git a/pkg/multicloud/aliyun/private_zone_record.go b/pkg/multicloud/aliyun/private_zone_record.go index 0f736370e2..b9134f9994 100644 --- a/pkg/multicloud/aliyun/private_zone_record.go +++ b/pkg/multicloud/aliyun/private_zone_record.go @@ -159,7 +159,7 @@ func (self *SPvtzRecord) GetDnsName() string { } func (self *SPvtzRecord) GetStatus() string { - return api.DNS_ZONE_STATUS_AVAILABLE + return api.DNS_RECORDSET_STATUS_AVAILABLE } func (self *SPvtzRecord) GetEnabled() bool { diff --git a/pkg/multicloud/aws/dnshostedzone.go b/pkg/multicloud/aws/dnshostedzone.go index b1c6ebf8f3..df493b9bfa 100644 --- a/pkg/multicloud/aws/dnshostedzone.go +++ b/pkg/multicloud/aws/dnshostedzone.go @@ -23,6 +23,7 @@ import ( "yunion.io/x/jsonutils" "yunion.io/x/pkg/errors" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" "yunion.io/x/onecloud/pkg/multicloud" ) @@ -60,7 +61,7 @@ func (self *SHostedZone) GetGlobalId() string { } func (self *SHostedZone) GetStatus() string { - return "" + return api.DNS_ZONE_STATUS_AVAILABLE } func (self *SHostedZone) Refresh() error { diff --git a/pkg/multicloud/aws/dnsrecordset.go b/pkg/multicloud/aws/dnsrecordset.go index 67b36442ca..1781f9aae5 100644 --- a/pkg/multicloud/aws/dnsrecordset.go +++ b/pkg/multicloud/aws/dnsrecordset.go @@ -25,6 +25,7 @@ import ( "yunion.io/x/pkg/errors" "yunion.io/x/pkg/util/stringutils" + api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudprovider" ) @@ -292,7 +293,7 @@ func (client *SAwsClient) RemoveDnsRecordSet(hostedZoneId string, opts *cloudpro } func (self *SdnsRecordSet) GetStatus() string { - return "" + return api.DNS_RECORDSET_STATUS_AVAILABLE } func (self *SdnsRecordSet) GetEnabled() bool { diff --git a/pkg/multicloud/qcloud/dnspod_record.go b/pkg/multicloud/qcloud/dnspod_record.go index 6d5e6b0332..94be68a4c9 100644 --- a/pkg/multicloud/qcloud/dnspod_record.go +++ b/pkg/multicloud/qcloud/dnspod_record.go @@ -236,7 +236,7 @@ func (self *SDnsRecord) GetDnsName() string { func (self *SDnsRecord) GetStatus() string { if self.Status != "spam" { - return api.DNS_ZONE_STATUS_AVAILABLE + return api.DNS_RECORDSET_STATUS_AVAILABLE } return api.DNS_ZONE_STATUS_UNKNOWN }