-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathServerImage.cs
More file actions
312 lines (279 loc) · 16 KB
/
Copy pathServerImage.cs
File metadata and controls
312 lines (279 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
namespace net.openstack.Core.Domain
{
using System;
using net.openstack.Core.Exceptions.Response;
using net.openstack.Core.Providers;
using Newtonsoft.Json;
/// <summary>
/// Extends <see cref="SimpleServerImage"/> with detailed information about an image.
/// </summary>
/// <seealso cref="IComputeProvider.ListImagesWithDetails"/>
/// <seealso cref="IComputeProvider.GetImage"/>
/// <seealso href="http://docs.openstack.org/api/openstack-compute/2/content/Get_Image_Details-d1e4848.html">Get Image Details (OpenStack Compute API v2 and Extensions Reference)</seealso>
/// <threadsafety static="true" instance="false"/>
[JsonObject(MemberSerialization.OptIn)]
public class ServerImage : SimpleServerImage
{
/// <summary>
/// This is the backing field for the <see cref="Server"/> property.
/// </summary>
private SimpleServer _server;
/// <summary>
/// Gets the default disk configuration used when creating, rebuilding, or resizing servers
/// with the image. For images created from servers, the value is inherited from the server.
/// </summary>
/// <remarks>
/// <note>This property is defined by the Rackspace-specific Disk Configuration Extension to the OpenStack Compute API.</note>
/// </remarks>
/// <seealso href="http://docs.rackspace.com/servers/api/v2/cs-devguide/content/ch_extensions.html#diskconfig_attribute">Disk Configuration Extension (Rackspace Next Generation Cloud Servers Developer Guide - API v2)</seealso>
[JsonProperty("OS-DCF:diskConfig")]
public DiskConfiguration DiskConfig { get; private set; }
/// <summary>
/// Gets the "status" property of the image.
/// <note type="warning">The value of this property is not defined. Do not use.</note>
/// </summary>
[JsonProperty("status")]
public ImageState Status
{
get;
private set;
}
/// <summary>
/// Gets the "created" property of the image.
/// <note type="warning">The value of this property is not defined. Do not use.</note>
/// </summary>
[JsonProperty("created")]
public DateTimeOffset Created { get; private set; }
/// <summary>
/// Gets the image completion progress, as a percentage.
/// <note type="warning">The value of this property is not defined. Do not use.</note>
/// </summary>
/// <value>A percentage from 0 to 100 (inclusive) representing the image completion progress.</value>
[JsonProperty("progress")]
public int Progress { get; private set; }
/// <summary>
/// Gets the "updated" property of the image.
/// <note type="warning">The value of this property is not defined. Do not use.</note>
/// </summary>
[JsonProperty("updated")]
public DateTimeOffset Updated { get; private set; }
/// <summary>
/// Gets the minimum disk requirements needed to create a server with the image.
/// <note type="warning">The value of this property is not defined. Do not use.</note>
/// </summary>
/// <seealso href="http://docs.openstack.org/api/openstack-compute/2/content/List_Images-d1e4435.html">List Images (OpenStack Compute API v2 and Extensions Reference)</seealso>
[JsonProperty("minDisk")]
public int MinDisk { get; private set; }
/// <summary>
/// Gets the "server" property of the image.
/// <note type="warning">The value of this property is not defined. Do not use.</note>
/// </summary>
[JsonProperty("server")]
public SimpleServer Server
{
get
{
// this is handled in the getter because the Provider/Region/Identity
// properties of the current instance might not be set at the point
// this property is set
if (_server != null)
{
_server.Provider = Provider;
_server.Region = Region;
_server.Identity = Identity;
}
return _server;
}
private set
{
_server = value;
}
}
/// <summary>
/// Gets the minimum RAM requirements needed to create a server with the image.
/// <note type="warning">The value of this property is not defined. Do not use.</note>
/// </summary>
/// <seealso href="http://docs.openstack.org/api/openstack-compute/2/content/List_Images-d1e4435.html">List Images (OpenStack Compute API v2 and Extensions Reference)</seealso>
[JsonProperty("minRam")]
public int MinRAM { get; private set; }
/// <inheritdoc/>
protected override void UpdateThis(SimpleServerImage serverImage)
{
if (serverImage == null)
throw new ArgumentNullException("serverImage");
base.UpdateThis(serverImage);
var details = serverImage as ServerImage;
if (details == null)
return;
DiskConfig = details.DiskConfig;
Status = details.Status;
Created = details.Created;
Progress = details.Progress;
Updated = details.Updated;
MinDisk = details.MinDisk;
MinRAM = details.MinRAM;
}
/// <summary>
/// Gets the metadata associated with the specified image.
/// </summary>
/// <returns>A <see cref="Metadata"/> object containing the metadata associated with the image.</returns>
/// <exception cref="ResponseException">If the REST API request failed.</exception>
/// <seealso cref="IComputeProvider.ListImageMetadata"/>
/// <seealso href="http://docs.openstack.org/api/openstack-compute/2/content/List_Metadata-d1e5089.html">List Metadata (OpenStack Compute API v2 and Extensions Reference)</seealso>
public Metadata GetMetadata()
{
return Provider.ListImageMetadata(Id, Region, Identity);
}
/// <summary>
/// Sets the metadata associated with the specified image, replacing any existing metadata.
/// </summary>
/// <param name="metadata">The metadata to associate with the image.</param>
/// <returns><see langword="true"/> if the metadata for the image was successfully updated; otherwise, <see langword="false"/>.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="metadata"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">If <paramref name="metadata"/> contains any values with empty keys.</exception>
/// <exception cref="ResponseException">If the REST API request failed.</exception>
/// <seealso cref="IComputeProvider.SetImageMetadata"/>
/// <seealso href="http://docs.openstack.org/api/openstack-compute/2/content/Create_or_Replace_Metadata-d1e5358.html">Set Metadata (OpenStack Compute API v2 and Extensions Reference)</seealso>
public bool SetMetadata(Metadata metadata)
{
if (metadata == null)
throw new ArgumentNullException("metadata");
return Provider.SetImageMetadata(Id, metadata, Region, Identity);
}
/// <summary>
/// Updates the metadata for the specified image.
/// </summary>
/// <remarks>
/// For each item in <paramref name="metadata"/>, if the key exists, the value is updated; otherwise, the item is added.
/// </remarks>
/// <param name="metadata">The image metadata to update.</param>
/// <returns><see langword="true"/> if the metadata for the image was successfully updated; otherwise, <see langword="false"/>.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="metadata"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">If <paramref name="metadata"/> contains any values with empty keys.</exception>
/// <exception cref="ResponseException">If the REST API request failed.</exception>
/// <seealso cref="IComputeProvider.UpdateImageMetadata"/>
/// <seealso href="http://docs.openstack.org/api/openstack-compute/2/content/Update_Metadata-d1e5208.html">Update Metadata (OpenStack Compute API v2 and Extensions Reference)</seealso>
public bool AddMetadata(Metadata metadata)
{
if (metadata == null)
throw new ArgumentNullException("metadata");
return Provider.UpdateImageMetadata(Id, metadata, Region, Identity);
}
/// <summary>
/// Sets the value for the specified metadata item. If the key already exists, it is updated; otherwise, a new metadata item is added.
/// </summary>
/// <param name="key">The metadata key.</param>
/// <param name="value">The new value for the metadata item.</param>
/// <returns><see langword="true"/> if the metadata for the image was successfully updated; otherwise, <see langword="false"/>.</returns>
/// <exception cref="ArgumentNullException">
/// If <paramref name="key"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="value"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentException">If <paramref name="key"/> is empty.</exception>
/// <exception cref="ResponseException">If the REST API request failed.</exception>
/// <seealso cref="IComputeProvider.SetImageMetadataItem"/>
/// <seealso href="http://docs.openstack.org/api/openstack-compute/2/content/Create_or_Update_a_Metadata_Item-d1e5633.html">Set Metadata Item (OpenStack Compute API v2 and Extensions Reference)</seealso>
public bool AddMetadata(string key, string value)
{
if (key == null)
throw new ArgumentNullException("key");
if (value == null)
throw new ArgumentNullException("value");
if (string.IsNullOrEmpty(key))
throw new ArgumentException("key cannot be empty");
return Provider.SetImageMetadataItem(Id, key, value, Region, Identity);
}
/// <summary>
/// Updates the metadata for the specified image.
/// </summary>
/// <remarks>
/// For each item in <paramref name="metadata"/>, if the key exists, the value is updated; otherwise, the item is added.
/// </remarks>
/// <param name="metadata">The image metadata to update.</param>
/// <returns><see langword="true"/> if the metadata for the image was successfully updated; otherwise, <see langword="false"/>.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="metadata"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">If <paramref name="metadata"/> contains any values with empty keys.</exception>
/// <exception cref="ResponseException">If the REST API request failed.</exception>
/// <seealso cref="IComputeProvider.UpdateImageMetadata"/>
/// <seealso href="http://docs.openstack.org/api/openstack-compute/2/content/Update_Metadata-d1e5208.html">Update Metadata (OpenStack Compute API v2 and Extensions Reference)</seealso>
public bool UpdateMetadata(Metadata metadata)
{
if (metadata == null)
throw new ArgumentNullException("metadata");
return Provider.UpdateImageMetadata(Id, metadata, Region, Identity);
}
/// <summary>
/// Deletes the specified metadata items from the image.
/// </summary>
/// <remarks>
/// <note>
/// This method ignores the values in <paramref name="metadata"/>. Metadata items are
/// removed whether or not their current values match those in <paramref name="metadata"/>.
/// </note>
/// </remarks>
/// <param name="metadata">A collection of metadata items to delete.</param>
/// <returns><see langword="true"/> if all of the metadata item were removed; otherwise, <see langword="false"/>.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="metadata"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">If <paramref name="metadata"/> contains a null or empty key.</exception>
/// <exception cref="ResponseException">If the REST API request failed.</exception>
/// <seealso cref="IComputeProvider.DeleteImageMetadataItem"/>
/// <seealso href="http://docs.openstack.org/api/openstack-compute/2/content/Delete_Metadata_Item-d1e5790.html">Delete Metadata Item (OpenStack Compute API v2 and Extensions Reference)</seealso>
public bool DeleteMetadata(Metadata metadata)
{
if (metadata == null)
throw new ArgumentNullException("metadata");
bool success = true;
foreach (var item in metadata)
{
if (string.IsNullOrEmpty(item.Key))
throw new ArgumentException("metadata cannot contain any empty keys");
success &= DeleteMetadataItem(item.Key);
}
return success;
}
/// <summary>
/// Deletes the specified metadata item from the image.
/// </summary>
/// <param name="key">The metadata key.</param>
/// <returns><see langword="true"/> if the metadata item was removed; otherwise, <see langword="false"/>.</returns>
/// <exception cref="ArgumentNullException">If <paramref name="key"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException">If <paramref name="key"/> is empty.</exception>
/// <exception cref="ResponseException">If the REST API request failed.</exception>
/// <seealso cref="IComputeProvider.DeleteImageMetadataItem"/>
/// <seealso href="http://docs.openstack.org/api/openstack-compute/2/content/Delete_Metadata_Item-d1e5790.html">Delete Metadata Item (OpenStack Compute API v2 and Extensions Reference)</seealso>
public bool DeleteMetadataItem(string key)
{
if (key == null)
throw new ArgumentNullException("key");
if (string.IsNullOrEmpty(key))
throw new ArgumentException("key cannot be empty");
return Provider.DeleteImageMetadataItem(Id, key, Region, Identity);
}
/// <summary>
/// Sets the value for the specified metadata item. If the key already exists, it is updated; otherwise, a new metadata item is added.
/// </summary>
/// <param name="key">The metadata key.</param>
/// <param name="value">The new value for the metadata item.</param>
/// <returns><see langword="true"/> if the metadata for the image was successfully updated; otherwise, <see langword="false"/>.</returns>
/// <exception cref="ArgumentNullException">
/// If <paramref name="key"/> is <see langword="null"/>.
/// <para>-or-</para>
/// <para>If <paramref name="value"/> is <see langword="null"/>.</para>
/// </exception>
/// <exception cref="ArgumentException">If <paramref name="key"/> is empty.</exception>
/// <exception cref="ResponseException">If the REST API request failed.</exception>
/// <seealso cref="IComputeProvider.SetImageMetadataItem"/>
/// <seealso href="http://docs.openstack.org/api/openstack-compute/2/content/Create_or_Update_a_Metadata_Item-d1e5633.html">Set Metadata Item (OpenStack Compute API v2 and Extensions Reference)</seealso>
public bool UpdateMetadataItem(string key, string value)
{
if (key == null)
throw new ArgumentNullException("key");
if (value == null)
throw new ArgumentNullException("value");
if (string.IsNullOrEmpty(key))
throw new ArgumentException("key cannot be empty");
return Provider.SetImageMetadataItem(Id, key, value, Region, Identity);
}
}
}