Cleanups and got wwclient net/http pipe to cpio working

This commit is contained in:
Gregory Kurtzer
2020-11-02 22:43:07 -08:00
parent 78b13b5b4b
commit bc12f1ff65
6 changed files with 28 additions and 19 deletions

View File

@@ -11,7 +11,7 @@ func kernel(w http.ResponseWriter, req *http.Request) {
node, err := getSanity(req)
if err != nil {
w.WriteHeader(404)
log.Panicln(err)
log.Println(err)
return
}

View File

@@ -11,7 +11,7 @@ func kmods(w http.ResponseWriter, req *http.Request) {
node, err := getSanity(req)
if err != nil {
w.WriteHeader(404)
log.Panicln(err)
log.Println(err)
return
}
if node.KernelVersion != "" {

View File

@@ -11,7 +11,7 @@ func overlay(w http.ResponseWriter, req *http.Request) {
node, err := getSanity(req)
if err != nil {
w.WriteHeader(404)
log.Panicln(err)
log.Println(err)
return
}

View File

@@ -13,7 +13,7 @@ func runtime(w http.ResponseWriter, req *http.Request) {
node, err := getSanity(req)
if err != nil {
w.WriteHeader(404)
log.Panicln(err)
log.Println(err)
return
}

View File

@@ -4,12 +4,13 @@ package main
import (
"fmt"
"io"
"log"
"os"
"strconv"
"strings"
"github.com/hpcng/warewulf/internal/pkg/errors"
"github.com/hpcng/warewulf/internal/pkg/assets"
"github.com/hpcng/warewulf/internal/pkg/errors"
"net/http"
)
// TODO: https://github.com/danderson/netboot/blob/master/pixiecore/dhcp.go
@@ -23,6 +24,7 @@ func getSanity(req *http.Request) (assets.NodeInfo, error) {
hwaddr := strings.ReplaceAll(url[2], "-", ":")
node, err := assets.FindByHwaddr(hwaddr)
log.Printf("REQ: %s: %s\n", hwaddr, req.URL.Path)
if err != nil {
return node, errors.New("Could not find HW address")
}

View File

@@ -1,10 +1,13 @@
package main
import (
"bufio"
"fmt"
"io"
"log"
"net"
"net/http"
"os"
"os/exec"
"time"
)
@@ -12,15 +15,14 @@ import (
func main() {
os.Chdir("/")
// Setting up the connection manually so we can ensure a low port
localAddr, err := net.ResolveIPAddr("ip", "localhost")
if err != nil {
panic(err)
}
// You also need to do this to make it work and not give you a
// "mismatched local address type ip"
// This will make the ResolveIPAddr a TCPAddr without needing to
// say what SRC port number to use.
localTCPAddr := net.TCPAddr{
IP: localAddr.IP,
Port: 987,
@@ -42,14 +44,13 @@ func main() {
},
}
for true {
var resp *http.Response
for true {
var err error
fmt.Printf("Connecting ....\n")
resp, err = webclient.Get("http://localhost:9873/files/runtime/xx-xx-xx-xx-xx-xx")
resp, err = webclient.Get("http://192.168.1.1:9873/runtime/xx-xx-xx-xx-xx")
if err == nil {
break
} else {
@@ -58,15 +59,21 @@ func main() {
time.Sleep(1000 * time.Millisecond)
}
fmt.Println("Response status:", resp.Status)
scanner := bufio.NewScanner(resp.Body)
for i := 0; scanner.Scan() && i < 5; i++ {
fmt.Println(scanner.Text())
}
if err := scanner.Err(); err != nil {
panic(err)
fmt.Printf("Connection accepted to remote host\n")
command := exec.Command("cpio", "-i")
stdin, err := command.StdinPipe()
if err != nil {
log.Fatal(err)
}
go func() {
defer stdin.Close()
io.Copy(stdin, resp.Body)
}()
command.Run()
resp.Body.Close()
time.Sleep(5000 * time.Millisecond)
}
}