Skip to content

Commit 52244ff

Browse files
author
Mathis Rocher
committed
fix(ovhcloud-cli): use EditResource for volume update
Signed-off-by: Mathis Rocher <mathis.rocher@corp.ovh.com>
1 parent 643c4f7 commit 52244ff

2 files changed

Lines changed: 153 additions & 39 deletions

File tree

internal/assets/api-schemas/cloud.json

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,10 +3140,45 @@
31403140
"type": "object",
31413141
"description": "Replication storage job",
31423142
"properties": {
3143+
"completed": {
3144+
"type": "integer",
3145+
"description": "Number of successfully replicated objects",
3146+
"readOnly": true
3147+
},
3148+
"creationDate": {
3149+
"type": "string",
3150+
"description": "Job creation date",
3151+
"format": "date-time",
3152+
"readOnly": true
3153+
},
3154+
"failed": {
3155+
"type": "integer",
3156+
"description": "Number of failed replicated objects",
3157+
"readOnly": true
3158+
},
31433159
"id": {
31443160
"type": "string",
31453161
"description": "Job ID",
31463162
"readOnly": true
3163+
},
3164+
"status": {
3165+
"allOf": [
3166+
{
3167+
"$ref": "#/components/schemas/cloud.storage.StorageJobReplicationStatusEnum"
3168+
}
3169+
],
3170+
"description": "Job replication status",
3171+
"readOnly": true
3172+
},
3173+
"stuck": {
3174+
"type": "integer",
3175+
"description": "Number of stuck replicated objects",
3176+
"readOnly": true
3177+
},
3178+
"total": {
3179+
"type": "integer",
3180+
"description": "Total number of objects to replicate",
3181+
"readOnly": true
31473182
}
31483183
}
31493184
},
@@ -7038,6 +7073,11 @@
70387073
"type": "boolean",
70397074
"description": "Enable DHCP on the private network"
70407075
},
7076+
"enableGatewayIP": {
7077+
"type": "boolean",
7078+
"description": "Enable gateway IP",
7079+
"nullable": true
7080+
},
70417081
"ipVersion": {
70427082
"type": "integer",
70437083
"description": "IP version"
@@ -23865,6 +23905,16 @@
2386523905
"type": "object",
2386623906
"description": "Share Quota",
2386723907
"properties": {
23908+
"maxShareBackupGigabytes": {
23909+
"type": "integer",
23910+
"description": "Maximum share backup gigabytes",
23911+
"readOnly": true
23912+
},
23913+
"maxShareBackups": {
23914+
"type": "integer",
23915+
"description": "Maximum number of share backups",
23916+
"readOnly": true
23917+
},
2386823918
"maxShareSizePerShare": {
2386923919
"type": "integer",
2387023920
"description": "Maximum share size of a share",
@@ -23885,6 +23935,16 @@
2388523935
"description": "Maximum number of shares in the quota",
2388623936
"readOnly": true
2388723937
},
23938+
"usedShareBackupGigabytes": {
23939+
"type": "integer",
23940+
"description": "Used share backup gigabytes",
23941+
"readOnly": true
23942+
},
23943+
"usedShareBackups": {
23944+
"type": "integer",
23945+
"description": "Used number of share backups",
23946+
"readOnly": true
23947+
},
2388823948
"usedShareSizeTotal": {
2388923949
"type": "integer",
2389023950
"description": "Used share total size for project",
@@ -25509,6 +25569,17 @@
2550925569
"STANDARD_IA"
2551025570
]
2551125571
},
25572+
"cloud.storage.StorageJobReplicationStatusEnum": {
25573+
"type": "string",
25574+
"description": "Storage job replication status",
25575+
"enum": [
25576+
"Active",
25577+
"Completed",
25578+
"Created",
25579+
"Failed",
25580+
"Preparing"
25581+
]
25582+
},
2551225583
"cloud.storage.TypeEnum": {
2551325584
"type": "string",
2551425585
"description": "TypeEnum",
@@ -281333,6 +281404,72 @@
281333281404
}
281334281405
},
281335281406
"/cloud/project/{serviceName}/region/{regionName}/storage/{name}/job/replication": {
281407+
"get": {
281408+
"operationId": "getReplicationJobsOnStorageContainer",
281409+
"summary": "Get replication jobs on S3™* compatible buckets",
281410+
"description": "<sup>*</sup> S3 is a trademark filed by Amazon Technologies,Inc. OVHcloud's service is not sponsored by, endorsed by, or otherwise affiliated with Amazon Technologies,Inc.",
281411+
"security": [
281412+
{
281413+
"oAuth2AuthCode": []
281414+
}
281415+
],
281416+
"parameters": [
281417+
{
281418+
"in": "path",
281419+
"name": "name",
281420+
"description": "Name",
281421+
"required": true,
281422+
"schema": {
281423+
"type": "string"
281424+
}
281425+
},
281426+
{
281427+
"in": "path",
281428+
"name": "regionName",
281429+
"description": "Region name",
281430+
"required": true,
281431+
"schema": {
281432+
"type": "string"
281433+
}
281434+
},
281435+
{
281436+
"in": "path",
281437+
"name": "serviceName",
281438+
"description": "Service name",
281439+
"required": true,
281440+
"schema": {
281441+
"type": "string"
281442+
}
281443+
}
281444+
],
281445+
"responses": {
281446+
"200": {
281447+
"description": "successful operation",
281448+
"content": {
281449+
"application/json": {
281450+
"schema": {
281451+
"type": "array",
281452+
"items": {
281453+
"$ref": "#/components/schemas/cloud.StorageJobReplication"
281454+
}
281455+
}
281456+
}
281457+
}
281458+
}
281459+
},
281460+
"x-badges": [
281461+
{
281462+
"color": "blue",
281463+
"label": "Beta version"
281464+
}
281465+
],
281466+
"x-iam-actions": [
281467+
{
281468+
"name": "publicCloudProject:apiovh:region/storage/job/replication/get",
281469+
"required": true
281470+
}
281471+
]
281472+
},
281336281473
"post": {
281337281474
"operationId": "createReplicationJobOnStorageContainer",
281338281475
"summary": "Create replication job on S3™* compatible buckets",

internal/services/cloud/cloud_storage_block.go

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -81,50 +81,27 @@ func EditVolume(cmd *cobra.Command, args []string) {
8181
return
8282
}
8383

84-
if cmd.Flags().NFlag() == 0 {
85-
display.OutputInfo(&flags.OutputFormatConfig, nil, "🟠 No parameters given, nothing to edit")
84+
// Fetch the volume to get its region for the region-scoped endpoint
85+
var volume map[string]any
86+
if err := httpLib.Client.Get(
87+
fmt.Sprintf("/v1/cloud/project/%s/volume/%s", projectID, url.PathEscape(args[0])),
88+
&volume,
89+
); err != nil {
90+
display.OutputError(&flags.OutputFormatConfig, "failed to fetch volume: %s", err)
8691
return
8792
}
8893

89-
// Build PUT body with only the fields explicitly provided by the user
90-
body := make(map[string]any)
91-
if cmd.Flags().Changed("name") {
92-
body["name"] = VolumeEditSpec.Name
93-
}
94-
if cmd.Flags().Changed("description") {
95-
body["description"] = VolumeEditSpec.Description
96-
}
97-
if cmd.Flags().Changed("type") {
98-
body["type"] = VolumeEditSpec.Type
99-
}
100-
if cmd.Flags().Changed("size") {
101-
body["size"] = VolumeEditSpec.Size
102-
}
103-
104-
// Use the region-scoped endpoint when --type or --size is provided,
105-
// otherwise use the project-scoped endpoint for name/description changes
106-
var endpoint string
107-
if cmd.Flags().Changed("type") || cmd.Flags().Changed("size") {
108-
// Fetch the volume to get its region (required for the region-scoped endpoint)
109-
var volume map[string]any
110-
if err := httpLib.Client.Get(
111-
fmt.Sprintf("/v1/cloud/project/%s/volume/%s", projectID, url.PathEscape(args[0])),
112-
&volume,
113-
); err != nil {
114-
display.OutputError(&flags.OutputFormatConfig, "failed to fetch volume: %s", err)
115-
return
116-
}
117-
region := volume["region"].(string)
118-
endpoint = fmt.Sprintf("/v1/cloud/project/%s/region/%s/volume/%s", projectID, url.PathEscape(region), url.PathEscape(args[0]))
119-
} else {
120-
endpoint = fmt.Sprintf("/v1/cloud/project/%s/volume/%s", projectID, url.PathEscape(args[0]))
121-
}
122-
if err := httpLib.Client.Put(endpoint, body, nil); err != nil {
123-
display.OutputError(&flags.OutputFormatConfig, "failed to update volume: %s", err)
94+
region := volume["region"].(string)
95+
if err := common.EditResource(
96+
cmd,
97+
"/cloud/project/{serviceName}/region/{regionName}/volume/{volumeId}",
98+
fmt.Sprintf("/v1/cloud/project/%s/region/%s/volume/%s", projectID, url.PathEscape(region), url.PathEscape(args[0])),
99+
VolumeEditSpec,
100+
assets.CloudOpenapiSchema,
101+
); err != nil {
102+
display.OutputError(&flags.OutputFormatConfig, "%s", err)
124103
return
125104
}
126-
127-
display.OutputInfo(&flags.OutputFormatConfig, nil, "✅ Volume %s updated successfully", args[0])
128105
}
129106

130107
func CreateVolume(cmd *cobra.Command, args []string) {

0 commit comments

Comments
 (0)