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); }
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."); }