Ejemplo n.º 1
0
        /// <inheritdoc/>
        public async Task <GrpcGetVmNetworkAdaptersReply> GetVmNetworkAdaptersAsync(GrpcGetVmNetworkAdaptersRequest request, CallContext context = default)
        {
            await SyncContext.Clear;

            try
            {
                var adapters = hyperv.GetVmNetworkAdapters(machineName: request.MachineName, waitForAddresses: request.WaitForAddresses);

                return(new GrpcGetVmNetworkAdaptersReply(adapters: adapters.Select(adapter => adapter.ToProto()).ToList()));
            }
            catch (Exception e)
            {
                return(new GrpcGetVmNetworkAdaptersReply(e));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the virtual network adapters attached to the named virtual machine.
        /// </summary>
        /// <param name="machineName">The machine name.</param>
        /// <param name="waitForAddresses">Optionally wait until at least one adapter has been able to acquire at least one IPv4 address.</param>
        /// <returns>The list of network adapters.</returns>
        public List <VirtualNetworkAdapter> GetVmNetworkAdapters(string machineName, bool waitForAddresses = false)
        {
            if (isAdmin)
            {
                return(hypervClient.GetVmNetworkAdapters(machineName: machineName, waitForAddresses: waitForAddresses));
            }
            else
            {
                var request = new GrpcGetVmNetworkAdaptersRequest(machineName: machineName, waitForAddresses: waitForAddresses);
                var reply   = desktopService.GetVmNetworkAdaptersAsync(request).Result;

                reply.Error.EnsureSuccess();

                return(reply.Adapters.Select(adapter => adapter.ToLocal()).ToList());
            }
        }