Exemplo n.º 1
0
        public async Task <VmOptions> GetVmIsoOptions(string id)
        {
            await Task.Delay(0);

            VmOptions opt = new VmOptions()
            {
                Iso = new string[] {
                    "test1.iso",
                    "test2.iso",
                    "test3.iso",
                    "test4.iso",
                    "test5.iso",
                    "test6.iso",
                    "test7.iso",
                    "test8.iso",
                    "test9.iso",
                    "test10.iso",
                    "test11.iso",
                    "test12.iso",
                    "test13.iso",
                    "test14.iso",
                    "test15.iso",
                    "test16.iso",
                    "test17.iso",
                    "test18.iso",
                    "really-long-iso-name-that-needs-to-wrap-1.0.0.test2.iso"
                },
            };

            return(opt);
        }
Exemplo n.º 2
0
 public ConnectionService(
     IOptions <VmOptions> options,
     ILogger <ConnectionService> logger
     )
 {
     _options = options.Value;
     _logger  = logger;
 }
Exemplo n.º 3
0
        public async Task <VmOptions> GetVmNetOptions(string id)
        {
            await Task.Delay(0);

            VmOptions opt = new VmOptions()
            {
                Net = new string[] { "bridge-net", "isp-att" }
            };

            return(opt);
        }
Exemplo n.º 4
0
 public TaskService(
     IOptions <VmOptions> options,
     ILogger <TaskService> logger,
     IHubContext <ProgressHub> progressHub,
     IConnectionService connectionService
     )
 {
     _options           = options.Value;
     _logger            = logger;
     _progressHub       = progressHub;
     _connectionService = connectionService;
 }
Exemplo n.º 5
0
        public async Task <Vm> ChangeConfiguration(string id, VmKeyValue change)
        {
            _logger.LogDebug("changing " + id + " " + change.Key + "=" + change.Value);

            Vm vm = await Load(id);

            if (vm == null)
            {
                throw new InvalidOperationException();
            }

            VimClient host = FindHostByVm(id);
            VmOptions vmo  = null;

            var    segments = change.Value.Split(':');
            string val      = segments.First();
            string tag      = segments.Length > 1
                ? $":{segments.Last()}"
                : "";

            //sanitize inputs
            if (change.Key == "iso")
            {
                // vmo = await GetVmIsoOptions(vm.Name.Tag());
                // if (!vmo.Iso.Contains(change.Value))
                //     throw new InvalidOperationException();
                var isopath = new DatastorePath(val);
                isopath.Merge(host.Options.IsoStore);
                change = new VmKeyValue
                {
                    Key   = "iso",
                    Value = isopath.ToString() + tag
                };
            }

            if (change.Key == "net" && !change.Value.StartsWith("_none_"))
            {
                vmo = await GetVmNetOptions(vm.Name.Tag());

                if (!vmo.Net.Contains(val))
                {
                    throw new InvalidOperationException();
                }
            }

            return(await host.Change(id, change));
        }
Exemplo n.º 6
0
        public async Task <Vm> ChangeConfiguration(string id, VmKeyValue change)
        {
            _logger.LogDebug("changing " + id + " " + change.Key + "=" + change.Value);
            Vm vm = await Load(id);

            if (vm == null)
            {
                throw new InvalidOperationException();
            }

            VimClient host = FindHostByVm(id);
            VmOptions vmo  = null;

            //sanitize inputs
            if (change.Key == "iso")
            {
                // vmo = await GetVmIsoOptions(vm.Name.Tag());
                // if (!vmo.Iso.Contains(change.Value))
                //     throw new InvalidOperationException();
                var isopath = new DatastorePath(change.Value);
                isopath.Merge(host.Options.IsoStore);
                change = new VmKeyValue
                {
                    Key   = "iso",
                    Value = isopath.ToString()
                };
            }

            if (change.Key == "net")
            {
                vmo = await GetVmNetOptions(vm.Name.Tag());

                if (!vmo.Net.Contains(change.Value))
                {
                    throw new InvalidOperationException();
                }
            }

            return(await host.Change(id, change));
        }
Exemplo n.º 7
0
        public VmService(
            IOptions <VmOptions> options,
            IOptions <RewriteHostOptions> rewriteHostOptions,
            ILogger <VmService> logger,
            IConfiguration configuration,
            IConnectionService connectionService
            )
        {
            _options            = options.Value;
            _rewriteHostOptions = rewriteHostOptions.Value;

            _logger = logger;
            vmApiClient.BaseAddress = new Uri(_options.ApiUrl);
            vmApiClient.DefaultRequestHeaders.Accept.Clear();
            vmApiClient.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));

            _connectionService = connectionService;
            _client            = connectionService.GetClient();
            _sic           = connectionService.GetServiceContent();
            _props         = connectionService.GetProps();
            _configuration = configuration;
        }
Exemplo n.º 8
0
        public async Task <ActionResult <VmOptions> > Nets(string id)
        {
            VmOptions result = await _pod.GetVmNetOptions(id);

            return(Ok(result));
        }