Exemplo n.º 1
0
        public async Task read_kvp_entries(string filePath)
        {
            var dic = new Dictionary <string, string>();

            await foreach (var entry in HypervUtils.ReadKvpPoolAsync(filePath))
            {
                dic[entry.Name] = entry.Value;
            }

            Assert.Contains("VirtualMachineId", (IDictionary <string, string>)dic);
            Assert.Contains("VirtualMachineName", (IDictionary <string, string>)dic);
            Assert.Contains("PhysicalHostNameFullyQualified", (IDictionary <string, string>)dic);
        }
Exemplo n.º 2
0
        public override async Task <NodeGetInfoResponse> NodeGetInfo(NodeGetInfoRequest request, ServerCallContext context)
        {
            //KVP daemon for KVP transfers to and from the host
            //centos: sudo yum install -y hyperv-daemons

            //read hostname from kvp values
            //strings /var/lib/hyperv/.kvp_pool_3|sed -n '/PhysicalHostNameFullyQualified/ {n;p}'

            //KVP byte array of fix sized fields key:512,value:2048 /0 filled
            //The byte array contains a UTF-8 encoded string,
            //which is padded out to the max size with null characters.
            //However, null string termination is not guaranteed (see kvp_send_key).
            //https://stackoverflow.com/questions/17530460/code-sample-for-reading-values-from-hyper-v-kvp-component-on-linux-aka-kvp-data

            var vmId = string.Empty;

            await foreach (var entry in HypervUtils.ReadKvpPoolAsync().WithCancellation(context.CancellationToken))
            {
                switch (entry.Name)
                {
                case "VirtualMachineId":
                    vmId = entry.Value;
                    break;

                //case "VirtualMachineName":
                //case "PhysicalHostNameFullyQualified":
                default:
                    break;
                }
            }

            if (string.IsNullOrEmpty(vmId))
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, string.Empty),
                                       "hyperv kvp could not be read");
            }

            var rsp = new NodeGetInfoResponse
            {
                NodeId = vmId,
                //todo MaxVolumesPerNode = 4*64 -1 //todo query by lsscsi
                //maybe AccessibleTopology from FailoverCluster query
            };

            return(rsp);
        }
Exemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddOptions <HypervCsiDriverOptions>()
            .Bind(Configuration.GetSection("Driver"))
            .PostConfigure(opt =>
            {
                switch (opt.Type)
                {
                case HypervCsiDriverType.Controller:
                    //load hyperv host from kvp
                    if (string.IsNullOrEmpty(opt.HostName))
                    {
                        var(_, value) = HypervUtils.ReadKvpPoolAsync()
                                        .FirstOrDefaultAsync(n => n.Name == "PhysicalHostNameFullyQualified")
                                        .Result;

                        if (!string.IsNullOrEmpty(value))
                        {
                            opt.HostName = value;
                        }
                        if (string.IsNullOrEmpty(opt.UserName))
                        {
                            opt.UserName = "******";         //aka windows root
                        }
                    }
                    break;
                }
            })
            .Validate(opt =>
            {
                switch (opt.Type)
                {
                case HypervCsiDriverType.Controller:
                    if (string.IsNullOrEmpty(opt.HostName))
                    {
                        return(false);
                    }
                    return(true);

                case HypervCsiDriverType.Node:
                    return(true);

                default:
                    return(false);
                }
            });


            var driverType = Configuration.GetValue <HypervCsiDriverType>("Driver:Type");

            switch (driverType)
            {
            case HypervCsiDriverType.Controller:
                services.AddSingleton <IHypervVolumeService, HypervVolumeService>();
                break;

            case HypervCsiDriverType.Node:
                services.AddSingleton <IHypervNodeService, LinuxNodeService>();
                break;
            }

            services.AddGrpc();
        }