forked from digitalocean/doctl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[droplets]: add support for droplet backup policy (digitalocean#1609)
* [droplets]: add support for droplet backup policy * add internal droplets package to parse a policy * fix tests, add a new test for droplet actions backup policy update * add droplet backup policies into droplet create * rename droplet-action command to change-backup-policy * fix tests after command renaming * add enable backups with policy to droplet actions * add tests for EnableBackupsWithPolicy * add enable-backups-with-policy to droplet-actions test * add get droplet backup policy * add list droplet backup policies for all existing droplets * add list supported droplet backup policies * use a flag to apply a backup policy when enabling backups rather than use a separate droplet action for that * add a wait flag for a droplet change backup policy * renaming to clarify instance we refer in a loop * reduce naming for get backup policy * fix integration tests making backup policy optional in droplet actions enable backups * group droplet backup-policies read commands under backup-policies sub command. * protect against panics on list for Droplets that do not have backups enabled * pass droplet backup policies with the flags instead of a config file * adding an empty backup policy to integration droplet action test * add a key to the test * add a check for a default backup policy when it's missing on backup enabling; revert changes in integration tests * add a comment and an integration test to enable droplet backups with backup policy * add an integration test for change_backup_policy in droplet_action * add an integration test for creating a droplet with backups enabled and backup policy applied * add template and format flags to droplet backup policies get; add integration tests for droplet backup policies get * rename integration tet file; add integration test for listing backup policies for all droplets * add integration tests for listing droplet supported droplet backup policies * avoid using default values, use api defaults in droplet actions * fix test: incorrect update in test * avoid using defaults; use api defaults in droplet create
- Loading branch information
Showing
17 changed files
with
1,101 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package displayers | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/digitalocean/doctl/do" | ||
) | ||
|
||
type DropletBackupPolicy struct { | ||
DropletBackupPolicies []do.DropletBackupPolicy | ||
} | ||
|
||
var _ Displayable = &DropletBackupPolicy{} | ||
|
||
func (d *DropletBackupPolicy) JSON(out io.Writer) error { | ||
return writeJSON(d.DropletBackupPolicies, out) | ||
} | ||
|
||
func (d *DropletBackupPolicy) Cols() []string { | ||
cols := []string{ | ||
"DropletID", "BackupEnabled", "BackupPolicyPlan", "BackupPolicyWeekday", "BackupPolicyHour", | ||
"BackupPolicyWindowLengthHours", "BackupPolicyRetentionPeriodDays", | ||
"NextBackupWindowStart", "NextBackupWindowEnd", | ||
} | ||
return cols | ||
} | ||
|
||
func (d *DropletBackupPolicy) ColMap() map[string]string { | ||
return map[string]string{ | ||
"DropletID": "Droplet ID", "BackupEnabled": "Enabled", | ||
"BackupPolicyPlan": "Plan", "BackupPolicyWeekday": "Weekday", "BackupPolicyHour": "Hour", | ||
"BackupPolicyWindowLengthHours": "Window Length Hours", "BackupPolicyRetentionPeriodDays": "Retention Period Days", | ||
"NextBackupWindowStart": "Next Window Start", "NextBackupWindowEnd": "Next Window End", | ||
} | ||
} | ||
|
||
func (d *DropletBackupPolicy) KV() []map[string]any { | ||
out := make([]map[string]any, 0) | ||
for _, policy := range d.DropletBackupPolicies { | ||
if policy.BackupPolicy != nil && policy.NextBackupWindow != nil { | ||
m := map[string]any{ | ||
"DropletID": policy.DropletID, "BackupEnabled": policy.BackupEnabled, | ||
"BackupPolicyPlan": policy.BackupPolicy.Plan, | ||
"BackupPolicyWeekday": policy.BackupPolicy.Weekday, "BackupPolicyHour": policy.BackupPolicy.Hour, | ||
"BackupPolicyWindowLengthHours": policy.BackupPolicy.WindowLengthHours, "BackupPolicyRetentionPeriodDays": policy.BackupPolicy.RetentionPeriodDays, | ||
"NextBackupWindowStart": policy.NextBackupWindow.Start, "NextBackupWindowEnd": policy.NextBackupWindow.End, | ||
} | ||
out = append(out, m) | ||
} | ||
} | ||
|
||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package displayers | ||
|
||
import ( | ||
"io" | ||
|
||
"github.com/digitalocean/doctl/do" | ||
) | ||
|
||
type DropletSupportedBackupPolicy struct { | ||
DropletSupportedBackupPolicies []do.DropletSupportedBackupPolicy | ||
} | ||
|
||
var _ Displayable = &DropletSupportedBackupPolicy{} | ||
|
||
func (d *DropletSupportedBackupPolicy) JSON(out io.Writer) error { | ||
return writeJSON(d.DropletSupportedBackupPolicies, out) | ||
} | ||
|
||
func (d *DropletSupportedBackupPolicy) Cols() []string { | ||
cols := []string{ | ||
"Name", "PossibleWindowStarts", "WindowLengthHours", "RetentionPeriodDays", "PossibleDays", | ||
} | ||
return cols | ||
} | ||
|
||
func (d *DropletSupportedBackupPolicy) ColMap() map[string]string { | ||
return map[string]string{ | ||
"Name": "Name", "PossibleWindowStarts": "Possible Window Starts", | ||
"WindowLengthHours": "Window Length Hours", "RetentionPeriodDays": "Retention Period Days", "PossibleDays": "Possible Days", | ||
} | ||
} | ||
|
||
func (d *DropletSupportedBackupPolicy) KV() []map[string]any { | ||
out := make([]map[string]any, 0) | ||
for _, supported := range d.DropletSupportedBackupPolicies { | ||
m := map[string]any{ | ||
"Name": supported.Name, "PossibleWindowStarts": supported.PossibleWindowStarts, "WindowLengthHours": supported.WindowLengthHours, | ||
"RetentionPeriodDays": supported.RetentionPeriodDays, "PossibleDays": supported.PossibleDays, | ||
} | ||
out = append(out, m) | ||
} | ||
|
||
return out | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.