Skip to content

Commit 8edc42f

Browse files
committed
Merge pull request #425 from sharwell/fix-420
Add special support for IPAddress.None for servers
2 parents 7fe1830 + 36af44c commit 8edc42f

File tree

8 files changed

+74
-40
lines changed

8 files changed

+74
-40
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace net.openstack.Core.Domain.Converters
2+
{
3+
using System;
4+
using System.Net;
5+
using Newtonsoft.Json;
6+
7+
/// <summary>
8+
/// This implementation of <see cref="JsonConverter"/> extends the behavior of
9+
/// <see cref="IPAddressSimpleConverter"/> by treating null values in the JSON representation as
10+
/// <see cref="IPAddress.None"/> instead of <see langword="null"/>.
11+
/// </summary>
12+
/// <threadsafety static="true" instance="false"/>
13+
/// <preliminary/>
14+
public class IPAddressNoneIsNullSimpleConverter : IPAddressSimpleConverter
15+
{
16+
/// <inheritdoc/>
17+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
18+
{
19+
object result = base.ReadJson(reader, objectType, existingValue, serializer);
20+
return result ?? IPAddress.None;
21+
}
22+
23+
/// <inheritdoc/>
24+
protected override string ConvertToString(IPAddress obj)
25+
{
26+
if (IPAddress.None.Equals(obj))
27+
return null;
28+
29+
return base.ConvertToString(obj);
30+
}
31+
}
32+
}

