Exemple #1
0
        public async Task <int> VerifyDisks(VmTemplate template)
        {
            await Delay();

            NormalizeTemplate(template, _optPod);
            int    progress = -1;
            VmDisk disk     = template.Disks.FirstOrDefault();

            if (disk != null)
            {
                if (disk.Path.Contains("blank-"))
                {
                    return(100);
                }

                MockDisk mock = _disks.FirstOrDefault(o => o.Path == disk.Path);
                if (mock == null)
                {
                    _disks.Add(new MockDisk
                    {
                        CreatedAt = DateTime.Now,
                        Path      = disk.Path,
                        Disk      = disk
                    });
                }
                progress = 100;
                // if (mock != null)
                // {
                //     float elapsed = (int)DateTime.Now.Subtract(mock.CreatedAt).TotalSeconds;
                //     progress = (int) Math.Min(100, (elapsed / 10) * 100);
                // }
            }
            return(progress);
        }
Exemple #2
0
        public async Task <int> CreateDisks(VmTemplate template)
        {
            NormalizeTemplate(template, _optPod);
            string key = template.Name; //template.IsolationTag + "-" + template.Id;
            Vm     vm  = (await Find(key)).FirstOrDefault();

            if (vm != null)
            {
                return(100);
            }


            int progress = await VerifyDisks(template);

            if (progress < 0)
            {
                VmDisk disk = template.Disks.First();
                // if (!_tasks.ContainsKey(key))
                //     _tasks.Add(key, new VmTask {
                //         Name = "initializing",
                //         WhenCreated = DateTime.UtcNow,
                //         Id = key
                //     });
                _logger.LogDebug("disk: creating " + disk.Path);
                _disks.Add(new MockDisk
                {
                    CreatedAt = DateTime.Now,
                    Path      = disk.Path,
                    Disk      = disk
                });
            }
            return(progress);
        }
Exemple #3
0
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the value to convert into an instance of <see cref="VmDisk" />.</param>
 /// <returns>
 /// an instance of <see cref="VmDisk" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public static object ConvertFrom(dynamic sourceValue)
 {
     if (null == sourceValue)
     {
         return(null);
     }
     try
     {
         VmDisk.FromJsonString(typeof(string) == sourceValue.GetType() ? sourceValue : sourceValue.ToJsonString());
     }
     catch
     {
         // Unable to use JSON pattern
     }
     try
     {
         return(new VmDisk
         {
             DataSourceReference = ReferenceTypeConverter.ConvertFrom(sourceValue.DataSourceReference),
             DeviceProperties = VmDiskDevicePropertiesTypeConverter.ConvertFrom(sourceValue.DeviceProperties),
             DiskSizeBytes = sourceValue.DiskSizeBytes,
             DiskSizeMib = sourceValue.DiskSizeMib,
             Uuid = sourceValue.Uuid,
             VolumeGroupReference = ReferenceTypeConverter.ConvertFrom(sourceValue.VolumeGroupReference),
         });
     }
     catch
     {
     }
     return(null);
 }
Exemple #4
0
        public async Task <int> CreateDisksOld(VmTemplate template)
        {
            int progress = await VerifyDisks(template);

            if (progress < 0)
            {
                VmDisk disk = template.Disks.First();
                _logger.LogDebug("disk: creating " + disk.Path);
                _disks.Add(new MockDisk
                {
                    CreatedAt = DateTime.Now,
                    Path      = disk.Path,
                    Disk      = disk
                });
            }
            return(0);
        }
Exemple #5
0
        public async Task <int> DeleteDisks(VmTemplate template)
        {
            int progress = await VerifyDisks(template);

            if (progress < 0)
            {
                return(-1);
            }

            if (progress == 100)
            {
                VmDisk   disk = template.Disks.First();
                MockDisk mock = _disks.FirstOrDefault(o => o.Path == disk.Path);
                if (mock != null)
                {
                    _logger.LogDebug("disk: deleting " + disk.Path);
                    _disks.Remove(mock);
                    return(-1);
                }
            }
            throw new Exception("Cannot delete disk that isn't fully created.");
        }
Exemple #6
0
        public async Task CreateDisk(VmDisk disk)
        {
            await Connect();
            await MakeDirectories(disk.Path);

            string adapter = (disk.Controller.HasValue())
                ? disk.Controller.Replace("lsilogic", "lsiLogic").Replace("buslogic", "busLogic")
                : "lsiLogic";
            var task = await _vim.CreateVirtualDisk_TaskAsync(
                _vdm,
                disk.Path,
                _datacenter,
                new FileBackedVirtualDiskSpec
            {
                diskType    = "thin",
                adapterType = adapter,
                capacityKb  = disk.Size * 1000 * 1000,
                profile     = null
            }
                );

            await WaitForVimTask(task);
        }