-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathImageReference.cs
More file actions
70 lines (62 loc) · 3.83 KB
/
Copy pathImageReference.cs
File metadata and controls
70 lines (62 loc) · 3.83 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
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenStack.Compute.v2_1.Serialization;
using OpenStack.Images.v2;
using OpenStack.Serialization;
namespace OpenStack.Compute.v2_1
{
/// <summary>
/// Reference to an image.
/// </summary>
public class ImageReference : IHaveExtraData, IServiceResource
{
/// <summary>
/// The image identifier.
/// </summary>
[JsonProperty("id")]
public virtual Identifier Id { get; set; }
/// <summary />
[JsonExtensionData]
IDictionary<string, JToken> IHaveExtraData.Data { get; set; } = new Dictionary<string, JToken>();
object IServiceResource.Owner { get; set; }
/// <inheritdoc cref="ComputeApi.GetImageAsync{T}" />
/// <exception cref="InvalidOperationException">When the <see cref="ImageReference"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
public Task<Image> GetImageAsync(CancellationToken cancellationToken = default(CancellationToken))
{
var owner = this.GetOwnerOrThrow<ComputeApi>();
return owner.GetImageAsync<Image>(Id, cancellationToken);
}
/// <inheritdoc cref="ComputeApi.GetImageMetadataAsync{T}" />
/// <exception cref="InvalidOperationException">When the <see cref="ImageReference"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
public Task<ImageMetadata> GetMetadataAsync(CancellationToken cancellationToken = default(CancellationToken))
{
var owner = this.GetOwnerOrThrow<ComputeApi>();
return owner.GetImageMetadataAsync<ImageMetadata>(Id, cancellationToken);
}
/// <inheritdoc cref="ComputeApi.GetImageMetadataItemAsync" />
/// <exception cref="InvalidOperationException">When the <see cref="ImageReference"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
public Task<string> GetMetadataItemAsync(string key, CancellationToken cancellationToken = default(CancellationToken))
{
var owner = this.GetOwnerOrThrow<ComputeApi>();
return owner.GetImageMetadataItemAsync(Id, key, cancellationToken);
}
/// <inheritdoc cref="ComputeApi.DeleteImageAsync" />
/// <exception cref="InvalidOperationException">When the <see cref="Server"/> instance was not constructed by the <see cref="ComputeService"/>, as it is missing the appropriate internal state to execute service calls.</exception>
public virtual async Task DeleteAsync(CancellationToken cancellationToken = default(CancellationToken))
{
var owner = this.GetOwnerOrThrow<ComputeApi>();
await owner.DeleteImageAsync(Id, cancellationToken).ConfigureAwait(false);
}
/// <inheritdoc cref="ComputeApi.WaitUntilImageIsDeletedAsync{TImage,TStatus}" />
/// <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>
public virtual async Task WaitUntilDeletedAsync(TimeSpan? refreshDelay = null, TimeSpan? timeout = null, IProgress<bool> progress = null, CancellationToken cancellationToken = default(CancellationToken))
{
var owner = this.GetOwnerOrThrow<ComputeApi>();
await owner.WaitUntilImageIsDeletedAsync<Image, ImageStatus>(Id, null, refreshDelay, timeout, progress, cancellationToken).ConfigureAwait(false);
}
}
}