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
3 changes: 2 additions & 1 deletion doc/ovhcloud_cloud_instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ Manage instances in the given cloud project
* [ovhcloud cloud instance image](ovhcloud_cloud_instance_image.md) - List available images in the given cloud project
* [ovhcloud cloud instance interface](ovhcloud_cloud_instance_interface.md) - Manage interfaces of the given instance
* [ovhcloud cloud instance list](ovhcloud_cloud_instance_list.md) - List your instances
* [ovhcloud cloud instance lock](ovhcloud_cloud_instance_lock.md) - Lock the given instance to prevent accidental actions and modifications
* [ovhcloud cloud instance reboot](ovhcloud_cloud_instance_reboot.md) - Reboot the given instance
* [ovhcloud cloud instance reboot-rescue](ovhcloud_cloud_instance_reboot-rescue.md) - Reboot the given instance in rescue mode
* [ovhcloud cloud instance reinstall](ovhcloud_cloud_instance_reinstall.md) - Reinstall the given instance
* [ovhcloud cloud instance resume](ovhcloud_cloud_instance_resume.md) - Resume the given suspended instance
* [ovhcloud cloud instance set-flavor](ovhcloud_cloud_instance_set-flavor.md) - Migrate the given instance to the specified flavor
* [ovhcloud cloud instance set-name](ovhcloud_cloud_instance_set-name.md) - Set the name of the given instance
* [ovhcloud cloud instance shelve](ovhcloud_cloud_instance_shelve.md) - Shelve the given instance
* [ovhcloud cloud instance start](ovhcloud_cloud_instance_start.md) - Start the given instance
* [ovhcloud cloud instance stop](ovhcloud_cloud_instance_stop.md) - Stop the given instance
* [ovhcloud cloud instance unlock](ovhcloud_cloud_instance_unlock.md) - Unlock the given instance
* [ovhcloud cloud instance unshelve](ovhcloud_cloud_instance_unshelve.md) - Unshelve the given instance

39 changes: 39 additions & 0 deletions doc/ovhcloud_cloud_instance_lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## ovhcloud cloud instance lock

Lock the given instance to prevent accidental actions and modifications

```
ovhcloud cloud instance lock <instance_id> [flags]
```

### Options

```
-h, --help help for lock
--wait Wait for the instance to be locked before exiting
```

### Options inherited from parent commands

```
--cloud-project string Cloud project ID
-d, --debug Activate debug mode (will log all HTTP requests details)
-e, --ignore-errors Ignore errors in API calls when it is not fatal to the execution
-o, --output string Output format: json, yaml, interactive, or a custom format expression (using https://github.com/PaesslerAG/gval syntax)
Examples:
--output json
--output yaml
--output interactive
--output 'id' (to extract a single field)
--output 'nested.field.subfield' (to extract a nested field)
--output '[id, "name"]' (to extract multiple fields as an array)
--output '{"newKey": oldKey, "otherKey": nested.field}' (to extract and rename fields in an object)
--output 'name+","+type' (to extract and concatenate fields in a string)
--output '(nbFieldA + nbFieldB) * 10' (to compute values from numeric fields)
--profile string Use a specific profile from the configuration file
```

### SEE ALSO

* [ovhcloud cloud instance](ovhcloud_cloud_instance.md) - Manage instances in the given cloud project

1 change: 1 addition & 0 deletions doc/ovhcloud_cloud_instance_reboot.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ovhcloud cloud instance reboot <instance_id> [flags]
```
-h, --help help for reboot
-t, --type string Reboot type: hard or soft (default is soft) (default "soft")
--wait Wait for the instance to be rebooted before exiting
```

### Options inherited from parent commands
Expand Down
1 change: 1 addition & 0 deletions doc/ovhcloud_cloud_instance_shelve.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ovhcloud cloud instance shelve <instance_id> [flags]

```
-h, --help help for shelve
--wait Wait for the instance to be shelved before exiting
```

### Options inherited from parent commands
Expand Down
1 change: 1 addition & 0 deletions doc/ovhcloud_cloud_instance_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ovhcloud cloud instance start <instance_id> [flags]

```
-h, --help help for start
--wait Wait for the instance to be started before exiting
```

### Options inherited from parent commands
Expand Down
1 change: 1 addition & 0 deletions doc/ovhcloud_cloud_instance_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ ovhcloud cloud instance stop <instance_id> [flags]

```
-h, --help help for stop
--wait Wait for the instance to be stopped before exiting
```

### Options inherited from parent commands
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
## ovhcloud cloud instance resume
## ovhcloud cloud instance unlock

Resume the given suspended instance
Unlock the given instance

```
ovhcloud cloud instance resume <instance_id> [flags]
ovhcloud cloud instance unlock <instance_id> [flags]
```

### Options

```
-h, --help help for resume
-h, --help help for unlock
--wait Wait for the instance to be unlocked before exiting
```