src/corelib/Core/Domain/ServerBase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ public bool HardReboot()
240240
/// <param name="imageId">The image to rebuild the server from. This is specified as an image ID (see <see cref="SimpleServerImage.Id"/>) or a full URL.</param>
241241
/// <param name="flavor">The new flavor for server. This is obtained from <see cref="Flavor.Id"/>.</param>
242242
/// <param name="adminPassword">The new admin password for the server.</param>
243-
/// <param name="accessIPv4">The new IP v4 address for the server. If the value is <see langword="null"/>, the server's IP v4 address is not updated.</param>
244-
/// <param name="accessIPv6">The new IP v6 address for the server. If the value is <see langword="null"/>, the server's IP v6 address is not updated.</param>
243+
/// <param name="accessIPv4">The new IP v4 address for the server, or <see cref="IPAddress.None"/> to remove the configured IP v4 address for the server. If the value is <see langword="null"/>, the server's IP v4 address is not updated.</param>
244+
/// <param name="accessIPv6">The new IP v6 address for the server, or <see cref="IPAddress.None"/> to remove the configured IP v6 address for the server. If the value is <see langword="null"/>, the server's IP v6 address is not updated.</param>
245245
/// <param name="metadata">The list of metadata to associate with the server. If the value is <see langword="null"/>, the metadata associated with the server is not changed during the rebuild operation.</param>
246246
/// <param name="diskConfig">The disk configuration. If the value is <see langword="null"/>, the default configuration for the specified image is used.</param>
247247
/// <param name="personality">The path and contents of a file to inject in the target file system during the rebuild operation. If the value is <see langword="null"/>, no file is injected.</param>
@@ -260,9 +260,9 @@ public bool HardReboot()
260260
/// <para>-or-</para>
261261
/// <para>If <paramref name="adminPassword"/> is empty.</para>
262262
/// <para>-or-</para>
263-
/// <para>If the <see cref="AddressFamily"/> of <paramref name="accessIPv4"/> is not <see cref="AddressFamily.InterNetwork"/></para>
263+
/// <para>If <paramref name="accessIPv4"/> is not <see cref="IPAddress.None"/> and the <see cref="AddressFamily"/> of <paramref name="accessIPv4"/> is not <see cref="AddressFamily.InterNetwork"/>.</para>
264264
/// <para>-or-</para>
265-
/// <para>If the <see cref="AddressFamily"/> of <paramref name="accessIPv6"/> is not <see cref="AddressFamily.InterNetworkV6"/></para>
265+
/// <para>If <paramref name="accessIPv6"/> is not <see cref="IPAddress.None"/> and the <see cref="AddressFamily"/> of <paramref name="accessIPv6"/> is not <see cref="AddressFamily.InterNetworkV6"/>.</para>
266266
/// </exception>
267267
/// <exception cref="NotSupportedException">
268268
/// If the provider does not support the given <paramref name="diskConfig"/>.
@@ -278,9 +278,9 @@ public bool Rebuild(string name, string imageId, string flavor, string adminPass
278278
throw new ArgumentException("imageId cannot be empty");
279279
if (string.IsNullOrEmpty(flavor))
280280
throw new ArgumentException("flavor cannot be empty");
281-
if (accessIPv4 != null && accessIPv4.AddressFamily != AddressFamily.InterNetwork)
281+
if (accessIPv4 != null && !IPAddress.None.Equals(accessIPv4) && accessIPv4.AddressFamily != AddressFamily.InterNetwork)
282282
throw new ArgumentException("The specified value for accessIPv4 is not an IP v4 address.", "accessIPv4");
283-
if (accessIPv6 != null && accessIPv6.AddressFamily != AddressFamily.InterNetworkV6)
283+
if (accessIPv6 != null && !IPAddress.None.Equals(accessIPv6) && accessIPv6.AddressFamily != AddressFamily.InterNetworkV6)
284284
throw new ArgumentException("The specified value for accessIPv6 is not an IP v6 address.", "accessIPv6");
285285
if (diskConfig != null && diskConfig != DiskConfiguration.Auto && diskConfig != DiskConfiguration.Manual)
286286
throw new NotSupportedException("The specified disk configuration is not supported.");

src/corelib/Core/Providers/IComputeProvider.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,18 @@ public interface IComputeProvider
193193
/// </remarks>
194194
/// <param name="serverId">The server ID. This is obtained from <see cref="ServerBase.Id">ServerBase.Id</see>.</param>
195195
/// <param name="name">The new name for the server. If the value is <see langword="null"/>, the server name is not changed.</param>
196-
/// <param name="accessIPv4">The new IP v4 address for the server. If the value is <see langword="null"/>, the server's IP v4 address is not updated.</param>
197-
/// <param name="accessIPv6">The new IP v6 address for the server. If the value is <see langword="null"/>, the server's IP v6 address is not updated.</param>
196+
/// <param name="accessIPv4">The new IP v4 address for the server, or <see cref="IPAddress.None"/> to remove the configured IP v4 address for the server. If the value is <see langword="null"/>, the server's IP v4 address is not updated.</param>
197+
/// <param name="accessIPv6">The new IP v6 address for the server, or <see cref="IPAddress.None"/> to remove the configured IP v6 address for the server. If the value is <see langword="null"/>, the server's IP v6 address is not updated.</param>
198198
/// <param name="region">The region in which to execute this action. If not specified, the user's default region will be used.</param>
199199
/// <param name="identity">The cloud identity to use for this request. If not specified, the default identity for the current provider instance will be used.</param>
200200
/// <returns><see langword="true"/> if the server was successfully updated; otherwise <see langword="false"/>.</returns>
201201
/// <exception cref="ArgumentNullException">If <paramref name="serverId"/> is <see langword="null"/>.</exception>
202202
/// <exception cref="ArgumentException">
203203
/// If <paramref name="serverId"/> is empty.
204204
/// <para>-or-</para>
205-
/// <para>If the <see cref="AddressFamily"/> of <paramref name="accessIPv4"/> is not <see cref="AddressFamily.InterNetwork"/></para>
205+
/// <para>If <paramref name="accessIPv4"/> is not <see cref="IPAddress.None"/> and the <see cref="AddressFamily"/> of <paramref name="accessIPv4"/> is not <see cref="AddressFamily.InterNetwork"/>.</para>
206206
/// <para>-or-</para>
207-
/// <para>If the <see cref="AddressFamily"/> of <paramref name="accessIPv6"/> is not <see cref="AddressFamily.InterNetworkV6"/></para>
207+
/// <para>If <paramref name="accessIPv6"/> is not <see cref="IPAddress.None"/> and the <see cref="AddressFamily"/> of <paramref name="accessIPv6"/> is not <see cref="AddressFamily.InterNetworkV6"/>.</para>
208208
/// </exception>
209209
/// <exception cref="NotSupportedException">
210210
/// If the provider does not support the given <paramref name="identity"/> type.
@@ -378,8 +378,8 @@ public interface IComputeProvider
378378
/// <param name="imageName">The image to rebuild the server from. This is specified as an image ID (see <see cref="SimpleServerImage.Id"/>) or a full URL.</param>
379379
/// <param name="flavor">The new flavor for server. This is obtained from <see cref="Flavor.Id"/>.</param>
380380
/// <param name="adminPassword">The new admin password for the server.</param>
381-
/// <param name="accessIPv4">The new IP v4 address for the server. If the value is <see langword="null"/>, the server's IP v4 address is not updated.</param>
382-
/// <param name="accessIPv6">The new IP v6 address for the server. If the value is <see langword="null"/>, the server's IP v6 address is not updated.</param>
381+
/// <param name="accessIPv4">The new IP v4 address for the server, or <see cref="IPAddress.None"/> to remove the configured IP v4 address for the server. If the value is <see langword="null"/>, the server's IP v4 address is not updated.</param>
382+
/// <param name="accessIPv6">The new IP v6 address for the server, or <see cref="IPAddress.None"/> to remove the configured IP v6 address for the server. If the value is <see langword="null"/>, the server's IP v6 address is not updated.</param>
383383
/// <param name="metadata">The list of metadata to associate with the server. If the value is <see langword="null"/>, the metadata associated with the server is not changed during the rebuild operation.</param>
384384
/// <param name="diskConfig">The disk configuration. If the value is <see langword="null"/>, the default configuration for the specified image is used.</param>
385385
/// <param name="personality">The path and contents of a file to inject in the target file system during the rebuild operation. If the value is <see langword="null"/>, no file is injected.</param>
@@ -404,9 +404,9 @@ public interface IComputeProvider
404404
/// <para>-or-</para>
405405
/// <para>If <paramref name="adminPassword"/> is empty.</para>
406406
/// <para>-or-</para>
407-
/// <para>If the <see cref="AddressFamily"/> of <paramref name="accessIPv4"/> is not <see cref="AddressFamily.InterNetwork"/></para>
407+
/// <para>If <paramref name="accessIPv4"/> is not <see cref="IPAddress.None"/> and the <see cref="AddressFamily"/> of <paramref name="accessIPv4"/> is not <see cref="AddressFamily.InterNetwork"/>.</para>
408408
/// <para>-or-</para>
409-
/// <para>If the <see cref="AddressFamily"/> of <paramref name="accessIPv6"/> is not <see cref="AddressFamily.InterNetworkV6"/></para>
409+
/// <para>If <paramref name="accessIPv6"/> is not <see cref="IPAddress.None"/> and the <see cref="AddressFamily"/> of <paramref name="accessIPv6"/> is not <see cref="AddressFamily.InterNetworkV6"/>.</para>
410410
/// </exception>
411411
/// <exception cref="NotSupportedException">
412412
/// If the provider does not support the given <paramref name="diskConfig"/>.

src/corelib/Providers/Rackspace/CloudServersProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,9 @@ public bool UpdateServer(string serverId, string name = null, IPAddress accessIP
248248
throw new ArgumentNullException("serverId");
249249
if (string.IsNullOrEmpty(serverId))
250250
throw new ArgumentException("serverId cannot be empty");
251-
if (accessIPv4 != null && accessIPv4.AddressFamily != AddressFamily.InterNetwork)
251+
if (accessIPv4 != null && !IPAddress.None.Equals(accessIPv4) && accessIPv4.AddressFamily != AddressFamily.InterNetwork)
252252
throw new ArgumentException("The specified value for accessIPv4 is not an IP v4 address.", "accessIPv4");
253-
if (accessIPv6 != null && accessIPv6.AddressFamily != AddressFamily.InterNetworkV6)
253+
if (accessIPv6 != null && !IPAddress.None.Equals(accessIPv6) && accessIPv6.AddressFamily != AddressFamily.InterNetworkV6)
254254
throw new ArgumentException("The specified value for accessIPv6 is not an IP v6 address.", "accessIPv6");
255255
CheckIdentity(identity);
256256

@@ -545,9 +545,9 @@ public Server RebuildServer(string serverId, string serverName, string imageName
545545
throw new ArgumentException("imageName cannot be empty");
546546
if (string.IsNullOrEmpty(flavor))
547547
throw new ArgumentException("flavor cannot be empty");
548-
if (accessIPv4 != null && accessIPv4.AddressFamily != AddressFamily.InterNetwork)
548+
if (accessIPv4 != null && !IPAddress.None.Equals(accessIPv4) && accessIPv4.AddressFamily != AddressFamily.InterNetwork)
549549
throw new ArgumentException("The specified value for accessIPv4 is not an IP v4 address.", "accessIPv4");
550-
if (accessIPv6 != null && accessIPv6.AddressFamily != AddressFamily.InterNetworkV6)
550+
if (accessIPv6 != null && !IPAddress.None.Equals(accessIPv6) && accessIPv6.AddressFamily != AddressFamily.InterNetworkV6)
551551
throw new ArgumentException("The specified value for accessIPv6 is not an IP v6 address.", "accessIPv6");
552552
if (diskConfig != null && diskConfig != DiskConfiguration.Auto && diskConfig != DiskConfiguration.Manual)
553553
throw new NotSupportedException("The specified disk configuration is not supported.");

src/corelib/Providers/Rackspace/Objects/Request/ServerRebuildDetails.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ internal class ServerRebuildDetails
6363
/// The new IP v4 address for the server. If the value is <see langword="null"/>, the server's IP v4 address is not updated.
6464
/// </summary>
6565
[JsonProperty("accessIPv4", DefaultValueHandling = DefaultValueHandling.Include)]
66-
[JsonConverter(typeof(IPAddressSimpleConverter))]
66+
[JsonConverter(typeof(IPAddressNoneIsNullSimpleConverter))]
6767
public IPAddress AccessIPv4 { get; private set; }
6868

6969
/// <summary>
7070
/// The new IP v6 address for the server. If the value is <see langword="null"/>, the server's IP v6 address is not updated.
7171
/// </summary>
7272
[JsonProperty("accessIPv6", DefaultValueHandling = DefaultValueHandling.Include)]
73-
[JsonConverter(typeof(IPAddressSimpleConverter))]
73+
[JsonConverter(typeof(IPAddressNoneIsNullSimpleConverter))]
7474
public IPAddress AccessIPv6 { get; private set; }
7575

7676
/// <summary>
@@ -80,8 +80,8 @@ internal class ServerRebuildDetails
8080
/// <param name="imageName">The image to rebuild the server from. This is specified as an image ID (see <see cref="SimpleServerImage.Id"/>) or a full URL.</param>
8181
/// <param name="flavor">The new flavor for server. This is obtained from <see cref="net.openstack.Core.Domain.Flavor.Id"/>.</param>
8282
/// <param name="adminPassword">The new admin password for the server.</param>
83-
/// <param name="accessIPv4">The new IP v4 address for the server. If the value is <see langword="null"/>, the server's IP v4 address is not updated.</param>
84-
/// <param name="accessIPv6">The new IP v6 address for the server. If the value is <see langword="null"/>, the server's IP v6 address is not updated.</param>
83+
/// <param name="accessIPv4">The new IP v4 address for the server, or <see cref="IPAddress.None"/> to remove the configured IP v4 address for the server. If the value is <see langword="null"/>, the server's IP v4 address is not updated.</param>
84+
/// <param name="accessIPv6">The new IP v6 address for the server, or <see cref="IPAddress.None"/> to remove the configured IP v6 address for the server. If the value is <see langword="null"/>, the server's IP v6 address is not updated.</param>
8585
/// <param name="metadata">The list of metadata to associate with the server. If the value is <see langword="null"/>, the metadata associated with the server is not changed during the rebuild operation.</param>
8686
/// <param name="diskConfig">The disk configuration. If the value is <see langword="null"/>, the default configuration for the specified image is used.</param>
8787
/// <param name="personality">The path and contents of a file to inject in the target file system during the rebuild operation. If the value is <see langword="null"/>, no file is injected.</param>
@@ -99,9 +99,9 @@ internal class ServerRebuildDetails
9999
/// <para>-or-</para>
100100
/// <para>If <paramref name="adminPassword"/> is empty.</para>
101101
/// <para>-or-</para>
102-
/// <para>If the <see cref="AddressFamily"/> of <paramref name="accessIPv4"/> is not <see cref="AddressFamily.InterNetwork"/></para>
102+
/// <para>If <paramref name="accessIPv4"/> is not <see cref="IPAddress.None"/> and the <see cref="AddressFamily"/> of <paramref name="accessIPv4"/> is not <see cref="AddressFamily.InterNetwork"/>.</para>
103103
/// <para>-or-</para>
104-
/// <para>If the <see cref="AddressFamily"/> of <paramref name="accessIPv6"/> is not <see cref="AddressFamily.InterNetworkV6"/></para>
104+
/// <para>If <paramref name="accessIPv6"/> is not <see cref="IPAddress.None"/> and the <see cref="AddressFamily"/> of <paramref name="accessIPv6"/> is not <see cref="AddressFamily.InterNetworkV6"/>.</para>
105105
/// </exception>
106106
public ServerRebuildDetails(string name, string imageName, string flavor, string adminPassword, IPAddress accessIPv4, IPAddress accessIPv6, Metadata metadata, DiskConfiguration diskConfig, Personality personality)
107107
{
@@ -117,9 +117,9 @@ public ServerRebuildDetails(string name, string imageName, string flavor, string
117117
throw new ArgumentException("flavor cannot be empty");
118118
if (string.IsNullOrEmpty(adminPassword))
119119
throw new ArgumentException("adminPassword cannot be empty");
120-
if (accessIPv4 != null && accessIPv4.AddressFamily != AddressFamily.InterNetwork)
120+
if (accessIPv4 != null && !IPAddress.None.Equals(accessIPv4) && accessIPv4.AddressFamily != AddressFamily.InterNetwork)
121121
throw new ArgumentException("The specified value for accessIPv4 is not an IP v4 address.", "accessIPv4");
122-
if (accessIPv6 != null && accessIPv6.AddressFamily != AddressFamily.InterNetworkV6)
122+
if (accessIPv6 != null && !IPAddress.None.Equals(accessIPv6) && accessIPv6.AddressFamily != AddressFamily.InterNetworkV6)
123123
throw new ArgumentException("The specified value for accessIPv6 is not an IP v6 address.", "accessIPv6");
124124

125125
Name = name;

0 commit comments

Comments
 (0)