/
run_local_instance.go
65 lines (52 loc) · 1.52 KB
/
run_local_instance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cmd
import (
"fmt"
"github.com/nanovms/ops/lepton"
"github.com/nanovms/ops/network"
"github.com/nanovms/ops/provider/onprem"
"github.com/nanovms/ops/qemu"
"github.com/nanovms/ops/types"
)
// RunLocalInstance runs a virtual machine in a hypervisor
func RunLocalInstance(c *types.Config) (err error) {
if c.Mounts != nil {
c.VolumesDir = lepton.LocalVolumeDir
err = onprem.AddMountsFromConfig(c)
if err != nil {
return
}
}
hypervisor := qemu.HypervisorInstance()
if hypervisor == nil {
ErrNoHypervisor := "No hypervisor found on $PATH"
InfoInstallOps := "Please install OPS using curl https://ops.city/get.sh -sSfL | sh"
return fmt.Errorf("%s\n%s", ErrNoHypervisor, InfoInstallOps)
}
tapDeviceName := c.RunConfig.TapName
bridged := c.RunConfig.Bridged
ipaddress := c.RunConfig.IPAddress
bridgeipaddress := c.RunConfig.BridgeIPAddress
netmask := c.RunConfig.NetMask
bridgeName := c.RunConfig.BridgeName
if bridged && bridgeName == "" {
bridgeName = "br0"
}
networkService := network.NewIprouteNetworkService()
if tapDeviceName != "" {
err = network.SetupNetworkInterfaces(networkService, tapDeviceName, bridgeName, ipaddress, netmask, bridgeipaddress)
if err != nil {
return
}
}
fmt.Println("running local instance")
c.RunConfig.Kernel = c.Kernel
fmt.Printf("booting %s ...\n", c.RunConfig.ImageName)
hypervisor.Start(&c.RunConfig)
if tapDeviceName != "" {
err = network.TurnOffNetworkInterfaces(networkService, tapDeviceName, bridgeName)
if err != nil {
return
}
}
return
}