Skip to content

Commit 09d2d77

Browse files
authored
Merge pull request #56 from liquidweb/add-rm-pub-ips-update
add `cloud network {public,private}` to plans
2 parents c3a6cf3 + 3663bcb commit 09d2d77

18 files changed

+585
-165
lines changed

cmd/cloudNetworkPrivateAttach.go

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import (
2020

2121
"github.com/spf13/cobra"
2222

23-
"github.com/liquidweb/liquidweb-cli/types/api"
24-
"github.com/liquidweb/liquidweb-cli/validate"
23+
"github.com/liquidweb/liquidweb-cli/instance"
2524
)
2625

26+
var cloudNetworkPrivateAttachCmdUniqIdFlag []string
27+
2728
var cloudNetworkPrivateAttachCmd = &cobra.Command{
2829
Use: "attach",
2930
Short: "Attach a Cloud Server to a Private Network",
@@ -39,40 +40,23 @@ Applications that communicate internally will frequently use this for both secur
3940
and cost-savings.
4041
`,
4142
Run: func(cmd *cobra.Command, args []string) {
42-
uniqIdFlag, _ := cmd.Flags().GetString("uniq-id")
43-
44-
validateFields := map[interface{}]interface{}{
45-
uniqIdFlag: "UniqId",
46-
}
47-
if err := validate.Validate(validateFields); err != nil {
48-
lwCliInst.Die(err)
49-
}
43+
params := &instance.CloudNetworkPrivateAttachParams{}
5044

51-
apiArgs := map[string]interface{}{"uniq_id": uniqIdFlag}
52-
53-
var attachedDetails apiTypes.CloudNetworkPrivateIsAttachedResponse
54-
err := lwCliInst.CallLwApiInto("bleed/network/private/isattached", apiArgs, &attachedDetails)
55-
if err != nil {
56-
lwCliInst.Die(err)
57-
}
58-
if attachedDetails.IsAttached {
59-
lwCliInst.Die(fmt.Errorf("Cloud Server is already attached to the Private Network"))
60-
}
45+
params.UniqId = cloudNetworkPrivateAttachCmdUniqIdFlag
6146

62-
var details apiTypes.CloudNetworkPrivateAttachResponse
63-
err = lwCliInst.CallLwApiInto("bleed/network/private/attach", apiArgs, &details)
47+
status, err := lwCliInst.CloudNetworkPrivateAttach(params)
6448
if err != nil {
6549
lwCliInst.Die(err)
6650
}
6751

68-
fmt.Printf("Attaching %s to private network\n", details.Attached)
69-
fmt.Printf("\n\nYou can check progress with 'cloud server status --uniq-id %s'\n", uniqIdFlag)
52+
fmt.Print(status)
7053
},
7154
}
7255

7356
func init() {
7457
cloudNetworkPrivateCmd.AddCommand(cloudNetworkPrivateAttachCmd)
75-
cloudNetworkPrivateAttachCmd.Flags().String("uniq-id", "", "uniq-id of the Cloud Server")
58+
cloudNetworkPrivateAttachCmd.Flags().StringSliceVar(&cloudNetworkPrivateAttachCmdUniqIdFlag, "uniq-id",
59+
[]string{}, "uniq-ids separated by ',' of Cloud Servers to attach to private networking")
7660
if err := cloudNetworkPrivateAttachCmd.MarkFlagRequired("uniq-id"); err != nil {
7761
lwCliInst.Die(err)
7862
}

cmd/cloudNetworkPrivateDetach.go

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import (
2020

2121
"github.com/spf13/cobra"
2222

23-
"github.com/liquidweb/liquidweb-cli/types/api"
24-
"github.com/liquidweb/liquidweb-cli/validate"
23+
"github.com/liquidweb/liquidweb-cli/instance"
2524
)
2625

26+
var cloudNetworkPrivateDetachCmdUniqIdFlag []string
27+
2728
var cloudNetworkPrivateDetachCmd = &cobra.Command{
2829
Use: "detach",
2930
Short: "Detach a Cloud Server from a Private Network",
@@ -39,40 +40,23 @@ Applications that communicate internally will frequently use this for both secur
3940
and cost-savings.
4041
`,
4142
Run: func(cmd *cobra.Command, args []string) {
42-
uniqIdFlag, _ := cmd.Flags().GetString("uniq-id")
43-
44-
validateFields := map[interface{}]interface{}{
45-
uniqIdFlag: "UniqId",
46-
}
47-
if err := validate.Validate(validateFields); err != nil {
48-
lwCliInst.Die(err)
49-
}
43+
params := &instance.CloudNetworkPrivateDetachParams{}
5044

51-
apiArgs := map[string]interface{}{"uniq_id": uniqIdFlag}
52-
53-
var attachedDetails apiTypes.CloudNetworkPrivateIsAttachedResponse
54-
err := lwCliInst.CallLwApiInto("bleed/network/private/isattached", apiArgs, &attachedDetails)
55-
if err != nil {
56-
lwCliInst.Die(err)
57-
}
58-
if !attachedDetails.IsAttached {
59-
lwCliInst.Die(fmt.Errorf("Cloud Server is already detached to the Private Network"))
60-
}
45+
params.UniqId = cloudNetworkPrivateDetachCmdUniqIdFlag
6146

62-
var details apiTypes.CloudNetworkPrivateDetachResponse
63-
err = lwCliInst.CallLwApiInto("bleed/network/private/detach", apiArgs, &details)
47+
status, err := lwCliInst.CloudNetworkPrivateDetach(params)
6448
if err != nil {
6549
lwCliInst.Die(err)
6650
}
6751

68-
fmt.Printf("Detaching %s from private network\n", details.Detached)
69-
fmt.Printf("\n\nYou can check progress with 'cloud server status --uniq-id %s'\n\n", uniqIdFlag)
52+
fmt.Print(status)
7053
},
7154
}
7255

