Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipass multiuser #237

Merged
merged 2 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions platform/host_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,11 @@ func (bh *BraveHost) InitUnit(backend Backend, unitParams shared.Service) (err e
return err
}

// Check for existing container with this unit name
if _, _, err := lxdServer.GetInstance(unitName); err == nil {
return fmt.Errorf("container with name %q is already running on %q remote", unitName, deployRemoteName)
}

deployArch, err := GetLXDServerArch(lxdServer)
if err != nil {
return err
Expand Down
64 changes: 63 additions & 1 deletion platform/multipass.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,71 @@ func (vm Multipass) BraveBackendInit() error {
return err
}

// If a VM with this name already exists skip init - we will reuse the existing VM
// If a VM with this name already exists skip init - we will reuse the existing VM and LXD bridge
_, err = shared.ExecCommandWReturn("multipass", "info", vm.Settings.Name)
if err == nil {
// Set up new user's profile and storage space
err = shared.ExecCommand("multipass",
"exec",
vm.Settings.Name,
"--",
shared.SnapLXC,
"profile",
"create",
vm.Settings.Profile)
if err != nil {
return errors.New("failed to create LXD profile: " + err.Error())
}

err = shared.ExecCommand("multipass",
"exec",
vm.Settings.Name,
"--",
shared.SnapLXC,
"storage",
"create",
vm.Settings.StoragePool.Name,
vm.Settings.StoragePool.Type,
"size="+vm.Settings.StoragePool.Size)
if err != nil {
return errors.New("failed to create storage pool: " + err.Error())
}

err = shared.ExecCommand("multipass",
"exec",
vm.Settings.Name,
"--",
shared.SnapLXC,
"profile",
"device",
"add",
vm.Settings.Profile,
"root",
"disk",
"path=/",
"pool="+vm.Settings.StoragePool.Name)
if err != nil {
return errors.New("failed to add storage disk to profile: " + err.Error())
}

err = shared.ExecCommand("multipass",
"exec",
vm.Settings.Name,
"--",
shared.SnapLXC,
"profile",
"device",
"add",
vm.Settings.Profile,
"eth0",
"nic",
"nictype=bridged",
"parent="+vm.Settings.Network.Name,
"name=eth0")
if err != nil {
return errors.New("failed to add network device to profile: " + err.Error())
}

vm.Settings.Status = "active"
err = UpdateBraveSettings(vm.Settings)
if err != nil {
Expand Down