|
| 1 | +package recovery |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "github.com/hostinger/api-cli/api" |
| 6 | + "github.com/hostinger/api-cli/client" |
| 7 | + "github.com/hostinger/api-cli/output" |
| 8 | + "github.com/hostinger/api-cli/utils" |
| 9 | + "github.com/spf13/cobra" |
| 10 | + "log" |
| 11 | +) |
| 12 | + |
| 13 | +var StartCmd = &cobra.Command{ |
| 14 | + Use: "start <virtual machine ID>", |
| 15 | + Short: "Start recovery mode", |
| 16 | + Long: `This endpoint initiates the recovery mode for a specified virtual machine. |
| 17 | +Recovery mode is a special state that allows users to perform system rescue operations, such as repairing file systems, |
| 18 | +recovering data, or troubleshooting issues that prevent the virtual machine from booting normally. |
| 19 | +
|
| 20 | +Virtual machine will boot recovery disk image and original disk image will be mounted in /mnt directory.`, |
| 21 | + Args: cobra.MatchAll(cobra.ExactArgs(1)), |
| 22 | + Run: func(cmd *cobra.Command, args []string) { |
| 23 | + r, err := api.Request().VPSStartRecoveryModeV1WithResponse(context.TODO(), utils.StringToInt(args[0]), startRequestParameters(cmd)) |
| 24 | + if err != nil { |
| 25 | + log.Fatal(err) |
| 26 | + } |
| 27 | + |
| 28 | + output.Format(cmd, r.Body, r.StatusCode()) |
| 29 | + }, |
| 30 | +} |
| 31 | + |
| 32 | +func init() { |
| 33 | + StartCmd.Flags().StringP("password", "", "", "Temporary root password for recovery mode") |
| 34 | + |
| 35 | + StartCmd.MarkFlagRequired("password") |
| 36 | +} |
| 37 | + |
| 38 | +func startRequestParameters(cmd *cobra.Command) client.VPSStartRecoveryModeV1JSONRequestBody { |
| 39 | + password, _ := cmd.Flags().GetString("password") |
| 40 | + |
| 41 | + return client.VPSStartRecoveryModeV1JSONRequestBody{ |
| 42 | + RootPassword: password, |
| 43 | + } |
| 44 | +} |
0 commit comments