yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/zstack/shell/network.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/zstack" 19 "yunion.io/x/onecloud/pkg/util/shellutils" 20 ) 21 22 func init() { 23 type NetworkListOptions struct { 24 ZoneId string 25 WireId string 26 VpcId string 27 NetworkId string 28 } 29 shellutils.R(&NetworkListOptions{}, "network-list", "List networks", func(cli *zstack.SRegion, args *NetworkListOptions) error { 30 networks, err := cli.GetNetworks(args.ZoneId, args.WireId, args.VpcId, args.NetworkId) 31 if err != nil { 32 return err 33 } 34 printList(networks, len(networks), 0, 0, []string{}) 35 return nil 36 }) 37 38 type NetworkDeleteOptions struct { 39 ID string 40 } 41 42 shellutils.R(&NetworkDeleteOptions{}, "network-delete", "Delete network", func(cli *zstack.SRegion, args *NetworkDeleteOptions) error { 43 return cli.DeleteNetwork(args.ID) 44 }) 45 46 type NetworkCreateOptions struct { 47 NAME string 48 Desc string 49 WIRE string 50 CIDR string 51 } 52 53 shellutils.R(&NetworkCreateOptions{}, "network-create", "Create network", func(cli *zstack.SRegion, args *NetworkCreateOptions) error { 54 network, err := cli.CreateNetwork(args.NAME, args.CIDR, args.WIRE, args.Desc) 55 if err != nil { 56 return err 57 } 58 printObject(network) 59 return nil 60 }) 61 62 type L3NetworkListOptions struct { 63 ZoneId string 64 WireId string 65 Id string 66 } 67 68 shellutils.R(&L3NetworkListOptions{}, "l3network-list", "List networks", func(cli *zstack.SRegion, args *L3NetworkListOptions) error { 69 l3networks, err := cli.GetL3Networks(args.ZoneId, args.WireId, args.Id) 70 if err != nil { 71 return err 72 } 73 printList(l3networks, len(l3networks), 0, 0, []string{}) 74 return nil 75 }) 76 77 type NetworkServicesOptions struct { 78 } 79 80 shellutils.R(&NetworkServicesOptions{}, "network-service-list", "List network services", func(cli *zstack.SRegion, args *NetworkServicesOptions) error { 81 service, err := cli.GetNetworkServices() 82 if err != nil { 83 return err 84 } 85 printObject(service) 86 return nil 87 }) 88 89 type NetworkServiceProviderOptions struct { 90 Type string 91 } 92 93 shellutils.R(&NetworkServiceProviderOptions{}, "network-service-provider-list", "List network service providers", func(cli *zstack.SRegion, args *NetworkServiceProviderOptions) error { 94 providers, err := cli.GetNetworkServiceProviders(args.Type) 95 if err != nil { 96 return err 97 } 98 printList(providers, len(providers), 0, 0, []string{}) 99 return nil 100 }) 101 102 type NetworkServiceAttachOptions struct { 103 Services []string 104 ID string 105 } 106 107 shellutils.R(&NetworkServiceAttachOptions{}, "network-service-attach", "Attach network service to l3network", func(cli *zstack.SRegion, args *NetworkServiceAttachOptions) error { 108 cli.AttachServiceForl3Network(args.ID, args.Services) 109 return nil 110 }) 111 112 type NetworkServiceRefOptions struct { 113 L3Id string 114 Type string 115 } 116 117 shellutils.R(&NetworkServiceRefOptions{}, "network-service-ref", "List network service ref", func(cli *zstack.SRegion, args *NetworkServiceRefOptions) error { 118 refs, err := cli.GetNetworkServiceRef(args.L3Id, args.Type) 119 if err != nil { 120 return err 121 } 122 printList(refs, len(refs), 0, 0, []string{}) 123 return nil 124 }) 125 126 type NetworkServiceRemoveOptions struct { 127 L3ID string 128 SERVICE string `choices:"Userdata|DHCP|VipQos|HostRoute|Eip|SecurityGroup|DNS|SNAT"` 129 } 130 131 shellutils.R(&NetworkServiceRemoveOptions{}, "remove-network-service", "Remove l3network service", func(cli *zstack.SRegion, args *NetworkServiceRemoveOptions) error { 132 return cli.RemoveNetworkService(args.L3ID, args.SERVICE) 133 }) 134 135 }