Exemplo n.º 1
0
        public async Task <IActionResult> GetArbo(Guid id)
        {
            var server = await GetServer(id, true);

            if (server == null)
            {
                return(NotFound());
            }
            if (server.Type != ServerType.VMware)
            {
                throw new ArgumentException($"Server GUID {{{id}}} is not of type {ServerType.VMware}");
            }

            var arbo = new VMwareArbo();

            using (var proxy = new Vim25Proxy.Proxy(server.Ip))
            {
                var vmserver = server as DBVMwareServer;
                await proxy.Login(vmserver.Username, vmserver.Password);

                arbo.Folders = await proxy.GetFolders();

                arbo.Pools = await proxy.GetPools();
            }

            return(Ok(arbo));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Get(Guid id, bool refresh = false)
        {
            var server = await GetServer(id, refresh);

            if (server == null)
            {
                return(NotFound());
            }
            if (refresh)
            {
                switch (server.Type)
                {
                case ServerType.VMware:

                    using (var proxy = new Vim25Proxy.Proxy(server.Ip))
                    {
                        var vmserver = server as DBVMwareServer;
                        await proxy.Login(vmserver.Username, vmserver.Password);

                        vmserver.Username = null;
                        vmserver.Password = null;
                        vmserver.VMs      = (await proxy.GetVMs()).OrderBy(kv => kv.Name).Select(vm => new string[] { vm.MoRef, vm.Name }).ToArray();
                        await metaDB.UpdateServer(vmserver);
                    }
                    break;
                }
            }

            return(Ok(server));
        }