@@ -27,41 +27,42 @@ import (
2727)
2828
2929type CloudServerCreateParams struct {
30- Template string `yaml:"template"`
31- Type string `yaml:"type"`
32- Hostname string `yaml:"hostname"`
33- Ips int `yaml:"ips"`
34- PoolIps []string `yaml:"pool-ips"`
35- PublicSshKey string `yaml:"public-ssh-key"`
36- ConfigId int `yaml:"config-id"`
37- BackupPlan string `yaml:"backup-plan"`
38- BackupPlanQuota int `yaml:"backup-plan- quota"`
39- Bandwidth string `yaml:"bandwidth"`
40- Zone int `yaml:"zone"`
41- WinAv string `yaml:"winav"` // windows
42- MsSql string `yaml:"ms-sql"` // windows
43- PrivateParent string `yaml:"private-parent"`
44- Password string `yaml:"password"`
45- Memory int `yaml:"memory"` // required only if private parent
46- Diskspace int `yaml:"diskspace"` // required only if private parent
47- Vcpu int `yaml:"vcpu"` // required only if private parent
48- BackupId int `yaml:"backup-id"` //create from backup
49- ImageId int `yaml:"image-id"` // create from image
30+ Template string `yaml:"template"`
31+ Type string `yaml:"type"`
32+ Hostname string `yaml:"hostname"`
33+ Ips int `yaml:"ips"`
34+ PoolIps []string `yaml:"pool-ips"`
35+ PublicSshKey string `yaml:"public-ssh-key"`
36+ ConfigId int `yaml:"config-id"`
37+ BackupDays int `yaml:"backup-days"` // daily backup plan; how many days to keep a backup
38+ BackupQuota int `yaml:"backup-quota"` // backup quota plan; how many gb of backups to keep
39+ Bandwidth string `yaml:"bandwidth"`
40+ Zone int `yaml:"zone"`
41+ WinAv string `yaml:"winav"` // windows
42+ MsSql string `yaml:"ms-sql"` // windows
43+ PrivateParent string `yaml:"private-parent"`
44+ Password string `yaml:"password"`
45+ Memory int `yaml:"memory"` // required only if private parent
46+ Diskspace int `yaml:"diskspace"` // required only if private parent
47+ Vcpu int `yaml:"vcpu"` // required only if private parent
48+ BackupId int `yaml:"backup-id"` //create from backup
49+ ImageId int `yaml:"image-id"` // create from image
5050}
5151
5252func (s * CloudServerCreateParams ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
5353 // define defaults
5454 type rawType CloudServerCreateParams
5555 raw := rawType {
56- BackupId : - 1 ,
57- ImageId : - 1 ,
58- Vcpu : - 1 ,
59- Memory : - 1 ,
60- Diskspace : - 1 ,
61- Bandwidth : "SS.5000" ,
62- BackupPlan : "None" ,
63- Ips : 1 ,
64- Type : "SS.VPS" ,
56+ BackupId : - 1 ,
57+ BackupDays : - 1 ,
58+ BackupQuota : - 1 ,
59+ ImageId : - 1 ,
60+ Vcpu : - 1 ,
61+ Memory : - 1 ,
62+ Diskspace : - 1 ,
63+ Bandwidth : "SS.5000" ,
64+ Ips : 1 ,
65+ Type : "SS.VPS" ,
6566 } // Put your defaults here
6667 if err := unmarshal (& raw ); err != nil {
6768 return err
@@ -126,13 +127,16 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) (string, er
126127 return "" , fmt .Errorf ("at least one of the following flags must be set --template --image-id --backup-id" )
127128 }
128129
130+ if params .BackupDays != - 1 && params .BackupQuota != - 1 {
131+ return "" , fmt .Errorf ("flags --backup-days and --backup-quota conflict" )
132+ }
133+
129134 validateFields := map [interface {}]interface {}{
130- params .Zone : map [string ]string {"type" : "PositiveInt" , "optional" : "true" },
131- params .Hostname : "NonEmptyString" ,
132- params .Type : "NonEmptyString" ,
133- params .Ips : "PositiveInt" ,
134- params .Password : "NonEmptyString" ,
135- params .BackupPlan : "NonEmptyString" ,
135+ params .Zone : map [string ]string {"type" : "PositiveInt" , "optional" : "true" },
136+ params .Hostname : "NonEmptyString" ,
137+ params .Type : "NonEmptyString" ,
138+ params .Ips : "PositiveInt" ,
139+ params .Password : "NonEmptyString" ,
136140 }
137141 if params .BackupId != - 1 {
138142 validateFields [params .BackupId ] = "PositiveInt"
@@ -152,6 +156,13 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) (string, er
152156 return "" , err
153157 }
154158
159+ cloudBackupPlan := "None"
160+ if params .BackupDays != - 1 {
161+ cloudBackupPlan = "Daily"
162+ } else if params .BackupQuota != - 1 {
163+ cloudBackupPlan = "Quota"
164+ }
165+
155166 // buildout args for bleed/server/create
156167 createArgs := map [string ]interface {}{
157168 "domain" : params .Hostname ,
@@ -166,7 +177,7 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) (string, er
166177 "value" : params .Ips ,
167178 "count" : 0 ,
168179 },
169- "LiquidWebBackupPlan" : params . BackupPlan ,
180+ "LiquidWebBackupPlan" : cloudBackupPlan ,
170181 },
171182 }
172183
@@ -258,14 +269,22 @@ func (ci *Client) CloudServerCreate(params *CloudServerCreateParams) (string, er
258269 createArgs ["memory" ] = params .Memory
259270 }
260271
261- if params .BackupPlan == "Quota" {
262- createArgs ["features" ].(map [string ]interface {})["BackupQuota" ] = params .BackupPlanQuota
272+ if cloudBackupPlan == "Quota" {
273+ createArgs ["features" ].(map [string ]interface {})["BackupQuota" ] = params .BackupQuota
274+ } else if cloudBackupPlan == "Daily" {
275+ createArgs ["features" ].(map [string ]interface {})["BackupDay" ] = map [string ]int {
276+ "value" : 1 ,
277+ "num_units" : params .BackupDays ,
278+ }
263279 }
264280
265281 if params .PublicSshKey != "" {
266282 createArgs ["public_ssh_key" ] = params .PublicSshKey
267283 }
268284
285+ //pretty, _ := ci.JsonEncodeAndPrettyPrint(createArgs)
286+ //fmt.Println(pretty)
287+
269288 result , err := ci .LwCliApiClient .Call ("bleed/server/create" , createArgs )
270289 if err != nil {
271290 return "" , err
0 commit comments