yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aws/shell/hostedzone.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 "yunion.io/x/cloudmux/pkg/cloudprovider" 19 "yunion.io/x/cloudmux/pkg/multicloud/aws" 20 "yunion.io/x/onecloud/pkg/util/shellutils" 21 ) 22 23 func init() { 24 type Route53LocationListOptions struct{} 25 shellutils.R(&Route53LocationListOptions{}, "route53location-list", "List route53location", func(cli *aws.SRegion, args *Route53LocationListOptions) error { 26 locations, err := cli.GetClient().ListGeoLocations() 27 if err != nil { 28 return err 29 } 30 printList(locations, len(locations), 0, 20, []string{}) 31 return nil 32 }) 33 34 type HostedZoneListOptions struct{} 35 shellutils.R(&HostedZoneListOptions{}, "hostedzone-list", "List hostedzone", func(cli *aws.SRegion, args *HostedZoneListOptions) error { 36 hostzones, err := cli.GetClient().GetHostedZones() 37 if err != nil { 38 return err 39 } 40 printList(hostzones, len(hostzones), 0, 20, []string{}) 41 return nil 42 }) 43 44 type HostedZoneCreateOptions struct { 45 NAME string `help:"Domain name"` 46 Type string `choices:"PublicZone|PrivateZone"` 47 Vpc string `help:"vpc id"` 48 Region string `help:"region id"` 49 } 50 shellutils.R(&HostedZoneCreateOptions{}, "hostedzone-create", "Create hostedzone", func(cli *aws.SRegion, args *HostedZoneCreateOptions) error { 51 opts := cloudprovider.SDnsZoneCreateOptions{} 52 opts.Name = args.NAME 53 opts.ZoneType = cloudprovider.TDnsZoneType(args.Type) 54 if len(args.Vpc) > 0 && len(args.Region) > 0 { 55 vpc := cloudprovider.SPrivateZoneVpc{} 56 vpc.Id = args.Vpc 57 vpc.RegionId = args.Region 58 opts.Vpcs = []cloudprovider.SPrivateZoneVpc{vpc} 59 } 60 hostzones, err := cli.GetClient().CreateHostedZone(&opts) 61 if err != nil { 62 return err 63 } 64 printObject(hostzones) 65 return nil 66 }) 67 type HostedZoneGetOptions struct { 68 HOSTEDZONEID string 69 } 70 shellutils.R(&HostedZoneGetOptions{}, "hostedzone-show", "get hostedzone by id", func(cli *aws.SRegion, args *HostedZoneGetOptions) error { 71 72 hostedzone, err := cli.GetClient().GetHostedZoneById(args.HOSTEDZONEID) 73 if err != nil { 74 return err 75 } 76 printObject(hostedzone) 77 return nil 78 }) 79 80 type HostedZoneVpcListOptions struct { 81 HOSTEDZONEID string 82 } 83 shellutils.R(&HostedZoneVpcListOptions{}, "hostedzonevpc-list", "List hostedzonevpc", func(cli *aws.SRegion, args *HostedZoneVpcListOptions) error { 84 vpcs, err := cli.GetClient().GetHostedZoneVpcs(args.HOSTEDZONEID) 85 if err != nil { 86 return err 87 } 88 printList(vpcs, len(vpcs), 0, 20, []string{}) 89 return nil 90 }) 91 92 type HostedZoneAddVpcOptions struct { 93 HOSTEDZONEID string 94 VPC string 95 REGION string 96 } 97 shellutils.R(&HostedZoneAddVpcOptions{}, "hostedzone-add-vpc", "associate vpc with hostedzone", func(cli *aws.SRegion, args *HostedZoneAddVpcOptions) error { 98 99 err := cli.GetClient().AssociateVPCWithHostedZone(args.VPC, args.REGION, args.HOSTEDZONEID) 100 if err != nil { 101 return err 102 } 103 return nil 104 }) 105 106 type HostedZoneRemoveVpcOptions struct { 107 HOSTEDZONEID string 108 VPC string 109 REGION string 110 } 111 shellutils.R(&HostedZoneRemoveVpcOptions{}, "hostedzone-rmvpc", "disassociate vpc with hostedzone", func(cli *aws.SRegion, args *HostedZoneRemoveVpcOptions) error { 112 113 err := cli.GetClient().DisassociateVPCFromHostedZone(args.VPC, args.REGION, args.HOSTEDZONEID) 114 if err != nil { 115 return err 116 } 117 return nil 118 }) 119 120 type HostedZoneDeleteOptions struct { 121 HOSTEDZONEID string 122 } 123 shellutils.R(&HostedZoneDeleteOptions{}, "hostedzone-delete", "delete hostedzone", func(cli *aws.SRegion, args *HostedZoneDeleteOptions) error { 124 err := cli.GetClient().DeleteHostedZone(args.HOSTEDZONEID) 125 if err != nil { 126 return err 127 } 128 return nil 129 }) 130 131 type DnsRecordSetListOptions struct { 132 HOSTEDZONEID string 133 } 134 shellutils.R(&DnsRecordSetListOptions{}, "dnsrecordset-list", "List dnsrecordset", func(cli *aws.SRegion, args *DnsRecordSetListOptions) error { 135 dnsrecordsets, err := cli.GetClient().GetSdnsRecordSets(args.HOSTEDZONEID) 136 if err != nil { 137 return err 138 } 139 printList(dnsrecordsets, len(dnsrecordsets), 0, 20, []string{}) 140 return nil 141 }) 142 143 type DnsRecordSetCreateOptions struct { 144 HOSTEDZONEID string `help:"HostedzoneId"` 145 NAME string `help:"Domain name"` 146 VALUE string `help:"dns record value"` 147 TTL int64 `help:"ttl"` 148 TYPE string `help:"dns type"` 149 PolicyType string `help:"PolicyType"` 150 Identify string `help:"Identify"` 151 } 152 shellutils.R(&DnsRecordSetCreateOptions{}, "dnsrecordset-create", "create dnsrecordset", func(cli *aws.SRegion, args *DnsRecordSetCreateOptions) error { 153 opts := cloudprovider.DnsRecordSet{} 154 opts.DnsName = args.NAME 155 opts.DnsType = cloudprovider.TDnsType(args.TYPE) 156 opts.DnsValue = args.VALUE 157 opts.Ttl = args.TTL 158 opts.ExternalId = args.Identify 159 err := cli.GetClient().AddDnsRecordSet(args.HOSTEDZONEID, &opts) 160 if err != nil { 161 return err 162 } 163 return nil 164 }) 165 166 type DnsRecordSetupdateOptions struct { 167 HOSTEDZONEID string `help:"HostedzoneId"` 168 NAME string `help:"Domain name"` 169 VALUE string `help:"dns record value"` 170 TTL int64 `help:"ttl"` 171 TYPE string `help:"dns type"` 172 Identify string `help:"Identify"` 173 } 174 shellutils.R(&DnsRecordSetupdateOptions{}, "dnsrecordset-update", "update dnsrecordset", func(cli *aws.SRegion, args *DnsRecordSetupdateOptions) error { 175 opts := cloudprovider.DnsRecordSet{} 176 opts.DnsName = args.NAME 177 opts.DnsType = cloudprovider.TDnsType(args.TYPE) 178 opts.DnsValue = args.VALUE 179 opts.Ttl = args.TTL 180 opts.ExternalId = args.Identify 181 err := cli.GetClient().UpdateDnsRecordSet(args.HOSTEDZONEID, &opts) 182 if err != nil { 183 return err 184 } 185 return nil 186 }) 187 188 type DnsRecordSetDeleteOptions struct { 189 HOSTEDZONEID string `help:"HostedzoneId"` 190 NAME string `help:"Domain name"` 191 VALUE string `help:"dns record value"` 192 TTL int64 `help:"ttl"` 193 TYPE string `help:"dns type"` 194 Identify string `help:"Identify"` 195 } 196 shellutils.R(&DnsRecordSetDeleteOptions{}, "dnsrecordset-delete", "delete dnsrecordset", func(cli *aws.SRegion, args *DnsRecordSetDeleteOptions) error { 197 opts := cloudprovider.DnsRecordSet{} 198 opts.DnsName = args.NAME 199 opts.DnsType = cloudprovider.TDnsType(args.TYPE) 200 opts.DnsValue = args.VALUE 201 opts.Ttl = args.TTL 202 opts.ExternalId = args.Identify 203 err := cli.GetClient().RemoveDnsRecordSet(args.HOSTEDZONEID, &opts) 204 if err != nil { 205 return err 206 } 207 return nil 208 }) 209 }