コード例 #1
0
ファイル: VMService.cs プロジェクト: din000111/easyadmin
        public static async Task <ServicesResponse> GetFullVms(Adapter adapter)
        {
            var servicesResponse         = new ServicesResponse();
            ServicesResponse vmsResponse = await GetVMs(adapter);

            if (!vmsResponse.isSuccess)
            {
                return(servicesResponse);
            }

            List <Vm> ovirtVms = ((Vms)vmsResponse.resultObject).Vm;

            ServicesResponse diskResponse = await DiskService.GetDisks(adapter);

            if (!vmsResponse.isSuccess)
            {
                return(servicesResponse);
            }

            Shared.Ovirt.Disk.Disks ovirtDisks = (Shared.Ovirt.Disk.Disks)diskResponse.resultObject;

            foreach (Vm ovirtVm in ovirtVms)
            {
                ServicesResponse ovirtVmDiskAttachmentResponse = await ApiService.GetRequest(adapter,
                                                                                             typeof(Shared.Ovirt.Disk.DiskAttachments),
                                                                                             ovirtVm.Link.SingleOrDefault(l => l.Rel == "diskattachments")?.Href);

                if (!ovirtVmDiskAttachmentResponse.isSuccess)
                {
                    break;
                }
                ovirtVm.DiskAttachments = (Shared.Ovirt.Disk.DiskAttachments)ovirtVmDiskAttachmentResponse.resultObject;
                ovirtVm.DiskAttachments.DiskAttachment.ForEach(x => x.Disk = ovirtDisks.Disk.SingleOrDefault(y => y.Id == x.Disk.Id));
            }

            List <Shared.Ovirt.Datacenter.DataCenter> datacenters = ((DataCenters)(await DatacenterService.GetDatacenters(adapter)).resultObject).DataCenter;
            List <Shared.Ovirt.Cluster> clusters = ((Clusters)(await ClusterService.GetClusters(adapter)).resultObject).Cluster;

            List <Shared.Common.Vm> commonVMs = ovirtVms.ConvertAll(x => (Shared.Common.Vm)x);

            foreach (var vm in commonVMs)
            {
                vm.Adapter            = adapter;
                vm.AdapterId          = adapter.Id;
                vm.Cluster            = clusters.SingleOrDefault(x => x.Id == vm.Cluster.Id);
                vm.ClusterId          = vm.Cluster.Id;
                vm.Cluster.Datacenter = datacenters.SingleOrDefault(x => x.Id == vm.Cluster.Datacenter.Id);
                vm.DatacenterId       = vm.Cluster.Datacenter.Id;
                vm.ClusterName        = vm.Cluster.Name;
                vm.DatacenterName     = vm.Cluster.Datacenter.Name;
            }
            servicesResponse.isSuccess    = true;
            servicesResponse.resultObject = commonVMs;

            return(servicesResponse);
        }
コード例 #2
0
ファイル: VMService.cs プロジェクト: din000111/easyadmin
        public static async Task <ServicesResponse> RequestVm(Shared.Common.Vm commonVm, Adapter adapter, string networkId = null, int hddSize = 0, string dcId = null)
        {
            var vMRequested = Vm.CreatedVM(commonVm);
            ServicesResponse servicesResponse = new ServicesResponse();

            if (adapter?.Credentials == null)
            {
                servicesResponse.errorCode    = 500;
                servicesResponse.errorMessage = "Adapter or credentials is null";
                return(servicesResponse);
            }

            servicesResponse = await ApiService.PostRequest <Vm>(adapter, vMRequested, "ovirt-engine/api/vms");

            if (!servicesResponse.isSuccess || vMRequested.Template?.Name != "Blank")
            {
                return(servicesResponse);
            }
            Vm vM = (Vm)servicesResponse.resultObject;

            if (vM == null)
            {
                throw new Exception("vm var is null but created successfully.");
            }

            ServicesResponse newNicResponse = await NetworkService.CreateNic(vM.Id, networkId, adapter);

            if (!newNicResponse.isSuccess)
            {
                return(newNicResponse);
            }

            ServicesResponse storageDomainsRequest = await StorageDomainsService.GetStorageDomains(adapter);

            if (!storageDomainsRequest.isSuccess)
            {
                return(storageDomainsRequest);
            }
            OvirtStorageDomains.StorageDomains storageDomains = (OvirtStorageDomains.StorageDomains)storageDomainsRequest.resultObject;
            OvirtStorageDomains.StorageDomain  storageDomain  = storageDomains.StorageDomain
                                                                .FirstOrDefault(dcs => dcs.Data_centers.Data_center.Id == dcId && dcs.Master && dcs.Available > (hddSize * 20 ^ 30) && dcs.Type == "data");


            ServicesResponse newDiskResponse = await DiskService.CreateDisk(vM, hddSize, storageDomain?.Id, adapter);

            return(newDiskResponse);
        }
コード例 #3
0
ファイル: BackupService.cs プロジェクト: din000111/easyadmin
        public static async Task <ServicesResponse> EnableIncrementalBackupAsync(Adapter adapter, Vm vm)
        {
            var diskAttachmentsRequest = await DiskService.GetDiskAttachments(adapter, vm);

            if (!diskAttachmentsRequest.isSuccess)
            {
                return(new ServicesResponse
                {
                    errorMessage = diskAttachmentsRequest.errorMessage,
                    errorCode = diskAttachmentsRequest.errorCode,
                    resultObject = diskAttachmentsRequest.resultObject,
                    isSuccess = diskAttachmentsRequest.isSuccess
                });
            }
            foreach (var diskAttachment in diskAttachmentsRequest.resultObject.DiskAttachment)
            {
                var newDiskAttachment = new DiskAttachment {
                    Interface = diskAttachment.Interface,
                    Disk      = new Disk {
                        Id     = diskAttachment.Disk.Id,
                        Backup = "incremental"
                    }
                };

                var enableBackupRequest = await ApiService.PostRequest(adapter, newDiskAttachment, $"ovirt-engine/api/vms/{vm.Id}/diskattachments");

                return(enableBackupRequest);
            }
            return(new ServicesResponse
            {
                errorMessage = diskAttachmentsRequest.errorMessage,
                errorCode = diskAttachmentsRequest.errorCode,
                resultObject = diskAttachmentsRequest.resultObject,
                isSuccess = diskAttachmentsRequest.isSuccess
            });
        }