public async Task CreatePublicIPTest() { Trace.WriteLine("Looking up the RackConnect network..."); var network = (await _rackConnectService.ListNetworksAsync()).First(); Trace.Write("Creating a test cloud server..."); var server = _testData.CreateServer(network.Id); Trace.WriteLine(server.Id); Trace.Write("Assigning a public ip address to the test cloud server... "); var ipRequest = new PublicIPCreateDefinition { ServerId = server.Id, ShouldRetain = true }; var ip = await _testData.CreatePublicIP(ipRequest); await ip.WaitUntilActiveAsync(); Trace.WriteLine(ip.PublicIPv4Address); Assert.NotNull(ip); Assert.Equal(server.Id, ip.Server.ServerId); Assert.NotNull(ip.PublicIPv4Address); Assert.Equal(PublicIPStatus.Active, ip.Status); Trace.WriteLine("Retrieving public IPs assigned to the test cloud server..."); var filterByServer = new ListPublicIPsFilter { ServerId = server.Id }; var ips = await _rackConnectService.ListPublicIPsAsync(filterByServer); Assert.NotNull(ips); Assert.True(ips.Any(x => x.Id == ip.Id)); Trace.WriteLine("Update the IP address to not be retained..."); ip = await _rackConnectService.UpdatePublicIPAsync(ip.Id, new PublicIPUpdateDefinition { ShouldRetain = false }); await ip.WaitUntilActiveAsync(); Assert.NotNull(ip); Assert.False(ip.ShouldRetain); Trace.WriteLine("Removing public IP from test cloud server..."); await ip.DeleteAsync(); await ip.WaitUntilDeletedAsync(); Trace.WriteLine($"Verifying that {ip.PublicIPv4Address} is no longer assigned..."); ips = await _rackConnectService.ListPublicIPsAsync(filterByServer); Assert.NotNull(ips); Assert.False(ips.Any(x => x.Id == ip.Id)); }
public async Task CreatePublicIPTest() { Trace.WriteLine("Looking up the RackConnect network..."); var network = (await _rackConnectService.ListNetworksAsync()).First(); Trace.Write("Creating a test cloud server..."); var server = _testData.CreateServer(network.Id); Trace.WriteLine(server.Id); Trace.Write("Assigning a public ip address to the test cloud server... "); var ipRequest = new PublicIPCreateDefinition {ServerId = server.Id, ShouldRetain = true}; var ip = await _testData.CreatePublicIP(ipRequest); await ip.WaitUntilActiveAsync(); Trace.WriteLine(ip.PublicIPv4Address); Assert.NotNull(ip); Assert.Equal(server.Id, ip.Server.ServerId); Assert.NotNull(ip.PublicIPv4Address); Assert.Equal(PublicIPStatus.Active, ip.Status); Trace.WriteLine("Retrieving public IPs assigned to the test cloud server..."); var filterByServer = new ListPublicIPsFilter {ServerId = server.Id}; var ips = await _rackConnectService.ListPublicIPsAsync(filterByServer); Assert.NotNull(ips); Assert.True(ips.Any(x => x.Id == ip.Id)); Trace.WriteLine("Update the IP address to not be retained..."); ip = await _rackConnectService.UpdatePublicIPAsync(ip.Id, new PublicIPUpdateDefinition { ShouldRetain = false }); await ip.WaitUntilActiveAsync(); Assert.NotNull(ip); Assert.False(ip.ShouldRetain); Trace.WriteLine("Removing public IP from test cloud server..."); await ip.DeleteAsync(); await ip.WaitUntilDeletedAsync(); Trace.WriteLine($"Verifying that {ip.PublicIPv4Address} is no longer assigned..."); ips = await _rackConnectService.ListPublicIPsAsync(filterByServer); Assert.NotNull(ips); Assert.False(ips.Any(x => x.Id == ip.Id)); }
/// <summary> /// Lists all public IP addresses associated with the account. /// </summary> /// <param name="filter">Optional filter parameters.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns> /// A collection of public IP addresses associated with the account. /// </returns> public async Task <IEnumerable <PublicIP> > ListPublicIPsAsync(ListPublicIPsFilter filter = null, CancellationToken cancellationToken = default(CancellationToken)) { filter = filter ?? new ListPublicIPsFilter(); Url endpoint = await _urlBuilder.GetEndpoint(cancellationToken).ConfigureAwait(false); var ips = await endpoint .AppendPathSegments("public_ips") .SetQueryParams(new { cloud_server_id = filter.ServerId, retain = filter.IsRetained }) .Authenticate(_authenticationProvider) .GetJsonAsync <IEnumerable <PublicIP> >(cancellationToken) .ConfigureAwait(false); foreach (var ip in ips) { SetOwner(ip); } return(ips); }
/// <summary> /// Lists all public IP addresses associated with the account. /// </summary> /// <param name="filter">Optional filter parameters.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns> /// A collection of public IP addresses associated with the account. /// </returns> public async Task<IEnumerable<PublicIP>> ListPublicIPsAsync(ListPublicIPsFilter filter = null, CancellationToken cancellationToken = default(CancellationToken)) { filter = filter ?? new ListPublicIPsFilter(); Url endpoint = await _urlBuilder.GetEndpoint(cancellationToken).ConfigureAwait(false); var ips = await endpoint .AppendPathSegments("public_ips") .SetQueryParams(new { cloud_server_id = filter.ServerId, retain = filter.IsRetained }) .Authenticate(_authenticationProvider) .GetJsonAsync<IEnumerable<PublicIP>>(cancellationToken) .ConfigureAwait(false); foreach (var ip in ips) { SetOwner(ip); } return ips; }
/// <inheritdoc cref="RackConnectService.ListPublicIPsAsync"/> public static IEnumerable<PublicIP> ListPublicIPs(this RackConnectService rackConnectService, ListPublicIPsFilter filter = null) { return rackConnectService.ListPublicIPsAsync(filter).ForceSynchronous(); }