|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Extensions; |
| 4 | +using System.Linq; |
4 | 5 | using System.Runtime.Serialization; |
5 | 6 | using System.Threading; |
6 | 7 | using System.Threading.Tasks; |
@@ -242,10 +243,33 @@ public string AdminPassword |
242 | 243 |
|
243 | 244 | /// <inheritdoc cref="ComputeApi.AssociateFloatingIPAsync" /> |
244 | 245 | /// <exception cref="InvalidOperationException">When this instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception> |
245 | | - public virtual Task AssociateFloatingIPAsync(AssociateFloatingIPRequest request, CancellationToken cancellationToken = default(CancellationToken)) |
| 246 | + public virtual async Task AssociateFloatingIPAsync(AssociateFloatingIPRequest request, CancellationToken cancellationToken = default(CancellationToken)) |
246 | 247 | { |
247 | 248 | var compute = this.GetOwnerOrThrow<ComputeApi>(); |
248 | | - return compute.AssociateFloatingIPAsync(Id, request, cancellationToken); |
| 249 | + await compute.AssociateFloatingIPAsync(Id, request, cancellationToken); |
| 250 | + |
| 251 | + Addresses = await compute.ListServerAddressesAsync<ServerAddressCollection>(Id, cancellationToken); |
| 252 | + } |
| 253 | + |
| 254 | + /// <inheritdoc cref="ComputeApi.DisassociateFloatingIPAsync" /> |
| 255 | + /// <exception cref="InvalidOperationException">When this instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception> |
| 256 | + public virtual async Task DisassociateFloatingIPAsync(string floatingIPAddress, CancellationToken cancellationToken = default(CancellationToken)) |
| 257 | + { |
| 258 | + var compute = this.GetOwnerOrThrow<ComputeApi>(); |
| 259 | + await compute.DisassociateFloatingIPAsync(Id, floatingIPAddress, cancellationToken); |
| 260 | + |
| 261 | + // Remove the address from the current instance immediately |
| 262 | + foreach (KeyValuePair<string, IList<ServerAddress>> group in Addresses) |
| 263 | + { |
| 264 | + foreach (ServerAddress address in group.Value) |
| 265 | + { |
| 266 | + if (address.Type == AddressType.Floating && address.IP == floatingIPAddress) |
| 267 | + { |
| 268 | + Addresses[group.Key].Remove(address); |
| 269 | + return; |
| 270 | + } |
| 271 | + } |
| 272 | + } |
249 | 273 | } |
250 | 274 |
|
251 | 275 | /// <summary /> |
|
0 commit comments