Skip to content

Commit 2d5c595

Browse files
authored
Merge pull request #19 from ovh/dev/aamstutz/add-cloud-db
feat: Add several commands for cloud databases
2 parents 5eacd93 + 0ef6d91 commit 2d5c595

19 files changed

Lines changed: 793 additions & 7 deletions

doc/ovhcloud_cloud_database.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Manage databases in the given cloud project
2323
### SEE ALSO
2424

2525
* [ovhcloud cloud](ovhcloud_cloud.md) - Manage your projects and services in the Public Cloud universe
26+
* [ovhcloud cloud database create](ovhcloud_cloud_database_create.md) - Create a new database
27+
* [ovhcloud cloud database delete](ovhcloud_cloud_database_delete.md) - Delete a specific database
2628
* [ovhcloud cloud database get](ovhcloud_cloud_database_get.md) - Get a specific database
2729
* [ovhcloud cloud database list](ovhcloud_cloud_database_list.md) - List your databases
2830

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
## ovhcloud cloud database create
2+
3+
Create a new database
4+
5+
### Synopsis
6+
7+
Use this command to create a database in the given public cloud project.
8+
There are two ways to define the creation parameters:
9+
10+
1. Using only CLI flags:
11+
12+
ovhcloud cloud database create --engine mysql --version 8 --plan essential --nodes-list "db1-4:DE"
13+
14+
2. Using your default text editor:
15+
16+
ovhcloud cloud database create --engine kafka --editor
17+
18+
You will be able to choose from several examples of parameters. Once an example has been selected, the CLI will open your
19+
default text editor to update the parameters. When saving the file, the creation will start.
20+
21+
Note that it is also possible to override values in the presented examples using command line flags like the following:
22+
23+
ovhcloud cloud database create --engine mysql --editor --version 8
24+
25+
26+
```
27+
ovhcloud cloud database create [flags]
28+
```
29+
30+
### Options
31+
32+
```
33+
--backups-regions strings Regions on which the backups are stored
34+
--backups-time string Time on which backups start every day
35+
--description string Database description
36+
--disk-size int Disk size (GB)
37+
--editor Use a text editor to define parameters
38+
--engine string Database engine (you can get the list of available engines using 'ovhcloud cloud reference database list-engines')
39+
--fork-from.backup-id string Backup ID (not compatible with fork-from.point-in-time)
40+
--fork-from.point-in-time string Point in time to restore from (not compatible with fork-from.backup-id)
41+
--fork-from.service-id string Service ID that owns the backups
42+
-h, --help help for create
43+
--ip-restrictions strings IP blocks authorized to access the cluster (CIDR format)
44+
--maintenance-time string Time on which maintenances can start every day
45+
--network-id string Private network ID in which the cluster is deployed
46+
--nodes-list strings List of nodes (format: flavor1:region1,flavor2:region2...)
47+
--nodes-pattern.flavor string Flavor of all nodes
48+
--nodes-pattern.number int Number of nodes
49+
--nodes-pattern.region string Region of all nodes
50+
--plan string Database plan (you can get the list of available plans using 'ovhcloud cloud reference database list-plans')
51+
--subnet-id string Private subnet ID in which the cluster is deployed
52+
--version string Database version (you can get the list of available versions using 'ovhcloud cloud reference database list-engines')
53+
```
54+
55+
### Options inherited from parent commands
56+
57+
```
58+
--cloud-project string Cloud project ID
59+
-d, --debug Activate debug mode (will log all HTTP requests details)
60+
-f, --format string Output value according to given format (expression using gval format)
61+
-e, --ignore-errors Ignore errors in API calls when it is not fatal to the execution
62+
-i, --interactive Interactive output
63+
-j, --json Output in JSON
64+
-y, --yaml Output in YAML
65+
```
66+
67+
### SEE ALSO
68+
69+
* [ovhcloud cloud database](ovhcloud_cloud_database.md) - Manage databases in the given cloud project
70+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## ovhcloud cloud database delete
2+
3+
Delete a specific database
4+
5+
```
6+
ovhcloud cloud database delete <database_id> [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
-h, --help help for delete
13+
```
14+
15+
### Options inherited from parent commands
16+
17+
```
18+
--cloud-project string Cloud project ID
19+
-d, --debug Activate debug mode (will log all HTTP requests details)
20+
-f, --format string Output value according to given format (expression using gval format)
21+
-e, --ignore-errors Ignore errors in API calls when it is not fatal to the execution
22+
-i, --interactive Interactive output
23+
-j, --json Output in JSON
24+
-y, --yaml Output in YAML
25+
```
26+
27+
### SEE ALSO
28+
29+
* [ovhcloud cloud database](ovhcloud_cloud_database.md) - Manage databases in the given cloud project
30+

