Skip to content

Commit

Permalink
update to packngo-0.4.1 with Packet -> Equinix Metal renames
Browse files Browse the repository at this point in the history
Signed-off-by: Marques Johansson <[email protected]>
  • Loading branch information
displague committed Oct 8, 2020
1 parent a44f643 commit ffd0876
Show file tree
Hide file tree
Showing 61 changed files with 118 additions and 96 deletions.
2 changes: 1 addition & 1 deletion cmd/assign_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ packet ip assign -d [device-id] -a [ip-address]
`,
RunE: func(cmd *cobra.Command, args []string) error {
assignment, _, err := PacknGo.DeviceIPs.Assign(deviceID, &packngo.AddressStruct{Address: address})
assignment, _, err := apiClient.DeviceIPs.Assign(deviceID, &packngo.AddressStruct{Address: address})
if err != nil {
return errors.Wrap(err, "Could not assign Device IP address")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/attach_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ packet volume attach --id [volume_UUID] --device-id [device_UUID]
`,
RunE: func(cmd *cobra.Command, args []string) error {
a, _, err := PacknGo.VolumeAttachments.Create(volumeID, deviceID)
a, _, err := apiClient.VolumeAttachments.Create(volumeID, deviceID)
if err != nil {
return errors.Wrap(err, "Could not create volume attachment")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/available.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ packet ip available --reservation-id [reservation_id] --cidr [size_of_subnet]
`,
RunE: func(cmd *cobra.Command, args []string) error {
result, _, err := PacknGo.ProjectIPs.AvailableAddresses(reservationID, &packngo.AvailableRequest{CIDR: cidr})
result, _, err := apiClient.ProjectIPs.AvailableAddresses(reservationID, &packngo.AvailableRequest{CIDR: cidr})

if err != nil {
return errors.Wrap(err, "Could not get available IP addresses")
Expand Down
2 changes: 1 addition & 1 deletion cmd/check_capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ packet capacity check -f [facility] -p [plan] -q [quantity]
},
}

availability, _, err := PacknGo.CapacityService.Check(req)
availability, _, err := apiClient.CapacityService.Check(req)
if err != nil {
return errors.Wrap(err, "Could not check capacity")
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ var (
Version string = "devel"
)

const (
consumerToken = "Equinix Metal CLI"
apiTokenEnvVar = "PACKET_TOKEN"
apiURL = "https://api.equinix.com/metal/v1/"
)

// NewCli struct
func NewCli() *Cli {
var err error
cli := &Cli{}
cli.Client, err = packngo.NewClientWithBaseURL("Packet CLI", os.Getenv("PACKET_TOKEN"), nil, "https://api.packet.net/")
cli.Client, err = packngo.NewClientWithBaseURL(consumerToken, apiToken(), nil, apiURL)
if err != nil {
fmt.Println("Client error:", err)
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/completion.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2020 Packet, an Equinix Company Developers <help@packet.com>
Copyright © 2020 Equinix Metal Developers <support@equinixmetal.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
Expand Down
5 changes: 1 addition & 4 deletions cmd/create_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ var (
operatingSystem string
billingCycle string

storage string
userdata string
userdataFile string
customdata string
Expand Down Expand Up @@ -91,7 +90,6 @@ packet device create --hostname [hostname] --plan [plan] --facility [facility_co
OS: operatingSystem,
BillingCycle: billingCycle,
ProjectID: projectID,
Storage: storage,
UserData: userdata,
CustomData: customdata,
IPXEScriptURL: ipxescripturl,
Expand All @@ -104,7 +102,7 @@ packet device create --hostname [hostname] --plan [plan] --facility [facility_co
TerminationTime: endDt,
}

device, _, err := PacknGo.Devices.Create(request)
device, _, err := apiClient.Devices.Create(request)
if err != nil {
return errors.Wrap(err, "Could not create Device")
}
Expand All @@ -129,7 +127,6 @@ func init() {
_ = createDeviceCmd.MarkFlagRequired("hostname")
_ = createDeviceCmd.MarkFlagRequired("operating-system")

createDeviceCmd.Flags().StringVarP(&storage, "storage", "s", "", "UUID of the storage")
createDeviceCmd.Flags().StringVarP(&ipxescripturl, "ipxe-script-url", "i", "", "URL to the iPXE script")
createDeviceCmd.Flags().StringVarP(&userdata, "userdata", "u", "", "Userdata for device initialization (can not be used with --userdata-file)")
createDeviceCmd.Flags().StringVarP(&userdataFile, "userdata-file", "", "", "Path to a userdata file for device initialization (can not be used with --userdata)")
Expand Down
2 changes: 1 addition & 1 deletion cmd/create_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ packet organization create -n [name]
req.Logo = logo
}

org, _, err := PacknGo.Organizations.Create(req)
org, _, err := apiClient.Organizations.Create(req)
if err != nil {
return errors.Wrap(err, "Could not create Organization")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/create_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ packet project create --name [project_name]
req.PaymentMethodID = paymentMethodID
}

p, _, err := PacknGo.Projects.Create(&req)
p, _, err := apiClient.Projects.Create(&req)
if err != nil {
return errors.Wrap(err, "Could not create Project")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/create_ssh-key.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ packet ssh-key create --key [public_key] --label [label]
Key: key,
}

s, _, err := PacknGo.SSHKeys.Create(&req)
s, _, err := apiClient.SSHKeys.Create(&req)
if err != nil {
return errors.Wrap(err, "Could not create SSHKey")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/create_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ packet virtual-network create --project-id [project_UUID] --facility [facility_c
req.Description = description
}

n, _, err := PacknGo.ProjectVirtualNetworks.Create(req)
n, _, err := apiClient.ProjectVirtualNetworks.Create(req)
if err != nil {
return errors.Wrap(err, "Could not create ProjectVirtualNetwork")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/create_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var createVolumeCmd = &cobra.Command{
req.Locked = locked
}

v, _, err := PacknGo.Volumes.Create(req, projectID)
v, _, err := apiClient.Volumes.Create(req, projectID)
if err != nil {
return errors.Wrap(err, "Could not create Volume")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var deleteDeviceCmd = &cobra.Command{
}

func deleteDevice(id string) error {
_, err := PacknGo.Devices.Delete(id)
_, err := apiClient.Devices.Delete(id, force)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ packet organization delete -i [organization_UUID]
}

func deleteOrganization(id string) error {
_, err := PacknGo.Organizations.Delete(id)
_, err := apiClient.Organizations.Delete(id)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ packet project delete --id [project_UUID]
}

func deleteProject(id string) error {
_, err := PacknGo.Projects.Delete(id)
_, err := apiClient.Projects.Delete(id)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete_ssh-key.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ packet ssh-key delete --id [ssh-key_UUID]
}

func deleteSSHKey(id string) error {
_, err := PacknGo.SSHKeys.Delete(id)
_, err := apiClient.SSHKeys.Delete(id)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ packet virtual-network delete -i [virtual_network_UUID]
}

func deleteVnet(id string) error {
_, err := PacknGo.ProjectVirtualNetworks.Delete(id)
_, err := apiClient.ProjectVirtualNetworks.Delete(id)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ packet volume delete --id [volume_UUID]
}

func deleteVolume(id string) error {
_, err := PacknGo.Volumes.Delete(id)
_, err := apiClient.Volumes.Delete(id)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/detach_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ packet volume detach --id [attachment_UUID]
`,
RunE: func(cmd *cobra.Command, args []string) error {
_, err := PacknGo.VolumeAttachments.Delete(attachmentID)
_, err := apiClient.VolumeAttachments.Delete(attachmentID)
if err != nil {
return errors.Wrap(err, "Could not detach Volume")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/disable2fa.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ packet 2fa disable -a -t [token]
if sms == app {
return fmt.Errorf("Either sms or app should be set")
} else if sms {
_, err := PacknGo.TwoFactorAuth.DisableSms(token)
_, err := apiClient.TwoFactorAuth.DisableSms(token)
if err != nil {
return errors.Wrap(err, "Could not disable Two-Factor Authentication via SMS")
}
} else if app {
_, err := PacknGo.TwoFactorAuth.DisableApp(token)
_, err := apiClient.TwoFactorAuth.DisableApp(token)
if err != nil {
return errors.Wrap(err, "Could not disable Two-Factor Authentication via App")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/disable_vpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Disable VPN service:
packet vpn disable
`,
RunE: func(cmd *cobra.Command, args []string) error {
_, err := PacknGo.VPN.Disable()
_, err := apiClient.VPN.Disable()
if err != nil {
return errors.Wrap(err, "Could not disable VPN service")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/docs.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2020 Packet, an Equinix Company Developers <help@packet.com>
Copyright © 2020 Equinix Metal Developers <support@equinixmetal.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
Expand Down
4 changes: 2 additions & 2 deletions cmd/enable2fa.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ packet 2fa enable -a -t [token]
if sms == app {
return fmt.Errorf("Either sms or app should be set")
} else if sms {
_, err := PacknGo.TwoFactorAuth.EnableSms(token)
_, err := apiClient.TwoFactorAuth.EnableSms(token)
if err != nil {
return errors.Wrap(err, "Could not enable Two-Factor Authentication")
}
} else if app {
_, err := PacknGo.TwoFactorAuth.EnableApp(token)
_, err := apiClient.TwoFactorAuth.EnableApp(token)
if err != nil {
return errors.Wrap(err, "Could not enable Two-Factor Authentication")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/enable_vpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Enable VPN service:
packet vpn enable
`,
RunE: func(cmd *cobra.Command, args []string) error {
_, err := PacknGo.VPN.Enable()
_, err := apiClient.VPN.Enable()
if err != nil {
return errors.Wrap(err, "Could not enable VPN Service")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/move_hardware_reservation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ packet hardware_reservation move -i [hardware_reservation_UUID] -p [project_UUID
`,
RunE: func(cmd *cobra.Command, args []string) error {
header := []string{"ID", "Facility", "Plan", "Created"}
r, _, err := PacknGo.HardwareReservations.Move(hardwareReservationID, projectID)
r, _, err := apiClient.HardwareReservations.Move(hardwareReservationID, projectID)
if err != nil {
return errors.Wrap(err, "Could not move Hardware Reservation")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/payment_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ packet organization get payment-methods --id [organization_UUID]
`,
RunE: func(cmd *cobra.Command, args []string) error {
paymentMethods, _, err := PacknGo.Organizations.ListPaymentMethods(organizationID)
paymentMethods, _, err := apiClient.Organizations.ListPaymentMethods(organizationID)
if err != nil {
return errors.Wrap(err, "Could not list Payment Methods")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/reboot_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ packet device reboot --id [device_UUID]
`,
RunE: func(cmd *cobra.Command, args []string) error {
_, err := PacknGo.Devices.Reboot(deviceID)
_, err := apiClient.Devices.Reboot(deviceID)
if err != nil {
return errors.Wrap(err, "Could not reboot Device")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/receive_2fa.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ packet 2fa receive -a
}

if sms {
_, err := PacknGo.TwoFactorAuth.ReceiveSms()
_, err := apiClient.TwoFactorAuth.ReceiveSms()
if err != nil {
return errors.Wrap(err, "Could not issue token via SMS")
}
Expand All @@ -57,7 +57,7 @@ packet 2fa receive -a
return nil
}

otpURI, _, err := PacknGo.TwoFactorAuth.SeedApp()
otpURI, _, err := apiClient.TwoFactorAuth.SeedApp()
if err != nil {
return errors.Wrap(err, "Could not get the OTP Seed URI")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/remove_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ packet ip remove --id [reservation-UUID]
`,
RunE: func(cmd *cobra.Command, args []string) error {
_, err := PacknGo.ProjectIPs.Remove(reservationID)
_, err := apiClient.ProjectIPs.Remove(reservationID)
if err != nil {
return errors.Wrap(err, "Could not remove IP address Reservation")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/request_ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ packet ip request --quantity [quantity] --facility [facility_code] --type [addre
Facility: &facility,
}

reservation, _, err := PacknGo.ProjectIPs.Request(projectID, req)
reservation, _, err := apiClient.ProjectIPs.Request(projectID, req)
if err != nil {
return errors.Wrap(err, "Could not request IP addresses")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/retrieve_capacity.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ packet capacity get
`,
RunE: func(cmd *cobra.Command, args []string) error {
var err error
capacities, _, err := PacknGo.CapacityService.List()
capacities, _, err := apiClient.CapacityService.List()
if err != nil {
return errors.Wrap(err, "Could not get Capacity")
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/retrieve_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ packet device get --id [device_UUID]
} else if deviceID == "" && projectID == "" {
return fmt.Errorf("Either id or project-id should be set.")
} else if projectID != "" {
devices, _, err := PacknGo.Devices.List(projectID, listOptions(nil, nil))
devices, _, err := apiClient.Devices.List(projectID, listOptions(nil, nil))
if err != nil {
return errors.Wrap(err, "Could not list Devices")
}
Expand All @@ -59,7 +59,7 @@ packet device get --id [device_UUID]

return output(devices, header, &data)
} else if deviceID != "" {
device, _, err := PacknGo.Devices.Get(deviceID, nil)
device, _, err := apiClient.Devices.Get(deviceID, nil)
if err != nil {
return errors.Wrap(err, "Could not get Devices")
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/retrieve_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@ When using "--json" or "--yaml", "--include=relationships" is implied.
if deviceID != "" && projectID != "" && organizationID != "" && eventID != "" {
return fmt.Errorf("The id, project-id, device-id, and organization-id parameters are mutually exclusive")
} else if deviceID != "" {
events, _, err = PacknGo.Devices.ListEvents(deviceID, listOpt)
events, _, err = apiClient.Devices.ListEvents(deviceID, listOpt)
if err != nil {
return errors.Wrap(err, "Could not list Device Events")
}
} else if projectID != "" {
events, _, err = PacknGo.Projects.ListEvents(projectID, listOpt)
events, _, err = apiClient.Projects.ListEvents(projectID, listOpt)
if err != nil {
return errors.Wrap(err, "Could not list Project Events")
}
} else if organizationID != "" {
events, _, err = PacknGo.Organizations.ListEvents(organizationID, listOpt)
events, _, err = apiClient.Organizations.ListEvents(organizationID, listOpt)
if err != nil {
return errors.Wrap(err, "Could not list Organization Events")
}
} else if eventID != "" {
getOpt := &packngo.GetOptions{Includes: listOpt.Includes}
event, _, err := PacknGo.Events.Get(eventID, getOpt)
event, _, err := apiClient.Events.Get(eventID, getOpt)
if err != nil {
return errors.Wrap(err, "Could not get Event")
}
Expand All @@ -96,7 +96,7 @@ When using "--json" or "--yaml", "--include=relationships" is implied.
data[0] = []string{event.ID, event.Body, event.Type, event.CreatedAt.String()}
return output(event, header, &data)
} else {
events, _, err = PacknGo.Events.List(listOpt)
events, _, err = apiClient.Events.List(listOpt)
if err != nil {
return errors.Wrap(err, "Could not list Events")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/retrieve_facilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ packet facilities get
`,
RunE: func(cmd *cobra.Command, args []string) error {
facilities, _, err := PacknGo.Facilities.List(listOptions(nil, nil))
facilities, _, err := apiClient.Facilities.List(listOptions(nil, nil))
if err != nil {
return errors.Wrap(err, "Could not list Facilities")
}
Expand Down
Loading

0 comments on commit ffd0876

Please sign in to comment.