Refactor run service func to create vm

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
This commit is contained in:
Darko Draskovic
2023-08-18 17:53:28 +02:00
parent 0049ce2b28
commit de9feccc51
3 changed files with 10 additions and 3 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
build
cmd/manager/img
cmd/manager/iso
cmd/manager/tmp
-2
View File
@@ -9,8 +9,6 @@ import (
var re = regexp.MustCompile(`'([^']*)'`)
const bootTime = 5 * time.Second
func entityName(msg string) (string, error) {
match := re.FindStringSubmatch(msg)
if len(match) < 1 {
+9
View File
@@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"strings"
"time"
"github.com/digitalocean/go-libvirt"
"github.com/ultravioletrs/agent/agent"
@@ -22,6 +23,8 @@ import (
const firmwareVars = "OVMF_VARS"
const qcow2Img = "focal-server-cloudimg-amd64"
const bootTime = 10 * time.Second
var (
// ErrMalformedEntity indicates malformed entity specification (e.g.
// invalid username or password).
@@ -138,6 +141,12 @@ func (ms *managerService) createQemuVM(ctx context.Context) (*exec.Cmd, error) {
}
func (ms *managerService) Run(ctx context.Context, computation []byte) (string, error) {
_, err := ms.createQemuVM(ctx)
if err != nil {
return "", err
}
time.Sleep(bootTime)
res, err := ms.agent.Run(ctx, &agent.RunRequest{Computation: computation})
if err != nil {
return "", err