yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/huawei/shell/vpc.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/huawei" 20 "yunion.io/x/onecloud/pkg/util/shellutils" 21 ) 22 23 func init() { 24 type VpcListOptions struct { 25 } 26 shellutils.R(&VpcListOptions{}, "vpc-list", "List vpcs", func(cli *huawei.SRegion, args *VpcListOptions) error { 27 vpcs, e := cli.GetVpcs() 28 if e != nil { 29 return e 30 } 31 printList(vpcs, 0, 0, 0, nil) 32 return nil 33 }) 34 35 type VpcCreateOptions struct { 36 NAME string 37 CIDR string 38 Desc string 39 } 40 41 shellutils.R(&VpcCreateOptions{}, "vpc-create", "Create vpc", func(cli *huawei.SRegion, args *VpcCreateOptions) error { 42 vpc, err := cli.CreateVpc(args.NAME, args.CIDR, args.Desc) 43 if err != nil { 44 return err 45 } 46 printObject(vpc) 47 return nil 48 }) 49 50 type VpcIdOption struct { 51 ID string 52 } 53 54 shellutils.R(&VpcIdOption{}, "vpc-delete", "Delete vpc", func(cli *huawei.SRegion, args *VpcIdOption) error { 55 return cli.DeleteVpc(args.ID) 56 }) 57 58 type VpcPeeringListOPtion struct { 59 VPCID string 60 } 61 shellutils.R(&VpcPeeringListOPtion{}, "vpcPeering-list", "List vpcPeering", func(cli *huawei.SRegion, args *VpcPeeringListOPtion) error { 62 vpcPeerings, err := cli.GetVpcPeerings(args.VPCID) 63 if err != nil { 64 return err 65 } 66 printList(vpcPeerings, 0, 0, 0, nil) 67 return nil 68 }) 69 70 type VpcPeeringShowOPtion struct { 71 VPCPEERINGID string 72 } 73 shellutils.R(&VpcPeeringShowOPtion{}, "vpcPeering-show", "show vpcPeering", func(cli *huawei.SRegion, args *VpcPeeringShowOPtion) error { 74 vpcPeering, err := cli.GetVpcPeering(args.VPCPEERINGID) 75 if err != nil { 76 return err 77 } 78 printObject(vpcPeering) 79 return nil 80 }) 81 82 type VpcPeeringCreateOPtion struct { 83 NAME string 84 VPCID string 85 PEERVPCID string 86 PEEROWNERID string 87 } 88 shellutils.R(&VpcPeeringCreateOPtion{}, "vpcPeering-create", "create vpcPeering", func(cli *huawei.SRegion, args *VpcPeeringCreateOPtion) error { 89 opts := cloudprovider.VpcPeeringConnectionCreateOptions{} 90 opts.Name = args.NAME 91 opts.PeerVpcId = args.PEERVPCID 92 opts.PeerAccountId = args.PEEROWNERID 93 vpcPeering, err := cli.CreateVpcPeering(args.VPCID, &opts) 94 if err != nil { 95 return err 96 } 97 printObject(vpcPeering) 98 return nil 99 }) 100 101 type VpcPeeringAcceptOPtion struct { 102 VPCPEERINGID string 103 } 104 shellutils.R(&VpcPeeringAcceptOPtion{}, "vpcPeering-accept", "Accept vpcPeering", func(cli *huawei.SRegion, args *VpcPeeringAcceptOPtion) error { 105 err := cli.AcceptVpcPeering(args.VPCPEERINGID) 106 if err != nil { 107 return err 108 } 109 return nil 110 }) 111 112 type VpcPeeringDeleteOPtion struct { 113 VPCPEERINGID string 114 } 115 shellutils.R(&VpcPeeringDeleteOPtion{}, "vpcPeering-delete", "Delete vpcPeering", func(cli *huawei.SRegion, args *VpcPeeringDeleteOPtion) error { 116 err := cli.DeleteVpcPeering(args.VPCPEERINGID) 117 if err != nil { 118 return err 119 } 120 return nil 121 }) 122 }