yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/google/shell/loadbalancer.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/multicloud/google" 19 "yunion.io/x/onecloud/pkg/util/shellutils" 20 ) 21 22 func init() { 23 type ElbListOptions struct { 24 } 25 shellutils.R(&ElbListOptions{}, "lb-list", "List loadbalancers", func(cli *google.SRegion, args *ElbListOptions) error { 26 elbs, err := cli.GetRegionalLoadbalancers() 27 if err != nil { 28 return err 29 } 30 31 printList(elbs, len(elbs), 0, 0, []string{}) 32 return nil 33 }) 34 35 type ElbShowOptions struct { 36 RESOURCEID string `json:"resourceid"` 37 } 38 shellutils.R(&ElbShowOptions{}, "lb-bss", "List all loadbalancer backend services", func(cli *google.SRegion, args *ElbShowOptions) error { 39 lb, err := cli.GetLoadbalancer(args.RESOURCEID) 40 if err != nil { 41 return err 42 } 43 44 elbs, err := lb.GetBackendServices() 45 if err != nil { 46 return err 47 } 48 49 printList(elbs, len(elbs), 0, 0, []string{}) 50 return nil 51 }) 52 53 shellutils.R(&ElbShowOptions{}, "lb-frs", "List all loadbalancer forward rules", func(cli *google.SRegion, args *ElbShowOptions) error { 54 lb, err := cli.GetLoadbalancer(args.RESOURCEID) 55 if err != nil { 56 return err 57 } 58 59 elbs, err := lb.GetForwardingRules() 60 if err != nil { 61 return err 62 } 63 64 printList(elbs, len(elbs), 0, 0, []string{}) 65 return nil 66 }) 67 68 shellutils.R(&ElbShowOptions{}, "lb-http", "List loadbalancer https proxies", func(cli *google.SRegion, args *ElbShowOptions) error { 69 elb, err := cli.GetLoadbalancer(args.RESOURCEID) 70 if err != nil { 71 return err 72 } 73 74 hps, e := elb.GetTargetHttpProxies() 75 if e != nil { 76 return e 77 } 78 printList(hps, len(hps), 0, 0, []string{}) 79 return nil 80 }) 81 82 shellutils.R(&ElbShowOptions{}, "lb-https", "List loadbalancer https proxies", func(cli *google.SRegion, args *ElbShowOptions) error { 83 elb, err := cli.GetLoadbalancer(args.RESOURCEID) 84 if err != nil { 85 return err 86 } 87 88 hps, e := elb.GetTargetHttpsProxies() 89 if e != nil { 90 return e 91 } 92 printList(hps, len(hps), 0, 0, []string{}) 93 return nil 94 }) 95 96 shellutils.R(&ElbShowOptions{}, "lb-igs", "List all loadbalancer instance groups", func(cli *google.SRegion, args *ElbShowOptions) error { 97 elb, err := cli.GetLoadbalancer(args.RESOURCEID) 98 if err != nil { 99 return err 100 } 101 102 hps, e := elb.GetInstanceGroups() 103 if e != nil { 104 return e 105 } 106 printList(hps, len(hps), 0, 0, []string{}) 107 return nil 108 }) 109 110 shellutils.R(&ElbShowOptions{}, "lbl-list", "List all loadbalancer listeners", func(cli *google.SRegion, args *ElbShowOptions) error { 111 elb, err := cli.GetLoadbalancer(args.RESOURCEID) 112 if err != nil { 113 return err 114 } 115 116 hps, e := elb.GetLoadbalancerListeners() 117 if e != nil { 118 return e 119 } 120 printList(hps, len(hps), 0, 0, []string{}) 121 return nil 122 }) 123 124 shellutils.R(&ElbShowOptions{}, "lblr-list", "List all loadbalancer listener rules", func(cli *google.SRegion, args *ElbShowOptions) error { 125 elb, err := cli.GetLoadbalancer(args.RESOURCEID) 126 if err != nil { 127 return err 128 } 129 130 hps, e := elb.GetLoadbalancerListeners() 131 if e != nil { 132 return e 133 } 134 135 rules := make([]google.SLoadbalancerListenerRule, 0) 136 137 for i := range hps { 138 _rules, ee := hps[i].GetLoadbalancerListenerRules() 139 if e != nil { 140 return ee 141 } 142 143 rules = append(rules, _rules...) 144 } 145 146 printList(rules, len(rules), 0, 0, []string{}) 147 return nil 148 }) 149 150 shellutils.R(&ElbShowOptions{}, "lbbg-list", "List all loadbalancer backendgroups", func(cli *google.SRegion, args *ElbShowOptions) error { 151 lb, err := cli.GetLoadbalancer(args.RESOURCEID) 152 if err != nil { 153 return err 154 } 155 156 lbbg, e := lb.GetLoadbalancerBackendGroups() 157 if e != nil { 158 return e 159 } 160 161 printList(lbbg, len(lbbg), 0, 0, []string{}) 162 return nil 163 }) 164 165 shellutils.R(&ElbShowOptions{}, "lbb-list", "List all loadbalancer backends", func(cli *google.SRegion, args *ElbShowOptions) error { 166 lb, err := cli.GetLoadbalancer(args.RESOURCEID) 167 if err != nil { 168 return err 169 } 170 171 lbbg, e := lb.GetLoadbalancerBackendGroups() 172 if e != nil { 173 return e 174 } 175 176 lbbs := make([]google.SLoadbalancerBackend, 0) 177 for i := range lbbg { 178 backends, err := lbbg[i].GetLoadbalancerBackends() 179 if err != nil { 180 return err 181 } 182 183 lbbs = append(lbbs, backends...) 184 } 185 186 printList(lbbs, len(lbbs), 0, 0, []string{}) 187 return nil 188 }) 189 190 shellutils.R(&ElbShowOptions{}, "lbhc-list", "List all loadbalancer health checks", func(cli *google.SRegion, args *ElbShowOptions) error { 191 lb, err := cli.GetLoadbalancer(args.RESOURCEID) 192 if err != nil { 193 return err 194 } 195 196 hcs, e := lb.GetHealthChecks() 197 if e != nil { 198 return e 199 } 200 201 printList(hcs, len(hcs), 0, 0, []string{}) 202 return nil 203 }) 204 205 shellutils.R(&ElbListOptions{}, "cert-list", "List region certificates", func(cli *google.SRegion, args *ElbListOptions) error { 206 certs, err := cli.GetRegionalSslCertificates("") 207 if err != nil { 208 return err 209 } 210 211 printList(certs, len(certs), 0, 0, []string{}) 212 return nil 213 }) 214 }