Skip to content

Commit

Permalink
fix: For Resetting always_pxe flag
Browse files Browse the repository at this point in the history
  • Loading branch information
codinja1188 committed Oct 17, 2023
1 parent 230615a commit 33b13fa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/metal_device_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metal device create -p <project_id> (-m <metro> | -f <facility>) -P <plan> -H <h
### Options

```
-a, --always-pxe Sets whether the device always PXE boots on reboot.
-a, --always-pxe string Sets whether the device always PXE boots on reboot.
-b, --billing-cycle string Billing cycle (default "hourly")
-c, --customdata string Custom data to be included with your device's metadata.
-f, --facility string Code of the facility where the device will be created
Expand Down
2 changes: 1 addition & 1 deletion docs/metal_device_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ metal device update -i <device_id> [-H <hostname>] [-d <description>] [--locked
### Options

```
-a, --always-pxe Sets the device to always iPXE on reboot.
-a, --always-pxe string Sets the device to always iPXE on reboot.
-c, --customdata string Adds or updates custom data to be included with your device's metadata.
-d, --description string Adds or updates the description for the device.
-h, --help help for update
Expand Down
24 changes: 18 additions & 6 deletions internal/devices/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"
"time"

metal "github.com/equinix-labs/metal-go/metal/v1"
Expand All @@ -48,7 +49,7 @@ func (c *Client) Create() *cobra.Command {
tags []string
ipxescripturl string
publicIPv4SubnetSize int
alwaysPXE bool
alwaysPXE string
hardwareReservationID string
spotInstance bool
spotPriceMax float64
Expand Down Expand Up @@ -125,8 +126,14 @@ func (c *Client) Create() *cobra.Command {
if billingCycle != "" {
facilityDeviceRequest.DeviceCreateInFacilityInput.SetBillingCycle(*validBillingCycle)
}
if alwaysPXE {
facilityDeviceRequest.DeviceCreateInFacilityInput.SetAlwaysPxe(alwaysPXE)
if alwaysPXE != "" {
if strings.Compare(alwaysPXE, "true") == 0 {
facilityDeviceRequest.DeviceCreateInFacilityInput.SetAlwaysPxe(true)
}

if strings.Compare(alwaysPXE, "false") == 0 {
facilityDeviceRequest.DeviceCreateInFacilityInput.SetAlwaysPxe(false)
}
}

if ipxescripturl != "" {
Expand Down Expand Up @@ -165,8 +172,13 @@ func (c *Client) Create() *cobra.Command {
metroDeviceRequest.DeviceCreateInMetroInput.SetBillingCycle(*validBillingCycle)
}

if alwaysPXE {
metroDeviceRequest.DeviceCreateInMetroInput.SetAlwaysPxe(alwaysPXE)
if alwaysPXE != "" {
if strings.Compare(alwaysPXE, "true") == 0 {
metroDeviceRequest.DeviceCreateInMetroInput.SetAlwaysPxe(true)
}
if strings.Compare(alwaysPXE, "false") == 0 {
metroDeviceRequest.DeviceCreateInMetroInput.SetAlwaysPxe(false)
}
}

if ipxescripturl != "" {
Expand Down Expand Up @@ -219,7 +231,7 @@ func (c *Client) Create() *cobra.Command {
createDeviceCmd.Flags().IntVarP(&publicIPv4SubnetSize, "public-ipv4-subnet-size", "S", 0, "Size of the public IPv4 subnet.")
createDeviceCmd.Flags().StringVarP(&hardwareReservationID, "hardware-reservation-id", "r", "", "The UUID of a hardware reservation, if you are provisioning a server from your reserved hardware.")
createDeviceCmd.Flags().StringVarP(&billingCycle, "billing-cycle", "b", "hourly", "Billing cycle ")
createDeviceCmd.Flags().BoolVarP(&alwaysPXE, "always-pxe", "a", false, "Sets whether the device always PXE boots on reboot.")
createDeviceCmd.Flags().StringVarP(&alwaysPXE, "always-pxe", "a", "", "Sets whether the device always PXE boots on reboot.")
createDeviceCmd.Flags().BoolVarP(&spotInstance, "spot-instance", "s", false, "Provisions the device as a spot instance.")
createDeviceCmd.Flags().Float64VarP(&spotPriceMax, "spot-price-max", "", 0, `Sets the maximum spot market price for the device: --spot-price-max=1.2`)
createDeviceCmd.Flags().StringVarP(&terminationTime, "termination-time", "T", "", `Device termination time: --termination-time="2023-08-24T15:04:05Z"`)
Expand Down
14 changes: 10 additions & 4 deletions internal/devices/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"

metal "github.com/equinix-labs/metal-go/metal/v1"

Expand All @@ -37,7 +38,7 @@ func (c *Client) Update() *cobra.Command {
userdata string
hostname string
tags []string
alwaysPXE bool
alwaysPXE string
ipxescripturl string
customdata string
deviceID string
Expand Down Expand Up @@ -74,8 +75,13 @@ func (c *Client) Update() *cobra.Command {
deviceUpdate.Tags = tags
}

if alwaysPXE {
deviceUpdate.SetAlwaysPxe(alwaysPXE)
if alwaysPXE != "" {
if strings.Compare(alwaysPXE, "true") == 0 {
deviceUpdate.SetAlwaysPxe(true)
}
if strings.Compare(alwaysPXE, "false") == 0 {
deviceUpdate.SetAlwaysPxe(false)
}
}

if ipxescripturl != "" {
Expand Down Expand Up @@ -110,7 +116,7 @@ func (c *Client) Update() *cobra.Command {
updateDeviceCmd.Flags().StringVarP(&userdata, "userdata", "u", "", "Adds or updates the userdata for the device.")
updateDeviceCmd.Flags().BoolVarP(&locked, "locked", "l", false, "Locks or unlocks the device for future changes.")
updateDeviceCmd.Flags().StringSliceVarP(&tags, "tags", "t", []string{}, `Adds or updates the tags for the device --tags="tag1,tag2".`)
updateDeviceCmd.Flags().BoolVarP(&alwaysPXE, "always-pxe", "a", false, "Sets the device to always iPXE on reboot.")
updateDeviceCmd.Flags().StringVarP(&alwaysPXE, "always-pxe", "a", "", "Sets the device to always iPXE on reboot.")
updateDeviceCmd.Flags().StringVarP(&ipxescripturl, "ipxe-script-url", "s", "", "Add or update the URL of the iPXE script.")
updateDeviceCmd.Flags().StringVarP(&customdata, "customdata", "c", "", "Adds or updates custom data to be included with your device's metadata.")
_ = updateDeviceCmd.MarkFlagRequired("id")
Expand Down

0 comments on commit 33b13fa

Please sign in to comment.