示例#1
0
        public async Task <IActionResult> GetConsole(Vm vM)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (vM?.Adapter == null)
            {
                return(BadRequest());
            }

            Adapter adapter = await _context.Adapters.Where(x => x.IsOK)
                              .Include(c => c.Credentials)
                              .Include(p => p.Provider)
                              .Where(a => a.Id == vM.Adapter.Id)
                              .SingleOrDefaultAsync();

            var servicesResponse = new ServicesResponse <GraphicsConsole>();

            switch (adapter.Provider.Id)
            {
            case (int)ProviderType.Ovirt:
                servicesResponse = await VmService.GetVmConsole(adapter, vM.Id);

                break;

            case (int)ProviderType.VMware:
                servicesResponse = await EasyAdmin.Services.VMware.VmService.GetConsole(adapter, vM);

                break;
            }
            if (!servicesResponse.isSuccess)
            {
                return(BadRequest(servicesResponse.errorMessage));
            }
            return(Ok(servicesResponse.resultObject));
        }