Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ARGS:
engine Database engine of the database (PostgreSQL, MySQL, ...)
user-name Name of the user created when the instance is created
password Password of the user
node-type=DB-DEV-S Type of node to use for the instance (DB-DEV-S | DB-DEV-M | DB-DEV-L | DB-DEV-XL | DB-GP-XS | DB-GP-S | DB-GP-M | DB-GP-L | DB-GP-XL)
node-type=DB-DEV-S Type of node to use for the instance
[is-ha-cluster] Whether or not High-Availability is enabled
[disable-backup] Whether or not backups are disabled
[tags.{index}] Tags to apply to the instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ USAGE:

ARGS:
instance-id UUID of the instance you want to upgrade
[node-type] Node type of the instance you want to upgrade to (DB-DEV-S | DB-DEV-M | DB-DEV-L | DB-DEV-XL | DB-GP-XS | DB-GP-S | DB-GP-M | DB-GP-L | DB-GP-XL)
[node-type] Node type of the instance you want to upgrade to
[enable-ha] Set to true to enable high availability on your instance
[volume-size] Increase your block storage volume size
[volume-type] Change your instance storage type (lssd | bssd)
Expand Down
4 changes: 2 additions & 2 deletions docs/commands/rdb.md
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ scw rdb instance create [arg=value ...]
| engine | Required | Database engine of the database (PostgreSQL, MySQL, ...) |
| user-name | Required | Name of the user created when the instance is created |
| password | Required | Password of the user |
| node-type | Required<br />Default: `DB-DEV-S`<br />One of: `DB-DEV-S`, `DB-DEV-M`, `DB-DEV-L`, `DB-DEV-XL`, `DB-GP-XS`, `DB-GP-S`, `DB-GP-M`, `DB-GP-L`, `DB-GP-XL` | Type of node to use for the instance |
| node-type | Required<br />Default: `DB-DEV-S` | Type of node to use for the instance |
| is-ha-cluster | | Whether or not High-Availability is enabled |
| disable-backup | | Whether or not backups are disabled |
| tags.{index} | | Tags to apply to the instance |
Expand Down Expand Up @@ -761,7 +761,7 @@ scw rdb instance upgrade <instance-id ...> [arg=value ...]
| Name | | Description |
|------|---|-------------|
| instance-id | Required | UUID of the instance you want to upgrade |
| node-type | One of: `DB-DEV-S`, `DB-DEV-M`, `DB-DEV-L`, `DB-DEV-XL`, `DB-GP-XS`, `DB-GP-S`, `DB-GP-M`, `DB-GP-L`, `DB-GP-XL` | Node type of the instance you want to upgrade to |
| node-type | | Node type of the instance you want to upgrade to |
| enable-ha | | Set to true to enable high availability on your instance |
| volume-size | | Increase your block storage volume size |
| volume-type | One of: `lssd`, `bssd` | Change your instance storage type |
Expand Down
12 changes: 0 additions & 12 deletions internal/namespaces/rdb/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ import (
"github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
)

var nodeTypes = []string{
"DB-DEV-S",
"DB-DEV-M",
"DB-DEV-L",
"DB-DEV-XL",
"DB-GP-XS",
"DB-GP-S",
"DB-GP-M",
"DB-GP-L",
"DB-GP-XL",
}

func GetCommands() *core.Commands {
cmds := GetGeneratedCommands()

Expand Down
30 changes: 28 additions & 2 deletions internal/namespaces/rdb/v1/custom_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,35 @@ func instanceCloneBuilder(c *core.Command) *core.Command {
return c
}

// Caching ListNodeType response for shell completion
var completeListNodeTypeCache *rdb.ListNodeTypesResponse

func autoCompleteNodeType(ctx context.Context, prefix string) core.AutocompleteSuggestions {
suggestions := core.AutocompleteSuggestions(nil)

client := core.ExtractClient(ctx)
api := rdb.NewAPI(client)

if completeListNodeTypeCache == nil {
res, err := api.ListNodeTypes(&rdb.ListNodeTypesRequest{}, scw.WithAllPages())
if err != nil {
return nil
}
completeListNodeTypeCache = res
}

for _, nodeType := range completeListNodeTypeCache.NodeTypes {
if strings.HasPrefix(nodeType.Name, prefix) {
suggestions = append(suggestions, nodeType.Name)
}
}

return suggestions
}

func instanceCreateBuilder(c *core.Command) *core.Command {
c.ArgSpecs.GetByName("node-type").Default = core.DefaultValueSetter("DB-DEV-S")
c.ArgSpecs.GetByName("node-type").EnumValues = nodeTypes
c.ArgSpecs.GetByName("node-type").AutoCompleteFunc = autoCompleteNodeType

c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
api := rdb.NewAPI(core.ExtractClient(ctx))
Expand All @@ -148,7 +174,7 @@ func instanceCreateBuilder(c *core.Command) *core.Command {
}

func instanceUpgradeBuilder(c *core.Command) *core.Command {
c.ArgSpecs.GetByName("node-type").EnumValues = nodeTypes
c.ArgSpecs.GetByName("node-type").AutoCompleteFunc = autoCompleteNodeType

c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
api := rdb.NewAPI(core.ExtractClient(ctx))
Expand Down
Loading