doc/ovhcloud_cloud_instance_create.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ There are three ways to define the creation parameters:
99

1010
1. Using only CLI flags:
1111

12-
ovhcloud cloud instance create GRA9 --name MyNewInstance --boot-from.image <image_id> --flavor <flavor_id> ...
12+
ovhcloud cloud instance create GRA9 --name MyNewInstance --boot-from.image <image_id> --flavor <flavor_id>
1313

1414
2. Using a configuration file:
1515

@@ -61,11 +61,11 @@ ovhcloud cloud instance create <region (e.g. GRA, BHS, SBG)> [flags]
6161
--backup-cron string Autobackup Unix Cron pattern (eg: '0 0 * * *')
6262
--backup-rotation int Number of backups to keep
6363
--billing-period string Billing period (hourly, monthly), default is hourly (default "hourly")
64-
--boot-from.image string Image ID to boot from
64+
--boot-from.image string Image ID to boot from (you can use 'ovhcloud cloud reference list-images' to get the image ID)
6565
--boot-from.volume string Volume ID to boot from
6666
--bulk int Number of instances to create
6767
--editor Use a text editor to define parameters
68-
--flavor string Flavor ID
68+
--flavor string Flavor ID (you can use 'ovhcloud cloud reference list-flavors' to get the flavor ID)
6969
--flavor-selector Use the interactive flavor selector
7070
--from-file string File containing parameters
7171
--group string Group ID

doc/ovhcloud_cloud_reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Fetch reference data in the given cloud project
2424

