cmd: Temporarily use my fork of the packet.net API

This adds a new call to update an existing device.

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
Rolf Neugebauer 2017-08-16 12:08:56 +01:00
parent 44c4ea5dba
commit d246ea9130
18 changed files with 34 additions and 2 deletions

View File

@ -16,7 +16,7 @@ import (
"path/filepath" "path/filepath"
"time" "time"
"github.com/packethost/packngo" "github.com/rn/packngo"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent" "golang.org/x/crypto/ssh/agent"

View File

@ -13,10 +13,10 @@ github.com/gophercloud/gophercloud 2804b72cf099b41d2e25c8afcca786f9f962ddee
github.com/jmespath/go-jmespath bd40a432e4c76585ef6b72d3fd96fb9b6dc7b68d github.com/jmespath/go-jmespath bd40a432e4c76585ef6b72d3fd96fb9b6dc7b68d
github.com/mitchellh/go-ps 4fdf99ab29366514c69ccccddab5dc58b8d84062 github.com/mitchellh/go-ps 4fdf99ab29366514c69ccccddab5dc58b8d84062
github.com/moby/hyperkit a82b409a87f12fa3306813410c37f4eed270efac github.com/moby/hyperkit a82b409a87f12fa3306813410c37f4eed270efac
github.com/packethost/packngo 9d9409c8c09de7695281e900a776cca03676026a
github.com/radu-matei/azure-sdk-for-go 3b12823551999669c9a325a32472508e0af7978e github.com/radu-matei/azure-sdk-for-go 3b12823551999669c9a325a32472508e0af7978e
github.com/radu-matei/azure-vhd-utils e52754d5569d2a643a7775f72ff2a6cf524f4c25 github.com/radu-matei/azure-vhd-utils e52754d5569d2a643a7775f72ff2a6cf524f4c25
github.com/rn/iso9660wrap 4606f848a055435cdef85305960b0e1bb788d506 github.com/rn/iso9660wrap 4606f848a055435cdef85305960b0e1bb788d506
github.com/rn/packngo eacc1098296fb3d75607a13e2607474ce40f55b9
github.com/sirupsen/logrus 1.0.2 github.com/sirupsen/logrus 1.0.2
github.com/vmware/govmomi 6f8ebd89d521d9f9af7a6c2219c4deee511020dd github.com/vmware/govmomi 6f8ebd89d521d9f9af7a6c2219c4deee511020dd
golang.org/x/crypto 573951cbe80bb6352881271bb276f48749eab6f4 golang.org/x/crypto 573951cbe80bb6352881271bb276f48749eab6f4

View File

@ -9,6 +9,7 @@ type DeviceService interface {
List(ProjectID string) ([]Device, *Response, error) List(ProjectID string) ([]Device, *Response, error)
Get(string) (*Device, *Response, error) Get(string) (*Device, *Response, error)
Create(*DeviceCreateRequest) (*Device, *Response, error) Create(*DeviceCreateRequest) (*Device, *Response, error)
Update(string, *DeviceUpdateRequest) (*Device, *Response, error)
Delete(string) (*Response, error) Delete(string) (*Response, error)
Reboot(string) (*Response, error) Reboot(string) (*Response, error)
PowerOff(string) (*Response, error) PowerOff(string) (*Response, error)
@ -38,6 +39,7 @@ type Device struct {
Facility *Facility `json:"facility,omitempty"` Facility *Facility `json:"facility,omitempty"`
Project *Project `json:"project,omitempty"` Project *Project `json:"project,omitempty"`
ProvisionPer float32 `json:"provisioning_percentage,omitempty"` ProvisionPer float32 `json:"provisioning_percentage,omitempty"`
UserData string `json:"userdata",omitempty`
IPXEScriptUrl string `json:"ipxe_script_url,omitempty"` IPXEScriptUrl string `json:"ipxe_script_url,omitempty"`
AlwaysPXE bool `json:"always_pxe,omitempty"` AlwaysPXE bool `json:"always_pxe,omitempty"`
} }
@ -61,6 +63,18 @@ type DeviceCreateRequest struct {
AlwaysPXE bool `json:"always_pxe,omitempty"` AlwaysPXE bool `json:"always_pxe,omitempty"`
} }
// DeviceUpdateRequest type used to update a Packet device
type DeviceUpdateRequest struct {
HostName string `json:"hostname"`
Description string `json:"description"`
BillingCycle string `json:"billing_cycle"`
UserData string `json:"userdata"`
Locked bool `json:"locked"`
Tags []string `json:"tags"`
AlwaysPXE bool `json:"always_pxe,omitempty"`
IPXEScriptUrl string `json:"ipxe_script_url,omitempty"`
}
func (d DeviceCreateRequest) String() string { func (d DeviceCreateRequest) String() string {
return Stringify(d) return Stringify(d)
} }
@ -133,6 +147,24 @@ func (s *DeviceServiceOp) Create(createRequest *DeviceCreateRequest) (*Device, *
return device, resp, err return device, resp, err
} }
// Update updates an existing device
func (s *DeviceServiceOp) Update(deviceID string, updateRequest *DeviceUpdateRequest) (*Device, *Response, error) {
path := fmt.Sprintf("%s/%s?include=facility", deviceBasePath, deviceID)
req, err := s.client.NewRequest("PUT", path, updateRequest)
if err != nil {
return nil, nil, err
}
device := new(Device)
resp, err := s.client.Do(req, device)
if err != nil {
return nil, resp, err
}
return device, resp, err
}
// Delete deletes a device // Delete deletes a device
func (s *DeviceServiceOp) Delete(deviceID string) (*Response, error) { func (s *DeviceServiceOp) Delete(deviceID string) (*Response, error) {
path := fmt.Sprintf("%s/%s", deviceBasePath, deviceID) path := fmt.Sprintf("%s/%s", deviceBasePath, deviceID)