@@ -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
2726var 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
9458func 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" )
0 commit comments