2525
* [ovhcloud cloud](ovhcloud_cloud.md) - Manage your projects and services in the Public Cloud universe
2626
* [ovhcloud cloud reference container-registry](ovhcloud_cloud_reference_container-registry.md) - Fetch container registry reference data in the given cloud project
27+
* [ovhcloud cloud reference database](ovhcloud_cloud_reference_database.md) - Fetch database reference data in the given cloud project
2728
* [ovhcloud cloud reference list-flavors](ovhcloud_cloud_reference_list-flavors.md) - List available flavors in the given cloud project
2829
* [ovhcloud cloud reference list-images](ovhcloud_cloud_reference_list-images.md) - List available images in the given cloud project
2930
* [ovhcloud cloud reference rancher](ovhcloud_cloud_reference_rancher.md) - Fetch Rancher reference data in the given cloud project
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## ovhcloud cloud reference database
2+
3+
Fetch database reference data in the given cloud project
4+
5+
### Options
6+
7+
```
8+
-h, --help help for database
9+
```
10+
11+
### Options inherited from parent commands
12+
13+
```
14+
--cloud-project string Cloud project ID
15+
-d, --debug Activate debug mode (will log all HTTP requests details)
16+
-f, --format string Output value according to given format (expression using gval format)
17+
-e, --ignore-errors Ignore errors in API calls when it is not fatal to the execution
18+
-i, --interactive Interactive output
19+
-j, --json Output in JSON
20+
-y, --yaml Output in YAML
21+
```
22+
23+
### SEE ALSO
24+
25+
* [ovhcloud cloud reference](ovhcloud_cloud_reference.md) - Fetch reference data in the given cloud project
26+
* [ovhcloud cloud reference database list-engines](ovhcloud_cloud_reference_database_list-engines.md) - List available database engines in the given cloud project
27+
* [ovhcloud cloud reference database list-node-flavors](ovhcloud_cloud_reference_database_list-node-flavors.md) - List available database node flavors in the given cloud project
28+
* [ovhcloud cloud reference database list-plans](ovhcloud_cloud_reference_database_list-plans.md) - List available database plans in the given cloud project
29+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## ovhcloud cloud reference database list-engines
2+
3+
List available database engines in the given cloud project
4+
5+
```
6+
ovhcloud cloud reference database list-engines [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
--filter stringArray Filter results by any property using https://github.com/PaesslerAG/gval syntax'
13+
-h, --help help for list-engines
14+
```
15+
16+
### Options inherited from parent commands
17+
18+
```
19+
--cloud-project string Cloud project ID
20+
-d, --debug Activate debug mode (will log all HTTP requests details)
21+
-f, --format string Output value according to given format (expression using gval format)
22+
-e, --ignore-errors Ignore errors in API calls when it is not fatal to the execution
23+
-i, --interactive Interactive output
24+
-j, --json Output in JSON
25+
-y, --yaml Output in YAML
26+
```
27+
28+
### SEE ALSO
29+
30+
* [ovhcloud cloud reference database](ovhcloud_cloud_reference_database.md) - Fetch database reference data in the given cloud project
31+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## ovhcloud cloud reference database list-node-flavors
2+
3+
List available database node flavors in the given cloud project
4+
5+
```
6+
ovhcloud cloud reference database list-node-flavors [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
--filter stringArray Filter results by any property using https://github.com/PaesslerAG/gval syntax'
13+
-h, --help help for list-node-flavors
14+
```
15+
16+
### Options inherited from parent commands
17+
18+
```
19+
--cloud-project string Cloud project ID
20+
-d, --debug Activate debug mode (will log all HTTP requests details)
21+
-f, --format string Output value according to given format (expression using gval format)
22+
-e, --ignore-errors Ignore errors in API calls when it is not fatal to the execution
23+
-i, --interactive Interactive output
24+
-j, --json Output in JSON
25+
-y, --yaml Output in YAML
26+
```
27+
28+
### SEE ALSO
29+
30+
* [ovhcloud cloud reference database](ovhcloud_cloud_reference_database.md) - Fetch database reference data in the given cloud project
31+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## ovhcloud cloud reference database list-plans
2+
3+
List available database plans in the given cloud project
4+
5+
```
6+
ovhcloud cloud reference database list-plans [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
--filter stringArray Filter results by any property using https://github.com/PaesslerAG/gval syntax'
13+
-h, --help help for list-plans
14+
```
15+
16+
### Options inherited from parent commands
17+
18+
```
19+
--cloud-project string Cloud project ID
20+
-d, --debug Activate debug mode (will log all HTTP requests details)
21+
-f, --format string Output value according to given format (expression using gval format)
22+
-e, --ignore-errors Ignore errors in API calls when it is not fatal to the execution
23+
-i, --interactive Interactive output
24+
-j, --json Output in JSON
25+
-y, --yaml Output in YAML
26+
```
27+
28+
### SEE ALSO
29+
30+
* [ovhcloud cloud reference database](ovhcloud_cloud_reference_database.md) - Fetch database reference data in the given cloud project
31+

internal/cmd/cloud_database.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,77 @@ func initCloudDatabaseCommand(cloudCmd *cobra.Command) {
3131
Args: cobra.ExactArgs(1),
3232
})
3333

