{"modulePath":"github.com/hostinger/api-cli","version":"v1.2.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package virtual_machines\n\n## Variables\n\n```go\nvar AttachedPublicKeysCmd = \u0026cobra.Command{\n\tUse:   \"attached-public-keys \u003cvirtual-machine-id\u003e\",\n\tShort: \"Get attached public keys\",\n\tLong:  \"Retrieve public keys attached to a specified virtual machine.\\n\\nUse this endpoint to view SSH keys configured for specific VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSGetAttachedPublicKeysV1WithResponse(context.TODO(), utils.StringToInt(args[0]), attachedPublicKeysParams(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar GetCmd = \u0026cobra.Command{\n\tUse:   \"get \u003cvirtual-machine-id\u003e\",\n\tShort: \"Get virtual machine details\",\n\tLong:  \"Retrieve detailed information about a specified virtual machine.\\n\\nUse this endpoint to view comprehensive VPS configuration and status.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSGetVirtualMachineDetailsV1WithResponse(context.TODO(), utils.StringToInt(args[0]))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar GroupCmd = \u0026cobra.Command{\n\tUse:     \"virtual-machines\",\n\tAliases: []string{\"vm\"},\n\tShort:   \"Virtual machine commands\",\n}\n```\n\n```go\nvar ListCmd = \u0026cobra.Command{\n\tUse:   \"list\",\n\tShort: \"Get virtual machines\",\n\tLong:  \"Retrieve all available virtual machines.\\n\\nUse this endpoint to view available VPS instances.\",\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSGetVirtualMachinesV1WithResponse(context.TODO())\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar MetricsCmd = \u0026cobra.Command{\n\tUse:   \"metrics \u003cvirtual-machine-id\u003e\",\n\tShort: \"Get metrics\",\n\tLong:  \"Retrieve historical metrics for a specified virtual machine.\\n\\nIt includes the following metrics: \\n- CPU usage\\n- Memory usage\\n- Disk usage\\n- Network usage\\n- Uptime\\n\\nUse this endpoint to monitor VPS performance and resource utilization over time.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSGetMetricsV1WithResponse(context.TODO(), utils.StringToInt(args[0]), metricsParams(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar PurchaseCmd = \u0026cobra.Command{\n\tUse:   \"purchase\",\n\tShort: \"Purchase new virtual machine\",\n\tLong:  \"Purchase and setup a new virtual machine.\\n\\nIf virtual machine setup fails for any reason, login to\\n[hPanel](https://hpanel.hostinger.com/) and complete the setup manually.\\n\\nIf no payment method is provided, your default payment method will be used automatically.\\n\\nUse this endpoint to create new VPS instances.\",\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tpayload, err := json.Marshal(purchaseBody(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\t\tr, err := api.Request().VPSPurchaseNewVirtualMachineV1WithBodyWithResponse(context.TODO(), \"application/json\", bytes.NewReader(payload))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar RecreateCmd = \u0026cobra.Command{\n\tUse:   \"recreate \u003cvirtual-machine-id\u003e\",\n\tShort: \"Recreate virtual machine\",\n\tLong:  \"Recreate a virtual machine from scratch.\\n\\nThe recreation process involves reinstalling the operating system and\\nresetting the virtual machine to its initial state.\\nSnapshots, if there are any, will be deleted.\\n\\n## Password Requirements\\nPassword will be checked against leaked password databases. \\nRequirements for the password are:\\n- At least 12 characters long\\n- At least one uppercase letter\\n- At least one lowercase letter\\n- At least one number\\n- Is not leaked publicly\\n\\n**This operation is irreversible and will result in the loss of all data stored on the virtual machine!**\\n\\nUse this endpoint to completely rebuild VPS instances with fresh OS installation.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tpayload, err := json.Marshal(recreateBody(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\t\tr, err := api.Request().VPSRecreateVirtualMachineV1WithBodyWithResponse(context.TODO(), utils.StringToInt(args[0]), \"application/json\", bytes.NewReader(payload))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar ResetHostnameCmd = \u0026cobra.Command{\n\tUse:   \"reset-hostname \u003cvirtual-machine-id\u003e\",\n\tShort: \"Reset hostname\",\n\tLong:  \"Reset hostname and PTR record of a specified virtual machine to default value.\\n\\nUse this endpoint to restore default hostname configuration for VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSResetHostnameV1WithResponse(context.TODO(), utils.StringToInt(args[0]))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar RestartCmd = \u0026cobra.Command{\n\tUse:   \"restart \u003cvirtual-machine-id\u003e\",\n\tShort: \"Restart virtual machine\",\n\tLong:  \"Restart a specified virtual machine by fully stopping and starting it.\\n\\nIf the virtual machine was stopped, it will be started.\\n\\nUse this endpoint to reboot VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSRestartVirtualMachineV1WithResponse(context.TODO(), utils.StringToInt(args[0]))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar SetHostnameCmd = \u0026cobra.Command{\n\tUse:   \"set-hostname \u003cvirtual-machine-id\u003e\",\n\tShort: \"Set hostname\",\n\tLong:  \"Set hostname for a specified virtual machine.\\n\\nChanging hostname does not update PTR record automatically.\\nIf you want your virtual machine to be reachable by a hostname, \\nyou need to point your domain A/AAAA records to virtual machine IP as well.\\n\\nUse this endpoint to configure custom hostnames for VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tpayload, err := json.Marshal(setHostnameBody(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\t\tr, err := api.Request().VPSSetHostnameV1WithBodyWithResponse(context.TODO(), utils.StringToInt(args[0]), \"application/json\", bytes.NewReader(payload))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar SetNameserversCmd = \u0026cobra.Command{\n\tUse:   \"set-nameservers \u003cvirtual-machine-id\u003e\",\n\tShort: \"Set nameservers\",\n\tLong:  \"Set nameservers for a specified virtual machine.\\n\\nBe aware, that improper nameserver configuration can lead to the virtual\\nmachine being unable to resolve domain names.\\n\\nUse this endpoint to configure custom DNS resolvers for VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tpayload, err := json.Marshal(setNameserversBody(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\t\tr, err := api.Request().VPSSetNameserversV1WithBodyWithResponse(context.TODO(), utils.StringToInt(args[0]), \"application/json\", bytes.NewReader(payload))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar SetPanelPasswordCmd = \u0026cobra.Command{\n\tUse:   \"set-panel-password \u003cvirtual-machine-id\u003e\",\n\tShort: \"Set panel password\",\n\tLong:  \"Set panel password for a specified virtual machine.\\n\\nIf virtual machine does not use panel OS, the request will still be processed without any effect.\\nRequirements for password are same as in the [recreate virtual machine\\nendpoint](/#tag/vps-virtual-machine/POST/api/vps/v1/virtual-machines/{virtualMachineId}/recreate).\\n\\nUse this endpoint to configure control panel access credentials for VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tpayload, err := json.Marshal(setPanelPasswordBody(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\t\tr, err := api.Request().VPSSetPanelPasswordV1WithBodyWithResponse(context.TODO(), utils.StringToInt(args[0]), \"application/json\", bytes.NewReader(payload))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar SetRootPasswordCmd = \u0026cobra.Command{\n\tUse:   \"set-root-password \u003cvirtual-machine-id\u003e\",\n\tShort: \"Set root password\",\n\tLong:  \"Set root password for a specified virtual machine.\\n\\nRequirements for password are same as in the [recreate virtual machine\\nendpoint](/#tag/vps-virtual-machine/POST/api/vps/v1/virtual-machines/{virtualMachineId}/recreate).\\n\\nUse this endpoint to update administrator credentials for VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tpayload, err := json.Marshal(setRootPasswordBody(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\t\tr, err := api.Request().VPSSetRootPasswordV1WithBodyWithResponse(context.TODO(), utils.StringToInt(args[0]), \"application/json\", bytes.NewReader(payload))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar SetupCmd = \u0026cobra.Command{\n\tUse:   \"setup \u003cvirtual-machine-id\u003e\",\n\tShort: \"Setup purchased virtual machine\",\n\tLong:  \"Setup newly purchased virtual machine with `initial` state.\\n\\nUse this endpoint to configure and initialize purchased VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tpayload, err := json.Marshal(setupBody(cmd))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\t\tr, err := api.Request().VPSSetupPurchasedVirtualMachineV1WithBodyWithResponse(context.TODO(), utils.StringToInt(args[0]), \"application/json\", bytes.NewReader(payload))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar StartCmd = \u0026cobra.Command{\n\tUse:   \"start \u003cvirtual-machine-id\u003e\",\n\tShort: \"Start virtual machine\",\n\tLong:  \"Start a specified virtual machine.\\n\\nIf the virtual machine is already running, the request will still be processed without any effect.\\n\\nUse this endpoint to power on stopped VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSStartVirtualMachineV1WithResponse(context.TODO(), utils.StringToInt(args[0]))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n```go\nvar StopCmd = \u0026cobra.Command{\n\tUse:   \"stop \u003cvirtual-machine-id\u003e\",\n\tShort: \"Stop virtual machine\",\n\tLong:  \"Stop a specified virtual machine.\\n\\nIf the virtual machine is already stopped, the request will still be processed without any effect.\\n\\nUse this endpoint to power off running VPS instances.\",\n\tArgs:  cobra.MatchAll(cobra.ExactArgs(1)),\n\tRun: func(cmd *cobra.Command, args []string) {\n\t\tr, err := api.Request().VPSStopVirtualMachineV1WithResponse(context.TODO(), utils.StringToInt(args[0]))\n\t\tif err != nil {\n\t\t\tlog.Fatal(err)\n\t\t}\n\n\t\toutput.Format(cmd, r.Body, r.StatusCode())\n\t},\n}\n```\n\n","path":"github.com/hostinger/api-cli/cmd/vps/virtual_machines","name":"virtual_machines","synopsis":"","isRedistributable":true}
