-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Nico Schieder
committed
Jan 12, 2018
1 parent
d8f84fa
commit 2375dd5
Showing
4 changed files
with
99 additions
and
3 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,41 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newServerDisableBackupCommand(cli *CLI) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "disable-backup [FLAGS] SERVER", | ||
Short: "Disable backups of a server", | ||
Args: cobra.ExactArgs(1), | ||
TraverseChildren: true, | ||
DisableFlagsInUseLine: true, | ||
RunE: cli.wrap(runServerDisableBackup), | ||
} | ||
return cmd | ||
} | ||
|
||
func runServerDisableBackup(cli *CLI, cmd *cobra.Command, args []string) error { | ||
idOrName := args[0] | ||
server, _, err := cli.Client().Server.Get(cli.Context, idOrName) | ||
if err != nil { | ||
return err | ||
} | ||
if server == nil { | ||
return fmt.Errorf("server not found: %s", idOrName) | ||
} | ||
|
||
action, _, err := cli.Client().Server.DisableBackup(cli.Context, server) | ||
if err != nil { | ||
return err | ||
} | ||
errCh, _ := waitAction(cli.Context, cli.Client(), action) | ||
if err := <-errCh; err != nil { | ||
return err | ||
} | ||
fmt.Printf("Backups of server %s disabled\n", idOrName) | ||
return nil | ||
} |
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,48 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newServerEnableBackupCommand(cli *CLI) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "enable-backup [FLAGS] SERVER", | ||
Short: "Enable backups for a server", | ||
Args: cobra.ExactArgs(1), | ||
TraverseChildren: true, | ||
DisableFlagsInUseLine: true, | ||
RunE: cli.wrap(runServerEnableBackup), | ||
} | ||
cmd.Flags().String( | ||
"window", "", | ||
"The time window for the daily backup to run. All times are in UTC. 22-02 means that the backup will be started between 10 PM and 2 AM.") | ||
cmd.Flag("window").Annotations = map[string][]string{ | ||
cobra.BashCompCustom: {"__hcloud_backup_windows"}, | ||
} | ||
return cmd | ||
} | ||
|
||
func runServerEnableBackup(cli *CLI, cmd *cobra.Command, args []string) error { | ||
idOrName := args[0] | ||
server, _, err := cli.Client().Server.Get(cli.Context, idOrName) | ||
if err != nil { | ||
return err | ||
} | ||
if server == nil { | ||
return fmt.Errorf("server not found: %s", idOrName) | ||
} | ||
|
||
window, _ := cmd.Flags().GetString("window") | ||
action, _, err := cli.Client().Server.EnableBackup(cli.Context, server, window) | ||
if err != nil { | ||
return err | ||
} | ||
errCh, _ := waitAction(cli.Context, cli.Client(), action) | ||
if err := <-errCh; err != nil { | ||
return err | ||
} | ||
fmt.Printf("Backups of server %s enabled\n", idOrName) | ||
return nil | ||
} |