34+
databaseCmd.AddCommand(getDatabaseCreationCmd())
35+
36+
databaseCmd.AddCommand(&cobra.Command{
37+
Use: "delete <database_id>",
38+
Short: "Delete a specific database",
39+
Run: cloud.DeleteDatabase,
40+
Args: cobra.ExactArgs(1),
41+
})
42+
3443
cloudCmd.AddCommand(databaseCmd)
3544
}
45+
46+
func getDatabaseCreationCmd() *cobra.Command {
47+
databaseCreateCmd := &cobra.Command{
48+
Use: "create",
49+
Short: "Create a new database",
50+
Long: `Use this command to create a database in the given public cloud project.
51+
There are two ways to define the creation parameters:
52+
53+
1. Using only CLI flags:
54+
55+
ovhcloud cloud database create --engine mysql --version 8 --plan essential --nodes-list "db1-4:DE"
56+
57+
2. Using your default text editor:
58+
59+
ovhcloud cloud database create --engine kafka --editor
60+
61+
You will be able to choose from several examples of parameters. Once an example has been selected, the CLI will open your
62+
default text editor to update the parameters. When saving the file, the creation will start.
63+
64+
Note that it is also possible to override values in the presented examples using command line flags like the following:
65+
66+
ovhcloud cloud database create --engine mysql --editor --version 8
67+
`,
68+
Run: cloud.CreateDatabase,
69+
Args: cobra.NoArgs,
70+
}
71+
72+
// Database details
73+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.Engine, "engine", "", "Database engine (you can get the list of available engines using 'ovhcloud cloud reference database list-engines')")
74+
databaseCreateCmd.MarkFlagRequired("engine")
75+
databaseCreateCmd.Flags().StringSliceVar(&cloud.DatabaseSpec.Backups.Regions, "backups-regions", nil, "Regions on which the backups are stored")
76+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.Backups.Time, "backups-time", "", "Time on which backups start every day")
77+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.Description, "description", "", "Database description")
78+
databaseCreateCmd.Flags().IntVar(&cloud.DatabaseSpec.Disk.Size, "disk-size", 0, "Disk size (GB)")
79+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.ForkFrom.BackupID, "fork-from.backup-id", "", "Backup ID (not compatible with fork-from.point-in-time)")
80+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.ForkFrom.PointInTime, "fork-from.point-in-time", "", "Point in time to restore from (not compatible with fork-from.backup-id)")
81+
databaseCreateCmd.MarkFlagsMutuallyExclusive("fork-from.backup-id", "fork-from.point-in-time")
82+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.ForkFrom.ServiceID, "fork-from.service-id", "", "Service ID that owns the backups")
83+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.MaintenanceTime, "maintenance-time", "", "Time on which maintenances can start every day")
84+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.Plan, "plan", "", "Database plan (you can get the list of available plans using 'ovhcloud cloud reference database list-plans')")
85+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.Version, "version", "", "Database version (you can get the list of available versions using 'ovhcloud cloud reference database list-engines')")
86+
87+
// Network configuration
88+
databaseCreateCmd.Flags().StringSliceVar(&cloud.DatabaseSpec.CLIIPRestrictions, "ip-restrictions", nil, "IP blocks authorized to access the cluster (CIDR format)")
89+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.NetworkID, "network-id", "", "Private network ID in which the cluster is deployed")
90+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.SubnetID, "subnet-id", "", "Private subnet ID in which the cluster is deployed")
91+
92+
// Nodes pattern definition
93+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.NodesPattern.Flavor, "nodes-pattern.flavor", "", "Flavor of all nodes")
94+
databaseCreateCmd.Flags().IntVar(&cloud.DatabaseSpec.NodesPattern.Number, "nodes-pattern.number", 0, "Number of nodes")
95+
databaseCreateCmd.Flags().StringVar(&cloud.DatabaseSpec.NodesPattern.Region, "nodes-pattern.region", "", "Region of all nodes")
96+
97+
// Nodes list definition
98+
databaseCreateCmd.Flags().StringSliceVar(&cloud.DatabaseSpec.CLINodesList, "nodes-list", nil, "List of nodes (format: flavor1:region1,flavor2:region2...)")
99+
databaseCreateCmd.MarkFlagsMutuallyExclusive("nodes-pattern.flavor", "nodes-list")
100+
databaseCreateCmd.MarkFlagsMutuallyExclusive("nodes-pattern.number", "nodes-list")
101+
databaseCreateCmd.MarkFlagsMutuallyExclusive("nodes-pattern.region", "nodes-list")
102+
103+
// Common flags for other mean to define parameters
104+
addInteractiveEditorFlag(databaseCreateCmd)
105+
106+
return databaseCreateCmd
107+
}

0 commit comments

Comments
 (0)