예제 #1
0
        public async Task <InterfaceDTO> AddRouterInterface(string subnetId, string routerId)
        {
            var payload = new InterfaceDTO
            {
                SubnetId = subnetId
            };

            var result = await HttpClientPutInterfaceNetworkApi <InterfaceDTO>(_configuration, "routers/" + routerId + "/add_router_interface", "id", payload);

            // var payloadExternal = new InterfaceDTO
            // {
            //     SubnetId = "5071db6d-4e9b-4d51-bc71-4e741f99db4f"
            // };
            // await HttpClientPutInterfaceNetworkApi<InterfaceDTO>(_configuration, "routers/" + routerId + "/add_router_interface", "id", payloadExternal);

            return(result);
        }
예제 #2
0
        public async Task <A> HttpClientPutInterfaceNetworkApi <A>(IConfiguration configuration, string endPoint, string propertyReturn, InterfaceDTO payload)
        {
            var client = _httpClientFactory.CreateClient("NetworkAPI");

            client.DefaultRequestHeaders.TryAddWithoutValidation("X-Auth-Token", await GetOpenstackToken(configuration));

            var jsonSerializerSettings = new JsonSerializerSettings();

            jsonSerializerSettings.MissingMemberHandling = MissingMemberHandling.Ignore;
            var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(payload, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore
            }));



            var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");

            httpContent.Headers.ContentLength = stringPayload.Length;



            var response = await client.PutAsync(client.BaseAddress + endPoint, httpContent);

            response.EnsureSuccessStatusCode();
            string conteudo = JObject.Parse(response.Content.ReadAsStringAsync().Result).ToString();

            A retorno = JsonConvert.DeserializeObject <A>(conteudo, jsonSerializerSettings);

            return(retorno);
        }