7356
func init() {
7457
cloudNetworkPrivateCmd.AddCommand(cloudNetworkPrivateDetachCmd)
75-
cloudNetworkPrivateDetachCmd.Flags().String("uniq-id", "", "uniq-id of the Cloud Server")
58+
cloudNetworkPrivateDetachCmd.Flags().StringSliceVar(&cloudNetworkPrivateDetachCmdUniqIdFlag, "uniq-id",
59+
[]string{}, "uniq-ids separated by ',' of Cloud Servers to detach from private networking")
7660
if err := cloudNetworkPrivateDetachCmd.MarkFlagRequired("uniq-id"); err != nil {
7761
lwCliInst.Die(err)
7862
}

cmd/cloudNetworkPublicAdd.go

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import (
2020

2121
"github.com/spf13/cobra"
2222

23-
"github.com/liquidweb/liquidweb-cli/types/api"
24-
"github.com/liquidweb/liquidweb-cli/validate"
23+
"github.com/liquidweb/liquidweb-cli/instance"
2524
)
2625

2726
var cloudNetworkPublicAddCmdPoolIpsFlag []string
@@ -31,71 +30,36 @@ var cloudNetworkPublicAddCmd = &cobra.Command{
3130
Short: "Add Public IP(s) to a Cloud Server",
3231
Long: `Add Public IP(s) to a Cloud Server.
3332
34-
Add a number of IPs to an existing Cloud Server. If the reboot flag is passed, the
35-
server will be stopped, have the new IP addresses configured, and then started.
33+
Add a number of IPs to an existing Cloud Server. If the configure-ips flag is
34+
passed in, the IP addresses will be automatically configured within the guest
35+
operating system.
3636
37-
When the reboot flag is not passed, the IP will be assigned to the server, but it
38-
will be up to the administrator to configure the IP address(es) within the server.
39-
`,
37+
If the configure-ips flag is not passed, the IP addresses will be assigned, and
38+
routing will be allowed. However the IP(s) will not be automatically configured
39+
in the guest operating system. In this scenario, it will be up to the system
40+
administrator to add the IP(s) to the network configuration.`,
4041
Run: func(cmd *cobra.Command, args []string) {
41-
uniqIdFlag, _ := cmd.Flags().GetString("uniq-id")
42-
rebootFlag, _ := cmd.Flags().GetBool("reboot")
43-
newIpsFlag, _ := cmd.Flags().GetInt64("new-ips")
42+
params := &instance.CloudNetworkPublicAddParams{}
4443

45-
validateFields := map[interface{}]interface{}{
46-
uniqIdFlag: "UniqId",
47-
}
48-
if err := validate.Validate(validateFields); err != nil {
49-
lwCliInst.Die(err)
50-
}
44+
params.UniqId, _ = cmd.Flags().GetString("uniq-id")
45+
params.ConfigureIps, _ = cmd.Flags().GetBool("configure-ips")
46+
params.NewIps, _ = cmd.Flags().GetInt64("new-ips")
47+
params.PoolIps = cloudNetworkPublicAddCmdPoolIpsFlag
5148

52-
if newIpsFlag == 0 && len(cloudNetworkPublicAddCmdPoolIpsFlag) == 0 {
53-
lwCliInst.Die(fmt.Errorf("at least one of --new-ips --pool-ips must be given"))
54-
}
55-
56-
apiArgs := map[string]interface{}{
57-
"reboot": rebootFlag,
58-
"uniq_id": uniqIdFlag,
59-
}
60-
if newIpsFlag != 0 {
61-
apiArgs["ip_count"] = newIpsFlag
62-
validateFields := map[interface{}]interface{}{newIpsFlag: "PositiveInt64"}
63-
if err := validate.Validate(validateFields); err != nil {
64-
lwCliInst.Die(err)
65-
}
66-
}
67-
if len(cloudNetworkPublicAddCmdPoolIpsFlag) != 0 {
68-
apiArgs["pool_ips"] = cloudNetworkPublicAddCmdPoolIpsFlag
69-
validateFields := map[interface{}]interface{}{}
70-
for _, ip := range cloudNetworkPublicAddCmdPoolIpsFlag {
71-
validateFields[ip] = "IP"
72-
}
73-
if err := validate.Validate(validateFields); err != nil {
74-
lwCliInst.Die(err)
75-
}
76-
}
77-
78-
var details apiTypes.NetworkIpAdd
79-
err := lwCliInst.CallLwApiInto("bleed/network/ip/add", apiArgs, &details)
49+
status, err := lwCliInst.CloudNetworkPublicAdd(params)
8050
if err != nil {
8151
lwCliInst.Die(err)
8252
}
8353

84-
fmt.Printf("Adding [%s] to Cloud Server\n", details.Adding)
85-
86-
if rebootFlag {
87-
fmt.Println("Server will be rebooted and IP(s) automatically configured.")
88-
} else {
89-
fmt.Println("Server will not be rebooted. IP's will need to be manually configured.")
90-
}
54+
fmt.Print(status)
9155
},
9256
}
9357

9458
func init() {
9559
cloudNetworkPublicCmd.AddCommand(cloudNetworkPublicAddCmd)
9660
cloudNetworkPublicAddCmd.Flags().String("uniq-id", "", "uniq-id of the Cloud Server")
97-
cloudNetworkPublicAddCmd.Flags().Bool("reboot", false,
98-
"wheter or not to automatically configure the new IP address(es) in the server (requires reboot)")
61+
cloudNetworkPublicAddCmd.Flags().Bool("configure-ips", false,
62+
"wheter or not to automatically configure the new IP address(es) in the server")
9963
cloudNetworkPublicAddCmd.Flags().Int64("new-ips", 0, "amount of new ips to (randomly) grab")
10064
cloudNetworkPublicAddCmd.Flags().StringSliceVar(&cloudNetworkPublicAddCmdPoolIpsFlag, "pool-ips", []string{},
10165
"ips from your IP Pool separated by ',' to assign to the Cloud Server")

cmd/cloudNetworkPublicRemove.go

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ import (
2020

2121
"github.com/spf13/cobra"
2222

23-
"github.com/liquidweb/liquidweb-cli/types/api"
24-
"github.com/liquidweb/liquidweb-cli/validate"
23+
"github.com/liquidweb/liquidweb-cli/instance"
2524
)
2625

2726
var cloudNetworkPublicRemoveCmdIpsFlag []string
@@ -31,57 +30,36 @@ var cloudNetworkPublicRemoveCmd = &cobra.Command{
3130
Short: "Remove Public IP(s) from a Cloud Server",
3231
Long: `Remove Public IP(s) from a Cloud Server.
3332
34-
Remove specific Public IP(s) from a Cloud Server. If the reboot flag is passed in, the machine
35-
will be stopped, have the old IP addresses removed, and then started.
33+
Remove specific Public IP(s) from a Cloud Server. If the configure-ips flag is passed in,
34+
the IP addresses given will also be automatically removed from the guest operating system.
3635
37-
If the reboot flag is not passed, the IP will be unassigned, and you will no longer be able
38-
to route the IP. However the machine will not be shutdown to remove it from its network
39-
configuration. It will be up to the administrator to remove the IP from the servers network
40-
configuration.
36+
If the configure-ips flag is not passed, the IP will be unassigned, and you will no longer
37+
be able to route the IP. However the IP(s) will still be set in the guest operating system.
38+
In this scenario, it will be up to the system administrator to remove the IP(s) from the
39+
network configuration.
4140
4241
Note that you cannot remove the Cloud Servers primary ip with this command.`,
4342
Run: func(cmd *cobra.Command, args []string) {
44-
uniqIdFlag, _ := cmd.Flags().GetString("uniq-id")
45-
rebootFlag, _ := cmd.Flags().GetBool("reboot")
43+
params := &instance.CloudNetworkPublicRemoveParams{}
4644

47-
validateFields := map[interface{}]interface{}{
48-
uniqIdFlag: "UniqId",
49-
}
50-
if err := validate.Validate(validateFields); err != nil {
51-
lwCliInst.Die(err)
52-
}
45+
params.UniqId, _ = cmd.Flags().GetString("uniq-id")
46+
params.ConfigureIps, _ = cmd.Flags().GetBool("configure-ips")
47+
params.Ips = cloudNetworkPublicRemoveCmdIpsFlag
5348

54-
apiArgs := map[string]interface{}{
55-
"reboot": rebootFlag,
56-
"uniq_id": uniqIdFlag,
49+
status, err := lwCliInst.CloudNetworkPublicRemove(params)
50+
if err != nil {
51+
lwCliInst.Die(err)
5752
}
5853

59-
for _, ip := range cloudNetworkPublicRemoveCmdIpsFlag {
60-
validateFields := map[interface{}]interface{}{
61-
ip: "IP",
62-
}
63-
if err := validate.Validate(validateFields); err != nil {
64-
fmt.Printf("%s ... skipping\n", err)
65-
continue
66-
}
67-
68-
var details apiTypes.NetworkIpRemove
69-
apiArgs["ip"] = ip
70-
err := lwCliInst.CallLwApiInto("bleed/network/ip/remove", apiArgs, &details)
71-
if err != nil {
72-
lwCliInst.Die(err)
73-
}
74-
75-
fmt.Printf("Removing [%s] from Cloud Server\n", details.Removing)
76-
}
54+
fmt.Print(status)
7755
},
7856
}
7957

8058
func init() {
8159
cloudNetworkPublicCmd.AddCommand(cloudNetworkPublicRemoveCmd)
8260
cloudNetworkPublicRemoveCmd.Flags().String("uniq-id", "", "uniq-id of the Cloud Server")
83-
cloudNetworkPublicRemoveCmd.Flags().Bool("reboot", false,
84-
"whether or not to automatically remove the IP address(es) in the server config (requires reboot)")
61+
cloudNetworkPublicRemoveCmd.Flags().Bool("configure-ips", false,
62+
"whether or not to automatically remove the IP address(es) in the server config")
8563
cloudNetworkPublicRemoveCmd.Flags().StringSliceVar(&cloudNetworkPublicRemoveCmdIpsFlag, "ips", []string{},
8664
"ips separated by ',' to remove from the Cloud Server")
8765

cmd/cloudServerBlockStorageOptimized.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ purposely runs very tight. To work around this we can reduce the RAM allocated
3232
to the Cloud Server to give more to the hypervisor. We call this Cloud Block
3333
Storage Optimized.
3434
35-
Enabling or disabling Cloud Block Storage will cause your Cloud Server to reboot.
35+
Enabling or disabling Cloud Block Storage Optimized will cause your Cloud Server to reboot.
3636
3737
For a full list of capabilities, please refer to the "Available Commands" section.`,
3838

cmd/cloudServerBlockStorageOptimizedDisable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ purposely runs very tight. To work around this we can reduce the RAM allocated
3535
to the Cloud Server to give more to the hypervisor. We call this Cloud Block
3636
Storage Optimized.
3737
38-
Disabling Cloud Block Storage will cause your Cloud Server to reboot.`,
38+
Disabling Cloud Block Storage Optimized will cause your Cloud Server to reboot.`,
3939

4040
Run: func(cmd *cobra.Command, args []string) {
4141
uniqIdFlag, _ := cmd.Flags().GetString("uniq-id")

cmd/cloudServerBlockStorageOptimizedEnable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ purposely runs very tight. To work around this we can reduce the RAM allocated
3535
to the Cloud Server to give more to the hypervisor. We call this Cloud Block
3636
Storage Optimized.
3737
38-
Enabling Cloud Block Storage will cause your Cloud Server to reboot.`,
38+
Enabling Cloud Block Storage Optimized will cause your Cloud Server to reboot.`,
3939

4040
Run: func(cmd *cobra.Command, args []string) {
4141
uniqIdFlag, _ := cmd.Flags().GetString("uniq-id")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
cloud:
3+
network:
4+
private:
5+
attach:
6+
- uniq-id:
7+
- "{{- .Var.uniq_id -}}"
8+
- "{{- .Var.uniq_id2 -}}"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
cloud:
3+
network:
4+
private:
5+
detach:
6+
- uniq-id:
7+
- "{{- .Var.uniq_id -}}"
8+
- "{{- .Var.uniq_id2 -}}"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
cloud:
3+
network:
4+
public:
5+
add:
6+
- uniq-id: "{{- .Var.uniq_id -}}"
7+
configure-ips: true
8+
new-ips: 2
9+
- uniq-id: "{{- .Var.uniq_id -}}"
10+
configure-ips: true
11+
pool-ips:
12+
- "{{- .Var.poolip1 -}}"

0 commit comments

Comments
 (0)