yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/huawei/shell/natgateway.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 NatGatewayOptions struct { 25 NatGatewayID string `help:"Nat Gateway ID"` 26 VpcID string `help:"Vpc ID"` 27 } 28 shellutils.R(&NatGatewayOptions{}, "nat-list", "List nat gateway", func(region *huawei.SRegion, args *NatGatewayOptions) error { 29 natGateways, err := region.GetNatGateways(args.VpcID, args.NatGatewayID) 30 if err != nil { 31 return err 32 } 33 printList(natGateways, 0, 0, 0, nil) 34 return nil 35 }) 36 37 type NatGatewayIdOptions struct { 38 ID string `help:"Nat Id"` 39 } 40 41 shellutils.R(&NatGatewayIdOptions{}, "nat-delete", "Delete nat gateways", func(cli *huawei.SRegion, args *NatGatewayIdOptions) error { 42 return cli.DeleteNatGateway(args.ID) 43 }) 44 45 shellutils.R(&NatGatewayIdOptions{}, "nat-show", "Show nat gateways", func(cli *huawei.SRegion, args *NatGatewayIdOptions) error { 46 nat, err := cli.GetNatGateway(args.ID) 47 if err != nil { 48 return err 49 } 50 printObject(nat) 51 return nil 52 }) 53 54 type SCreateDNatOptions struct { 55 GatewayID string `help:"Nat Gateway ID" positional:"true"` 56 Protocol string `help:"Protocol(tcp/udp)" positional:"true"` 57 ExternalIPID string `help:"External IP ID" positional:"true"` 58 ExternalPort int `help:"External Port" positional:"true"` 59 InternalIP string `help:"Internal IP" positional:"true"` 60 InternalPort int `help:"Nat Gateway ID" positional:"true"` 61 } 62 shellutils.R(&SCreateDNatOptions{}, "dnat-create", "Create dnat", func(region *huawei.SRegion, args *SCreateDNatOptions) error { 63 rule := cloudprovider.SNatDRule{ 64 Protocol: args.Protocol, 65 ExternalIPID: args.ExternalIPID, 66 ExternalPort: args.ExternalPort, 67 InternalIP: args.InternalIP, 68 InternalPort: args.InternalPort, 69 } 70 dnat, err := region.CreateNatDEntry(rule, args.GatewayID) 71 if err != nil { 72 return err 73 } 74 printObject(dnat) 75 return nil 76 }) 77 78 type SCreateSNatOptions struct { 79 GatewayID string `help:"Nat Gateway ID" positional:"true"` 80 SourceCIDR string `help:"Source cidr" positional:"true"` 81 ExternalIPID string `help:"External IP ID" positional:"true"` 82 } 83 shellutils.R(&SCreateSNatOptions{}, "snat-create", "Create snat", func(region *huawei.SRegion, args *SCreateSNatOptions) error { 84 rule := cloudprovider.SNatSRule{ 85 SourceCIDR: args.SourceCIDR, 86 ExternalIPID: args.ExternalIPID, 87 } 88 snat, err := region.CreateNatSEntry(rule, args.GatewayID) 89 if err != nil { 90 return err 91 } 92 printObject(snat) 93 return nil 94 }) 95 96 type SShowSNatOptions struct { 97 NatID string `help:"SNat ID" positional:"true"` 98 } 99 shellutils.R(&SShowSNatOptions{}, "snat-show", "Show snat", func(region *huawei.SRegion, args *SShowSNatOptions) error { 100 snat, err := region.GetNatSEntryByID(args.NatID) 101 if err != nil { 102 return err 103 } 104 printObject(snat) 105 return nil 106 }) 107 108 type SShowDNatOptions struct { 109 NatID string `help:"DNat ID" positional:"true"` 110 } 111 shellutils.R(&SShowDNatOptions{}, "dnat-show", "Show dnat", func(region *huawei.SRegion, args *SShowDNatOptions) error { 112 dnat, err := region.GetNatDEntryByID(args.NatID) 113 if err != nil { 114 return err 115 } 116 printObject(dnat) 117 return nil 118 }) 119 120 type SDeleteSNatOptions struct { 121 NatID string `help:"SNat ID" positional:"true"` 122 } 123 shellutils.R(&SDeleteSNatOptions{}, "snat-delete", "Delete snat", func(region *huawei.SRegion, args *SDeleteSNatOptions) error { 124 err := region.DeleteNatSEntry(args.NatID) 125 if err != nil { 126 return err 127 } 128 return nil 129 }) 130 131 type SDeleteDNatOptions struct { 132 NatID string `help:"DNat ID" positional:"true"` 133 } 134 shellutils.R(&SDeleteDNatOptions{}, "dnat-delete", "Delete dnat", func(region *huawei.SRegion, args *SDeleteDNatOptions) error { 135 err := region.DeleteNatDEntry(args.NatID) 136 if err != nil { 137 return err 138 } 139 return nil 140 }) 141 }