mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
Refactor run service func to create vm
Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
build
|
||||
cmd/manager/img
|
||||
cmd/manager/iso
|
||||
|
||||
cmd/manager/tmp
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user