示例#1
0
        public static async Task <ServicesResponse> UpdateVm(Adapter adapter, Shared.Common.Vm vm)
        {
            var ovirtVm          = Vm.UpdatedVM(vm);
            var servicesResponse = await ApiService.PutRequest <Vm, Vm>(adapter, ovirtVm, $"ovirt-engine/api/vms/{vm.Id}");

            return(servicesResponse);
        }
示例#2
0
        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
        public static async Task <ServicesResponse <OvirtDisk.DiskAttachments> > GetDiskAttachments(Adapter adapter, Shared.Common.Vm vm)
        {
            var servicesResponse = new ServicesResponse <OvirtDisk.DiskAttachments>();

            if (adapter?.Credentials == null)
            {
                servicesResponse.errorCode    = 500;
                servicesResponse.errorMessage = "Adapter or credentials is null";
                return(servicesResponse);
            }
            servicesResponse = await ApiService.GetRequest2 <OvirtDisk.DiskAttachments>(adapter, $"ovirt-engine/api/vms/{vm.Id}/diskattachments");

            return(servicesResponse);
        }