diff --git a/cmd/metal/.gitignore b/cmd/metal/.gitignore new file mode 100644 index 00000000..31e03d49 --- /dev/null +++ b/cmd/metal/.gitignore @@ -0,0 +1 @@ +metal diff --git a/docs/metal_device.md b/docs/metal_device.md index 4301dffb..a4eef26d 100644 --- a/docs/metal_device.md +++ b/docs/metal_device.md @@ -4,7 +4,7 @@ Device operations. For more information on provisioning on Equinix Metal, visit ### Synopsis -Device operations: create, get, update, delete, start, stop, and reboot. +Device operations: create, get, update, delete, reinstall, start, stop, and reboot. ### Options @@ -33,6 +33,7 @@ Device operations: create, get, update, delete, start, stop, and reboot. * [metal device delete](metal_device_delete.md) - Deletes a device. * [metal device get](metal_device_get.md) - Retrieves device list or device details. * [metal device reboot](metal_device_reboot.md) - Reboots a device. +* [metal device reinstall](metal_device_reinstall.md) - Reinstalls a device. * [metal device start](metal_device_start.md) - Starts a device. * [metal device stop](metal_device_stop.md) - Stops a device. * [metal device update](metal_device_update.md) - Updates a device. diff --git a/docs/metal_device_reinstall.md b/docs/metal_device_reinstall.md new file mode 100644 index 00000000..dc7259ab --- /dev/null +++ b/docs/metal_device_reinstall.md @@ -0,0 +1,39 @@ +## metal device reinstall + +Reinstalls a device. + +### Synopsis + +Reinstalls the provided device. The ID of the device to reinstall is required. + +``` +metal device reinstall -d [flags] +``` + +### Options + +``` + -h, --help help for reinstall + -d, --id string ID of device to be reinstalled + -O, --operating-system string Operating system name for the device + --preserve-data Avoid wiping data on disks where the os is *not* to be installed into +``` + +### Options inherited from parent commands + +``` + --config string Path to JSON or YAML configuration file + --exclude strings Comma separated Href references to collapse in results, may be dotted three levels deep + --filter stringArray Filter 'get' actions with name value pairs. Filter is not supported by all resources and is implemented as request query parameters. + --include strings Comma separated Href references to expand in results, may be dotted three levels deep + -o, --output string Output format (*table, json, yaml) + --search string Search keyword for use in 'get' actions. Search is not supported by all resources. + --sort-by string Sort fields for use in 'get' actions. Sort is not supported by all resources. + --sort-dir string Sort field direction for use in 'get' actions. Sort is not supported by all resources. + --token string Metal API Token (METAL_AUTH_TOKEN) +``` + +### SEE ALSO + +* [metal device](metal_device.md) - Device operations. For more information on provisioning on Equinix Metal, visit https://metal.equinix.com/developers/docs/deploy/. + diff --git a/internal/devices/device.go b/internal/devices/device.go index 8da6b3be..a3dc7199 100644 --- a/internal/devices/device.go +++ b/internal/devices/device.go @@ -38,7 +38,7 @@ func (c *Client) NewCommand() *cobra.Command { Use: `device`, Aliases: []string{"server", "servers", "devices"}, Short: "Device operations. For more information on provisioning on Equinix Metal, visit https://metal.equinix.com/developers/docs/deploy/.", - Long: "Device operations: create, get, update, delete, start, stop, and reboot.", + Long: "Device operations: create, get, update, delete, reinstall, start, stop, and reboot.", PersistentPreRun: func(cmd *cobra.Command, args []string) { if root := cmd.Root(); root != nil { @@ -57,6 +57,7 @@ func (c *Client) NewCommand() *cobra.Command { c.Delete(), c.Update(), c.Reboot(), + c.Reinstall(), c.Start(), c.Stop(), ) diff --git a/internal/devices/reinstall.go b/internal/devices/reinstall.go new file mode 100644 index 00000000..128ec3b2 --- /dev/null +++ b/internal/devices/reinstall.go @@ -0,0 +1,65 @@ +// Copyright © 2018 Jasmin Gacic +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package devices + +import ( + "fmt" + + "github.com/packethost/packngo" + "github.com/spf13/cobra" +) + +func (c *Client) Reinstall() *cobra.Command { + var ( + id string + + operatingSystem string + preserveData bool + ) + + reinstallDeviceCmd := &cobra.Command{ + Use: `reinstall -d `, + Short: "Reinstalls a device.", + Long: "Reinstalls the provided device. The ID of the device to reinstall is required.", + RunE: func(cmd *cobra.Command, args []string) error { + + request := packngo.DeviceReinstallFields{ + OperatingSystem: "", + PreserveData: preserveData, + DeprovisionFast: preserveData, + } + + _, err := c.Service.Reinstall(id, &request) + if err != nil { + err = fmt.Errorf("Could not reinstall Device: %w", err) + } + + return err + }, + } + reinstallDeviceCmd.Flags().StringVarP(&id, "id", "d", "", "ID of device to be reinstalled") + _ = reinstallDeviceCmd.MarkFlagRequired("id") + + reinstallDeviceCmd.Flags().StringVarP(&operatingSystem, "operating-system", "O", "", "Operating system name for the device") + reinstallDeviceCmd.Flags().BoolVarP(&preserveData, "preserve-data", "", false, "Avoid wiping data on disks where the os is *not* to be installed into") + + return reinstallDeviceCmd +}