예제 #1
0
        public async Task <Template> Delete(int id)
        {
            var entity = await _templateStore.Load(id);

            if (entity == null || !entity.Workspace.CanEdit(User))
            {
                throw new InvalidOperationException();
            }

            if (await _templateStore.IsParentTemplate(id))
            {
                throw new ParentTemplateException();
            }

            //delete associated vm
            var deployable = await GetDeployableTemplate(id);

            await _pod.DeleteAll($"{deployable.Name}#{deployable.IsolationTag}");

            //if root template, delete disk(s)
            // TODO: maybe always delete disks?
            if (entity.Parent == null)
            {
                await _pod.DeleteDisks(deployable);
            }

            await _templateStore.Delete(entity.Id);

            return(Mapper.Map <Template>(entity, WithActor()));
        }
예제 #2
0
        /// <summary>
        /// Delete a workspace
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Workspace</returns>
        public async Task <Workspace> Delete(string id)
        {
            var entity = await _store.Retrieve(id);

            await _pod.DeleteAll(id);

            await _store.DeleteWithTemplates(id, async templates => {
                var disktasks = Mapper.Map <ConvergedTemplate[]>(templates)
                                .Select(ct => _pod.DeleteDisks(ct.ToVirtualTemplate()))
                                .ToArray()
                ;

                await Task.WhenAll(disktasks);
            });

            return(Mapper.Map <Workspace>(entity));
        }
예제 #3
0
        public async Task <Template> Delete(string id)
        {
            var entity = await _store.Retrieve(id);

            if (await _store.HasDescendents(id))
            {
                throw new TemplateHasDescendents();
            }

            // delete associated vm
            var deployable = await GetDeployableTemplate(id);

            await _pod.DeleteAll($"{deployable.Name}#{deployable.IsolationTag}");

            // if root template, delete disk(s)
            if (entity.IsLinked.Equals(false))
            {
                await _pod.DeleteDisks(deployable);
            }

            await _store.Delete(id);

            return(Mapper.Map <Template>(entity));
        }