Beispiel #1
0
        private void NormalizeTemplate(VmTemplate template, HypervisorServiceConfiguration option, bool privileged = false)
        {
            if (!template.Iso.HasValue())
            {
                // need to have a backing file to add the cdrom device
                template.Iso = option.IsoStore + "null.iso";
            }

            var isopath = new DatastorePath(template.Iso);

            isopath.Merge(option.IsoStore);
            template.Iso = isopath.ToString();

            foreach (VmDisk disk in template.Disks)
            {
                if (!disk.Path.StartsWith(option.DiskStore)
                    )
                {
                    DatastorePath dspath = new DatastorePath(disk.Path);
                    dspath.Merge(option.DiskStore);
                    disk.Path = dspath.ToString();
                }

                if (disk.Source.HasValue() && !disk.Source.StartsWith(option.DiskStore)
                    )
                {
                    DatastorePath dspath = new DatastorePath(disk.Source);
                    dspath.Merge(option.DiskStore);
                    disk.Source = dspath.ToString();
                }
            }

            if (template.IsolationTag.HasValue())
            {
                string tag = "#" + template.IsolationTag;

                Regex rgx = new Regex("#.*");

                if (!template.Name.EndsWith(template.IsolationTag))
                {
                    template.Name = rgx.Replace(template.Name, "") + tag;
                }

                foreach (VmNet eth in template.Eth)
                {
                    if (privileged && _vlanman.Contains(eth.Net))
                    {
                        continue;
                    }

                    eth.Net = rgx.Replace(eth.Net, "") + tag;
                }
            }
        }
Beispiel #2
0
        public async Task <Vm> ChangeConfiguration(string id, VmKeyValue change)
        {
            _logger.LogDebug("changing " + id + " " + change.Key + "=" + change.Value);

            var ctx = GetVmContext(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(ctx.Host.Options.IsoStore);
                change = new VmKeyValue
                {
                    Key   = "iso",
                    Value = isopath.ToString() + tag
                };
            }

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

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

            return(await ctx.Host.Change(ctx.Vm.Id, change));
        }