mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #13839 from ioito/hotfix/qx-qcloud-dns-api
fix(region): qcloud use new dns api
This commit is contained in:
@@ -2959,9 +2959,13 @@ func (self *SCloudaccount) SyncDnsZones(ctx context.Context, userCred mcclient.T
|
||||
result.AddError(err)
|
||||
continue
|
||||
}
|
||||
if isNew {
|
||||
result.Add()
|
||||
if !isNew {
|
||||
_, err = dnsZone.newCache(ctx, userCred, self.Id, added[i])
|
||||
if err != nil {
|
||||
result.AddError(errors.Wrapf(err, "newCache"))
|
||||
}
|
||||
}
|
||||
result.Add()
|
||||
localZones = append(localZones, *dnsZone)
|
||||
remoteZones = append(remoteZones, added[i])
|
||||
}
|
||||
|
||||
@@ -2145,11 +2145,17 @@ func SyncCloudaccountResources(ctx context.Context, userCred mcclient.TokenCrede
|
||||
}
|
||||
|
||||
if cloudprovider.IsSupportProject(provider) && syncRange.NeedSyncResource(cloudprovider.CLOUD_CAPABILITY_PROJECT) {
|
||||
syncProjects(ctx, userCred, SSyncResultSet{}, account, provider)
|
||||
err = syncProjects(ctx, userCred, SSyncResultSet{}, account, provider)
|
||||
if err != nil {
|
||||
log.Errorf("Sync project for account %s error: %v", account.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
if cloudprovider.IsSupportDnsZone(provider) && syncRange.NeedSyncResource(cloudprovider.CLOUD_CAPABILITY_DNSZONE) {
|
||||
syncDns(ctx, userCred, SSyncResultSet{}, account, provider)
|
||||
err = syncDns(ctx, userCred, SSyncResultSet{}, account, provider)
|
||||
if err != nil {
|
||||
log.Errorf("Sync dns zone for account %s error: %v", account.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package qcloud
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -26,151 +27,121 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
)
|
||||
|
||||
type sDomianCountInfo struct {
|
||||
DomainTotal int `json:"domain_total"`
|
||||
}
|
||||
|
||||
type SDomian struct {
|
||||
multicloud.SResourceBase
|
||||
multicloud.QcloudTags
|
||||
client *SQcloudClient
|
||||
|
||||
ID int `json:"id"`
|
||||
Status string `json:"status"`
|
||||
GroupID string `json:"group_id"`
|
||||
SearchenginePush string `json:"searchengine_push"`
|
||||
IsMark string `json:"is_mark"`
|
||||
TTL string `json:"ttl"`
|
||||
CnameSpeedup string `json:"cname_speedup"`
|
||||
Remark string `json:"remark"`
|
||||
CreatedOn string `json:"created_on"`
|
||||
UpdatedOn string `json:"updated_on"`
|
||||
QProjectID int `json:"q_project_id"`
|
||||
Punycode string `json:"punycode"`
|
||||
ExtStatus string `json:"ext_status"`
|
||||
SrcFlag string `json:"src_flag"`
|
||||
Name string `json:"name"`
|
||||
Grade string `json:"grade"`
|
||||
GradeTitle string `json:"grade_title"`
|
||||
IsVip string `json:"is_vip"`
|
||||
Owner string `json:"owner"`
|
||||
Records string `json:"records"`
|
||||
MinTTL int `json:"min_ttl"`
|
||||
CNAMESpeedup string `json:"CNAMESpeedup"`
|
||||
CreatedOn string `json:"CreatedOn"`
|
||||
DNSStatus string `json:"DNSStatus"`
|
||||
DomainId int `json:"DomainId"`
|
||||
EffectiveDNS []string `json:"EffectiveDNS"`
|
||||
Grade string `json:"Grade"`
|
||||
GradeLevel int64 `json:"GradeLevel"`
|
||||
GradeTitle string `json:"GradeTitle"`
|
||||
GroupId int64 `json:"GroupId"`
|
||||
IsVip string `json:"IsVip"`
|
||||
Name string `json:"Name"`
|
||||
Owner string `json:"Owner"`
|
||||
Punycode string `json:"Punycode"`
|
||||
RecordCount int64 `json:"RecordCount"`
|
||||
Remark string `json:"Remark"`
|
||||
SearchEnginePush string `json:"SearchEnginePush"`
|
||||
Status string `json:"Status"`
|
||||
TTL int64 `json:"TTL"`
|
||||
UpdatedOn string `json:"UpdatedOn"`
|
||||
VipAutoRenew string `json:"VipAutoRenew"`
|
||||
VipEndAt string `json:"VipEndAt"`
|
||||
VipStartAt string `json:"VipStartAt"`
|
||||
}
|
||||
|
||||
// https://cloud.tencent.com/document/product/302/8505
|
||||
func (client *SQcloudClient) GetDomains(projectId string, offset int, limit int) ([]SDomian, int, error) {
|
||||
func (self *SQcloudClient) GetDomains(key string, offset int, limit int) ([]SDomian, int, error) {
|
||||
params := map[string]string{}
|
||||
params["offset"] = strconv.Itoa(offset)
|
||||
params["length"] = strconv.Itoa(limit)
|
||||
if len(projectId) > 0 {
|
||||
params["qProjectId"] = projectId
|
||||
params["Offset"] = strconv.Itoa(offset)
|
||||
if limit > 0 {
|
||||
params["Limit"] = strconv.Itoa(limit)
|
||||
}
|
||||
|
||||
resp, err := client.cnsRequest("DomainList", params)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "client.cnsRequest(DomainList, %s)", jsonutils.Marshal(params).String())
|
||||
if len(key) > 0 {
|
||||
params["Keyword"] = key
|
||||
}
|
||||
count := sDomianCountInfo{}
|
||||
err = resp.Unmarshal(&count, "info")
|
||||
resp, err := self.dnsRequest("DescribeDomainList", params)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "%s.Unmarshal(info)", resp.String())
|
||||
return nil, 0, errors.Wrapf(err, "DescribeDomainList")
|
||||
}
|
||||
domains := []SDomian{}
|
||||
err = resp.Unmarshal(&domains, "domains")
|
||||
err = resp.Unmarshal(&domains, "DomainList")
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "%s.Unmarshal(domains)", resp.String())
|
||||
return nil, 0, errors.Wrapf(err, "resp.Unmarshal DomainList")
|
||||
}
|
||||
|
||||
for i := 0; i < len(domains); i++ {
|
||||
domains[i].client = client
|
||||
}
|
||||
return domains, count.DomainTotal, nil
|
||||
total, err := resp.Float("DomainCountInfo", "DomainTotal")
|
||||
return domains, int(total), err
|
||||
}
|
||||
|
||||
func (client *SQcloudClient) GetAllDomains() ([]SDomian, error) {
|
||||
count := 0
|
||||
result := []SDomian{}
|
||||
for {
|
||||
// -1 所有项目; 0,default默认项目
|
||||
domains, total, err := client.GetDomains("-1", count, 100)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, " client.GetDomains(count, 100)")
|
||||
func (self *SQcloudClient) GetDomain(domain string) (*SDomian, error) {
|
||||
domains, _, err := self.GetDomains(domain, 0, 2)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range domains {
|
||||
if domains[i].Name == domain {
|
||||
domains[i].client = self
|
||||
return &domains[i], nil
|
||||
}
|
||||
result = append(result, domains...)
|
||||
count += len(domains)
|
||||
if total <= count {
|
||||
}
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, domain)
|
||||
}
|
||||
|
||||
func (self *SQcloudClient) GetICloudDnsZones() ([]cloudprovider.ICloudDnsZone, error) {
|
||||
result := []cloudprovider.ICloudDnsZone{}
|
||||
domains := []SDomian{}
|
||||
for {
|
||||
part, total, err := self.GetDomains("", len(domains), 1000)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
domains = append(domains, part...)
|
||||
if len(domains) >= total {
|
||||
break
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(result); i++ {
|
||||
result[i].client = client
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (client *SQcloudClient) GetICloudDnsZones() ([]cloudprovider.ICloudDnsZone, error) {
|
||||
result := []cloudprovider.ICloudDnsZone{}
|
||||
domains, err := client.GetAllDomains()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "client.GetDomains()")
|
||||
}
|
||||
for i := 0; i < len(domains); i++ {
|
||||
domains[i].client = self
|
||||
result = append(result, &domains[i])
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (client *SQcloudClient) GetDomainById(domainId string) (*SDomian, error) {
|
||||
domains, err := client.GetAllDomains()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "client.GetDomains()")
|
||||
}
|
||||
for i := 0; i < len(domains); i++ {
|
||||
if strconv.Itoa(domains[i].ID) == domainId {
|
||||
return &domains[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Wrapf(cloudprovider.ErrNotFound, "can't find %s", domainId)
|
||||
}
|
||||
|
||||
// https://cloud.tencent.com/document/product/302/8504
|
||||
func (client *SQcloudClient) CreateDomian(domianName string) (*SDomian, error) {
|
||||
func (self *SQcloudClient) CreateDomian(domianName string) (*SDomian, error) {
|
||||
params := map[string]string{}
|
||||
params["domain"] = domianName
|
||||
_, err := client.cnsRequest("DomainCreate", params)
|
||||
params["Domain"] = domianName
|
||||
_, err := self.dnsRequest("CreateDomain", params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "client.cnsRequest(DomainCreate, %s)", jsonutils.Marshal(params).String())
|
||||
return nil, errors.Wrapf(err, "CreateDomain")
|
||||
}
|
||||
domains, err := client.GetAllDomains()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "client.GetDomains()")
|
||||
}
|
||||
for i := 0; i < len(domains); i++ {
|
||||
if domains[i].Name == domianName {
|
||||
return &domains[i], nil
|
||||
}
|
||||
}
|
||||
return nil, errors.Wrap(cloudprovider.ErrNotFound, "domain not found after create")
|
||||
return self.GetDomain(domianName)
|
||||
}
|
||||
|
||||
func (client *SQcloudClient) CreateICloudDnsZone(opts *cloudprovider.SDnsZoneCreateOptions) (cloudprovider.ICloudDnsZone, error) {
|
||||
return client.CreateDomian(opts.Name)
|
||||
func (self *SQcloudClient) CreateICloudDnsZone(opts *cloudprovider.SDnsZoneCreateOptions) (cloudprovider.ICloudDnsZone, error) {
|
||||
domain, err := self.CreateDomian(opts.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return domain, nil
|
||||
}
|
||||
|
||||
// https://cloud.tencent.com/document/product/302/3873
|
||||
func (client *SQcloudClient) DeleteDomian(domianName string) error {
|
||||
params := map[string]string{}
|
||||
params["domain"] = domianName
|
||||
_, err := client.cnsRequest("DomainDelete", params)
|
||||
params["Domain"] = domianName
|
||||
_, err := client.dnsRequest("DeleteDomain", params)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "client.cnsRequest(DomainDelete, %s)", jsonutils.Marshal(params).String())
|
||||
return errors.Wrapf(err, "DeleteDomain")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SDomian) GetId() string {
|
||||
return strconv.Itoa(self.ID)
|
||||
return fmt.Sprintf("%d", self.DomainId)
|
||||
}
|
||||
|
||||
func (self *SDomian) GetName() string {
|
||||
@@ -181,14 +152,14 @@ func (self *SDomian) GetName() string {
|
||||
}
|
||||
|
||||
func (self *SDomian) GetGlobalId() string {
|
||||
return strconv.Itoa(self.ID)
|
||||
return self.Name
|
||||
}
|
||||
|
||||
func (self *SDomian) GetStatus() string {
|
||||
switch self.Status {
|
||||
case "enable":
|
||||
case "ENABLE":
|
||||
return api.DNS_ZONE_STATUS_AVAILABLE
|
||||
case "pause":
|
||||
case "PAUSE":
|
||||
return api.DNS_ZONE_STATUS_AVAILABLE
|
||||
default:
|
||||
return api.DNS_ZONE_STATUS_UNKNOWN
|
||||
@@ -196,23 +167,18 @@ func (self *SDomian) GetStatus() string {
|
||||
}
|
||||
|
||||
func (self *SDomian) GetEnabled() bool {
|
||||
if self.Status == "enable" {
|
||||
if self.Status == "ENABLE" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (self *SDomian) Refresh() error {
|
||||
domains, err := self.client.GetAllDomains()
|
||||
domain, err := self.client.GetDomain(self.Name)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "self.client.GetDomains()")
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(domains); i++ {
|
||||
if self.ID == domains[i].ID {
|
||||
return jsonutils.Update(self, &domains[i])
|
||||
}
|
||||
}
|
||||
return cloudprovider.ErrNotFound
|
||||
return jsonutils.Update(self, domain)
|
||||
}
|
||||
|
||||
func (self *SDomian) Delete() error {
|
||||
@@ -240,9 +206,16 @@ func (self *SDomian) RemoveVpc(vpc *cloudprovider.SPrivateZoneVpc) error {
|
||||
}
|
||||
|
||||
func (self *SDomian) GetIDnsRecordSets() ([]cloudprovider.ICloudDnsRecordSet, error) {
|
||||
records, err := self.client.GetAllDnsRecords(self.Name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "self.client.GetDnsRecords(%s)", self.Name)
|
||||
records := []SDnsRecord{}
|
||||
for {
|
||||
part, total, err := self.client.GetDnsRecords(self.Name, len(records), 1000)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
records = append(records, part...)
|
||||
if len(records) >= total {
|
||||
break
|
||||
}
|
||||
}
|
||||
result := []cloudprovider.ICloudDnsRecordSet{}
|
||||
for i := 0; i < len(records); i++ {
|
||||
@@ -258,17 +231,9 @@ func (self *SDomian) AddDnsRecordSet(opts *cloudprovider.DnsRecordSet) error {
|
||||
opts.DnsValue = values[i]
|
||||
recordId, err := self.client.CreateDnsRecord(opts, self.Name)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "self.client.CreateDnsRecord(%s, %s)", jsonutils.Marshal(opts).String(), self.Name)
|
||||
return errors.Wrapf(err, "CreateDnsRecord")
|
||||
}
|
||||
opts.ExternalId = recordId
|
||||
if !opts.Enabled {
|
||||
status := "disable"
|
||||
err = self.client.ModifyRecordStatus(status, opts.ExternalId, self.Name)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "self.client.ModifyRecordStatus(%s,%s,%s)", status, opts.ExternalId, self.Name)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -279,51 +244,35 @@ func (self *SDomian) UpdateDnsRecordSet(opts *cloudprovider.DnsRecordSet) error
|
||||
opts.DnsValue = values[i]
|
||||
err := self.client.ModifyDnsRecord(opts, self.Name)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "self.client.CreateDnsRecord(%s, %s)", jsonutils.Marshal(opts).String(), self.Name)
|
||||
}
|
||||
status := "enable"
|
||||
if !opts.Enabled {
|
||||
status = "disable"
|
||||
}
|
||||
err = self.client.ModifyRecordStatus(status, opts.ExternalId, self.Name)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "self.client.ModifyRecordStatus(%s,%s,%s)", status, opts.ExternalId, self.Name)
|
||||
return errors.Wrapf(err, "ModifyDnsRecord")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SDomian) RemoveDnsRecordSet(opts *cloudprovider.DnsRecordSet) error {
|
||||
recordId, err := strconv.Atoi(opts.ExternalId)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "strconv.Atoi(%s)", opts.ExternalId)
|
||||
}
|
||||
err = self.client.DeleteDnsRecord(recordId, self.GetName())
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "self.client.RemoveDnsRecord(%d,%s)", recordId, self.GetName())
|
||||
}
|
||||
return nil
|
||||
return self.client.DeleteDnsRecord(opts.ExternalId, self.GetName())
|
||||
}
|
||||
|
||||
func (self *SDomian) SyncDnsRecordSets(common, add, del, update []cloudprovider.DnsRecordSet) error {
|
||||
for i := 0; i < len(del); i++ {
|
||||
err := self.RemoveDnsRecordSet(&del[i])
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "self.RemoveDnsRecordSet(%s)", jsonutils.Marshal(del[i]).String())
|
||||
return errors.Wrapf(err, "RemoveDnsRecordSet(%s)", del[i].ExternalId)
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < len(add); i++ {
|
||||
err := self.AddDnsRecordSet(&add[i])
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "self.AddDnsRecordSet(%s)", jsonutils.Marshal(add[i]).String())
|
||||
return errors.Wrapf(err, "AddDnsRecordSet(%s)", add[i].Id)
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < len(update); i++ {
|
||||
err := self.UpdateDnsRecordSet(&update[i])
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "self.UpdateDnsRecordSet(%s)", jsonutils.Marshal(update[i]).String())
|
||||
return errors.Wrapf(err, "UpdateDnsRecordSet(%s)", update[i].ExternalId)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package qcloud
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -39,71 +40,40 @@ type SRecordCountInfo struct {
|
||||
}
|
||||
|
||||
type SDnsRecord struct {
|
||||
domain *SDomian
|
||||
ID int `json:"id"`
|
||||
TTL int `json:"ttl"`
|
||||
Value string `json:"value"`
|
||||
Enabled int `json:"enabled"`
|
||||
Status string `json:"status"`
|
||||
UpdatedOn string `json:"updated_on"`
|
||||
QProjectID int `json:"q_project_id"`
|
||||
Name string `json:"name"`
|
||||
Line string `json:"line"`
|
||||
LineID string `json:"line_id"`
|
||||
Type string `json:"type"`
|
||||
Remark string `json:"remark"`
|
||||
Mx int64 `json:"mx"`
|
||||
Hold string `json:"hold"`
|
||||
domain *SDomian
|
||||
|
||||
Line string `json:"Line"`
|
||||
LineId string `json:"LineId"`
|
||||
MX int64 `json:"MX"`
|
||||
MonitorStatus string `json:"MonitorStatus"`
|
||||
Name string `json:"Name"`
|
||||
RecordId int `json:"RecordId"`
|
||||
Remark string `json:"Remark"`
|
||||
Status string `json:"Status"`
|
||||
TTL int64 `json:"TTL"`
|
||||
Type string `json:"Type"`
|
||||
UpdatedOn string `json:"UpdatedOn"`
|
||||
Value string `json:"Value"`
|
||||
}
|
||||
|
||||
// https://cloud.tencent.com/document/product/302/8517
|
||||
func (client *SQcloudClient) GetDnsRecords(projectId string, sDomainName string, offset int, limit int) ([]SDnsRecord, int, error) {
|
||||
|
||||
func (self *SQcloudClient) GetDnsRecords(domain string, offset int, limit int) ([]SDnsRecord, int, error) {
|
||||
params := map[string]string{}
|
||||
params["offset"] = strconv.Itoa(offset)
|
||||
params["length"] = strconv.Itoa(limit)
|
||||
params["domain"] = sDomainName
|
||||
if len(projectId) > 0 {
|
||||
params["qProjectId"] = projectId
|
||||
params["Domain"] = domain
|
||||
params["Offset"] = strconv.Itoa(offset)
|
||||
if limit > 0 {
|
||||
params["Limit"] = strconv.Itoa(limit)
|
||||
}
|
||||
resp, err := client.cnsRequest("RecordList", params)
|
||||
resp, err := self.dnsRequest("DescribeRecordList", params)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "client.cnsRequest(RecordList, %s)", jsonutils.Marshal(params).String())
|
||||
return nil, 0, errors.Wrapf(err, "DescribeRecordList")
|
||||
}
|
||||
count := SRecordCountInfo{}
|
||||
err = resp.Unmarshal(&count, "info")
|
||||
ret := []SDnsRecord{}
|
||||
err = resp.Unmarshal(&ret, "RecordList")
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "%s.Unmarshal(info)", jsonutils.Marshal(resp).String())
|
||||
return nil, 0, errors.Wrapf(err, "resp.Unmarshal RecordList")
|
||||
}
|
||||
records := []SDnsRecord{}
|
||||
err = resp.Unmarshal(&records, "records")
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "%s.Unmarshal(records)", jsonutils.Marshal(resp).String())
|
||||
}
|
||||
RecordTotal, err := strconv.Atoi(count.RecordTotal)
|
||||
if err != nil {
|
||||
return nil, 0, errors.Wrapf(err, "strconv.Atoi(%s)", count.RecordTotal)
|
||||
}
|
||||
return records, RecordTotal, nil
|
||||
}
|
||||
|
||||
func (client *SQcloudClient) GetAllDnsRecords(sDomainName string) ([]SDnsRecord, error) {
|
||||
count := 0
|
||||
result := []SDnsRecord{}
|
||||
for true {
|
||||
// -1 所有项目; 0,default默认项目
|
||||
records, total, err := client.GetDnsRecords("-1", sDomainName, count, 100)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "client.GetDnsRecords(%s,%d,%d)", sDomainName, count, 100)
|
||||
}
|
||||
|
||||
result = append(result, records...)
|
||||
count += len(records)
|
||||
if total <= count {
|
||||
break
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
total, err := resp.Float("RecordCountInfo", "TotalCount")
|
||||
return ret, int(total), err
|
||||
}
|
||||
|
||||
func GetRecordLineLineType(policyinfo cloudprovider.TDnsPolicyValue) string {
|
||||
@@ -140,8 +110,8 @@ func GetRecordLineLineType(policyinfo cloudprovider.TDnsPolicyValue) string {
|
||||
}
|
||||
}
|
||||
|
||||
// https://cloud.tencent.com/document/api/302/8516
|
||||
func (client *SQcloudClient) CreateDnsRecord(opts *cloudprovider.DnsRecordSet, domainName string) (string, error) {
|
||||
// https://cloud.tencent.com/document/api/1427/56180
|
||||
func (self *SQcloudClient) CreateDnsRecord(opts *cloudprovider.DnsRecordSet, domainName string) (string, error) {
|
||||
params := map[string]string{}
|
||||
recordline := GetRecordLineLineType(opts.PolicyValue)
|
||||
if opts.Ttl < 600 {
|
||||
@@ -153,29 +123,27 @@ func (client *SQcloudClient) CreateDnsRecord(opts *cloudprovider.DnsRecordSet, d
|
||||
if len(opts.DnsName) < 1 {
|
||||
opts.DnsName = "@"
|
||||
}
|
||||
params["domain"] = domainName
|
||||
params["subDomain"] = opts.DnsName
|
||||
params["recordType"] = string(opts.DnsType)
|
||||
params["ttl"] = strconv.FormatInt(opts.Ttl, 10)
|
||||
params["value"] = opts.DnsValue
|
||||
params["recordLine"] = recordline
|
||||
params["Domain"] = domainName
|
||||
params["SubDomain"] = opts.DnsName
|
||||
params["RecordType"] = string(opts.DnsType)
|
||||
params["TTL"] = strconv.FormatInt(opts.Ttl, 10)
|
||||
params["Value"] = opts.DnsValue
|
||||
params["RecordLine"] = recordline
|
||||
if opts.DnsType == cloudprovider.DnsTypeMX {
|
||||
params["mx"] = strconv.FormatInt(opts.MxPriority, 10)
|
||||
params["MX"] = strconv.FormatInt(opts.MxPriority, 10)
|
||||
}
|
||||
resp, err := client.cnsRequest("RecordCreate", params)
|
||||
if !opts.Enabled {
|
||||
params["Status"] = "DISABLE"
|
||||
}
|
||||
resp, err := self.dnsRequest("CreateRecord", params)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "client.cnsRequest(RecordCreate, %s)", jsonutils.Marshal(params).String())
|
||||
return "", errors.Wrapf(err, "CreateRecord")
|
||||
}
|
||||
SRecordCreateRet := SRecordCreateRet{}
|
||||
err = resp.Unmarshal(&SRecordCreateRet, "record")
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "%s.Unmarshal(records)", jsonutils.Marshal(resp).String())
|
||||
}
|
||||
return SRecordCreateRet.ID, nil
|
||||
return resp.GetString("RecordId")
|
||||
}
|
||||
|
||||
// https://cloud.tencent.com/document/product/302/8511
|
||||
func (client *SQcloudClient) ModifyDnsRecord(opts *cloudprovider.DnsRecordSet, domainName string) error {
|
||||
// https://cloud.tencent.com/document/api/1427/56157
|
||||
func (self *SQcloudClient) ModifyDnsRecord(opts *cloudprovider.DnsRecordSet, domainName string) error {
|
||||
params := map[string]string{}
|
||||
recordline := GetRecordLineLineType(opts.PolicyValue)
|
||||
if opts.Ttl < 600 {
|
||||
@@ -188,19 +156,22 @@ func (client *SQcloudClient) ModifyDnsRecord(opts *cloudprovider.DnsRecordSet, d
|
||||
if len(subDomain) < 1 {
|
||||
subDomain = "@"
|
||||
}
|
||||
params["domain"] = domainName
|
||||
params["recordId"] = opts.ExternalId
|
||||
params["subDomain"] = subDomain
|
||||
params["recordType"] = string(opts.DnsType)
|
||||
params["ttl"] = strconv.FormatInt(opts.Ttl, 10)
|
||||
params["value"] = opts.DnsValue
|
||||
params["recordLine"] = recordline
|
||||
params["Domain"] = domainName
|
||||
params["RecordId"] = opts.ExternalId
|
||||
params["SubDomain"] = subDomain
|
||||
params["RecordType"] = string(opts.DnsType)
|
||||
params["TTL"] = strconv.FormatInt(opts.Ttl, 10)
|
||||
params["Value"] = opts.DnsValue
|
||||
params["RecordLine"] = recordline
|
||||
if opts.DnsType == cloudprovider.DnsTypeMX {
|
||||
params["mx"] = strconv.FormatInt(opts.MxPriority, 10)
|
||||
params["MX"] = strconv.FormatInt(opts.MxPriority, 10)
|
||||
}
|
||||
_, err := client.cnsRequest("RecordModify", params)
|
||||
if !opts.Enabled {
|
||||
params["Status"] = "DISABLE"
|
||||
}
|
||||
_, err := self.dnsRequest("ModifyRecord", params)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "client.cnsRequest(RecordModify, %s)", jsonutils.Marshal(params).String())
|
||||
return errors.Wrapf(err, "ModifyRecord")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -208,30 +179,30 @@ func (client *SQcloudClient) ModifyDnsRecord(opts *cloudprovider.DnsRecordSet, d
|
||||
// https://cloud.tencent.com/document/product/302/8519
|
||||
func (client *SQcloudClient) ModifyRecordStatus(status, recordId, domain string) error {
|
||||
params := map[string]string{}
|
||||
params["domain"] = domain
|
||||
params["recordId"] = recordId
|
||||
params["status"] = status // “disable” 和 “enable”
|
||||
_, err := client.cnsRequest("RecordStatus", params)
|
||||
params["Domain"] = domain
|
||||
params["RecordId"] = recordId
|
||||
params["Status"] = status // “disable” 和 “enable”
|
||||
_, err := client.dnsRequest("ModifyRecordStatus", params)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "client.cnsRequest(RecordModify, %s)", jsonutils.Marshal(params).String())
|
||||
return errors.Wrapf(err, "ModifyRecordStatus")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// https://cloud.tencent.com/document/api/302/8514
|
||||
func (client *SQcloudClient) DeleteDnsRecord(recordId int, domainName string) error {
|
||||
// https://cloud.tencent.com/document/api/1427/56176
|
||||
func (client *SQcloudClient) DeleteDnsRecord(recordId string, domainName string) error {
|
||||
params := map[string]string{}
|
||||
params["domain"] = domainName
|
||||
params["recordId"] = strconv.Itoa(recordId)
|
||||
_, err := client.cnsRequest("RecordDelete", params)
|
||||
params["Domain"] = domainName
|
||||
params["RecordId"] = recordId
|
||||
_, err := client.dnsRequest("DeleteRecord", params)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "client.cnsRequest(RecordDelete, %s)", jsonutils.Marshal(params).String())
|
||||
return errors.Wrapf(err, "DeleteRecord")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SDnsRecord) GetGlobalId() string {
|
||||
return strconv.Itoa(self.ID)
|
||||
return fmt.Sprintf("%d", self.RecordId)
|
||||
}
|
||||
|
||||
func (self *SDnsRecord) GetDnsName() string {
|
||||
@@ -239,14 +210,14 @@ func (self *SDnsRecord) GetDnsName() string {
|
||||
}
|
||||
|
||||
func (self *SDnsRecord) GetStatus() string {
|
||||
if self.Status != "spam" {
|
||||
if self.Status != "SPAM" {
|
||||
return api.DNS_RECORDSET_STATUS_AVAILABLE
|
||||
}
|
||||
return api.DNS_ZONE_STATUS_UNKNOWN
|
||||
}
|
||||
|
||||
func (self *SDnsRecord) GetEnabled() bool {
|
||||
return self.Enabled == 1
|
||||
return self.Status == "ENABLE"
|
||||
}
|
||||
|
||||
func (self *SDnsRecord) GetDnsType() cloudprovider.TDnsType {
|
||||
@@ -266,7 +237,7 @@ func (self *SDnsRecord) GetTTL() int64 {
|
||||
|
||||
func (self *SDnsRecord) GetMxPriority() int64 {
|
||||
if self.GetDnsType() == cloudprovider.DnsTypeMX {
|
||||
return self.Mx
|
||||
return self.MX
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -379,7 +379,11 @@ func (self *SQcloudProvider) GetICloudDnsZones() ([]cloudprovider.ICloudDnsZone,
|
||||
}
|
||||
|
||||
func (self *SQcloudProvider) GetICloudDnsZoneById(id string) (cloudprovider.ICloudDnsZone, error) {
|
||||
return self.client.GetDomainById(id)
|
||||
domain, err := self.client.GetDomain(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return domain, nil
|
||||
}
|
||||
|
||||
func (self *SQcloudProvider) CreateICloudDnsZone(opts *cloudprovider.SDnsZoneCreateOptions) (cloudprovider.ICloudDnsZone, error) {
|
||||
|
||||
@@ -69,6 +69,7 @@ const (
|
||||
QCLOUD_DCDB_API_VERSION = "2018-04-11"
|
||||
QCLOUD_KAFKA_API_VERSION = "2019-08-19"
|
||||
QCLOUD_TKE_API_VERSION = "2018-05-25"
|
||||
QCLOUD_DNS_API_VERSION = "2021-03-23"
|
||||
)
|
||||
|
||||
type QcloudClientConfig struct {
|
||||
@@ -267,9 +268,9 @@ func sslRequest(client *common.Client, apiName string, params map[string]string,
|
||||
}
|
||||
|
||||
// dnspod 解析服务
|
||||
func cnsRequest(client *common.Client, apiName string, params map[string]string, updateFunc func(string, string), debug bool) (jsonutils.JSONObject, error) {
|
||||
domain := "cns.api.qcloud.com"
|
||||
return _phpJsonRequest(client, &wssJsonResponse{}, domain, "/v2/index.php", "", apiName, params, updateFunc, debug)
|
||||
func dnsRequest(client *common.Client, apiName string, params map[string]string, updateFunc func(string, string), debug bool) (jsonutils.JSONObject, error) {
|
||||
domain := "dnspod.tencentcloudapi.com"
|
||||
return _jsonRequest(client, domain, QCLOUD_DNS_API_VERSION, apiName, params, updateFunc, debug, true)
|
||||
}
|
||||
|
||||
// 2017版API
|
||||
@@ -789,12 +790,12 @@ func (client *SQcloudClient) sslRequest(apiName string, params map[string]string
|
||||
return sslRequest(cli, apiName, params, client.cpcfg.UpdatePermission, client.debug)
|
||||
}
|
||||
|
||||
func (client *SQcloudClient) cnsRequest(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
func (client *SQcloudClient) dnsRequest(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
cli, err := client.getDefaultClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cnsRequest(cli, apiName, params, client.cpcfg.UpdatePermission, client.debug)
|
||||
return dnsRequest(cli, apiName, params, client.cpcfg.UpdatePermission, client.debug)
|
||||
}
|
||||
|
||||
func (client *SQcloudClient) vpc2017Request(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
|
||||
|
||||
@@ -24,17 +24,16 @@ import (
|
||||
|
||||
func init() {
|
||||
type DomianListOptions struct {
|
||||
Offset int
|
||||
Limit int
|
||||
ProjectId string
|
||||
Offset int
|
||||
Limit int
|
||||
Keyword string
|
||||
}
|
||||
shellutils.R(&DomianListOptions{}, "domain-list", "List domains", func(cli *qcloud.SRegion, args *DomianListOptions) error {
|
||||
domains, total, e := cli.GetClient().GetDomains(args.ProjectId, args.Offset, args.Limit)
|
||||
domains, total, e := cli.GetClient().GetDomains(args.Keyword, args.Offset, args.Limit)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
printList(domains, total, args.Offset, args.Limit, []string{})
|
||||
// cli.GetClient().GetAllDomains()
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -61,19 +60,29 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type DomianShowOptions struct {
|
||||
DOMAIN string
|
||||
}
|
||||
shellutils.R(&DomianShowOptions{}, "domain-show", "show domains", func(cli *qcloud.SRegion, args *DomianShowOptions) error {
|
||||
domain, err := cli.GetClient().GetDomain(args.DOMAIN)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(domain)
|
||||
return nil
|
||||
})
|
||||
|
||||
type DnsRecordListOptions struct {
|
||||
DOMAIN string
|
||||
ProjectId string
|
||||
Offset int
|
||||
Limit int
|
||||
DOMAIN string
|
||||
Offset int
|
||||
Limit int
|
||||
}
|
||||
shellutils.R(&DnsRecordListOptions{}, "dnsrecord-list", "List dndrecord", func(cli *qcloud.SRegion, args *DnsRecordListOptions) error {
|
||||
records, total, e := cli.GetClient().GetDnsRecords(args.ProjectId, args.DOMAIN, args.Offset, args.Limit)
|
||||
records, total, e := cli.GetClient().GetDnsRecords(args.DOMAIN, args.Offset, args.Limit)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
printList(records, total, args.Offset, args.Limit, []string{})
|
||||
// cli.GetClient().GetAllDnsRecords(args.Domain)
|
||||
return nil
|
||||
})
|
||||
|
||||
@@ -122,7 +131,7 @@ func init() {
|
||||
type DnsRecordUpdateStatusOptions struct {
|
||||
DOMAIN string
|
||||
RECORDID int
|
||||
STATUS string `choices:"disable|enable"`
|
||||
STATUS string `choices:"DISABLE|ENABLE"`
|
||||
}
|
||||
shellutils.R(&DnsRecordUpdateStatusOptions{}, "dnsrecord-updatestatus", "update dndrecord", func(cli *qcloud.SRegion, args *DnsRecordUpdateStatusOptions) error {
|
||||
e := cli.GetClient().ModifyRecordStatus(args.STATUS, strconv.Itoa(args.RECORDID), args.DOMAIN)
|
||||
@@ -134,7 +143,7 @@ func init() {
|
||||
|
||||
type DnsRecordRemoveOptions struct {
|
||||
DOMAIN string
|
||||
RECORDID int
|
||||
RECORDID string
|
||||
}
|
||||
shellutils.R(&DnsRecordRemoveOptions{}, "dnsrecord-delete", "delete dndrecord", func(cli *qcloud.SRegion, args *DnsRecordRemoveOptions) error {
|
||||
e := cli.GetClient().DeleteDnsRecord(args.RECORDID, args.DOMAIN)
|
||||
|
||||
Reference in New Issue
Block a user