Ejemplo n.º 1
0
        public async Task <ActionResult <Vm> > Reconfigure(string id, [FromBody] VmKeyValue change)
        {
            // need elevated privileges to change vm to special nets
            if (
                change.Key == "net" && !change.Value.Contains("#") &&
                (_user.Role == UserRole.User || _user.Role == UserRole.Builder)
                )
            {
                throw new ActionForbiddenException();
            }

            await AuthorizeAction(id, "change");

            Vm vm = await _pod.Load(id);

            SendBroadcast(vm, "change");

            return(Ok(await _pod.ChangeConfiguration(id, change)));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <Vm> > ReconfigureVm(string id, [FromBody] VmKeyValue change)
        {
            AuthorizeAny(
                () => Actor.IsAdmin,
                () => CanManageVm(id, Actor.Id).Result
                );

            // need elevated privileges to change vm to special nets
            if (
                Actor.IsBuilder.Equals(false) &&
                change.Key == "net" &&
                change.Value.Contains("#").Equals(false) &&
                _options.AllowUnprivilegedVmReconfigure.Equals(false)
                )
            {
                throw new ActionForbidden();
            }

            Vm vm = await _pod.ChangeConfiguration(id, change);

            SendBroadcast(vm, "change");

            return(Ok(vm));
        }
Ejemplo n.º 3
0
        public async Task <bool> ChangeVm(VmAction vmAction)
        {
            bool result = false;
            Vm   vm     = null;

            if (!Guid.TryParse(vmAction.Id, out Guid guid))
            {
                // lookup id from name
                vm = await _pod.Load(vmAction.Id);

                vmAction.Id = vm.Id;
            }

            switch (vmAction.Type)
            {
            case "stop":
                try
                {
                    await _pod.StopAll(vmAction.Id);
                } catch {}

                break;

            case "start":
            case "restart":

                try
                {
                    if (vmAction.Type == "restart")
                    {
                        await _pod.StopAll(vmAction.Id);
                    }
                } catch {}

                try
                {
                    await _pod.StartAll(vmAction.Id);
                } catch {}

                result = true;
                break;

            case "iso":

                if (vm == null)
                {
                    return(false);
                }

                // look up valid iso path
                var gamespace = await _gamespaceStore.Load(vm.Name.Tag());

                var allowedIsos = await _pod.GetVmIsoOptions(gamespace.Workspace.GlobalId);

                string path = allowedIsos.Iso.Where(x => x.Contains(vmAction.Message)).FirstOrDefault();

                _logger.LogDebug($"{vm.Name}, {vmAction.Message}, {gamespace.Workspace.Name}, {String.Join(" ", allowedIsos.Iso)}");

                await _pod.ChangeConfiguration(
                    vmAction.Id,
                    new VmKeyValue
                {
                    Key   = "iso",
                    Value = path
                }
                    );

                result = true;

                break;
            }

            return(result);
        }