Esempio n. 1
0
        public async Task <ActionResult <VmOptions> > LoadWorkspaceIsos(string id)
        {
            await Validate(new Entity { Id = id });

            AuthorizeAny(
                () => Actor.IsAdmin,
                () => _svc.CanEdit(id, Actor.Id).Result
                );

            return(Ok(
                       await _pod.GetVmIsoOptions(id)
                       ));
        }
Esempio n. 2
0
        public async Task <ActionResult <VmOptions> > GetVmIsoOptions(string id)
        {
            AuthorizeAny(
                () => Actor.IsAdmin,
                () => CanManageVm(id, Actor.Id).Result
                );

            return(Ok(
                       await _pod.GetVmIsoOptions(
                           await GetVmIsolationTag(id)
                           )
                       ));
        }
Esempio n. 3
0
        public async Task <ActionResult <VmOptions> > IsoOptions(string id)
        {
            await AuthorizeAction(id, "isooptions");

            Vm vm = await _pod.Load(id);

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

            string tag = vm.Name.Tag();

            return(Ok(await _pod.GetVmIsoOptions(tag)));
        }
Esempio n. 4
0
        public async Task <ActionResult <VmOptions> > Isos(string id)
        {
            VmOptions result = await _pod.GetVmIsoOptions(id);

            return(Ok(result));
        }
Esempio n. 5
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);
        }