Skip to content

Commit

Permalink
Merge pull request #237 from Szubie/multipass-multiuser
Browse files Browse the repository at this point in the history
Multipass multiuser
  • Loading branch information
idroz committed Dec 21, 2022
2 parents a748af9 + 177e052 commit fcfe4ff
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
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

0 comments on commit fcfe4ff

Please sign in to comment.