Skip to content

Commit 1c4d8a5

Browse files
authored
Merge pull request #15 from liquidweb/loadbalancer
Loadbalancer
2 parents d9afb4b + 579fa97 commit 1c4d8a5

19 files changed

+1693
-12
lines changed

cmd/networkIpPool.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ var networkIpPoolCmd = &cobra.Command{
2626
Short: "IP Pool specific operations",
2727
Long: `IP Pool specific operations.
2828
29+
Use an IP Pool to reserve IP addresses even when they aren't currently assigned
30+
to a server.
31+
2932
For a full list of capabilities, please refer to the "Available Commands" section.`,
3033
Run: func(cmd *cobra.Command, args []string) {
3134
cmd.Help()

cmd/networkLoadBalancer.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright © LiquidWeb
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"os"
20+
21+
"github.com/spf13/cobra"
22+
)
23+
24+
var networkLoadBalancerCmd = &cobra.Command{
25+
Use: "load-balancer",
26+
Short: "Load Balancer specific operations",
27+
Long: `Load Balancer specific operations.
28+
29+
A Load Balancer allows you to distribute traffic to multiple endpoints.
30+
31+
For a full list of capabilities, please refer to the "Available Commands" section.`,
32+
Run: func(cmd *cobra.Command, args []string) {
33+
cmd.Help()
34+
os.Exit(1)
35+
},
36+
}
37+
38+
func init() {
39+
networkCmd.AddCommand(networkLoadBalancerCmd)
40+
}

cmd/networkLoadBalancerAddNode.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
Copyright © LiquidWeb
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"fmt"
20+
21+
"github.com/spf13/cobra"
22+
23+
"github.com/liquidweb/liquidweb-cli/types/api"
24+
"github.com/liquidweb/liquidweb-cli/validate"
25+
)
26+
27+
var networkLoadBalancerAddNodeCmd = &cobra.Command{
28+
Use: "add-node",
29+
Short: "Add a node to an existing Load Balancer",
30+
Long: `Add a node (ip) to an existing Load Balancer.
31+
32+
A node is an ip address. You can only add ip addresses that are assigned to
33+
your account.
34+
`,
35+
Run: func(cmd *cobra.Command, args []string) {
36+
uniqIdFlag, _ := cmd.Flags().GetString("uniq_id")
37+
nodeFlag, _ := cmd.Flags().GetString("node")
38+
39+
validateFields := map[interface{}]interface{}{
40+
uniqIdFlag: "UniqId",
41+
nodeFlag: "IP",
42+
}
43+
if err := validate.Validate(validateFields); err != nil {
44+
lwCliInst.Die(err)
45+
}
46+
47+
apiArgs := map[string]interface{}{
48+
"uniq_id": uniqIdFlag,
49+
"node": nodeFlag,
50+
}
51+
52+
var details apiTypes.NetworkLoadBalancerDetails
53+
if err := lwCliInst.CallLwApiInto("bleed/network/loadbalancer/addnode", apiArgs,
54+
&details); err != nil {
55+
lwCliInst.Die(err)
56+
}
57+
58+
fmt.Print(details)
59+
},
60+
}
61+
62+
func init() {
63+
networkLoadBalancerCmd.AddCommand(networkLoadBalancerAddNodeCmd)
64+
networkLoadBalancerAddNodeCmd.Flags().String("uniq_id", "", "uniq_id of Load Balancer")
65+
networkLoadBalancerAddNodeCmd.Flags().String("node", "", "node (ip) to add to the Load Balancer")
66+
networkLoadBalancerAddNodeCmd.MarkFlagRequired("uniq_id")
67+
networkLoadBalancerAddNodeCmd.MarkFlagRequired("node")
68+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Copyright © LiquidWeb
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"fmt"
20+
21+
"github.com/spf13/cobra"
22+
23+
"github.com/liquidweb/liquidweb-cli/types/api"
24+
"github.com/liquidweb/liquidweb-cli/validate"
25+
)
26+
27+
var networkLoadBalancerAddServiceCmd = &cobra.Command{
28+
Use: "add-service",
29+
Short: "Add a service to an existing Load Balancer",
30+
Long: `Add a service to an existing Load Balancer.
31+
32+
A service represents a service to load balance.`,
33+
Run: func(cmd *cobra.Command, args []string) {
34+
uniqIdFlag, _ := cmd.Flags().GetString("uniq_id")
35+
srcPortFlag, _ := cmd.Flags().GetInt("src-port")
36+
destPortFlag, _ := cmd.Flags().GetInt("dest-port")
37+
38+
validateFields := map[interface{}]interface{}{
39+
uniqIdFlag: "UniqId",
40+
srcPortFlag: "NetworkPort",
41+
destPortFlag: "NetworkPort",
42+
}
43+
if err := validate.Validate(validateFields); err != nil {
44+
lwCliInst.Die(err)
45+
}
46+
47+
apiArgs := map[string]interface{}{
48+
"uniq_id": uniqIdFlag,
49+
"src_port": srcPortFlag,
50+
"dest_port": destPortFlag,
51+
}
52+
53+
var details apiTypes.NetworkLoadBalancerDetails
54+
if err := lwCliInst.CallLwApiInto("bleed/network/loadbalancer/addservice", apiArgs,
55+
&details); err != nil {
56+
lwCliInst.Die(err)
57+
}
58+
59+
fmt.Print(details)
60+
},
61+
}
62+
63+
func init() {
64+
networkLoadBalancerCmd.AddCommand(networkLoadBalancerAddServiceCmd)
65+
networkLoadBalancerAddServiceCmd.Flags().String("uniq_id", "", "uniq_id of Load Balancer")
66+
networkLoadBalancerAddServiceCmd.Flags().Int("src-port", -1, "source port")
67+
networkLoadBalancerAddServiceCmd.Flags().Int("dest-port", -1, "destination port")
68+
69+
networkLoadBalancerAddServiceCmd.MarkFlagRequired("uniq_id")
70+
networkLoadBalancerAddServiceCmd.MarkFlagRequired("src-port")
71+
networkLoadBalancerAddServiceCmd.MarkFlagRequired("dest-port")
72+
}

0 commit comments

Comments
 (0)