public async Task <NetworkDTO> CreateNetwork(string name) { var payload = new NeutronDTO { Network = new NetworkDTO { Name = "NETWORK_" + name } }; var network = await HttpClientPostNetworkApi <NetworkDTO>(_configuration, "networks", "network", payload); return(network); }
public async Task <FloatingIpDTO> AssociateFloatingIp(string networkId, string portId) { var payload = new NeutronDTO { FloatingIp = new FloatingIpDTO { FloatingNetworkId = networkId, PortId = portId } }; var result = await HttpClientPostNetworkApi <FloatingIpDTO>(_configuration, "floatingips", "floatingip", payload); return(result); }
public async Task <SubnetDTO> CreateSubnet(string networkId, string name) { var payload = new NeutronDTO { Subnet = new SubnetDTO { NetworkId = networkId, Name = "NETWORK_" + name, Cidr = "10.10.10.0/24", IpVersion = 4 } }; var subnet = await HttpClientPostNetworkApi <SubnetDTO>(_configuration, "subnets", "subnet", payload); return(subnet); }
public async Task <RouterDTO> CreateRouter(string name) { var payload = new NeutronDTO { Router = new RouterDTO { Name = "EXTERNAL_ROUTER_" + name, ExternalGatewayInfo = new ExternalGatewayDTO { NetworkId = "78c9ed54-cca8-4f1b-837d-b15c185cce17", EnableSnat = true } } }; var router = await HttpClientPostNetworkApi <RouterDTO>(_configuration, "routers", "router", payload); return(router); }
public async Task <A> HttpClientPostNetworkApi <A>(IConfiguration configuration, string endPoint, string propertyReturn, NeutronDTO 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.PostAsync(client.BaseAddress + endPoint, httpContent); response.EnsureSuccessStatusCode(); string conteudo = JObject.Parse(response.Content.ReadAsStringAsync().Result).ToString(); var parsedObject = JObject.Parse(conteudo); conteudo = parsedObject[propertyReturn].ToString(); A retorno = JsonConvert.DeserializeObject <A>(conteudo, jsonSerializerSettings); return(retorno); }