예제 #1
0
        public async Task <(bool found, bool update)> DeleteClusterAsync(Guid id)
        {
            var cluster = await clusterRepository.ReadAsync(c => c.Id == id);

            if (cluster == null)
            {
                return(false, false);
            }

            cluster.DeleteAt = DateTime.UtcNow;

            if ((await clusterRepository.UpdateClusterAsync(cluster)) > 0)
            {
                var nodes = await clusterNodeRepository.ReadsAsync(c => c.ClusterId == cluster.Id && c.DeleteAt == null);

                var selectedNode = await datacenterRepository.ReadAsync(f => f.Id == cluster.ProxmoxNodeId);

                var qemuClient = new QemuClient();

                foreach (var node in nodes)
                {
                    node.DeleteAt = DateTime.UtcNow;
                    await qemuClient.DeleteQemu(selectedNode.Name, node.OrderId);

                    await clusterNodeRepository.UpdateClusterNodeAsync(node);
                }

                return(true, await qemuClient.DeleteQemu(selectedNode.Name, cluster.OrderId));
            }

            return(true, false);
        }
예제 #2
0
        public async Task <(bool found, bool update)> DeleteClusterAsync(string id)
        {
            var cluster = await clusterRepository.ReadAsync(c => c.Id == id);

            if (cluster == null)
            {
                return(false, false);
            }

            cluster.DeleteAt = DateTime.UtcNow;

            if ((await clusterRepository.UpdateAsync(cluster)) > 0)
            {
                await traefikRouterService.DeleteClusterRules(cluster);

                var selectedSshKey = await sshKeyRepository.ReadAsync(cluster.SshKeyId);

                var selectedNode = await datacenterRepository.ReadAsync(f => f.Id == cluster.ProxmoxNodeId);

                var nodes = await clusterNodeRepository.ReadsAsync(c => c.ClusterId == cluster.Id && c.DeleteAt == null);

                var qemuClient = new QemuClient();

                foreach (var node in nodes)
                {
                    node.DeleteAt = DateTime.UtcNow;
                    await clusterNodeRepository.UpdateAsync(node);
                }

                var message = GenerateDeleteQueueMessage(cluster, selectedSshKey, selectedNode, int.Parse(cluster.Ip.Split(".").Last()), cluster.ProxmoxNodeId);

                queueService.QueueClusterDelete(message);

                return(true, true);
            }

            return(true, false);
        }