-
Notifications
You must be signed in to change notification settings - Fork 20
/
db_service_create.go
86 lines (66 loc) · 2.58 KB
/
db_service_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package cmd
import (
"fmt"
"strings"
exov2 "github.com/exoscale/egoscale/v2"
exoapi "github.com/exoscale/egoscale/v2/api"
"github.com/spf13/cobra"
)
type dbServiceCreateCmd struct {
_ bool `cli-cmd:"create"`
Type string `cli-arg:"#"`
Plan string `cli-arg:"#"`
Name string `cli-arg:"#"`
MaintenanceDOW string `cli-flag:"maintenance-dow" cli-usage:"automated Database Service maintenance day-of-week"`
MaintenanceTime string `cli-usage:"automated Database Service maintenance time (format HH:MM)"`
TerminationProtection bool `cli-usage:"enable Database Service termination protection"`
UserConfigFile string `cli-flag:"user-config" cli-short:"c" cli-usage:"path to JSON user config file"`
Zone string `cli-short:"z" cli-usage:"Database Service zone"`
}
func (c *dbServiceCreateCmd) cmdAliases() []string { return gCreateAlias }
func (c *dbServiceCreateCmd) cmdShort() string { return "Create a Database Service" }
func (c *dbServiceCreateCmd) cmdLong() string {
return fmt.Sprintf(`This command creates a Database Service.
Supported values for --maintenance-dow: %s
Supported output template annotations: %s`,
strings.Join(dbServiceMaintenanceDOWs, ", "),
strings.Join(outputterTemplateAnnotations(&dbServiceShowOutput{}), ", "))
}
func (c *dbServiceCreateCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
cmdSetZoneFlagFromDefault(cmd)
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *dbServiceCreateCmd) cmdRun(_ *cobra.Command, _ []string) error {
var err error
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(gCurrentAccount.Environment, c.Zone))
databaseService := &exov2.DatabaseService{
Name: &c.Name,
Plan: &c.Plan,
TerminationProtection: &c.TerminationProtection,
Type: &c.Type,
}
if c.MaintenanceDOW != "" && c.MaintenanceTime != "" {
databaseService.Maintenance = &exov2.DatabaseServiceMaintenance{
DOW: c.MaintenanceDOW,
Time: c.MaintenanceTime,
}
}
if c.UserConfigFile != "" {
if databaseService.UserConfig, err = getDatabaseServiceUserConfigFromFile(c.UserConfigFile); err != nil {
return fmt.Errorf("error parsing user config: %s", err)
}
}
decorateAsyncOperation(fmt.Sprintf("Creating Database Service %q...", *databaseService.Name), func() {
databaseService, err = cs.CreateDatabaseService(ctx, c.Zone, databaseService)
})
if err != nil {
return err
}
if !gQuiet {
return output(showDatabaseService(c.Zone, *databaseService.Name))
}
return nil
}
func init() {
cobra.CheckErr(registerCLICommand(dbCmd, &dbServiceCreateCmd{}))
}