Skip to content

Commit bb65079

Browse files
authored
Merge pull request #36 from liquidweb/cloud-backup-days-fixes
Cloud backup days fixes
2 parents 500a1e0 + aaeb464 commit bb65079

File tree

5 files changed

+92
-71
lines changed

5 files changed

+92
-71
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ Available Commands:
2626
cloud Interact with LiquidWeb's Cloud platform.
2727
help Help about any command
2828
network network actions
29+
plan Process YAML plan file
2930
version show build information
3031
3132
Flags:
32-
--config string config file (default is $HOME/.liquidweb-cli.yaml)
33-
-h, --help help for lw
33+
--config string config file (default is $HOME/.liquidweb-cli.yaml)
34+
-h, --help help for lw
35+
--use-context string forces current context, without persisting the context change
3436
3537
Use "lw [command] --help" for more information about a command.
3638
```
@@ -83,7 +85,6 @@ cloud:
8385
ips: 1
8486
public-ssh-key: "your public ssh key here
8587
config-id: 88
86-
backup-plan: "None"
8788
bandwidth: "SS.5000"
8889
```
8990

cmd/cloudServerCreate.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ For a list of backups, see 'cloud backups list'
6464
params.Ips, _ = cmd.Flags().GetInt("ips")
6565
pubSshKey, _ := cmd.Flags().GetString("public-ssh-key")
6666
params.ConfigId, _ = cmd.Flags().GetInt("config-id")
67-
params.BackupPlan, _ = cmd.Flags().GetString("backup-plan")
68-
params.BackupPlanQuota, _ = cmd.Flags().GetInt("backup-plan-quota")
67+
params.BackupDays, _ = cmd.Flags().GetInt("backup-days")
68+
params.BackupQuota, _ = cmd.Flags().GetInt("backup-quota")
6969
params.Bandwidth, _ = cmd.Flags().GetString("bandwidth")
7070
params.Zone, _ = cmd.Flags().GetInt("zone")
7171
params.WinAv, _ = cmd.Flags().GetString("winav")
@@ -110,14 +110,14 @@ func init() {
110110
cloudServerCreateCmd.Flags().String("public-ssh-key", sshPubKeyFile,
111111
"path to file containing the public ssh key you wish to be on the new Cloud Server")
112112
cloudServerCreateCmd.Flags().Int("config-id", 0, "config-id to use")
113-
cloudServerCreateCmd.Flags().String("backup-plan", "None", "Cloud Server backup plan to use")
114-
cloudServerCreateCmd.Flags().Int("backup-plan-quota", 300, "Quota amount. Should only be used with '--backup-plan Quota'")
113+
cloudServerCreateCmd.Flags().Int("backup-days", -1, "Enable daily backup plan. This is the amount of days to keep a backup")
114+
cloudServerCreateCmd.Flags().Int("backup-quota", -1, "Enable quota backup plan. This is the total amount of GB to keep.")
115115
cloudServerCreateCmd.Flags().String("bandwidth", "SS.10000", "bandwidth package to use")
116116
cloudServerCreateCmd.Flags().Int("zone", 0, "zone (id) to create new Cloud Server in (see 'cloud server options --zones')")
117117
cloudServerCreateCmd.Flags().String("password", "", "root or administrator password to set")
118118

119-
cloudServerCreateCmd.Flags().Int("backup-id", -1, "id of backup to create from (see 'cloud backup list')")
120-
cloudServerCreateCmd.Flags().Int("image-id", -1, "id of image to create from (see 'cloud image list')")
119+
cloudServerCreateCmd.Flags().Int("backup-id", -1, "id of cloud backup to create from (see 'cloud backup list')")
120+
cloudServerCreateCmd.Flags().Int("image-id", -1, "id of cloud image to create from (see 'cloud image list')")
121121

122122
cloudServerCreateCmd.Flags().StringSliceVar(&cloudServerCreateCmdPoolIpsFlag, "pool-ips", []string{},
123123
"ips from your IP Pool separated by ',' to assign to the new Cloud Server")

cmd/cloudServerUpdate.go

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,19 @@ Update details about your server, including the backup and bandwidth plans, and
3434
on the server. It merely updates what our records show.
3535
3636
bandwidth_plan is the bandwidth plan you wish to use. A quota of 0 indicates that you want
37-
as-you-go, usage-based bandwidth charges.`,
37+
as-you-go, usage-based bandwidth charges.
38+
39+
A quota backup plan allows you to save daily backups up to your set quota.
40+
A daily backup plan will save backups of a server up to your set days.
41+
42+
Either backup plan has a maximum retention of 90 days.
43+
`,
3844
Run: func(cmd *cobra.Command, args []string) {
3945
uniqIdFlag, _ := cmd.Flags().GetString("uniq-id")
4046
hostnameFlag, _ := cmd.Flags().GetString("hostname")
41-
backupPlanFlag, _ := cmd.Flags().GetString("backup-plan")
4247
disableBackupsFlag, _ := cmd.Flags().GetBool("disable-backups")
4348
bandwidthQuotaFlag, _ := cmd.Flags().GetInt64("bandwidth-quota")
49+
backupDaysFlag, _ := cmd.Flags().GetInt64("backup-days")
4450
backupQuotaFlag, _ := cmd.Flags().GetInt64("backup-quota")
4551

4652
validateFields := map[interface{}]interface{}{
@@ -50,19 +56,19 @@ as-you-go, usage-based bandwidth charges.`,
5056
lwCliInst.Die(err)
5157
}
5258

53-
if backupPlanFlag == "Quota" {
54-
if backupQuotaFlag == -1 {
55-
lwCliInst.Die(fmt.Errorf("cannot enable Quota backups without --backup-quota"))
56-
}
59+
if backupDaysFlag != -1 && backupQuotaFlag != -1 {
60+
lwCliInst.Die(fmt.Errorf("--backup-days and --backup-quota are conflicting flags"))
5761
}
5862

59-
if backupPlanFlag == "" && !disableBackupsFlag && hostnameFlag == "" &&
60-
bandwidthQuotaFlag == -1 {
63+
if backupDaysFlag == -1 && backupQuotaFlag == -1 && !disableBackupsFlag &&
64+
hostnameFlag == "" && bandwidthQuotaFlag == -1 {
6165
lwCliInst.Die(fmt.Errorf(
62-
"must pass one of: enable-backups disable-backups hostname bandwidth-quota"))
66+
"must pass a valid flag; check 'help cloud server update' for usage"))
6367
}
64-
if backupPlanFlag != "" && disableBackupsFlag {
65-
lwCliInst.Die(fmt.Errorf("cant both enable and disable backups"))
68+
if disableBackupsFlag {
69+
if backupDaysFlag != -1 || backupQuotaFlag != -1 {
70+
lwCliInst.Die(fmt.Errorf("cant both enable and disable backups"))
71+
}
6672
}
6773

6874
apiArgs := map[string]interface{}{
@@ -76,14 +82,13 @@ as-you-go, usage-based bandwidth charges.`,
7682
apiArgs["bandwidth_quota"] = bandwidthQuotaFlag
7783
}
7884

79-
if backupPlanFlag != "" {
80-
apiArgs["backup_plan"] = backupPlanFlag
81-
if backupPlanFlag == "Quota" {
82-
apiArgs["backup_quota"] = backupQuotaFlag
83-
}
84-
}
85-
86-
if disableBackupsFlag {
85+
if backupDaysFlag != -1 {
86+
apiArgs["backup_plan"] = "daily"
87+
apiArgs["backup_quota"] = backupDaysFlag
88+
} else if backupQuotaFlag != -1 {
89+
apiArgs["backup_plan"] = "quota"
90+
apiArgs["backup_quota"] = backupQuotaFlag
91+
} else if disableBackupsFlag {
8792
apiArgs["backup_plan"] = "None"
8893
}
8994

@@ -100,9 +105,9 @@ func init() {
100105
cloudServerCmd.AddCommand(cloudServerUpdateCmd)
101106

102107
cloudServerUpdateCmd.Flags().String("uniq-id", "", "uniq-id of the Cloud Server")
103-
cloudServerUpdateCmd.Flags().String("hostname", "", "hostname to set")
104-
cloudServerUpdateCmd.Flags().String("backup-plan", "", "Name of the backup plan")
105-
cloudServerUpdateCmd.Flags().Int64("backup-quota", -1, "Quota to set for Quota type backup-plan")
108+
cloudServerUpdateCmd.Flags().String("hostname", "", "hostname to set (will only update record at LiquidWeb)")
109+
cloudServerUpdateCmd.Flags().Int64("backup-days", -1, "Enable daily backup plan. This is the amount of days to keep a backup")
110+
cloudServerUpdateCmd.Flags().Int64("backup-quota", -1, "Enable quota backup plan. This is the total amount of GB to keep.")
106111
cloudServerUpdateCmd.Flags().Bool("disable-backups", false, "disable backups")
107112
cloudServerUpdateCmd.Flags().Int64("bandwidth-quota", -1,
108113
"bandwidth quota (0 indicates as-you-go, usage-based bandwidth charges)")

instance/cloudServerCreate.go

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,42 @@ import (
2727
)
2828

2929
type 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

5252
func (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,8 +269,13 @@ 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 != "" {

plan.yaml.example

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ cloud:
1010
ips: 1
1111
public-ssh-key: ""
1212
config-id: 88
13-
backup-plan: "daily"
14-
backup-plan-quota: 5
13+
backup-days: 5
1514
bandwidth: "SS.5000"
1615
backup-id: -1
1716
image-id: -1

0 commit comments

Comments
 (0)