コード例 #1
0
        //InfoBlox specific options.
        public async Task <InfobloxNetwork> GetNetworkAsync(string cidrNetwork)
        {
            // https://10.10.10.10/wapi/v2.9/network?network=10.10.10.10/8

            string apifunction = "network";
            string apicommand  = $"network={cidrNetwork}";
            string apipath     = $"{helperConfig.ApiRoute}/{helperConfig.ApiVersion}/{apifunction}";
            string content     = await IBXCallApi(HttpMethod.Get, apifunction, apipath, apicommand);

            InfobloxNetwork _subnet = (from subnet in (InfobloxNetworks.FromJson(content))
                                       select subnet).FirstOrDefault();

            return(_subnet);
        }
コード例 #2
0
        private async Task RetrieveConfigurationAsync()
        {
            //@{ var dataFileName = Environment.GetEnvironmentVariable("HOME").ToString() + "\\site\\wwwroot\\data.txt"; } Option 1
            //Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "file_at_root.txt");


            try
            {
                await Task.Run(() =>
                {
                    string configPath = "";
                    if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HOME")))
                    {
                        configPath = Environment.GetEnvironmentVariable("HOME") + "\\site\\wwwroot\\";
                    }
                    else
                    {
                        configPath = System.Environment.CurrentDirectory;
                    }

                    var builder = new ConfigurationBuilder().SetBasePath(configPath).AddJsonFile("appsettings.json", false, true);

                    var config = builder.Build();

                    helperConfig = config.GetSection("InfoBloxHelper").Get <HelperConfiguration>();

                    CreateAutorizationContextAsync().Wait();

                    acceptAnySsl = helperConfig.AcceptAnySsl;

                    SslBypassCheckAsync().Wait();

                    infoBloxSubnets = GetNetworkListsAsync().Result;

                    if (!String.IsNullOrEmpty(helperConfig.DefaultNetworkCIDR))
                    {
                        if (NetworkUtilities.ValidateCidrIp(helperConfig.DefaultNetworkCIDR).Value)
                        {
                            //defaultSubnet =  instance.GetNetworkAsync(helperConfig.DefaultNetworkCIDR).Result;
                            var _subnetResult = from subnet in infoBloxSubnets
                                                where (subnet.Network == helperConfig.DefaultNetworkCIDR)
                                                select subnet;

                            defaultSubnet = _subnetResult.FirstOrDefault();
                        }
                    }
                    else
                    {
                        //defaultSubnet =  instance.GetNetworkAsync(helperConfig.DefaultNetworkCIDR).Result;
                        var _subnetResult = (from subnet in infoBloxSubnets
                                             select subnet).Take(1);

                        defaultSubnet = _subnetResult.FirstOrDefault();
                    }
                });
            }
            catch (System.Exception)
            {
                throw;
            }
        }