mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
feat(region): dns records convert to zone file
This commit is contained in:
@@ -15,6 +15,11 @@
|
||||
package compute
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/cmd/climc/shell"
|
||||
modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
@@ -34,4 +39,15 @@ func init() {
|
||||
cmd.Perform("purge", &options.SDnsZoneIdOptions{})
|
||||
cmd.Perform("add-vpcs", &options.DnsZoneAddVpcsOptions{})
|
||||
cmd.Perform("remove-vpcs", &options.DnsZoneRemoveVpcsOptions{})
|
||||
cmd.GetWithCustomShow("exports", func(result jsonutils.JSONObject) {
|
||||
rr := make(map[string]string)
|
||||
err := result.Unmarshal(&rr)
|
||||
if err != nil {
|
||||
log.Errorf("error: %v", err)
|
||||
return
|
||||
}
|
||||
for _, v := range rr {
|
||||
fmt.Printf("%s\n", v)
|
||||
}
|
||||
}, &options.SDnsZoneIdOptions{})
|
||||
}
|
||||
|
||||
@@ -346,6 +346,18 @@ func (manager *SDnsRecordSetManager) FetchCustomizeColumns(
|
||||
return rows
|
||||
}
|
||||
|
||||
func (self *SDnsRecordSet) ToZoneLine() string {
|
||||
result := self.Name + "\t" + fmt.Sprint(self.TTL) + "\tIN\t" + self.DnsType + "\t"
|
||||
if self.MxPriority != 0 {
|
||||
result += fmt.Sprint(self.MxPriority) + "\t"
|
||||
}
|
||||
result += self.DnsValue
|
||||
if self.DnsType == "CNAME" || self.DnsType == "MX" || self.DnsType == "SRV" {
|
||||
result += "."
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (self *SDnsRecordSet) Delete(ctx context.Context, userCred mcclient.TokenCredential) error {
|
||||
policies, err := self.GetDnsTrafficPolicies()
|
||||
if err != nil {
|
||||
|
||||
@@ -578,6 +578,22 @@ func (self *SDnsZone) RealDelete(ctx context.Context, userCred mcclient.TokenCre
|
||||
return self.SEnabledStatusInfrasResourceBase.Delete(ctx, userCred)
|
||||
}
|
||||
|
||||
func (self *SDnsZone) GetDetailsExports(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (jsonutils.JSONObject, error) {
|
||||
records, err := self.GetDnsRecordSets()
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "GetDnsRecordSets")
|
||||
}
|
||||
result := "$ORIGIN " + self.Name + ".\n"
|
||||
lines := []string{}
|
||||
for _, record := range records {
|
||||
lines = append(lines, record.ToZoneLine())
|
||||
}
|
||||
result += strings.Join(lines, "\n")
|
||||
rr := make(map[string]string)
|
||||
rr["zone"] = result
|
||||
return jsonutils.Marshal(rr), nil
|
||||
}
|
||||
|
||||
func (self *SDnsZone) GetDnsRecordSets() ([]SDnsRecordSet, error) {
|
||||
records := []SDnsRecordSet{}
|
||||
q := DnsRecordSetManager.Query().Equals("dns_zone_id", self.Id)
|
||||
|
||||
Reference in New Issue
Block a user