yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/cloudprovider/dnszone.go (about)

     1  // Copyright 2019 Yunion
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package cloudprovider
    16  
    17  import (
    18  	"fmt"
    19  	"strings"
    20  
    21  	"yunion.io/x/jsonutils"
    22  	"yunion.io/x/pkg/utils"
    23  )
    24  
    25  type TDnsZoneType string
    26  type TDnsPolicyType string
    27  
    28  type TDnsType string
    29  
    30  type TDnsPolicyValue string
    31  
    32  type TDnsTTLRangeType string
    33  
    34  type TDnsProductType string
    35  
    36  const (
    37  	PublicZone  = TDnsZoneType("PublicZone")
    38  	PrivateZone = TDnsZoneType("PrivateZone")
    39  )
    40  
    41  const (
    42  	ContinuousTTlRange = TDnsTTLRangeType("ContinuousTTlRange")
    43  	DiscreteTTlRange   = TDnsTTLRangeType("DiscreteTTlRange")
    44  )
    45  
    46  const (
    47  	DnsPolicyTypeSimple           = TDnsPolicyType("Simple")           //简单
    48  	DnsPolicyTypeByCarrier        = TDnsPolicyType("ByCarrier")        //运营商
    49  	DnsPolicyTypeByGeoLocation    = TDnsPolicyType("ByGeoLocation")    //地理区域
    50  	DnsPolicyTypeBySearchEngine   = TDnsPolicyType("BySearchEngine")   //搜索引擎
    51  	DnsPolicyTypeIpRange          = TDnsPolicyType("IpRange")          //自定义IP范围
    52  	DnsPolicyTypeWeighted         = TDnsPolicyType("Weighted")         //加权
    53  	DnsPolicyTypeFailover         = TDnsPolicyType("Failover")         //故障转移
    54  	DnsPolicyTypeMultiValueAnswer = TDnsPolicyType("MultiValueAnswer") //多值应答
    55  	DnsPolicyTypeLatency          = TDnsPolicyType("Latency")          //延迟
    56  )
    57  
    58  const (
    59  	DnsTypeA            = TDnsType("A")
    60  	DnsTypeAAAA         = TDnsType("AAAA")
    61  	DnsTypeCAA          = TDnsType("CAA")
    62  	DnsTypeCNAME        = TDnsType("CNAME")
    63  	DnsTypeMX           = TDnsType("MX")
    64  	DnsTypeNS           = TDnsType("NS")
    65  	DnsTypeSRV          = TDnsType("SRV")
    66  	DnsTypeSOA          = TDnsType("SOA")
    67  	DnsTypeTXT          = TDnsType("TXT")
    68  	DnsTypePTR          = TDnsType("PTR")
    69  	DnsTypeDS           = TDnsType("DS")
    70  	DnsTypeDNSKEY       = TDnsType("DNSKEY")
    71  	DnsTypeIPSECKEY     = TDnsType("IPSECKEY")
    72  	DnsTypeNAPTR        = TDnsType("NAPTR")
    73  	DnsTypeSPF          = TDnsType("SPF")
    74  	DnsTypeSSHFP        = TDnsType("SSHFP")
    75  	DnsTypeTLSA         = TDnsType("TLSA")
    76  	DnsTypeREDIRECT_URL = TDnsType("REDIRECT_URL") //显性URL转发
    77  	DnsTypeFORWARD_URL  = TDnsType("FORWARD_URL")  //隐性URL转发
    78  )
    79  
    80  const (
    81  	DnsProductEnterpriseUltimate   = TDnsProductType("DP_EnterpriseUltimate")
    82  	DnsProductEnterpriseStandard   = TDnsProductType("DP_EnterpriseStandard")
    83  	DnsProductEnterpriseBasic      = TDnsProductType("DP_EnterpriseBasic")
    84  	DnsProductPersonalProfessional = TDnsProductType("DP_PersonalProfessional")
    85  	DnsProductFree                 = TDnsProductType("DP_Free")
    86  )
    87  
    88  var (
    89  	SUPPORTED_DNS_TYPES = []TDnsType{
    90  		DnsTypeA,
    91  		DnsTypeAAAA,
    92  		DnsTypeCAA,
    93  		DnsTypeCNAME,
    94  		DnsTypeMX,
    95  		DnsTypeNS,
    96  		DnsTypeSRV,
    97  		DnsTypeSOA,
    98  		DnsTypeTXT,
    99  		DnsTypePTR,
   100  		DnsTypeDS,
   101  		DnsTypeDNSKEY,
   102  		DnsTypeIPSECKEY,
   103  		DnsTypeNAPTR,
   104  		DnsTypeSPF,
   105  		DnsTypeSSHFP,
   106  		DnsTypeTLSA,
   107  		DnsTypeREDIRECT_URL,
   108  		DnsTypeFORWARD_URL,
   109  	}
   110  )
   111  
   112  var (
   113  	DnsPolicyValueEmpty = TDnsPolicyValue("")
   114  
   115  	DnsPolicyValueUnicom      = TDnsPolicyValue("unicom")
   116  	DnsPolicyValueTelecom     = TDnsPolicyValue("telecom")
   117  	DnsPolicyValueChinaMobile = TDnsPolicyValue("chinamobile")
   118  	DnsPolicyValueCernet      = TDnsPolicyValue("cernet")
   119  	DnsPolicyValueDrPeng      = TDnsPolicyValue("drpeng")
   120  	DnsPolicyValueBtvn        = TDnsPolicyValue("btvn")
   121  
   122  	DnsPolicyValueOversea  = TDnsPolicyValue("oversea")
   123  	DnsPolicyValueMainland = TDnsPolicyValue("mainland")
   124  
   125  	DnsPolicyValueBaidu   = TDnsPolicyValue("baidu")
   126  	DnsPolicyValueGoogle  = TDnsPolicyValue("google")
   127  	DnsPolicyValueBing    = TDnsPolicyValue("bing")
   128  	DnsPolicyValueYoudao  = TDnsPolicyValue("youdao")
   129  	DnsPolicyValueSousou  = TDnsPolicyValue("sousou")
   130  	DnsPolicyValueSougou  = TDnsPolicyValue("sougou")
   131  	DnsPolicyValueQihu360 = TDnsPolicyValue("qihu360")
   132  )
   133  
   134  var AwsGeoLocations = []TDnsPolicyValue{
   135  	TDnsPolicyValue("Default"),
   136  	TDnsPolicyValue("Andorra"),
   137  	TDnsPolicyValue("United Arab Emirates"),
   138  	TDnsPolicyValue("Afghanistan"),
   139  	TDnsPolicyValue("Antigua and Barbuda"),
   140  	TDnsPolicyValue("Anguilla"),
   141  	TDnsPolicyValue("Albania"),
   142  	TDnsPolicyValue("Armenia"),
   143  	TDnsPolicyValue("Angola"),
   144  	TDnsPolicyValue("Antarctica"),
   145  	TDnsPolicyValue("Argentina"),
   146  	TDnsPolicyValue("American Samoa"),
   147  	TDnsPolicyValue("Austria"),
   148  	TDnsPolicyValue("Australia"),
   149  	TDnsPolicyValue("Aruba"),
   150  	TDnsPolicyValue("Åland"),
   151  	TDnsPolicyValue("Azerbaijan"),
   152  	TDnsPolicyValue("Bosnia and Herzegovina"),
   153  	TDnsPolicyValue("Barbados"),
   154  	TDnsPolicyValue("Bangladesh"),
   155  	TDnsPolicyValue("Belgium"),
   156  	TDnsPolicyValue("Burkina Faso"),
   157  	TDnsPolicyValue("Bulgaria"),
   158  	TDnsPolicyValue("Bahrain"),
   159  	TDnsPolicyValue("Burundi"),
   160  	TDnsPolicyValue("Benin"),
   161  	TDnsPolicyValue("Saint Barthélemy"),
   162  	TDnsPolicyValue("Bermuda"),
   163  	TDnsPolicyValue("Brunei"),
   164  	TDnsPolicyValue("Bolivia"),
   165  	TDnsPolicyValue("Bonaire"),
   166  	TDnsPolicyValue("Brazil"),
   167  	TDnsPolicyValue("Bahamas"),
   168  	TDnsPolicyValue("Bhutan"),
   169  	TDnsPolicyValue("Botswana"),
   170  	TDnsPolicyValue("Belarus"),
   171  	TDnsPolicyValue("Belize"),
   172  	TDnsPolicyValue("Canada"),
   173  	TDnsPolicyValue("Cocos [Keeling] Islands"),
   174  	TDnsPolicyValue("Congo"),
   175  	TDnsPolicyValue("Central African Republic"),
   176  	TDnsPolicyValue("Republic of the Congo"),
   177  	TDnsPolicyValue("Switzerland"),
   178  	TDnsPolicyValue("Ivory Coast"),
   179  	TDnsPolicyValue("Cook Islands"),
   180  	TDnsPolicyValue("Chile"),
   181  	TDnsPolicyValue("Cameroon"),
   182  	TDnsPolicyValue("China"),
   183  	TDnsPolicyValue("Colombia"),
   184  	TDnsPolicyValue("Costa Rica"),
   185  	TDnsPolicyValue("Cuba"),
   186  	TDnsPolicyValue("Cape Verde"),
   187  	TDnsPolicyValue("Curaçao"),
   188  	TDnsPolicyValue("Cyprus"),
   189  	TDnsPolicyValue("Czech Republic"),
   190  	TDnsPolicyValue("Germany"),
   191  	TDnsPolicyValue("Djibouti"),
   192  	TDnsPolicyValue("Denmark"),
   193  	TDnsPolicyValue("Dominica"),
   194  	TDnsPolicyValue("Dominican Republic"),
   195  	TDnsPolicyValue("Algeria"),
   196  	TDnsPolicyValue("Ecuador"),
   197  	TDnsPolicyValue("Estonia"),
   198  	TDnsPolicyValue("Egypt"),
   199  	TDnsPolicyValue("Eritrea"),
   200  	TDnsPolicyValue("Spain"),
   201  	TDnsPolicyValue("Ethiopia"),
   202  	TDnsPolicyValue("Finland"),
   203  	TDnsPolicyValue("Fiji"),
   204  	TDnsPolicyValue("Falkland Islands"),
   205  	TDnsPolicyValue("Federated States of Micronesia"),
   206  	TDnsPolicyValue("Faroe Islands"),
   207  	TDnsPolicyValue("France"),
   208  	TDnsPolicyValue("Gabon"),
   209  	TDnsPolicyValue("United Kingdom"),
   210  	TDnsPolicyValue("Grenada"),
   211  	TDnsPolicyValue("Georgia"),
   212  	TDnsPolicyValue("French Guiana"),
   213  	TDnsPolicyValue("Guernsey"),
   214  	TDnsPolicyValue("Ghana"),
   215  	TDnsPolicyValue("Gibraltar"),
   216  	TDnsPolicyValue("Greenland"),
   217  	TDnsPolicyValue("Gambia"),
   218  	TDnsPolicyValue("Guinea"),
   219  	TDnsPolicyValue("Guadeloupe"),
   220  	TDnsPolicyValue("Equatorial Guinea"),
   221  	TDnsPolicyValue("Greece"),
   222  	TDnsPolicyValue("South Georgia and the South Sandwich Islands"),
   223  	TDnsPolicyValue("Guatemala"),
   224  	TDnsPolicyValue("Guam"),
   225  	TDnsPolicyValue("Guinea-Bissau"),
   226  	TDnsPolicyValue("Guyana"),
   227  	TDnsPolicyValue("Hong Kong"),
   228  	TDnsPolicyValue("Honduras"),
   229  	TDnsPolicyValue("Croatia"),
   230  	TDnsPolicyValue("Haiti"),
   231  	TDnsPolicyValue("Hungary"),
   232  	TDnsPolicyValue("Indonesia"),
   233  	TDnsPolicyValue("Ireland"),
   234  	TDnsPolicyValue("Israel"),
   235  	TDnsPolicyValue("Isle of Man"),
   236  	TDnsPolicyValue("India"),
   237  	TDnsPolicyValue("British Indian Ocean Territory"),
   238  	TDnsPolicyValue("Iraq"),
   239  	TDnsPolicyValue("Iran"),
   240  	TDnsPolicyValue("Iceland"),
   241  	TDnsPolicyValue("Italy"),
   242  	TDnsPolicyValue("Jersey"),
   243  	TDnsPolicyValue("Jamaica"),
   244  	TDnsPolicyValue("Hashemite Kingdom of Jordan"),
   245  	TDnsPolicyValue("Japan"),
   246  	TDnsPolicyValue("Kenya"),
   247  	TDnsPolicyValue("Kyrgyzstan"),
   248  	TDnsPolicyValue("Cambodia"),
   249  	TDnsPolicyValue("Kiribati"),
   250  	TDnsPolicyValue("Comoros"),
   251  	TDnsPolicyValue("Saint Kitts and Nevis"),
   252  	TDnsPolicyValue("North Korea"),
   253  	TDnsPolicyValue("Republic of Korea"),
   254  	TDnsPolicyValue("Kuwait"),
   255  	TDnsPolicyValue("Cayman Islands"),
   256  	TDnsPolicyValue("Kazakhstan"),
   257  	TDnsPolicyValue("Laos"),
   258  	TDnsPolicyValue("Lebanon"),
   259  	TDnsPolicyValue("Saint Lucia"),
   260  	TDnsPolicyValue("Liechtenstein"),
   261  	TDnsPolicyValue("Sri Lanka"),
   262  	TDnsPolicyValue("Liberia"),
   263  	TDnsPolicyValue("Lesotho"),
   264  	TDnsPolicyValue("Lithuania"),
   265  	TDnsPolicyValue("Luxembourg"),
   266  	TDnsPolicyValue("Latvia"),
   267  	TDnsPolicyValue("Libya"),
   268  	TDnsPolicyValue("Morocco"),
   269  	TDnsPolicyValue("Monaco"),
   270  	TDnsPolicyValue("Republic of Moldova"),
   271  	TDnsPolicyValue("Montenegro"),
   272  	TDnsPolicyValue("Saint Martin"),
   273  	TDnsPolicyValue("Madagascar"),
   274  	TDnsPolicyValue("Marshall Islands"),
   275  	TDnsPolicyValue("Macedonia"),
   276  	TDnsPolicyValue("Mali"),
   277  	TDnsPolicyValue("Myanmar [Burma]"),
   278  	TDnsPolicyValue("Mongolia"),
   279  	TDnsPolicyValue("Macao"),
   280  	TDnsPolicyValue("Northern Mariana Islands"),
   281  	TDnsPolicyValue("Martinique"),
   282  	TDnsPolicyValue("Mauritania"),
   283  	TDnsPolicyValue("Montserrat"),
   284  	TDnsPolicyValue("Malta"),
   285  	TDnsPolicyValue("Mauritius"),
   286  	TDnsPolicyValue("Maldives"),
   287  	TDnsPolicyValue("Malawi"),
   288  	TDnsPolicyValue("Mexico"),
   289  	TDnsPolicyValue("Malaysia"),
   290  	TDnsPolicyValue("Mozambique"),
   291  	TDnsPolicyValue("Namibia"),
   292  	TDnsPolicyValue("New Caledonia"),
   293  	TDnsPolicyValue("Niger"),
   294  	TDnsPolicyValue("Norfolk Island"),
   295  	TDnsPolicyValue("Nigeria"),
   296  	TDnsPolicyValue("Nicaragua"),
   297  	TDnsPolicyValue("Netherlands"),
   298  	TDnsPolicyValue("Norway"),
   299  	TDnsPolicyValue("Nepal"),
   300  	TDnsPolicyValue("Nauru"),
   301  	TDnsPolicyValue("Niue"),
   302  	TDnsPolicyValue("New Zealand"),
   303  	TDnsPolicyValue("Oman"),
   304  	TDnsPolicyValue("Panama"),
   305  	TDnsPolicyValue("Peru"),
   306  	TDnsPolicyValue("French Polynesia"),
   307  	TDnsPolicyValue("Papua New Guinea"),
   308  	TDnsPolicyValue("Philippines"),
   309  	TDnsPolicyValue("Pakistan"),
   310  	TDnsPolicyValue("Poland"),
   311  	TDnsPolicyValue("Saint Pierre and Miquelon"),
   312  	TDnsPolicyValue("Pitcairn Islands"),
   313  	TDnsPolicyValue("Puerto Rico"),
   314  	TDnsPolicyValue("Palestine"),
   315  	TDnsPolicyValue("Portugal"),
   316  	TDnsPolicyValue("Palau"),
   317  	TDnsPolicyValue("Paraguay"),
   318  	TDnsPolicyValue("Qatar"),
   319  	TDnsPolicyValue("Réunion"),
   320  	TDnsPolicyValue("Romania"),
   321  	TDnsPolicyValue("Serbia"),
   322  	TDnsPolicyValue("Russia"),
   323  	TDnsPolicyValue("Rwanda"),
   324  	TDnsPolicyValue("Saudi Arabia"),
   325  	TDnsPolicyValue("Solomon Islands"),
   326  	TDnsPolicyValue("Seychelles"),
   327  	TDnsPolicyValue("Sudan"),
   328  	TDnsPolicyValue("Sweden"),
   329  	TDnsPolicyValue("Singapore"),
   330  	TDnsPolicyValue("Saint Helena"),
   331  	TDnsPolicyValue("Slovenia"),
   332  	TDnsPolicyValue("Svalbard and Jan Mayen"),
   333  	TDnsPolicyValue("Slovakia"),
   334  	TDnsPolicyValue("Sierra Leone"),
   335  	TDnsPolicyValue("San Marino"),
   336  	TDnsPolicyValue("Senegal"),
   337  	TDnsPolicyValue("Somalia"),
   338  	TDnsPolicyValue("Suriname"),
   339  	TDnsPolicyValue("South Sudan"),
   340  	TDnsPolicyValue("São Tomé and Príncipe"),
   341  	TDnsPolicyValue("El Salvador"),
   342  	TDnsPolicyValue("Sint Maarten"),
   343  	TDnsPolicyValue("Syria"),
   344  	TDnsPolicyValue("Swaziland"),
   345  	TDnsPolicyValue("Turks and Caicos Islands"),
   346  	TDnsPolicyValue("Chad"),
   347  	TDnsPolicyValue("French Southern Territories"),
   348  	TDnsPolicyValue("Togo"),
   349  	TDnsPolicyValue("Thailand"),
   350  	TDnsPolicyValue("Tajikistan"),
   351  	TDnsPolicyValue("Tokelau"),
   352  	TDnsPolicyValue("East Timor"),
   353  	TDnsPolicyValue("Turkmenistan"),
   354  	TDnsPolicyValue("Tunisia"),
   355  	TDnsPolicyValue("Tonga"),
   356  	TDnsPolicyValue("Turkey"),
   357  	TDnsPolicyValue("Trinidad and Tobago"),
   358  	TDnsPolicyValue("Tuvalu"),
   359  	TDnsPolicyValue("Taiwan"),
   360  	TDnsPolicyValue("Tanzania"),
   361  	TDnsPolicyValue("Ukraine"),
   362  	TDnsPolicyValue("Uganda"),
   363  	TDnsPolicyValue("U.S. Minor Outlying Islands"),
   364  	TDnsPolicyValue("United States"),
   365  	TDnsPolicyValue("Alaska"),
   366  	TDnsPolicyValue("Alabama"),
   367  	TDnsPolicyValue("Arkansas"),
   368  	TDnsPolicyValue("Arizona"),
   369  	TDnsPolicyValue("California"),
   370  	TDnsPolicyValue("Colorado"),
   371  	TDnsPolicyValue("Connecticut"),
   372  	TDnsPolicyValue("District of Columbia"),
   373  	TDnsPolicyValue("Delaware"),
   374  	TDnsPolicyValue("Florida"),
   375  	TDnsPolicyValue("Georgia"),
   376  	TDnsPolicyValue("Hawaii"),
   377  	TDnsPolicyValue("Iowa"),
   378  	TDnsPolicyValue("Idaho"),
   379  	TDnsPolicyValue("Illinois"),
   380  	TDnsPolicyValue("Indiana"),
   381  	TDnsPolicyValue("Kansas"),
   382  	TDnsPolicyValue("Kentucky"),
   383  	TDnsPolicyValue("Louisiana"),
   384  	TDnsPolicyValue("Massachusetts"),
   385  	TDnsPolicyValue("Maryland"),
   386  	TDnsPolicyValue("Maine"),
   387  	TDnsPolicyValue("Michigan"),
   388  	TDnsPolicyValue("Minnesota"),
   389  	TDnsPolicyValue("Missouri"),
   390  	TDnsPolicyValue("Mississippi"),
   391  	TDnsPolicyValue("Montana"),
   392  	TDnsPolicyValue("North Carolina"),
   393  	TDnsPolicyValue("North Dakota"),
   394  	TDnsPolicyValue("Nebraska"),
   395  	TDnsPolicyValue("New Hampshire"),
   396  	TDnsPolicyValue("New Jersey"),
   397  	TDnsPolicyValue("New Mexico"),
   398  	TDnsPolicyValue("Nevada"),
   399  	TDnsPolicyValue("New York"),
   400  	TDnsPolicyValue("Ohio"),
   401  	TDnsPolicyValue("Oklahoma"),
   402  	TDnsPolicyValue("Oregon"),
   403  	TDnsPolicyValue("Pennsylvania"),
   404  	TDnsPolicyValue("Rhode Island"),
   405  	TDnsPolicyValue("South Carolina"),
   406  	TDnsPolicyValue("South Dakota"),
   407  	TDnsPolicyValue("Tennessee"),
   408  	TDnsPolicyValue("Texas"),
   409  	TDnsPolicyValue("Utah"),
   410  	TDnsPolicyValue("Virginia"),
   411  	TDnsPolicyValue("Vermont"),
   412  	TDnsPolicyValue("Washington"),
   413  	TDnsPolicyValue("Wisconsin"),
   414  	TDnsPolicyValue("West Virginia"),
   415  	TDnsPolicyValue("Wyoming"),
   416  	TDnsPolicyValue("Uruguay"),
   417  	TDnsPolicyValue("Uzbekistan"),
   418  	TDnsPolicyValue("Vatican City"),
   419  	TDnsPolicyValue("Saint Vincent and the Grenadines"),
   420  	TDnsPolicyValue("Venezuela"),
   421  	TDnsPolicyValue("British Virgin Islands"),
   422  	TDnsPolicyValue("U.S. Virgin Islands"),
   423  	TDnsPolicyValue("Vietnam"),
   424  	TDnsPolicyValue("Vanuatu"),
   425  	TDnsPolicyValue("Wallis and Futuna"),
   426  	TDnsPolicyValue("Samoa"),
   427  	TDnsPolicyValue("Kosovo"),
   428  	TDnsPolicyValue("Yemen"),
   429  	TDnsPolicyValue("Mayotte"),
   430  	TDnsPolicyValue("South Africa"),
   431  	TDnsPolicyValue("Zambia"),
   432  	TDnsPolicyValue("Zimbabwe"),
   433  	TDnsPolicyValue("Africa"),
   434  	TDnsPolicyValue("Antarctica"),
   435  	TDnsPolicyValue("Asia"),
   436  	TDnsPolicyValue("Europe"),
   437  	TDnsPolicyValue("North America"),
   438  	TDnsPolicyValue("Oceania"),
   439  	TDnsPolicyValue("South America"),
   440  }
   441  
   442  var AwsRegions = []TDnsPolicyValue{
   443  	TDnsPolicyValue("us-east-2"),
   444  	TDnsPolicyValue("us-east-1"),
   445  	TDnsPolicyValue("us-west-1"),
   446  	TDnsPolicyValue("us-west-2"),
   447  	TDnsPolicyValue("af-south-1"),
   448  	TDnsPolicyValue("ap-east-1"),
   449  	TDnsPolicyValue("ap-south-1"),
   450  	TDnsPolicyValue("ap-northeast-3"),
   451  	TDnsPolicyValue("ap-northeast-2"),
   452  	TDnsPolicyValue("ap-southeast-1"),
   453  	TDnsPolicyValue("ap-southeast-2"),
   454  	TDnsPolicyValue("ap-northeast-1"),
   455  	TDnsPolicyValue("ca-central-1"),
   456  	TDnsPolicyValue("cn-north-1"),
   457  	TDnsPolicyValue("cn-northwest-1"),
   458  	TDnsPolicyValue("eu-central-1"),
   459  	TDnsPolicyValue("eu-west-1"),
   460  	TDnsPolicyValue("eu-west-2"),
   461  	TDnsPolicyValue("eu-south-1"),
   462  	TDnsPolicyValue("eu-west-3"),
   463  	TDnsPolicyValue("eu-north-1"),
   464  	TDnsPolicyValue("me-south-1"),
   465  	TDnsPolicyValue("sa-east-1"),
   466  	TDnsPolicyValue("us-gov-east-1"),
   467  	TDnsPolicyValue("us-gov-west-1"),
   468  }
   469  
   470  var AwsFailovers = []TDnsPolicyValue{
   471  	TDnsPolicyValue("PRIMARY"),
   472  	TDnsPolicyValue("SECONDARY"),
   473  }
   474  
   475  type TTlRange struct {
   476  	RangeType   TDnsTTLRangeType
   477  	TTLMinValue int64
   478  	TTLMaxValue int64
   479  	AllowedTTLs []int64 // sorted
   480  }
   481  
   482  func (ttlR TTlRange) GetSuppportedTTL(ttl int64) int64 {
   483  	if ttlR.RangeType == ContinuousTTlRange {
   484  		if ttl < ttlR.TTLMinValue {
   485  			return ttlR.TTLMinValue
   486  		}
   487  		if ttl > ttlR.TTLMaxValue {
   488  			return ttlR.TTLMaxValue
   489  		}
   490  		return ttl
   491  	}
   492  	if ttlR.RangeType == DiscreteTTlRange {
   493  		if ttl < ttlR.AllowedTTLs[0] {
   494  			return ttlR.AllowedTTLs[0]
   495  		}
   496  		for i := 0; i < len(ttlR.AllowedTTLs)-1; i++ {
   497  			if ttl > ttlR.AllowedTTLs[i] && ttl < ttlR.AllowedTTLs[i+1] {
   498  				if ttl-ttlR.AllowedTTLs[i] < ttlR.AllowedTTLs[i+1]-ttl {
   499  					return ttlR.AllowedTTLs[i]
   500  				}
   501  				return ttlR.AllowedTTLs[i+1]
   502  			}
   503  		}
   504  		return ttlR.AllowedTTLs[len(ttlR.AllowedTTLs)-1]
   505  	}
   506  	return ttl
   507  }
   508  
   509  var TtlRangeAliyunEnterpriseUltimate = TTlRange{RangeType: ContinuousTTlRange, TTLMinValue: 1, TTLMaxValue: 86400}
   510  var TtlRangeAliyunEnterpriseStandard = TTlRange{RangeType: ContinuousTTlRange, TTLMinValue: 60, TTLMaxValue: 86400}
   511  var TtlRangeAliyunPersonal = TTlRange{RangeType: ContinuousTTlRange, TTLMinValue: 600, TTLMaxValue: 86400}
   512  var TtlRangeAliyunFree = TTlRange{RangeType: ContinuousTTlRange, TTLMinValue: 600, TTLMaxValue: 86400}
   513  
   514  var TtlRangeAliyunPvtz = TTlRange{RangeType: DiscreteTTlRange, AllowedTTLs: []int64{5, 10, 15, 20, 30, 60, 120, 300, 600, 1800, 3600, 43200, 86400}}
   515  
   516  var TtlRangeQcloudEnterpriseUltimate = TTlRange{RangeType: ContinuousTTlRange, TTLMinValue: 1, TTLMaxValue: 604800}
   517  var TtlRangeQcloudEnterpriseStandard = TTlRange{RangeType: ContinuousTTlRange, TTLMinValue: 30, TTLMaxValue: 604800}
   518  var TtlRangeQcloudEnterpriseBasic = TTlRange{RangeType: ContinuousTTlRange, TTLMinValue: 60, TTLMaxValue: 604800}
   519  var TtlRangeQcloudPersonalProfessional = TTlRange{RangeType: ContinuousTTlRange, TTLMinValue: 120, TTLMaxValue: 604800}
   520  var TtlRangeQcloudFree = TTlRange{RangeType: ContinuousTTlRange, TTLMinValue: 600, TTLMaxValue: 604800}
   521  
   522  type SPrivateZoneVpc struct {
   523  	Id       string
   524  	RegionId string
   525  }
   526  
   527  type SDnsZoneCreateOptions struct {
   528  	Name     string
   529  	Desc     string
   530  	ZoneType TDnsZoneType
   531  	Vpcs     []SPrivateZoneVpc
   532  	Options  *jsonutils.JSONDict
   533  }
   534  
   535  func IsSupportPolicyValue(v1 TDnsPolicyValue, arr []TDnsPolicyValue) bool {
   536  	isIn, _ := utils.InArray(v1, arr)
   537  	return isIn
   538  }
   539  
   540  type DnsRecordSet struct {
   541  	Id         string
   542  	ExternalId string
   543  
   544  	Desc string
   545  
   546  	Enabled       bool
   547  	DnsName       string
   548  	DnsType       TDnsType
   549  	DnsValue      string
   550  	Status        string
   551  	Ttl           int64
   552  	MxPriority    int64
   553  	PolicyType    TDnsPolicyType
   554  	PolicyValue   TDnsPolicyValue
   555  	PolicyOptions *jsonutils.JSONDict
   556  }
   557  
   558  func (r DnsRecordSet) GetGlobalId() string {
   559  	return r.ExternalId
   560  }
   561  
   562  func (r DnsRecordSet) GetName() string {
   563  	return r.DnsName
   564  }
   565  
   566  func (r DnsRecordSet) GetDnsName() string {
   567  	return r.DnsName
   568  }
   569  
   570  func (r DnsRecordSet) GetDnsValue() string {
   571  	return r.DnsValue
   572  }
   573  
   574  func (r DnsRecordSet) GetPolicyType() TDnsPolicyType {
   575  	return r.PolicyType
   576  }
   577  
   578  func (r DnsRecordSet) GetPolicyOptions() *jsonutils.JSONDict {
   579  	return r.PolicyOptions
   580  }
   581  
   582  func (r DnsRecordSet) GetPolicyValue() TDnsPolicyValue {
   583  	return r.PolicyValue
   584  }
   585  
   586  func (r DnsRecordSet) GetStatus() string {
   587  	return r.Status
   588  }
   589  
   590  func (r DnsRecordSet) GetTTL() int64 {
   591  	return r.Ttl
   592  }
   593  
   594  func (r DnsRecordSet) GetDnsType() TDnsType {
   595  	return r.DnsType
   596  }
   597  
   598  func (r DnsRecordSet) GetEnabled() bool {
   599  	return r.Enabled
   600  }
   601  
   602  func (r DnsRecordSet) GetMxPriority() int64 {
   603  	return r.MxPriority
   604  }
   605  
   606  func (record DnsRecordSet) Equals(r DnsRecordSet) bool {
   607  	if strings.ToLower(record.DnsName) != strings.ToLower(r.DnsName) {
   608  		return false
   609  	}
   610  	if record.DnsType != r.DnsType {
   611  		return false
   612  	}
   613  	if record.DnsValue != r.DnsValue {
   614  		return false
   615  	}
   616  	if record.PolicyType != r.PolicyType {
   617  		return false
   618  	}
   619  	if record.PolicyValue != r.PolicyValue {
   620  		return false
   621  	}
   622  	if record.Ttl != r.Ttl {
   623  		return false
   624  	}
   625  	if record.Enabled != r.Enabled {
   626  		return false
   627  	}
   628  	if record.DnsType == DnsTypeMX && record.MxPriority != r.MxPriority {
   629  		return false
   630  	}
   631  	return IsPolicyOptionEquals(record.PolicyOptions, r.PolicyOptions)
   632  }
   633  
   634  func (record DnsRecordSet) String() string {
   635  	return fmt.Sprintf("%s-%s-%s-%s-%s", record.DnsType, record.DnsName, record.DnsValue, record.PolicyType, record.PolicyValue)
   636  }
   637  
   638  func IsPolicyOptionEquals(o1, o2 *jsonutils.JSONDict) bool {
   639  	if o1 == nil {
   640  		o1 = jsonutils.NewDict()
   641  	}
   642  	if o2 == nil {
   643  		o2 = jsonutils.NewDict()
   644  	}
   645  	return o1.Equals(o2)
   646  }
   647  
   648  func CompareDnsRecordSet(iRecords []ICloudDnsRecordSet, local []DnsRecordSet, debug bool) ([]DnsRecordSet, []DnsRecordSet, []DnsRecordSet, []DnsRecordSet) {
   649  	common, added, removed, updated := []DnsRecordSet{}, []DnsRecordSet{}, []DnsRecordSet{}, []DnsRecordSet{}
   650  
   651  	localMaps := map[string]DnsRecordSet{}
   652  	remoteMaps := map[string]DnsRecordSet{}
   653  	for i := range iRecords {
   654  		record := DnsRecordSet{
   655  			ExternalId: iRecords[i].GetGlobalId(),
   656  
   657  			DnsName:       iRecords[i].GetDnsName(),
   658  			DnsType:       iRecords[i].GetDnsType(),
   659  			DnsValue:      iRecords[i].GetDnsValue(),
   660  			Status:        iRecords[i].GetStatus(),
   661  			Enabled:       iRecords[i].GetEnabled(),
   662  			Ttl:           iRecords[i].GetTTL(),
   663  			MxPriority:    iRecords[i].GetMxPriority(),
   664  			PolicyType:    iRecords[i].GetPolicyType(),
   665  			PolicyValue:   iRecords[i].GetPolicyValue(),
   666  			PolicyOptions: iRecords[i].GetPolicyOptions(),
   667  		}
   668  		remoteMaps[record.String()] = record
   669  	}
   670  	for i := range local {
   671  		localMaps[local[i].String()] = local[i]
   672  	}
   673  
   674  	for key, record := range localMaps {
   675  		remoteRecord, ok := remoteMaps[key]
   676  		if ok {
   677  			record.ExternalId = remoteRecord.ExternalId
   678  			remoteRecord.Id = record.Id
   679  			if !record.Equals(remoteRecord) {
   680  				updated = append(updated, remoteRecord)
   681  			} else {
   682  				common = append(common, record)
   683  			}
   684  		} else {
   685  			added = append(added, record)
   686  		}
   687  	}
   688  
   689  	for key, record := range remoteMaps {
   690  		_, ok := localMaps[key]
   691  		if !ok {
   692  			removed = append(removed, record)
   693  		}
   694  	}
   695  
   696  	return common, added, removed, updated
   697  }