Skip to content

Commit c5c32f9

Browse files
committed
add IPv6 to cloud server create,clone
1 parent a42afc8 commit c5c32f9

File tree

5 files changed

+73
-29
lines changed

5 files changed

+73
-29
lines changed

cmd/cloudNetworkPublicAdd.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
)
2525

2626
var cloudNetworkPublicAddCmdPoolIpsFlag []string
27+
var cloudNetworkPublicAddCmdPool6IpsFlag []string
2728

2829
var cloudNetworkPublicAddCmd = &cobra.Command{
2930
Use: "add",
@@ -41,17 +42,17 @@ administrator to add the IP(s) to the network configuration.
4142
4243
IPv6 Notes:
4344
44-
Only /64s will be given out, and new-ips refers to how many /64's to assign.
45-
There is a limit of one /64 per Cloud Server. If you need more than this, you
46-
can contact support.`,
45+
Only /64s will be given out. There is a limit of one /64 per Cloud Server. If
46+
you need more than this, you can contact support.`,
4747
Run: func(cmd *cobra.Command, args []string) {
4848
params := &instance.CloudNetworkPublicAddParams{}
4949

5050
params.UniqId, _ = cmd.Flags().GetString("uniq-id")
5151
params.ConfigureIps, _ = cmd.Flags().GetBool("configure-ips")
5252
params.NewIps, _ = cmd.Flags().GetInt64("new-ips")
53+
params.NewIp6s, _ = cmd.Flags().GetInt64("new-ip6s")
5354
params.PoolIps = cloudNetworkPublicAddCmdPoolIpsFlag
54-
params.IpVersion, _ = cmd.Flags().GetInt("ip-version")
55+
params.Pool6Ips = cloudNetworkPublicAddCmdPool6IpsFlag
5556

5657
status, err := lwCliInst.CloudNetworkPublicAdd(params)
5758
if err != nil {
@@ -67,11 +68,12 @@ func init() {
6768
cloudNetworkPublicAddCmd.Flags().String("uniq-id", "", "uniq-id of the Cloud Server")
6869
cloudNetworkPublicAddCmd.Flags().Bool("configure-ips", false,
6970
"wheter or not to automatically configure the new IP address(es) in the server")
70-
cloudNetworkPublicAddCmd.Flags().Int64("new-ips", 0, "amount of new ips to (randomly) grab")
71+
cloudNetworkPublicAddCmd.Flags().Int64("new-ips", 0, "amount of new IPv4 ips to (randomly) grab")
72+
cloudNetworkPublicAddCmd.Flags().Int64("new-ip6s", 0, "amount of new IPv6 /64's to (randomly) grab")
7173
cloudNetworkPublicAddCmd.Flags().StringSliceVar(&cloudNetworkPublicAddCmdPoolIpsFlag, "pool-ips", []string{},
72-
"ips from your IP Pool separated by ',' to assign to the Cloud Server")
73-
74-
cloudNetworkPublicAddCmd.Flags().Int("ip-version", 4, "IP version 4 or 6")
74+
"IPv4 ips from your IP Pool separated by ',' to assign to the Cloud Server")
75+
cloudNetworkPublicAddCmd.Flags().StringSliceVar(&cloudNetworkPublicAddCmdPool6IpsFlag, "pool6-ips", []string{},
76+
"IPv6 assignments from your IP Pool separated by ',' to assign to the Cloud Server")
7577

7678
if err := cloudNetworkPublicAddCmd.MarkFlagRequired("uniq-id"); err != nil {
7779
lwCliInst.Die(err)

cmd/cloudServerClone.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
)
2727

2828
var cloudServerCloneCmdPoolIpsFlag []string
29+
var cloudServerCloneCmdPool6IpsFlag []string
2930

3031
var cloudServerCloneCmd = &cobra.Command{
3132
Use: "clone",
@@ -51,6 +52,7 @@ Server is not on a Private Parent.`,
5152
passwordFlag, _ := cmd.Flags().GetString("password")
5253
zoneFlag, _ := cmd.Flags().GetInt64("zone")
5354
newIpsFlag, _ := cmd.Flags().GetInt64("new-ips")
55+
newIp6sFlag, _ := cmd.Flags().GetInt64("new-ip6s")
5456
hostnameFlag, _ := cmd.Flags().GetString("hostname")
5557
privateParentFlag, _ := cmd.Flags().GetString("private-parent")
5658
diskspaceFlag, _ := cmd.Flags().GetInt64("diskspace")
@@ -88,9 +90,10 @@ Server is not on a Private Parent.`,
8890

8991
// buildout api bleed/server/clone parameters
9092
cloneArgs := map[string]interface{}{
91-
"uniq_id": uniqIdFlag,
92-
"domain": hostnameFlag,
93-
"new_ips": newIpsFlag,
93+
"uniq_id": uniqIdFlag,
94+
"domain": hostnameFlag,
95+
"new_ips": newIpsFlag,
96+
"new_ip6s": newIp6sFlag,
9497
}
9598
if passwordFlag != "" {
9699
cloneArgs["password"] = passwordFlag
@@ -124,6 +127,12 @@ Server is not on a Private Parent.`,
124127
validateFields[ip] = "IP"
125128
}
126129
}
130+
if len(cloudServerCloneCmdPool6IpsFlag) > 0 {
131+
cloneArgs["pool6_ips"] = cloudServerCloneCmdPool6IpsFlag
132+
for _, ip := range cloudServerCloneCmdPool6IpsFlag {
133+
validateFields[ip] = "IpOrCidr"
134+
}
135+
}
127136

128137
if err := validate.Validate(validateFields); err != nil {
129138
lwCliInst.Die(err)
@@ -148,11 +157,14 @@ func init() {
148157
cloudServerCloneCmd.Flags().String("uniq-id", "", "uniq-id of Cloud Server to clone")
149158
cloudServerCloneCmd.Flags().String("password", "", "root or administrator password for new Cloud Server")
150159
cloudServerCloneCmd.Flags().Int64("zone", -1, "zone for new Cloud Server")
151-
cloudServerCloneCmd.Flags().Int64("new-ips", 1, "amount of IP addresses for new Cloud Server")
160+
cloudServerCloneCmd.Flags().Int64("new-ips", 1, "amount of IPv4 addresses for the new Cloud Server")
161+
cloudServerCloneCmd.Flags().Int64("new-ip6s", 0, "amount of new IPv6 /64's for the new Cloud Server")
152162
cloudServerCloneCmd.Flags().String("hostname", fmt.Sprintf("%s.%s.io", utils.RandomString(4),
153163
utils.RandomString(10)), "hostname for new Cloud Server")
154164
cloudServerCloneCmd.Flags().StringSliceVar(&cloudServerCloneCmdPoolIpsFlag, "pool-ips", []string{},
155-
"ips from your IP Pool separated by ',' to assign to the new Cloud Server")
165+
"IPv4 ips from your IP Pool separated by ',' to assign to the new Cloud Server")
166+
cloudServerCloneCmd.Flags().StringSliceVar(&cloudServerCloneCmdPool6IpsFlag, "pool6-ips", []string{},
167+
"IPv6 ips from your IP Pool separated by ',' to assign to the new Cloud Server")
156168

157169
// Private Parent
158170
cloudServerCloneCmd.Flags().String("private-parent", "",

cmd/cloudServerCreate.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
)
2929

3030
var cloudServerCreateCmdPoolIpsFlag []string
31+
var cloudServerCreateCmdPool6IpsFlag []string
3132

3233
var cloudServerCreateCmd = &cobra.Command{
3334
Use: "create",
@@ -68,6 +69,7 @@ cloud:
6869
zone: 40460
6970
hostname: "db1.dev.addictmud.org"
7071
ips: 1
72+
ip6s: 1
7173
public-ssh-key: ""
7274
config-id: 88
7375
backup-days: 5
@@ -77,6 +79,8 @@ cloud:
7779
pool-ips:
7880
- "10.111.12.13"
7981
- "10.12.13.14"
82+
pool6-ips:
83+
- "2607:fad0:3714:350c::/64"
8084
private-parent: "my pp"
8185
memory: 0
8286
diskspace: 0
@@ -93,6 +97,7 @@ lw plan --file /tmp/cloud.server.create.yaml
9397
params.Type, _ = cmd.Flags().GetString("type")
9498
params.Hostname, _ = cmd.Flags().GetString("hostname")
9599
params.Ips, _ = cmd.Flags().GetInt("ips")
100+
params.Ip6s, _ = cmd.Flags().GetInt("ip6s")
96101
pubSshKey, _ := cmd.Flags().GetString("public-ssh-key")
97102
params.ConfigId, _ = cmd.Flags().GetInt("config-id")
98103
params.BackupDays, _ = cmd.Flags().GetInt("backup-days")
@@ -109,6 +114,7 @@ lw plan --file /tmp/cloud.server.create.yaml
109114
params.BackupId, _ = cmd.Flags().GetInt("backup-id")
110115
params.ImageId, _ = cmd.Flags().GetInt("image-id")
111116
params.PoolIps = cloudServerCreateCmdPoolIpsFlag
117+
params.Pool6Ips = cloudServerCreateCmdPool6IpsFlag
112118

113119
sshPkeyContents, err := ioutil.ReadFile(filepath.Clean(pubSshKey))
114120
if err == nil {
@@ -138,7 +144,8 @@ func init() {
138144
cloudServerCreateCmd.Flags().String("template", "", "template to use (see 'cloud server options --templates')")
139145
cloudServerCreateCmd.Flags().String("type", "SS.VPS", "some examples of types; SS.VPS, SS.VPS.WIN, SS.VM, SS.VM.WIN")
140146
cloudServerCreateCmd.Flags().String("hostname", "", "hostname to set")
141-
cloudServerCreateCmd.Flags().Int("ips", 1, "amount of IP addresses")
147+
cloudServerCreateCmd.Flags().Int("ips", 1, "amount of IPv4 addresses")
148+
cloudServerCreateCmd.Flags().Int("ip6s", 0, "amount of IPv6 /64s")
142149
cloudServerCreateCmd.Flags().String("public-ssh-key", sshPubKeyFile,
143150
"path to file containing the public ssh key you wish to be on the new Cloud Server")
144151
cloudServerCreateCmd.Flags().Int("config-id", 0, "config-id to use")
@@ -152,7 +159,10 @@ func init() {
152159
cloudServerCreateCmd.Flags().Int("image-id", -1, "id of cloud image to create from (see 'cloud image list')")
153160

154161
cloudServerCreateCmd.Flags().StringSliceVar(&cloudServerCreateCmdPoolIpsFlag, "pool-ips", []string{},
155-
"ips from your IP Pool separated by ',' to assign to the new Cloud Server")
162+
"IPv4 ips from your IP Pool separated by ',' to assign to the new Cloud Server")
163+
164+
cloudServerCreateCmd.Flags().StringSliceVar(&cloudServerCreateCmdPool6IpsFlag, "pool6-ips", []string{},
165+
"IPv6 assignments from your IP Pool separated by ',' to assign to the new Cloud Server")
156166

157167
// private parent specific
158168
cloudServerCreateCmd.Flags().String("private-parent", "",

instance/cloudNetworkPublicAdd.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ type CloudNetworkPublicAddParams struct {
2727
UniqId string `yaml:"uniq-id"`
2828
ConfigureIps bool `yaml:"configure-ips"`
2929
NewIps int64 `yaml:"new-ips"`
30+
NewIp6s int64 `yaml:"new-ip6s"`
3031
PoolIps []string `yaml:"pool-ips"`
31-
IpVersion int `yaml:"ip-version"`
32+
Pool6Ips []string `yaml:"pool6-ips"`
3233
}
3334

3435
func (self *CloudNetworkPublicAddParams) UnmarshalYAML(unmarshal func(interface{}) error) error {
@@ -51,20 +52,14 @@ func (self *Client) CloudNetworkPublicAdd(params *CloudNetworkPublicAddParams) (
5152
return
5253
}
5354

54-
if params.NewIps == 0 && len(params.PoolIps) == 0 {
55-
err = fmt.Errorf("at least one of --new-ips --pool-ips must be given")
56-
return
57-
}
58-
59-
if params.IpVersion != 4 && params.IpVersion != 6 {
60-
err = fmt.Errorf("ip-version may only be 4 or 6")
55+
if params.NewIps == 0 && len(params.PoolIps) == 0 && params.NewIp6s == 0 && len(params.Pool6Ips) == 0 {
56+
err = fmt.Errorf("at least one of --new-ips --pool-ips --new-ip6s --pool6-ips must be given")
6157
return
6258
}
6359

6460
apiArgs := map[string]interface{}{
6561
"configure_ips": params.ConfigureIps,
6662
"uniq_id": params.UniqId,
67-
"ip_version": params.IpVersion,
6863
}
6964
if params.NewIps != 0 {
7065
apiArgs["ip_count"] = params.NewIps
@@ -77,6 +72,24 @@ func (self *Client) CloudNetworkPublicAdd(params *CloudNetworkPublicAddParams) (
7772
apiArgs["pool_ips"] = params.PoolIps
7873
validateFields := map[interface{}]interface{}{}
7974
for _, ip := range params.PoolIps {
75+
validateFields[ip] = "IP"
76+
}
77+
if err = validate.Validate(validateFields); err != nil {
78+
return
79+
}
80+
}
81+
82+
if params.NewIp6s != 0 {
83+
apiArgs["ip6_count"] = params.NewIp6s
84+
validateFields := map[interface{}]interface{}{params.NewIps: "PositiveInt64"}
85+
if err = validate.Validate(validateFields); err != nil {
86+
return
87+
}
88+
}
89+
if len(params.Pool6Ips) != 0 {
90+
apiArgs["pool6_ips"] = params.Pool6Ips
91+
validateFields := map[interface{}]interface{}{}
92+
for _, ip := range params.Pool6Ips {
8093
validateFields[ip] = "IpOrCidr"
8194
}
8295
if err = validate.Validate(validateFields); err != nil {

instance/cloudServerCreate.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ type CloudServerCreateParams struct {
3131
Type string `yaml:"type"`
3232
Hostname string `yaml:"hostname"`
3333
Ips int `yaml:"ips"`
34+
Ip6s int `yaml:"ip6s"`
3435
PoolIps []string `yaml:"pool-ips"`
36+
Pool6Ips []string `yaml:"pool6-ips"`
3537
PublicSshKey string `yaml:"public-ssh-key"`
3638
ConfigId int `yaml:"config-id"`
3739
BackupDays int `yaml:"backup-days"` // daily backup plan; how many days to keep a backup
@@ -169,11 +171,12 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) (string, er
169171

170172
// buildout args for bleed/server/create
171173
createArgs := map[string]interface{}{
172-
"domain": params.Hostname,
173-
"pool_ips": params.PoolIps,
174-
"new_ips": params.Ips,
175-
"zone": params.Zone,
176-
"password": params.Password,
174+
"domain": params.Hostname,
175+
"pool_ips": params.PoolIps,
176+
"pool6_ips": params.Pool6Ips,
177+
"new_ips": params.Ips,
178+
"zone": params.Zone,
179+
"password": params.Password,
177180
"features": map[string]interface{}{
178181
"Bandwidth": params.Bandwidth,
179182
"ConfigId": params.ConfigId,
@@ -185,6 +188,10 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) (string, er
185188
},
186189
}
187190

191+
if params.Ip6s > 0 {
192+
createArgs["new_ip6s"] = params.Ip6s
193+
}
194+
188195
var isWindows bool
189196
if params.Template != "" {
190197
createArgs["features"].(map[string]interface{})["Template"] = params.Template

0 commit comments

Comments
 (0)