diff --git a/docs/platform-packet.md b/docs/platform-packet.md index 36588094f..d92e85b96 100644 --- a/docs/platform-packet.md +++ b/docs/platform-packet.md @@ -22,6 +22,17 @@ The `linuxkit run packet` command can mostly either be configured via command line options or with environment variables. see `linuxkit run packet --help` for the options and environment variables. +By default, `linuxkit run` will provision a new machine and remove it +once you are done. With the `-keep` option the provisioned machine +will not be removed. You can then use the `-device` option with the +device ID on subsequent `linuxkit run` invocations to re-use an +existing machine. These subsequent runs will update the iPXE data so +you can boot alternative kernels on an existing machine. + +**Note**: The update of the iPXE configuration sometimes may take some +time and the first boot may fail. Hitting return on the console to +retry the boot typically fixes this. + ## Boot LinuxKit on Packet boots the `kernel+initrd` output from moby @@ -67,6 +78,9 @@ Packet requires `ssh` access, i.e., you must have uploaded your SSH keys to Packet beforehand. +You can exit the console vi `~.` on a new line once you are +disconnected from the serial, e.g. after poweroff. + **Note**: We also require that the Packet SOS host is in your `known_hosts` file, otherwise the connection to the console will fail. There is a Packet SOS host per zone. diff --git a/src/cmd/linuxkit/run_packet.go b/src/cmd/linuxkit/run_packet.go index eebf293d8..3de5a89c3 100644 --- a/src/cmd/linuxkit/run_packet.go +++ b/src/cmd/linuxkit/run_packet.go @@ -16,7 +16,7 @@ import ( "path/filepath" "time" - "github.com/packethost/packngo" + "github.com/rn/packngo" log "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/agent" @@ -60,6 +60,7 @@ func runPacket(args []string) { machineFlag := flags.String("machine", packetDefaultMachine, "Packet Machine Type (or "+packetMachineVar+")") apiKeyFlag := flags.String("api-key", "", "Packet API key (or "+packetAPIKeyVar+")") projectFlag := flags.String("project-id", "", "Packet Project ID (or "+packetProjectIDVar+")") + deviceFlag := flags.String("device", "", "The ID of an existing device") hostNameFlag := flags.String("hostname", packetDefaultHostname, "Hostname of new instance (or "+packetHostnameVar+")") nameFlag := flags.String("img-name", "", "Overrides the prefix used to identify the files. Defaults to [name] (or "+packetNameVar+")") alwaysPXE := flags.Bool("always-pxe", true, "Reboot from PXE every time.") @@ -150,20 +151,52 @@ func runPacket(args []string) { client := packngo.NewClient("", apiKey, nil) tags := []string{} - req := packngo.DeviceCreateRequest{ - HostName: hostname, - Plan: plan, - Facility: facility, - OS: osType, - BillingCycle: billing, - ProjectID: projectID, - UserData: userData, - Tags: tags, - AlwaysPXE: *alwaysPXE, - } - dev, _, err := client.Devices.Create(&req) - if err != nil { - log.Fatal(err) + + var dev *packngo.Device + var err error + if *deviceFlag != "" { + dev, _, err = client.Devices.Get(*deviceFlag) + if err != nil { + log.Fatalf("Getting info for device %s failed: %v", *deviceFlag, err) + } + b, err := json.MarshalIndent(dev, "", " ") + if err != nil { + log.Fatal(err) + } + log.Debugf("%s\n", string(b)) + + req := packngo.DeviceUpdateRequest{ + HostName: hostname, + BillingCycle: dev.BillingCycle, + UserData: userData, + Locked: dev.Locked, + Tags: dev.Tags, + AlwaysPXE: *alwaysPXE, + } + dev, _, err = client.Devices.Update(*deviceFlag, &req) + if err != nil { + log.Fatalf("Update device %s failed: %v", *deviceFlag, err) + } + if _, err := client.Devices.Reboot(*deviceFlag); err != nil { + log.Fatalf("Rebooting device %s failed: %v", *deviceFlag, err) + } + } else { + // Create a new device + req := packngo.DeviceCreateRequest{ + HostName: hostname, + Plan: plan, + Facility: facility, + OS: osType, + BillingCycle: billing, + ProjectID: projectID, + UserData: userData, + Tags: tags, + AlwaysPXE: *alwaysPXE, + } + dev, _, err = client.Devices.Create(&req) + if err != nil { + log.Fatalf("Creating device failed: %v", err) + } } b, err := json.MarshalIndent(dev, "", " ") if err != nil { @@ -200,12 +233,15 @@ func runPacket(args []string) { httpServer.Shutdown(ctx) } - if !*keepFlag { + if *keepFlag { + log.Printf("The machine is kept...") + log.Printf("Device ID: %s", dev.ID) + log.Printf("Serial: ssh %s@%s", dev.ID, sshHost) + } else { if _, err := client.Devices.Delete(dev.ID); err != nil { log.Fatalf("Unable to delete device: %v", err) } } - } // validateHTTPURL does a sanity check that a URL returns a 200 or 300 response diff --git a/src/cmd/linuxkit/vendor.conf b/src/cmd/linuxkit/vendor.conf index ac3ed2b4b..0cb7c403c 100644 --- a/src/cmd/linuxkit/vendor.conf +++ b/src/cmd/linuxkit/vendor.conf @@ -13,10 +13,10 @@ github.com/gophercloud/gophercloud 2804b72cf099b41d2e25c8afcca786f9f962ddee github.com/jmespath/go-jmespath bd40a432e4c76585ef6b72d3fd96fb9b6dc7b68d github.com/mitchellh/go-ps 4fdf99ab29366514c69ccccddab5dc58b8d84062 github.com/moby/hyperkit a82b409a87f12fa3306813410c37f4eed270efac -github.com/packethost/packngo 9d9409c8c09de7695281e900a776cca03676026a github.com/radu-matei/azure-sdk-for-go 3b12823551999669c9a325a32472508e0af7978e github.com/radu-matei/azure-vhd-utils e52754d5569d2a643a7775f72ff2a6cf524f4c25 github.com/rn/iso9660wrap 4606f848a055435cdef85305960b0e1bb788d506 +github.com/rn/packngo eacc1098296fb3d75607a13e2607474ce40f55b9 github.com/sirupsen/logrus 1.0.2 github.com/vmware/govmomi 6f8ebd89d521d9f9af7a6c2219c4deee511020dd golang.org/x/crypto 573951cbe80bb6352881271bb276f48749eab6f4 diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/LICENSE.txt b/src/cmd/linuxkit/vendor/github.com/rn/packngo/LICENSE.txt similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/LICENSE.txt rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/LICENSE.txt diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/README.md b/src/cmd/linuxkit/vendor/github.com/rn/packngo/README.md similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/README.md rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/README.md diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/devices.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/devices.go similarity index 85% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/devices.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/devices.go index a016f6757..7d347d762 100644 --- a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/devices.go +++ b/src/cmd/linuxkit/vendor/github.com/rn/packngo/devices.go @@ -9,6 +9,7 @@ type DeviceService interface { List(ProjectID string) ([]Device, *Response, error) Get(string) (*Device, *Response, error) Create(*DeviceCreateRequest) (*Device, *Response, error) + Update(string, *DeviceUpdateRequest) (*Device, *Response, error) Delete(string) (*Response, error) Reboot(string) (*Response, error) PowerOff(string) (*Response, error) @@ -38,6 +39,7 @@ type Device struct { Facility *Facility `json:"facility,omitempty"` Project *Project `json:"project,omitempty"` ProvisionPer float32 `json:"provisioning_percentage,omitempty"` + UserData string `json:"userdata",omitempty` IPXEScriptUrl string `json:"ipxe_script_url,omitempty"` AlwaysPXE bool `json:"always_pxe,omitempty"` } @@ -61,6 +63,18 @@ type DeviceCreateRequest struct { 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 { return Stringify(d) } @@ -133,6 +147,24 @@ func (s *DeviceServiceOp) Create(createRequest *DeviceCreateRequest) (*Device, * 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 func (s *DeviceServiceOp) Delete(deviceID string) (*Response, error) { path := fmt.Sprintf("%s/%s", deviceBasePath, deviceID) diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/email.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/email.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/email.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/email.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/facilities.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/facilities.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/facilities.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/facilities.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/ip.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/ip.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/ip.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/ip.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/operatingsystems.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/operatingsystems.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/operatingsystems.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/operatingsystems.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/packngo.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/packngo.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/packngo.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/packngo.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/plans.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/plans.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/plans.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/plans.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/projects.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/projects.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/projects.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/projects.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/rate.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/rate.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/rate.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/rate.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/sshkeys.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/sshkeys.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/sshkeys.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/sshkeys.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/timestamp.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/timestamp.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/timestamp.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/timestamp.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/user.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/user.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/user.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/user.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/utils.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/utils.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/utils.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/utils.go diff --git a/src/cmd/linuxkit/vendor/github.com/packethost/packngo/volumes.go b/src/cmd/linuxkit/vendor/github.com/rn/packngo/volumes.go similarity index 100% rename from src/cmd/linuxkit/vendor/github.com/packethost/packngo/volumes.go rename to src/cmd/linuxkit/vendor/github.com/rn/packngo/volumes.go