mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-08-05 16:53:48 +00:00
cmd/packet: Tidy up the code
prefix packet.net specific functions with 'packet' and make non-packet specific functions, such as validateHTTPURL() more generic so that they can easily be moved to 'utils.go' should they be needed elsewhere. Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
This commit is contained in:
parent
50c4eb5461
commit
90510777ad
@ -152,8 +152,13 @@ func runPacket(args []string) {
|
|||||||
// Make sure the URL works
|
// Make sure the URL works
|
||||||
initrdURL := fmt.Sprintf("%s/%s-initrd.img", url, name)
|
initrdURL := fmt.Sprintf("%s/%s-initrd.img", url, name)
|
||||||
kernelURL := fmt.Sprintf("%s/%s-kernel", url, name)
|
kernelURL := fmt.Sprintf("%s/%s-kernel", url, name)
|
||||||
validateHTTPURL(kernelURL)
|
log.Infof("Validating URls: %s %s", initrdURL, kernelURL)
|
||||||
validateHTTPURL(initrdURL)
|
if err := validateHTTPURL(kernelURL); err != nil {
|
||||||
|
log.Fatalf("Invalid kernel URL %s: %v", kernelURL, err)
|
||||||
|
}
|
||||||
|
if err := validateHTTPURL(initrdURL); err != nil {
|
||||||
|
log.Fatalf("Invalid initrd URL %s: %v", initrdURL, err)
|
||||||
|
}
|
||||||
|
|
||||||
client := packngo.NewClient("", apiKey, nil)
|
client := packngo.NewClient("", apiKey, nil)
|
||||||
tags := []string{}
|
tags := []string{}
|
||||||
@ -214,7 +219,7 @@ func runPacket(args []string) {
|
|||||||
sshHost := "sos." + dev.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(dev.ID, sshHost); err != nil {
|
if err := packetSOS(dev.ID, sshHost); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -250,19 +255,18 @@ func runPacket(args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
func validateHTTPURL(url string) {
|
func validateHTTPURL(url string) error {
|
||||||
log.Infof("Validating URL: %s", url)
|
|
||||||
resp, err := http.Head(url)
|
resp, err := http.Head(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
return err
|
||||||
}
|
}
|
||||||
if resp.StatusCode >= 400 {
|
if resp.StatusCode >= 400 {
|
||||||
log.Fatal("Got a non 200- or 300- HTTP response code: %s", resp)
|
return fmt.Errorf("Got a non 200- or 300- HTTP response code: %s", resp)
|
||||||
}
|
}
|
||||||
log.Debugf("OK: %d response code", resp.StatusCode)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func sshSOS(user, host string) error {
|
func packetSOS(user, host string) error {
|
||||||
log.Debugf("console: ssh %s@%s", user, host)
|
log.Debugf("console: ssh %s@%s", user, host)
|
||||||
|
|
||||||
hostKey, err := sshHostKey(host)
|
hostKey, err := sshHostKey(host)
|
||||||
|
Loading…
Reference in New Issue
Block a user