mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-09-08 10:21:27 +00:00
cmd: Remove the packet machine when done
Adds a new option, '-keep' which will keep the machine around, but by default remove the machine when done. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
@@ -66,6 +66,7 @@ func runPacket(args []string) {
|
|||||||
alwaysPXE := flags.Bool("always-pxe", true, "Reboot from PXE every time.")
|
alwaysPXE := flags.Bool("always-pxe", true, "Reboot from PXE every time.")
|
||||||
serveFlag := flags.String("serve", "", "Serve local files via the http port specified, e.g. ':8080'.")
|
serveFlag := flags.String("serve", "", "Serve local files via the http port specified, e.g. ':8080'.")
|
||||||
consoleFlag := flags.Bool("console", true, "Provide interactive access on the console.")
|
consoleFlag := flags.Bool("console", true, "Provide interactive access on the console.")
|
||||||
|
keepFlag := flags.Bool("keep", false, "Keep the machine after exiting/poweroff.")
|
||||||
if err := flags.Parse(args); err != nil {
|
if err := flags.Parse(args); err != nil {
|
||||||
log.Fatal("Unable to parse args")
|
log.Fatal("Unable to parse args")
|
||||||
}
|
}
|
||||||
@@ -95,6 +96,10 @@ func runPacket(args []string) {
|
|||||||
osType := "custom_ipxe"
|
osType := "custom_ipxe"
|
||||||
billing := "hourly"
|
billing := "hourly"
|
||||||
|
|
||||||
|
if !*keepFlag && !*consoleFlag {
|
||||||
|
log.Fatalf("Combination of keep=%t and console=%t makes little sense", *keepFlag, *consoleFlag)
|
||||||
|
}
|
||||||
|
|
||||||
// Read kernel command line
|
// Read kernel command line
|
||||||
var cmdline string
|
var cmdline string
|
||||||
if c, err := ioutil.ReadFile(prefix + "-cmdline"); err != nil {
|
if c, err := ioutil.ReadFile(prefix + "-cmdline"); err != nil {
|
||||||
@@ -148,26 +153,26 @@ func runPacket(args []string) {
|
|||||||
Tags: tags,
|
Tags: tags,
|
||||||
AlwaysPXE: *alwaysPXE,
|
AlwaysPXE: *alwaysPXE,
|
||||||
}
|
}
|
||||||
d, _, err := client.Devices.Create(&req)
|
dev, _, err := client.Devices.Create(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
b, err := json.MarshalIndent(d, "", " ")
|
b, err := json.MarshalIndent(dev, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
// log response json if in verbose mode
|
// log response json if in verbose mode
|
||||||
log.Debugf("%s\n", string(b))
|
log.Debugf("%s\n", string(b))
|
||||||
|
|
||||||
sshHost := "sos." + d.Facility.Code + ".packet.net"
|
sshHost := "sos." + dev.Facility.Code + ".packet.net"
|
||||||
if *consoleFlag {
|
if *consoleFlag {
|
||||||
// Connect to the serial console
|
// Connect to the serial console
|
||||||
if err := sshSOS(d.ID, sshHost); err != nil {
|
if err := sshSOS(dev.ID, sshHost); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Machine booting")
|
log.Printf("Machine booting")
|
||||||
log.Printf("Access the console with: ssh %s@%s", d.ID, sshHost)
|
log.Printf("Access the console with: ssh %s@%s", dev.ID, sshHost)
|
||||||
|
|
||||||
// if the serve option is present, wait till 'ctrl-c' is hit.
|
// if the serve option is present, wait till 'ctrl-c' is hit.
|
||||||
// Otherwise we wouldn't serve the files
|
// Otherwise we wouldn't serve the files
|
||||||
@@ -186,6 +191,13 @@ func runPacket(args []string) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
httpServer.Shutdown(ctx)
|
httpServer.Shutdown(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !*keepFlag {
|
||||||
|
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
|
// validateHTTPURL does a sanity check that a URL returns a 200 or 300 response
|
||||||
|
Reference in New Issue
Block a user