Support Bridged Network (#78)

* Support Bridged Network

Inspired by https://github.com/cirruslabs/tart/issues/473

* Fixed tests
This commit is contained in:
Fedor Korotkov 2023-04-20 07:04:07 -04:00 committed by GitHub
parent a8771a046e
commit dd5e588eb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 17 deletions

View File

@ -13,7 +13,8 @@ var ErrVMFailed = errors.New("failed to create VM")
var image string
var cpu uint64
var memory uint64
var softnet bool
var netSoftnet bool
var netBridged string
var headless bool
var stringToStringResources map[string]string
@ -28,7 +29,8 @@ func newCreateVMCommand() *cobra.Command {
command.PersistentFlags().StringVar(&image, "image", "ghcr.io/cirruslabs/macos-ventura-base:latest", "image to use")
command.PersistentFlags().Uint64Var(&cpu, "cpu", 4, "number of CPUs to use")
command.PersistentFlags().Uint64Var(&memory, "memory", 8*1024, "megabytes of memory to use")
command.PersistentFlags().BoolVar(&softnet, "softnet", false, "whether to use Softnet network isolation")
command.PersistentFlags().BoolVar(&netSoftnet, "net-softnet", false, "whether to use Softnet network isolation")
command.PersistentFlags().StringVar(&netBridged, "net-bridged", "", "whether to use Bridged network mode")
command.PersistentFlags().BoolVar(&headless, "headless", true, "whether to run without graphics")
command.PersistentFlags().StringToStringVar(&stringToStringResources, "resources", map[string]string{},
"resources to request for this VM")
@ -54,11 +56,12 @@ func runCreateVM(cmd *cobra.Command, args []string) error {
Meta: v1.Meta{
Name: name,
},
Image: image,
CPU: cpu,
Memory: memory,
Softnet: softnet,
Headless: headless,
Resources: resources,
Image: image,
CPU: cpu,
Memory: memory,
NetSoftnet: netSoftnet,
NetBridged: netBridged,
Headless: headless,
Resources: resources,
})
}

View File

@ -37,7 +37,6 @@ func TestSingleVM(t *testing.T) {
Image: "ghcr.io/cirruslabs/macos-ventura-base:latest",
CPU: 4,
Memory: 8 * 1024,
Softnet: false,
Headless: true,
Status: v1.VMStatusPending,
StartupScript: &v1.VMScript{
@ -113,7 +112,6 @@ func TestFailedStartupScript(t *testing.T) {
Image: "ghcr.io/cirruslabs/macos-ventura-base:latest",
CPU: 4,
Memory: 8 * 1024,
Softnet: false,
Headless: true,
Status: v1.VMStatusPending,
StartupScript: &v1.VMScript{
@ -213,7 +211,6 @@ func TestPortForwarding(t *testing.T) {
Image: "ghcr.io/cirruslabs/macos-ventura-base:latest",
CPU: 4,
Memory: 8 * 1024,
Softnet: false,
Headless: true,
})
require.NoError(t, err)

View File

@ -92,9 +92,12 @@ func (vm *VM) cloneAndConfigure(ctx context.Context) error {
func (vm *VM) run(ctx context.Context) error {
var runArgs = []string{"run"}
if vm.Resource.Softnet {
if vm.Resource.NetSoftnet {
runArgs = append(runArgs, "--net-softnet")
}
if vm.Resource.NetBridged != "" {
runArgs = append(runArgs, fmt.Sprintf("--net-bridged=%s", vm.Resource.NetBridged))
}
if vm.Resource.Headless {
runArgs = append(runArgs, "--no-graphics")

View File

@ -19,11 +19,12 @@ type Meta struct {
}
type VM struct {
Image string `json:"image"`
CPU uint64 `json:"cpu"`
Memory uint64 `json:"memory"`
Softnet bool `json:"softnet"`
Headless bool `json:"headless"`
Image string `json:"image"`
CPU uint64 `json:"cpu"`
Memory uint64 `json:"memory"`
NetSoftnet bool `json:"net-softnet"`
NetBridged string `json:"net-bridged"`
Headless bool `json:"headless"`
// Status field is used to track the lifecycle of the VM associated with this resource.
Status VMStatus `json:"status"`