yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/shell/dnspod.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 shell
    16  
    17  import (
    18  	"strconv"
    19  
    20  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    21  	"yunion.io/x/cloudmux/pkg/multicloud/qcloud"
    22  	"yunion.io/x/onecloud/pkg/util/shellutils"
    23  )
    24  
    25  func init() {
    26  	type DomianListOptions struct {
    27  		Offset  int
    28  		Limit   int
    29  		Keyword string
    30  	}
    31  	shellutils.R(&DomianListOptions{}, "domain-list", "List domains", func(cli *qcloud.SRegion, args *DomianListOptions) error {
    32  		domains, total, e := cli.GetClient().GetDomains(args.Keyword, args.Offset, args.Limit)
    33  		if e != nil {
    34  			return e
    35  		}
    36  		printList(domains, total, args.Offset, args.Limit, []string{})
    37  		return nil
    38  	})
    39  
    40  	type DomianCreateOptions struct {
    41  		DOMAIN string
    42  	}
    43  	shellutils.R(&DomianCreateOptions{}, "domain-create", "create domain", func(cli *qcloud.SRegion, args *DomianCreateOptions) error {
    44  		domain, e := cli.GetClient().CreateDomian(args.DOMAIN)
    45  		if e != nil {
    46  			return e
    47  		}
    48  		printObject(domain)
    49  		return nil
    50  	})
    51  
    52  	type DomianDeleteOptions struct {
    53  		DOMAIN string
    54  	}
    55  	shellutils.R(&DomianDeleteOptions{}, "domain-delete", "delete domains", func(cli *qcloud.SRegion, args *DomianDeleteOptions) error {
    56  		e := cli.GetClient().DeleteDomian(args.DOMAIN)
    57  		if e != nil {
    58  			return e
    59  		}
    60  		return nil
    61  	})
    62  
    63  	type DomianShowOptions struct {
    64  		DOMAIN string
    65  	}
    66  	shellutils.R(&DomianShowOptions{}, "domain-show", "show domains", func(cli *qcloud.SRegion, args *DomianShowOptions) error {
    67  		domain, err := cli.GetClient().GetDomain(args.DOMAIN)
    68  		if err != nil {
    69  			return err
    70  		}
    71  		printObject(domain)
    72  		return nil
    73  	})
    74  
    75  	type DnsRecordListOptions struct {
    76  		DOMAIN string
    77  		Offset int
    78  		Limit  int
    79  	}
    80  	shellutils.R(&DnsRecordListOptions{}, "dnsrecord-list", "List dndrecord", func(cli *qcloud.SRegion, args *DnsRecordListOptions) error {
    81  		records, total, e := cli.GetClient().GetDnsRecords(args.DOMAIN, args.Offset, args.Limit)
    82  		if e != nil {
    83  			return e
    84  		}
    85  		printList(records, total, args.Offset, args.Limit, []string{})
    86  		return nil
    87  	})
    88  
    89  	type DnsRecordCreateOptions struct {
    90  		DOMAIN string
    91  		NAME   string
    92  		VALUE  string //joined by '*'
    93  		TTL    int64
    94  		TYPE   string
    95  	}
    96  	shellutils.R(&DnsRecordCreateOptions{}, "dnsrecord-create", "create dndrecord", func(cli *qcloud.SRegion, args *DnsRecordCreateOptions) error {
    97  		change := cloudprovider.DnsRecordSet{}
    98  		change.DnsName = args.NAME
    99  		change.DnsValue = args.VALUE
   100  		change.Ttl = args.TTL
   101  		change.DnsType = cloudprovider.TDnsType(args.TYPE)
   102  		_, e := cli.GetClient().CreateDnsRecord(&change, args.DOMAIN)
   103  		if e != nil {
   104  			return e
   105  		}
   106  		return nil
   107  	})
   108  
   109  	type DnsRecordUpdateOptions struct {
   110  		DOMAIN   string
   111  		RECORDID int
   112  		NAME     string
   113  		VALUE    string //joined by '*'
   114  		TTL      int64
   115  		TYPE     string
   116  	}
   117  	shellutils.R(&DnsRecordUpdateOptions{}, "dnsrecord-update", "update dndrecord", func(cli *qcloud.SRegion, args *DnsRecordUpdateOptions) error {
   118  		change := cloudprovider.DnsRecordSet{}
   119  		change.DnsName = args.NAME
   120  		change.ExternalId = strconv.Itoa(args.RECORDID)
   121  		change.DnsValue = args.VALUE
   122  		change.Ttl = args.TTL
   123  		change.DnsType = cloudprovider.TDnsType(args.TYPE)
   124  		e := cli.GetClient().ModifyDnsRecord(&change, args.DOMAIN)
   125  		if e != nil {
   126  			return e
   127  		}
   128  		return nil
   129  	})
   130  
   131  	type DnsRecordUpdateStatusOptions struct {
   132  		DOMAIN   string
   133  		RECORDID int
   134  		STATUS   string `choices:"DISABLE|ENABLE"`
   135  	}
   136  	shellutils.R(&DnsRecordUpdateStatusOptions{}, "dnsrecord-updatestatus", "update dndrecord", func(cli *qcloud.SRegion, args *DnsRecordUpdateStatusOptions) error {
   137  		e := cli.GetClient().ModifyRecordStatus(args.STATUS, strconv.Itoa(args.RECORDID), args.DOMAIN)
   138  		if e != nil {
   139  			return e
   140  		}
   141  		return nil
   142  	})
   143  
   144  	type DnsRecordRemoveOptions struct {
   145  		DOMAIN   string
   146  		RECORDID string
   147  	}
   148  	shellutils.R(&DnsRecordRemoveOptions{}, "dnsrecord-delete", "delete dndrecord", func(cli *qcloud.SRegion, args *DnsRecordRemoveOptions) error {
   149  		e := cli.GetClient().DeleteDnsRecord(args.RECORDID, args.DOMAIN)
   150  		if e != nil {
   151  			return e
   152  		}
   153  		return nil
   154  	})
   155  }