Skip to content

Commit

Permalink
Fix: Resetting always_pxe flag as per user configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
codinja1188 committed Aug 14, 2023
1 parent 02057d8 commit a10376a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 11 deletions.
66 changes: 56 additions & 10 deletions internal/devices/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"context"
"fmt"
"os"
"time"

metal "github.com/equinix-labs/metal-go/metal/v1"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -75,18 +76,17 @@ func (c *Client) Create() *cobra.Command {
}
userdata = string(userdataRaw)
}
// var endDt time.Time

// if terminationTime != "" {
// parsedTime, err := time.Parse(time.RFC3339, terminationTime)
// if err != nil {
// return fmt.Errorf("could not parse time %q: %w", terminationTime, err)
// }
// endDt = parsedTime
// }
var endDt time.Time

if terminationTime != "" {
parsedTime, err := time.Parse(time.RFC3339, terminationTime)
if err != nil {
return fmt.Errorf("could not parse time %q: %w", terminationTime, err)
}
endDt = parsedTime
}
var facilityArgs []string

// var deviceCreateInFacilityInput *metal.DeviceCreateInFacilityInput
var request metal.ApiCreateDeviceRequest
if facility != "" {
facilityArgs = append(facilityArgs, facility)
Expand All @@ -99,8 +99,33 @@ func (c *Client) Create() *cobra.Command {
Hostname: &hostname,
},
}

if billingCycle != "" {
facilityDeviceRequest.DeviceCreateInFacilityInput.SetBillingCycle(billingCycle)
}
if userdata != "" && userdataFile != "" {
facilityDeviceRequest.DeviceCreateInFacilityInput.SetUserdata(userdata)
}

facilityDeviceRequest.DeviceCreateInFacilityInput.SetAlwaysPxe(alwaysPXE)

if ipxescripturl != "" {
facilityDeviceRequest.DeviceCreateInFacilityInput.SetIpxeScriptUrl(ipxescripturl)
}

publicSubnet := int32(publicIPv4SubnetSize)
facilityDeviceRequest.DeviceCreateInFacilityInput.SetPublicIpv4SubnetSize(publicSubnet)
facilityDeviceRequest.DeviceCreateInFacilityInput.SetTerminationTime(endDt)
facilityDeviceRequest.DeviceCreateInFacilityInput.SetTags(tags)
facilityDeviceRequest.DeviceCreateInFacilityInput.SetSpotInstance(spotInstance)
facilityDeviceRequest.DeviceCreateInFacilityInput.SetSpotPriceMax(float32(spotPriceMax))
if hardwareReservationID != "" {
facilityDeviceRequest.DeviceCreateInFacilityInput.SetHardwareReservationId(hardwareReservationID)
}

request = c.Service.CreateDevice(context.Background(), projectID).CreateDeviceRequest(facilityDeviceRequest).Include(nil).Exclude(nil)
}

if metro != "" {

metroDeviceRequest := metal.CreateDeviceRequest{
Expand All @@ -111,7 +136,28 @@ func (c *Client) Create() *cobra.Command {
Hostname: &hostname,
},
}
if billingCycle != "" {
metroDeviceRequest.DeviceCreateInMetroInput.SetBillingCycle(billingCycle)
}
if userdata != "" && userdataFile != "" {
metroDeviceRequest.DeviceCreateInMetroInput.SetUserdata(userdata)
}

metroDeviceRequest.DeviceCreateInMetroInput.SetAlwaysPxe(alwaysPXE)

if ipxescripturl != "" {
metroDeviceRequest.DeviceCreateInMetroInput.SetIpxeScriptUrl(ipxescripturl)
}

publicSubnet := int32(publicIPv4SubnetSize)
metroDeviceRequest.DeviceCreateInMetroInput.SetPublicIpv4SubnetSize(publicSubnet)
metroDeviceRequest.DeviceCreateInMetroInput.SetTerminationTime(endDt)
metroDeviceRequest.DeviceCreateInMetroInput.SetTags(tags)
metroDeviceRequest.DeviceCreateInMetroInput.SetSpotInstance(spotInstance)
metroDeviceRequest.DeviceCreateInMetroInput.SetSpotPriceMax(float32(spotPriceMax))
if hardwareReservationID != "" {
metroDeviceRequest.DeviceCreateInMetroInput.SetHardwareReservationId(hardwareReservationID)
}
request = c.Service.CreateDevice(context.Background(), projectID).CreateDeviceRequest(metroDeviceRequest).Include(nil).Exclude(nil)
}
device, _, err := request.Execute()
Expand Down
8 changes: 7 additions & 1 deletion internal/devices/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,14 @@ func (c *Client) Update() *cobra.Command {
deviceUpdate.Tags = tags
}

if f := cmd.Flag("always-pxe"); f.Changed {
deviceUpdate.SetAlwaysPxe(true)
}

if alwaysPXE {
deviceUpdate.AlwaysPxe = &alwaysPXE
deviceUpdate.SetAlwaysPxe(true)
} else {
deviceUpdate.SetAlwaysPxe(false)
}

if ipxescripturl != "" {
Expand Down

0 comments on commit a10376a

Please sign in to comment.