-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from mmlb/reinstall
Add support for device reinstall
- Loading branch information
Showing
5 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
metal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <device-id> [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/. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright © 2018 Jasmin Gacic <jasmin@stackpointcloud.com> | ||
// | ||
// 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 <device-id>`, | ||
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 | ||
} |