### Options inherited from parent commands
Expand Down
1 change: 1 addition & 0 deletions doc/ovhcloud_cloud_instance_unshelve.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ ovhcloud cloud instance unshelve <instance_id> [flags]

```
-h, --help help for unshelve
--wait Wait for the instance to be unshelved before exiting
```

### Options inherited from parent commands
Expand Down
23 changes: 12 additions & 11 deletions internal/assets/api-schemas/cloud_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2334,35 +2334,36 @@
},
"publicCloud.instance.InstanceActionParameters": {
"type": "object",
"description": "Optional parameters for an instance action",
"description": "Instance action parameters\n\nOptional parameters refining an imperative instance action. Each field applies only to a specific action type (see InstanceActionTypeEnum) and is ignored for other actions.",
"properties": {
"hard": {
"type": "boolean",
"description": "Whether to perform a hard reboot (only for REBOOT action)",
"description": "Hard reboot\n\nApplies only to the REBOOT action. When true, performs a hard reboot (power cycle) instead of a graceful, soft reboot. Defaults to a soft reboot when omitted.",
"nullable": true
},
"imageId": {
"type": "string",
"description": "Rescue image ID (only for RESCUE action)",
"description": "Rescue image\n\nApplies only to the RESCUE action. Identifier of the image to boot the instance from while in rescue mode. When omitted, the backend selects a default rescue image.",
"nullable": true
}
}
},
"publicCloud.instance.InstanceActionRequest": {
"type": "object",
"description": "Payload to perform an imperative action on an instance",
"description": "Instance action request\n\nPayload for triggering an imperative action on an instance (for example lock, reboot or rescue). Unlike the declarative PUT update, an action directly commands an administrative or operational state change.\n\nThe checksum from the last GET may be supplied to opt in to optimistic concurrency control; omitting it forces the action.",
"properties": {
"checksum": {
"type": "string",
"description": "Current resource checksum for optimistic concurrency control"
"description": "Concurrency-control checksum\n\nOptional checksum obtained from the last GET of the instance. When supplied, it must still match the instance's current checksum or the action is rejected with a 409 checksum-mismatch conflict, protecting against a concurrent modification. When omitted or empty, the concurrency check is skipped and the action is forced (last-write-wins).",
"nullable": true
},
"parameters": {
"allOf": [
{
"$ref": "#/components/schemas/publicCloud.instance.InstanceActionParameters"
}
],
"description": "Optional parameters for the action",
"description": "Parameters\n\nOptional parameters refining the requested action (see InstanceActionParameters). Only relevant for actions that accept options, such as a hard REBOOT or a RESCUE with a specific image; omit for actions that take none.",
"nullable": true
},
"type": {
Expand All @@ -2371,17 +2372,16 @@
"$ref": "#/components/schemas/publicCloud.instance.InstanceActionTypeEnum"
}
],
"description": "The action to perform"
"description": "Action type\n\nThe imperative action to perform on the instance (see InstanceActionTypeEnum: LOCK, UNLOCK, REBOOT, RESCUE, UNRESCUE)."
}
},
"required": [
"checksum",
"type"
]
},
"publicCloud.instance.InstanceActionTypeEnum": {
"type": "string",
"description": "Supported imperative action types for an instance",
"description": "Instance action type\n\nImperative action that can be triggered on an instance to change its administrative or operational state.\n\nValues\nLOCK — Lock the instance to prevent further actions on it, protecting it from accidental or unauthorized operations.\nUNLOCK — Remove a previously set lock, re-enabling actions on the instance.\nREBOOT — Restart the instance.\nRESCUE — Boot the instance into rescue mode from a rescue image so its root disk can be inspected or repaired.\nUNRESCUE — Return the instance from rescue mode to normal operation.",
"enum": [
"LOCK",
"REBOOT",
Expand Down Expand Up @@ -13601,6 +13601,7 @@
"/publicCloud/project/{projectId}/compute/instance/{instanceId}/action": {
"post": {
"summary": "Perform an action on a Public Cloud instance (reboot, rescue, unrescue)",
"description": "### Perform an instance action\n\nImperative endpoint for **power and lifecycle actions** on an instance. This is the **one place** such imperative operations live — distinct from the declarative `PUT` on the instance, which reconciles desired state from a `targetSpec` diff. Actions are **asynchronous**: the instance transitions through the relevant transient state and the response echoes the instance; poll `GET .../instance/{instanceId}` until `resourceStatus` is `READY` and `currentTasks` is empty.\n\n### Action `type`\nThe `type` field selects the operation:\n* `REBOOT` — reboot the instance (`parameters.hard` chooses a hard vs. soft reboot).\n* `START` / `STOP` — power the instance on / off.\n* `SHELVE` / `UNSHELVE` — shelve the instance (freeing hypervisor resources) and restore it.\n* `RESCUE` / `UNRESCUE` — boot into rescue mode (optionally from `parameters.imageId`) and return to normal boot.\n* `LOCK` / `UNLOCK` — lock the instance against accidental actions / modifications, and unlock it.\n\n### Optimistic concurrency (`checksum`)\nThe `checksum` is **optional**. When you send it, it must match the current server-side value or the action is rejected with a checksum-mismatch error — re-`GET` and retry. When you omit it (or send an empty string), the check is skipped and the action is forced (last-write-wins). An action requested while the instance is in an incompatible state is rejected with `ResourceInInvalidState`.",
"security": [
{
"oAuth2AuthCode": []
Expand Down Expand Up @@ -13777,8 +13778,8 @@
],
"x-badges": [
{
"color": "orange",
"label": "Internal use only"
"color": "blue",
"label": "Alpha version"
}
],
"x-iam-actions": [
Expand Down
53 changes: 37 additions & 16 deletions internal/cmd/cloud_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,27 @@ func initInstanceCommand(cloudCmd *cobra.Command) {
setNameCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for the instance to be ready before exiting")
instanceCmd.AddCommand(setNameCmd)

instanceCmd.AddCommand(&cobra.Command{
startCmd := &cobra.Command{
Use: "start <instance_id>",
Short: "Start the given instance",
ValidArgsFunction: completion.CloudResources("/v2/publicCloud/project/%s/compute/instance"),
Run: cloud.StartInstance,
Args: cobra.ExactArgs(1),
})
}
startCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for the instance to be started before exiting")
instanceCmd.AddCommand(startCmd)

instanceCmd.AddCommand(&cobra.Command{
stopCmd := &cobra.Command{
Use: "stop <instance_id>",
Short: "Stop the given instance",
ValidArgsFunction: completion.CloudResources("/v2/publicCloud/project/%s/compute/instance"),
Run: cloud.StopInstance,
Args: cobra.ExactArgs(1),
})
}
stopCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for the instance to be stopped before exiting")
instanceCmd.AddCommand(stopCmd)

instanceCmd.AddCommand(&cobra.Command{
shelveCmd := &cobra.Command{
Use: "shelve <instance_id>",
Short: "Shelve the given instance",
Long: `The resources dedicated to the Public Cloud instance are released.
Expand All @@ -210,9 +214,11 @@ The Snapshot Storage used to store the instance's data will be billed.`,
ValidArgsFunction: completion.CloudResources("/v2/publicCloud/project/%s/compute/instance"),
Run: cloud.ShelveInstance,
Args: cobra.ExactArgs(1),
})
}
shelveCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for the instance to be shelved before exiting")
instanceCmd.AddCommand(shelveCmd)

instanceCmd.AddCommand(&cobra.Command{
unshelveCmd := &cobra.Command{
Use: "unshelve <instance_id>",
Short: "Unshelve the given instance",
Long: `The resources dedicated to the Public Cloud instance are restored.
Expand All @@ -221,15 +227,9 @@ Instance billing will get back to normal and the snapshot used to store the inst
ValidArgsFunction: completion.CloudResources("/v2/publicCloud/project/%s/compute/instance"),
Run: cloud.UnshelveInstance,
Args: cobra.ExactArgs(1),
})

instanceCmd.AddCommand(&cobra.Command{
Use: "resume <instance_id>",
Short: "Resume the given suspended instance",
ValidArgsFunction: completion.CloudResources("/v2/publicCloud/project/%s/compute/instance"),
Run: cloud.ResumeInstance,
Args: cobra.ExactArgs(1),
})
}
unshelveCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for the instance to be unshelved before exiting")
instanceCmd.AddCommand(unshelveCmd)

rebootCmd := &cobra.Command{
Use: "reboot <instance_id>",
Expand All @@ -239,8 +239,29 @@ Instance billing will get back to normal and the snapshot used to store the inst
Args: cobra.ExactArgs(1),
}
rebootCmd.Flags().StringVarP(&cloud.InstanceRebootType, "type", "t", "soft", "Reboot type: hard or soft (default is soft)")
rebootCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for the instance to be rebooted before exiting")
instanceCmd.AddCommand(rebootCmd)

lockCmd := &cobra.Command{
Use: "lock <instance_id>",
Short: "Lock the given instance to prevent accidental actions and modifications",
ValidArgsFunction: completion.CloudResources("/v2/publicCloud/project/%s/compute/instance"),
Run: cloud.LockInstance,
Args: cobra.ExactArgs(1),
}
lockCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for the instance to be locked before exiting")
instanceCmd.AddCommand(lockCmd)

unlockCmd := &cobra.Command{
Use: "unlock <instance_id>",
Short: "Unlock the given instance",
ValidArgsFunction: completion.CloudResources("/v2/publicCloud/project/%s/compute/instance"),
Run: cloud.UnlockInstance,
Args: cobra.ExactArgs(1),
}
unlockCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for the instance to be unlocked before exiting")
instanceCmd.AddCommand(unlockCmd)

reinstallCmd := &cobra.Command{
Use: "reinstall <instance_id>",
Short: "Reinstall the given instance",
Expand Down
Loading
Loading