yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/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 "io/ioutil" 19 20 "yunion.io/x/cloudmux/pkg/multicloud/qcloud" 21 "yunion.io/x/onecloud/pkg/util/shellutils" 22 ) 23 24 func init() { 25 type LbListOptions struct { 26 } 27 shellutils.R(&LbListOptions{}, "lb-list", "List loadbalancers", func(cli *qcloud.SRegion, args *LbListOptions) error { 28 lbs, err := cli.GetILoadBalancers() 29 if err != nil { 30 return err 31 } 32 33 printList(lbs, 0, 0, 0, []string{}) 34 return nil 35 }) 36 37 type LbCertListOptions struct { 38 } 39 shellutils.R(&LbCertListOptions{}, "lbcert-list", "List certs", func(cli *qcloud.SRegion, args *LbCertListOptions) error { 40 certs, err := cli.GetCertificates("", "", "") 41 if err != nil { 42 return err 43 } 44 45 printList(certs, 0, 0, 0, []string{}) 46 return nil 47 }) 48 49 type LbCertIdOptions struct { 50 ID string `json:"id" help:"certificate id"` 51 } 52 shellutils.R(&LbCertIdOptions{}, "lbcert-show", "Show cert", func(cli *qcloud.SRegion, args *LbCertIdOptions) error { 53 cert, err := cli.GetCertificate(args.ID) 54 if err != nil { 55 return err 56 } 57 58 printObject(cert) 59 return nil 60 }) 61 62 shellutils.R(&LbCertIdOptions{}, "lbcert-delete", "delete cert", func(cli *qcloud.SRegion, args *LbCertIdOptions) error { 63 err := cli.DeleteCertificate(args.ID) 64 if err != nil { 65 return err 66 } 67 68 return nil 69 }) 70 71 type LbCertUploadOptions struct { 72 PublicKeyPath string `json:"public_key_path"` 73 PrivateKeyPath string `json:"private_key_path"` 74 CertType string `json:"cert_type"` 75 Desc string `json:"desc"` 76 } 77 78 shellutils.R(&LbCertUploadOptions{}, "lbcert-upload", "Upload cert", func(cli *qcloud.SRegion, args *LbCertUploadOptions) error { 79 public := "" 80 if len(args.PublicKeyPath) > 0 { 81 _public, err := ioutil.ReadFile(args.PublicKeyPath) 82 if err != nil { 83 return err 84 } 85 86 public = string(_public) 87 } 88 89 private := "" 90 if len(args.PrivateKeyPath) > 0 { 91 _private, err := ioutil.ReadFile(args.PrivateKeyPath) 92 if err != nil { 93 return err 94 } 95 96 private = string(_private) 97 } 98 certId, err := cli.CreateCertificate("", public, private, args.CertType, args.Desc) 99 if err != nil { 100 return err 101 } 102 103 print(certId) 104 return nil 105 }) 106 }