mosers
/
eaas-vde-proxy
Archiviert
1
0
Fork 0
Simon Moser vor 3 Jahren
Ursprung 8bd36090d7
Commit 00cc5a0cad
Signiert von: mosers
GPG-Schlüssel-ID: 96B3365A234B500C

@ -0,0 +1,51 @@
package cmd
import (
"bytes"
"io"
"log"
"os"
"os/exec"
)
type cmd struct {
fullCommand string
*exec.Cmd
bufOut bytes.Buffer
bufErr bytes.Buffer
}
func New(name string, args string) *cmd{
var bO, bE bytes.Buffer
c := cmd {
name + " " + args,
exec.Command(name, args),
bO,
bE,
}
c.Stdout = io.MultiWriter(os.Stdout, &c.bufOut)
c.Stderr = io.MultiWriter(os.Stderr, &c.bufErr)
return &c
}
func (c *cmd) Execute() {
err := c.Start()
if err != nil {
log.Printf("%s failed with %s\n", c.fullCommand, err)
}
}
func (c *cmd) GetOut() string {
return string(c.bufOut.Bytes())
}
func (c *cmd) GetErr() string {
return string(c.bufErr.Bytes())
}
func (c *cmd) WaitH() {
err := c.Wait()
if err != nil {
log.Printf("%s failed with %s\n", c.fullCommand, err)
}
}

@ -0,0 +1,3 @@
module proxy
go 1.13

@ -0,0 +1,31 @@
package main
import (
"proxy/cmd"
)
func main() {
//c1 := cmd.New("sh", "-c \"vde_plug /run/vde/sw_main.sock\"")
c2 := cmd.New("vde_plug", "/run/vde/sw_proxy.sock")
//c1 := cmd.New("ping", "localhost", "-c 10")
//c2 := cmd.New("nc", "google.com", "80")
//stdin, err := c2.StdinPipe()
//if err != nil {
// log.Fatal(err)
//}
//c1.Execute()
c2.Execute()
//time.Sleep(time.Second)
//io.WriteString(stdin, "GET / HTTP/1.0\n\n")
//time.Sleep(time.Second)
//stdin.Close()
//c1.WaitH()
c2.WaitH()
/* cmds := []*cmd.cmd{c1}
for _, x := range cmds {
go func(cmd *exec.Cmd) {
fmt.Printf(x.String())
}(cmd)
}*/
}

@ -1,25 +0,0 @@
package main
import (
"bytes"
"fmt"
"io"
"log"
"os"
"os/exec"
)
func main() {
cmd := exec.Command("ping", "127.0.0.1", "-c 10")
var stdoutBuf, stderrBuf bytes.Buffer
cmd.Stdout = io.MultiWriter(os.Stdout, &stdoutBuf)
cmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)
err := cmd.Run()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
outStr, errStr := string(stdoutBuf.Bytes()), string(stderrBuf.Bytes())
fmt.Printf("\nout:\n%s\nerr:\n%s\n", outStr, errStr)
}

@ -1,25 +1,34 @@
#!/bin/sh #!/bin/sh
# QEMU/VDE network environment preparation script # QEMU/VDE network environment preparation script
RUN='/run/vde'
qemu=/opt/qemu/build/qemu-system-x86_64
case "$1" in case "$1" in
start) start)
echo "Starting VDE network for QEMU: " echo "Starting VDE network for QEMU: "
vde_switch -daemon -mod 660 # Create run dir
slirpvde --dhcp --daemon sudo mkdir -p $RUN && sudo chown `id -un`:`id -gn` $RUN
qemu -m 512 -nic vde,mac='52:54:00:12:34:56' -hda alpine1.qcow2 -daemonize -vnc :1 # Main switch
qemu -m 512 -nic vde,mac='52:54:00:12:34:66' -hda alpine2.qcow2 -daemonize -vnc :1 vde_switch -daemon -s $RUN/sw_main.sock -p $RUN/sw_main.pid
# -nographic statt -daemonize -vnc :1 für Terminalinterface # Proxy switch -.-
vde_switch -daemon -s $RUN/sw_proxy.sock -p $RUN/sw_proxy.pid
# Slirp NAT
slirpvde --dhcp --daemon -s $RUN/sw_main.sock -p $RUN/slirp.pid
echo "Run:\nqemu -m 512 -nic vde,mac='52:54:00:12:34:56',sock=$RUN/sw_proxy.sock -hda alpine1.qcow2 -nographic"
$qemu -m 512 -nic vde,mac='52:54:00:12:34:66',sock=$RUN/sw_main.sock -hda alpine2.qcow2 -daemonize -vnc :1 -pidfile $RUN/vm_2.pid
;; ;;
stop) stop)
echo "Stopping VDE network for QEMU: " echo "Stopping VDE network for QEMU: "
pkill vde_switch kill `cat $RUN/*.pid | xargs`
pkill slirpvde
;; ;;
restart|reload) restart|reload)
$0 stop $0 stop
sleep 1 sleep 1
$0 start $0 start
;; ;;
status)
ps -fq `cat $RUN/*.pid | xargs | sed 's/ /,/g'`
;;
*) *)
echo "Usage: $0 {start|stop|restart|reload}" echo "Usage: $0 {start|stop|restart|reload}"
exit 1 exit 1