Added configuration pkg, iPXE templating, clean up, etc.

This commit is contained in:
Gregory Kurtzer
2020-11-04 18:45:36 -08:00
parent 260315cccd
commit d2ed5766cd
13 changed files with 127 additions and 85 deletions

View File

@@ -7,9 +7,9 @@ import (
"net/http"
"os"
"os/exec"
// "os/exec"
"time"
"github.com/hpcng/warewulf/internal/pkg/config"
)
func main() {
@@ -24,9 +24,18 @@ func main() {
os.Chdir("/warewulf/wwclient-test")
}
// Setup local port to 987
localTCPAddr := net.TCPAddr{
Port: 987,
config, err := config.New()
if err != nil {
fmt.Printf("ERROR: Could not load configuration file: %s\n", err)
return
}
localTCPAddr := net.TCPAddr{}
if config.InsecureRuntime == false {
// Setup local port to something privileged (<1024)
localTCPAddr.Port = 987
} else {
fmt.Printf("INFO: Running from an insecure port\n")
}
webclient := &http.Client{
@@ -52,7 +61,8 @@ func main() {
for true {
var err error
resp, err = webclient.Get("http://192.168.1.1:9873/overlay-runtime")
getString := fmt.Sprintf("http://%s:%d/overlay-runtime", config.Ipaddr, config.Port)
resp, err = webclient.Get(getString)
if err == nil {
break
} else {
@@ -79,25 +89,7 @@ func main() {
continue
}
/*
// TODO: Turn all of this into a pipe instead of having to use a tmpfile which
// I tried to get working, but when running on a node, it always gave a
// trying to write on closed file descriptor... This maybe ugly, but it
// works.
tmpfile := fmt.Sprintf("/tmp/.wwclient-%s", util.RandomString(14))
tmpFD, _ := os.Create(tmpfile)
defer tmpFD.Close()
io.Copy(tmpFD, resp.Body)
tmpFD.Close()
err := exec.Command("cpio", "-i", "-F", tmpfile).Run()
if err != nil {
fmt.Printf("%s", err)
}
os.Remove(tmpfile)
*/
log.Printf("Updating runtime system\n")
command := exec.Command("/bin/cpio", "-iu")
command.Stdin = resp.Body
@@ -105,27 +97,6 @@ func main() {
if err != nil {
log.Printf("ERROR: Failed running CPIO: %s\n", err)
}
/*
command.Wait()
stdin, err := command.StdinPipe()
if err != nil {
log.Println(err)
}
defer stdin.Close()
go func() {
bytes, err := io.Copy(stdin, resp.Body)
if err != nil {
log.Printf("ERROR: io.Copy() failed: %s\n", err)
} else {
log.Printf("Updated the runtime overlay (recv: %d)\n", bytes)
}
}()
command.Run()
*/
// defer webclient.CloseIdleConnections()
time.Sleep(30000 * time.Millisecond)
}