diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ContainerBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ContainerBase.cs
index 234ca6f7eb4d..77576e91cd69 100644
--- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ContainerBase.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ContainerBase.cs
@@ -1,30 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using System;
-using System.Globalization;
-using System.Threading;
-using System.Threading.Tasks;
-
namespace Azure.ResourceManager.Core
{
///
/// Base class representing collection of resources.
///
- /// The type of the class containing operations for the underlying resource.
/// The type of the resource identifier.
- public abstract class ContainerBase : OperationsBase
- where TOperations : ResourceOperationsBase where TIdentifier : ResourceIdentifier
+ public abstract class ContainerBase : OperationsBase
+ where TIdentifier : ResourceIdentifier
{
///
- /// Initializes a new instance of the class for mocking.
+ /// Initializes a new instance of the class for mocking.
///
protected ContainerBase()
{
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
///
/// The identifier of the resource that is the target of operations.
@@ -34,7 +28,7 @@ internal ContainerBase(ClientContext clientContext, TIdentifier id)
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The resource representing the parent resource.
protected ContainerBase(ResourceOperationsBase parent)
@@ -47,102 +41,5 @@ protected ContainerBase(ResourceOperationsBase parent)
/// Gets the parent resource of this resource.
///
protected ResourceOperationsBase Parent { get; }
-
- ///
- /// Returns the resource from Azure if it exists.
- ///
- /// The name of the resource you want to get.
- /// A token to allow the caller to cancel the call to the service.
- /// The default value is .
- /// Whether or not the resource existed.
- public virtual TOperations TryGet(string resourceName, CancellationToken cancellationToken = default)
- {
- using var scope = Diagnostics.CreateScope("ContainerBase`2.TryGet");
- scope.Start();
-
- var op = GetOperation(resourceName);
-
- try
- {
- return op.Get(cancellationToken).Value;
- }
- catch (RequestFailedException e) when (e.Status == 404)
- {
- return null;
- }
- catch (Exception e)
- {
- scope.Failed(e);
- throw;
- }
- }
-
- ///
- /// Returns the resource from Azure if it exists.
- ///
- /// The name of the resource you want to get.
- /// A token to allow the caller to cancel the call to the service.
- /// The default value is .
- /// Whether or not the resource existed.
- public async virtual Task TryGetAsync(string resourceName, CancellationToken cancellationToken = default)
- {
- using var scope = Diagnostics.CreateScope("ContainerBase`2.TryGet");
- scope.Start();
-
- var op = GetOperation(resourceName);
-
- try
- {
- return (await op.GetAsync(cancellationToken).ConfigureAwait(false)).Value;
- }
- catch (RequestFailedException e) when (e.Status == 404)
- {
- return null;
- }
- catch (Exception e)
- {
- scope.Failed(e);
- throw;
- }
- }
-
- ///
- /// Determines whether or not the azure resource exists in this container
- ///
- /// The name of the resource you want to check.
- /// A token to allow the caller to cancel the call to the service.
- /// The default value is .
- /// Whether or not the resource existed.
- public virtual bool DoesExist(string resourceName, CancellationToken cancellationToken = default)
- {
- return TryGet(resourceName, cancellationToken) == null ? false : true;
- }
-
- ///
- /// Determines whether or not the azure resource exists in this container
- ///
- /// The name of the resource you want to check.
- /// A token to allow the caller to cancel the call to the service.
- /// The default value is .
- /// Whether or not the resource existed.
- public virtual async Task DoesExistAsync(string resourceName, CancellationToken cancellationToken = default)
- {
- return await TryGetAsync(resourceName, cancellationToken).ConfigureAwait(false) == null ? false : true;
- }
-
- ///
- /// Get an instance of the operations this container holds.
- ///
- /// The name of the resource to scope the operations to.
- /// An instance of .
- protected virtual ResourceOperationsBase GetOperation(string resourceName)
- {
- return Activator.CreateInstance(
- typeof(TOperations).BaseType,
- System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance,
- null,
- new object[] { Parent, resourceName },
- CultureInfo.InvariantCulture) as ResourceOperationsBase;
- }
}
}
diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs
index aa19294913e9..7fcaaded8fe2 100644
--- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT License.
using System;
+using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
@@ -13,12 +14,12 @@ namespace Azure.ResourceManager.Core
/// The type of the resource identifier.
/// The type of the class containing operations for the underlying resource.
/// The type of the class containing properties for the underlying resource.
- public abstract class ResourceContainerBase : ContainerBase
+ public abstract class ResourceContainerBase : ContainerBase
where TIdentifier : ResourceIdentifier
where TOperations : ResourceOperationsBase
where TResource : class
{
- private static readonly object _parentLock = new object();
+ private readonly object _parentLock = new object();
private object _parentResource;
///
@@ -105,5 +106,102 @@ protected TParent GetParentResource()
/// A that on completion returns a response with the operation for this resource.
/// resourceName cannot be null or a whitespace.
public abstract Task> GetAsync(string resourceName, CancellationToken cancellationToken = default);
+
+ ///
+ /// Returns the resource from Azure if it exists.
+ ///
+ /// The name of the resource you want to get.
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// Whether or not the resource existed.
+ public virtual TOperations TryGet(string resourceName, CancellationToken cancellationToken = default)
+ {
+ using var scope = Diagnostics.CreateScope("ResourceContainerBase`3.TryGet");
+ scope.Start();
+
+ var op = GetOperation(resourceName);
+
+ try
+ {
+ return op.Get(cancellationToken).Value;
+ }
+ catch (RequestFailedException e) when (e.Status == 404)
+ {
+ return null;
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// Returns the resource from Azure if it exists.
+ ///
+ /// The name of the resource you want to get.
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// Whether or not the resource existed.
+ public virtual async Task TryGetAsync(string resourceName, CancellationToken cancellationToken = default)
+ {
+ using var scope = Diagnostics.CreateScope("ResourceContainerBase`3.TryGet");
+ scope.Start();
+
+ var op = GetOperation(resourceName);
+
+ try
+ {
+ return (await op.GetAsync(cancellationToken).ConfigureAwait(false)).Value;
+ }
+ catch (RequestFailedException e) when (e.Status == 404)
+ {
+ return null;
+ }
+ catch (Exception e)
+ {
+ scope.Failed(e);
+ throw;
+ }
+ }
+
+ ///
+ /// Determines whether or not the azure resource exists in this container
+ ///
+ /// The name of the resource you want to check.
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// Whether or not the resource existed.
+ public virtual bool DoesExist(string resourceName, CancellationToken cancellationToken = default)
+ {
+ return TryGet(resourceName, cancellationToken) != null;
+ }
+
+ ///
+ /// Determines whether or not the azure resource exists in this container
+ ///
+ /// The name of the resource you want to check.
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// Whether or not the resource existed.
+ public virtual async Task DoesExistAsync(string resourceName, CancellationToken cancellationToken = default)
+ {
+ return await TryGetAsync(resourceName, cancellationToken).ConfigureAwait(false) != null;
+ }
+
+ ///
+ /// Get an instance of the operations this container holds.
+ ///
+ /// The name of the resource to scope the operations to.
+ /// An instance of .
+ protected virtual ResourceOperationsBase GetOperation(string resourceName)
+ {
+ return Activator.CreateInstance(
+ typeof(TOperations).BaseType,
+ System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance,
+ null,
+ new object[] { Parent, resourceName },
+ CultureInfo.InvariantCulture) as ResourceOperationsBase;
+ }
}
}
diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs
index 5a422406ebd3..5e6aae942126 100644
--- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs
@@ -60,7 +60,7 @@ protected SingletonOperationsBase()
}
///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
/// The resource representing the parent resource.
protected SingletonOperationsBase(OperationsBase parent)
diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs
index 26cbf02b7264..4a8ee90dc1c7 100644
--- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs
+++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SubscriptionContainer.cs
@@ -3,6 +3,7 @@
using System;
using System.Threading;
+using System.Threading.Tasks;
using Azure.Core;
using Azure.ResourceManager.Resources;
@@ -11,7 +12,7 @@ namespace Azure.ResourceManager.Core
///
/// A class representing collection of Subscription and their operations
///
- public class SubscriptionContainer : ContainerBase
+ public class SubscriptionContainer : ResourceContainerBase
{
///
/// Initializes a new instance of the class for mocking.
@@ -103,6 +104,22 @@ protected override void Validate(ResourceIdentifier identifier)
throw new ArgumentException("Invalid parent for subscription container", nameof(identifier));
}
+ ///
+ public override Response Get(string subscriptionGuid, CancellationToken cancellationToken = default)
+ {
+ return new SubscriptionOperations(
+ new ClientContext(ClientOptions, Credential, BaseUri, Pipeline),
+ subscriptionGuid).Get(cancellationToken);
+ }
+
+ ///
+ public override Task> GetAsync(string subscriptionGuid, CancellationToken cancellationToken = default)
+ {
+ return new SubscriptionOperations(
+ new ClientContext(ClientOptions, Credential, BaseUri, Pipeline),
+ subscriptionGuid).GetAsync(cancellationToken);
+ }
+
///
/// Get an instance of the operations this container holds.
///
diff --git a/sdk/resourcemanager/Proto.Client/compute/Extensions/SubscriptionExtensions.cs b/sdk/resourcemanager/Proto.Client/compute/Extensions/SubscriptionExtensions.cs
index 8503f79e2b14..bb085bd408da 100644
--- a/sdk/resourcemanager/Proto.Client/compute/Extensions/SubscriptionExtensions.cs
+++ b/sdk/resourcemanager/Proto.Client/compute/Extensions/SubscriptionExtensions.cs
@@ -136,5 +136,28 @@ public static AsyncPageable ListAvailabilitySetsAsync(this Subs
);
}
#endregion
+
+ #region VMImage Operations
+ ///
+ /// Lists the Virtual Machine Extension Images Container for this SubscriptionOperations.
+ ///
+ /// The instance the method will execute against.
+ /// A collection of resource operations that may take multiple service requests to iterate over.
+ public static VirtualMachineExtensionImageContainer GetVmExtensionImages(this SubscriptionOperations subscription)
+ {
+ return new VirtualMachineExtensionImageContainer(subscription);
+ }
+
+ ///
+ /// Lists the Virtual Machine Images Container for this SubscriptionOperations.
+ ///
+ /// The instance the method will execute against.
+ /// A collection of resource operations that may take multiple service requests to iterate over.
+ public static VirtualMachineImageContainer GetVmImages(this SubscriptionOperations subscription)
+ {
+ return new VirtualMachineImageContainer(subscription);
+ }
+
+ #endregion
}
}
diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineExtensionImageContainer.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineExtensionImageContainer.cs
new file mode 100644
index 000000000000..07ead0dd3fc0
--- /dev/null
+++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineExtensionImageContainer.cs
@@ -0,0 +1,198 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using Azure;
+using Azure.ResourceManager.Compute;
+using Azure.ResourceManager.Compute.Models;
+using Azure.ResourceManager.Core;
+
+namespace Proto.Compute
+{
+ ///
+ /// A class representing collection of VirtualMachine and their operations over a ResourceGroup.
+ ///
+ public class VirtualMachineExtensionImageContainer : ContainerBase
+ {
+ private string _subsriptionId;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The subscription that is the parent of the VirtualMachinesExtensionImage.
+ internal VirtualMachineExtensionImageContainer(SubscriptionOperations subscription)
+ : base(subscription)
+ {
+ _subsriptionId = subscription.Id.SubscriptionId;
+ }
+
+ private VirtualMachineExtensionImagesOperations Operations => new ComputeManagementClient(
+ BaseUri,
+ _subsriptionId,
+ Credential,
+ ClientOptions.Convert()).VirtualMachineExtensionImages;
+
+ ///
+ /// Gets the valid resource type for this object
+ ///
+ protected override ResourceType ValidResourceType => SubscriptionOperations.ResourceType;
+
+ public Response Get(
+ string location,
+ string publisherName,
+ string type,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ return Operations.Get(location, publisherName, type, version, cancellationToken);
+ }
+
+ public async Task> GetAsync(
+ string location,
+ string publisherName,
+ string type,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ return await Operations.GetAsync(location, publisherName, type, version, cancellationToken)
+ .ConfigureAwait(false);
+ }
+
+ public IEnumerable ListTypes(
+ string location,
+ string publisherName,
+ CancellationToken cancellationToken = default)
+ {
+ return Operations.ListTypes(location, publisherName, cancellationToken).Value;
+ }
+
+ public async Task> ListTypesAsync(
+ string location,
+ string publisherName,
+ CancellationToken cancellationToken = default)
+ {
+ return (await Operations.ListTypesAsync(location, publisherName, cancellationToken).ConfigureAwait(false)).Value;
+ }
+
+ public IEnumerable ListVersions(
+ string location,
+ string publisherName,
+ string type,
+ string filter = null,
+ int? top = null,
+ string orderby = null,
+ CancellationToken cancellationToken = default)
+ {
+ return Operations.ListVersions(location, publisherName, type, filter: filter, top: top, orderby: orderby, cancellationToken: cancellationToken).Value;
+ }
+
+ public async Task> ListVersionsAsync(
+ string location,
+ string publisherName,
+ string type,
+ string filter = null,
+ int? top = null,
+ string orderby = null,
+ CancellationToken cancellationToken = default)
+ {
+ return (await Operations.ListVersionsAsync(location, publisherName, type, filter: filter, top: top, orderby: orderby, cancellationToken: cancellationToken).ConfigureAwait(false)).Value;
+ }
+
+ ///
+ /// Returns the resource from Azure if it exists.
+ ///
+ /// The location of the .
+ /// The publisherName of the .
+ /// The type of the .
+ /// The version of the .
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// An instance of resource or null if not found.
+ public VirtualMachineExtensionImage TryGet(
+ string location,
+ string publisherName,
+ string type,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ try
+ {
+ return Get(location:location, publisherName:publisherName, type:type, version:version, cancellationToken:cancellationToken).Value;
+ }
+ catch (RequestFailedException e) when (e.Status == 404)
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Returns the resource from Azure if it exists.
+ ///
+ /// The location of the .
+ /// The publisherName of the .
+ /// The type of the .
+ /// The version of the .
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// An instance of resource or null if not found.
+ public async Task TryGetAsync(
+ string location,
+ string publisherName,
+ string type,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ try
+ {
+ return (await GetAsync(location: location, publisherName: publisherName, type: type, version: version, cancellationToken: cancellationToken).ConfigureAwait(false)).Value;
+ }
+ catch (RequestFailedException e) when (e.Status == 404)
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Determines whether or not the azure resource exists in this container
+ ///
+ /// The location of the .
+ /// The publisherName of the .
+ /// The type of the .
+ /// The version of the .
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// Whether or not the resource existed.
+ public bool DoesExist(
+ string location,
+ string publisherName,
+ string type,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ return TryGet(location: location, publisherName: publisherName, type: type, version: version, cancellationToken: cancellationToken) != null;
+ }
+
+ ///
+ /// Determines whether or not the azure resource exists in this container
+ ///
+ /// The location of the .
+ /// The publisherName of the .
+ /// The type of the .
+ /// The version of the .
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// Whether or not the resource existed.
+ public async Task DoesExistAsync(
+ string location,
+ string publisherName,
+ string type,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ return await TryGetAsync(location: location, publisherName: publisherName, type: type, version: version, cancellationToken: cancellationToken).ConfigureAwait(false) != null;
+ }
+ }
+}
diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineImageContainer.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineImageContainer.cs
new file mode 100644
index 000000000000..30df61872173
--- /dev/null
+++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineImageContainer.cs
@@ -0,0 +1,251 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using Azure;
+using Azure.ResourceManager.Compute;
+using Azure.ResourceManager.Compute.Models;
+using Azure.ResourceManager.Core;
+
+namespace Proto.Compute
+{
+ ///
+ /// A class representing collection of VirtualMachine and their operations over a ResourceGroup.
+ ///
+ public class VirtualMachineImageContainer : ContainerBase
+ {
+ private string _subscriptionId;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The parent subscription.
+ internal VirtualMachineImageContainer(SubscriptionOperations parent)
+ : base(parent)
+ {
+ _subscriptionId = parent.Id.SubscriptionId;
+ }
+
+ private VirtualMachineImagesOperations Operations => new ComputeManagementClient(
+ BaseUri,
+ _subscriptionId,
+ Credential,
+ ClientOptions.Convert()).VirtualMachineImages;
+
+ protected override ResourceType ValidResourceType => SubscriptionOperations.ResourceType;
+
+ public Response Get(
+ string location,
+ string publisherName,
+ string offer,
+ string skus,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ return Operations.Get(location, publisherName, offer, skus, version, cancellationToken);
+ }
+
+ public async Task> GetAsync(
+ string location,
+ string publisherName,
+ string offer,
+ string skus,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ return await Operations.GetAsync(location, publisherName, offer, skus, version, cancellationToken);
+ }
+
+ public IEnumerable ListOffers(
+ string location,
+ string publisherName,
+ CancellationToken cancellationToken = default)
+ {
+ return Operations.ListOffers(location, publisherName, cancellationToken).Value;
+ }
+
+ public async Task> ListOffersAsync(
+ string location,
+ string publisherName,
+ CancellationToken cancellationToken = default)
+ {
+ return (await Operations.ListOffersAsync(location, publisherName, cancellationToken).ConfigureAwait(false)).Value;
+ }
+
+ public IEnumerable ListPublishers(
+ string location,
+ CancellationToken cancellationToken = default)
+ {
+ return Operations.ListPublishers(location, cancellationToken).Value;
+ }
+
+ public async Task> ListPublishersAsync(
+ string location,
+ CancellationToken cancellationToken = default)
+ {
+ return (await Operations.ListPublishersAsync(location, cancellationToken).ConfigureAwait(false)).Value;
+ }
+
+ public IEnumerable ListSkus(
+ string location,
+ string publisherName,
+ string offer,
+ CancellationToken cancellationToken = default)
+ {
+ return Operations.ListSkus(location, publisherName, offer, cancellationToken).Value;
+ }
+
+ public async Task> ListSkusAsync(
+ string location,
+ string publisherName,
+ string offer,
+ CancellationToken cancellationToken = default)
+ {
+ return (await Operations.ListSkusAsync(location, publisherName, offer, cancellationToken).ConfigureAwait(false)).Value;
+ }
+
+ public IEnumerable ListVersions(
+ string location,
+ string publisherName,
+ string offer,
+ string skus,
+ string expand = null,
+ int? top = null,
+ string orderby = null,
+ CancellationToken cancellationToken = default)
+ {
+ return Operations.List(location,
+ publisherName: publisherName,
+ offer: offer,
+ skus: skus,
+ expand: expand,
+ top: top,
+ orderby: orderby,
+ cancellationToken: cancellationToken).Value;
+ }
+
+ public async Task> ListVersionsAsync(
+ string location,
+ string publisherName,
+ string offer,
+ string skus,
+ string expand = null,
+ int? top = null,
+ string orderby = null,
+ CancellationToken cancellationToken = default)
+ {
+ return (await Operations.ListAsync(location,
+ publisherName: publisherName,
+ offer: offer,
+ skus: skus,
+ expand: expand,
+ top: top,
+ orderby: orderby,
+ cancellationToken: cancellationToken).ConfigureAwait(false)).Value;
+ }
+
+ ///
+ /// Returns the resource from Azure if it exists.
+ ///
+ /// The location of the .
+ /// The publisherName of the .
+ /// The offer of the .
+ /// The skus of the .
+ /// The version of the .
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// An instance of resource or null if not found.
+ public VirtualMachineImage TryGet(
+ string location,
+ string publisherName,
+ string offer,
+ string skus,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ try
+ {
+ return Get(location: location, publisherName: publisherName, offer: offer, skus: skus, version: version, cancellationToken: cancellationToken).Value;
+ }
+ catch (RequestFailedException e) when (e.Status == 404)
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Returns the resource from Azure if it exists.
+ ///
+ /// The location of the .
+ /// The publisherName of the .
+ /// The offer of the .
+ /// The skus of the .
+ /// The version of the .
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// An instance of resource or null if not found.
+ public async Task TryGetAsync(
+ string location,
+ string publisherName,
+ string offer,
+ string skus,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ try
+ {
+ return (await GetAsync(location: location, publisherName: publisherName, offer: offer, skus: skus, version: version, cancellationToken: cancellationToken).ConfigureAwait(false)).Value;
+ }
+ catch (RequestFailedException e) when (e.Status == 404)
+ {
+ return null;
+ }
+ }
+
+ ///
+ /// Determines whether or not the azure resource exists in this container
+ ///
+ /// The location of the .
+ /// The publisherName of the .
+ /// The offer of the .
+ /// The skus of the .
+ /// The version of the .
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// Whether or not the resource existed.
+ public bool DoesExist(
+ string location,
+ string publisherName,
+ string offer,
+ string skus,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ return TryGet(location: location, publisherName: publisherName, offer: offer, skus: skus, version: version, cancellationToken: cancellationToken) != null;
+ }
+
+ ///
+ /// Determines whether or not the azure resource exists in this container
+ ///
+ /// The location of the .
+ /// The publisherName of the .
+ /// The offer of the .
+ /// The skus of the .
+ /// The version of the .
+ /// A token to allow the caller to cancel the call to the service.
+ /// The default value is .
+ /// Whether or not the resource existed.
+ public async Task DoesExistAsync(
+ string location,
+ string publisherName,
+ string offer,
+ string skus,
+ string version,
+ CancellationToken cancellationToken = default)
+ {
+ return await TryGetAsync(location: location, publisherName: publisherName, offer: offer, skus: skus, version: version, cancellationToken: cancellationToken).ConfigureAwait(false) != null;
+ }
+ }
+}
diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineOperations.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineOperations.cs
index fc5bc5936412..79e47ac50fe1 100644
--- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineOperations.cs
+++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineOperations.cs
@@ -98,7 +98,7 @@ public async Task StartDeleteAsync(CancellationToken cancellationToke
/// The operation to start a virtual machine.
///
/// A token to allow the caller to cancel the call to the service. The default value is .
- /// A response with the operation for this resource.
+ /// A response with the operation for this resource.
public Response PowerOn(CancellationToken cancellationToken = default)
{
var operation = Operations.StartStart(Id.ResourceGroupName, Id.Name, cancellationToken);
@@ -109,7 +109,7 @@ public Response PowerOn(CancellationToken cancellationToken = default)
/// The operation to start a virtual machine.
///
/// A token to allow the caller to cancel the call to the service. The default value is .
- /// A that on completion returns a response with the operation for this resource.
+ /// A that on completion returns a response with the operation for this resource.
public async Task PowerOnAsync(CancellationToken cancellationToken = default)
{
var operation = await Operations.StartStartAsync(Id.ResourceGroupName, Id.Name, cancellationToken).ConfigureAwait(false);
@@ -143,7 +143,7 @@ public async Task StartPowerOnAsync(CancellationToken cancellationTok
///
/// The parameter to request non-graceful VM shutdown. True value for this flag indicates non-graceful shutdown whereas false indicates otherwise. Default value for this flag is false if not specified.
/// A token to allow the caller to cancel the call to the service. The default value is .
- /// A response with the operation for this resource.
+ /// A response with the operation for this resource.
public Response PowerOff(bool? skipShutdown = null, CancellationToken cancellationToken = default)
{
var operation = Operations.StartPowerOff(Id.ResourceGroupName, Id.Name, skipShutdown, cancellationToken);
@@ -155,7 +155,7 @@ public Response PowerOff(bool? skipShutdown = null, CancellationToken cancellati
///
/// The parameter to request non-graceful VM shutdown. True value for this flag indicates non-graceful shutdown whereas false indicates otherwise. Default value for this flag is false if not specified.
/// A token to allow the caller to cancel the call to the service. The default value is .
- /// A that on completion returns a response with the operation for this resource.
+ /// A that on completion returns a response with the operation for this resource.
public async Task PowerOffAsync(bool? skipShutdown = null, CancellationToken cancellationToken = default)
{
var operation = await Operations.StartPowerOffAsync(Id.ResourceGroupName, Id.Name, skipShutdown, cancellationToken).ConfigureAwait(false);
diff --git a/sdk/resourcemanager/Proto.Client/src/Program.cs b/sdk/resourcemanager/Proto.Client/src/Program.cs
index 2c7b4b69fb9c..e528a5c9874c 100644
--- a/sdk/resourcemanager/Proto.Client/src/Program.cs
+++ b/sdk/resourcemanager/Proto.Client/src/Program.cs
@@ -11,7 +11,7 @@ static void Main(string[] args)
Scenario scenario = null;
try
{
- scenario = ScenarioFactory.GetScenario(Scenarios.StartFromVm);
+ scenario = ScenarioFactory.GetScenario(Scenarios.VmImageTests);
scenario.Execute();
}
finally
diff --git a/sdk/resourcemanager/Proto.Client/src/ScenarioFactory.cs b/sdk/resourcemanager/Proto.Client/src/ScenarioFactory.cs
index 6f094ee6b67d..2d769ee9d9ea 100644
--- a/sdk/resourcemanager/Proto.Client/src/ScenarioFactory.cs
+++ b/sdk/resourcemanager/Proto.Client/src/ScenarioFactory.cs
@@ -42,6 +42,7 @@ enum Scenarios
CheckResourceGroupContainerAsync,
GenericResourceOperationsExample,
SingletonVmssUpgrade,
+ VmImageTests,
}
class ScenarioFactory
diff --git a/sdk/resourcemanager/Proto.Client/src/Scenarios/GetSubscription.cs b/sdk/resourcemanager/Proto.Client/src/Scenarios/GetSubscription.cs
index a05f1ed9d66f..dca02e127202 100644
--- a/sdk/resourcemanager/Proto.Client/src/Scenarios/GetSubscription.cs
+++ b/sdk/resourcemanager/Proto.Client/src/Scenarios/GetSubscription.cs
@@ -12,9 +12,8 @@ public override void Execute()
var sandboxId = "db1ab6f0-4769-4b27-930e-01e2ef9c123c";
var expectDisplayName = "Azure SDK sandbox";
var subOp = new ArmClient(new DefaultAzureCredential()).GetSubscriptions().TryGet(sandboxId);
- var result = subOp.Get();
- Debug.Assert(expectDisplayName == result.Value.Data.DisplayName);
- Console.WriteLine("Passed, got " + result.Value.Data.DisplayName);
+ Debug.Assert(expectDisplayName == subOp.Data.DisplayName);
+ Console.WriteLine("Passed, got " + subOp.Data.DisplayName);
}
}
diff --git a/sdk/resourcemanager/Proto.Client/src/Scenarios/VMImageTests.cs b/sdk/resourcemanager/Proto.Client/src/Scenarios/VMImageTests.cs
new file mode 100644
index 000000000000..fbf0377e6bba
--- /dev/null
+++ b/sdk/resourcemanager/Proto.Client/src/Scenarios/VMImageTests.cs
@@ -0,0 +1,148 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+using Azure.Identity;
+using Azure.ResourceManager.Core;
+using Proto.Compute;
+
+namespace Proto.Client
+{
+ class VmImageTests : Scenario
+ {
+ public override void Execute()
+ {
+ var client = new ArmClient(new DefaultAzureCredential());
+ Execute(client);
+ ExecuteAsync(client).ConfigureAwait(false).GetAwaiter().GetResult();
+ }
+
+ private void Execute(ArmClient client)
+ {
+ var subscription = client.DefaultSubscription;
+
+ var defaultLocation = ((LocationData)Context.Loc).Name;
+ var defaultPublisher = "redhat";
+
+ Console.WriteLine($"--------Start listing all VMImage publishers at {defaultLocation}--------");
+ foreach (var p in subscription.GetVmImages().ListPublishers(defaultLocation).Take(50))
+ {
+ Console.WriteLine(p.Name);
+ }
+
+ Console.WriteLine($"--------Start listing all VMImage offers for Publisher {defaultPublisher}--------");
+ foreach (var o in subscription.GetVmImages().ListOffers(defaultLocation, defaultPublisher).Take(3))
+ {
+ Console.WriteLine($"offer:\t{o.Name}");
+
+ foreach (var s in subscription.GetVmImages().ListSkus(defaultLocation, defaultPublisher, o.Name).Take(3))
+ {
+ Console.WriteLine($"\tsku:\t{s.Name}");
+
+ foreach (var v in subscription.GetVmImages().ListVersions(defaultLocation, defaultPublisher, o.Name, s.Name).Take(2))
+ {
+ Console.WriteLine($"\t\tversion:\t{v.Name}");
+
+ var vmImage = subscription.GetVmImages().Get(
+ defaultLocation,
+ defaultPublisher,
+ o.Name,
+ s.Name,
+ v.Name);
+ Console.WriteLine($"vmImage:\t\t\tVM Image:\t{vmImage.Value.Id}");
+ }
+ }
+ }
+
+ Console.WriteLine($"--------Start listing all VMExtensionImage offers for Publisher {defaultPublisher}--------");
+ foreach (var t in subscription.GetVmExtensionImages().ListTypes(defaultLocation, defaultPublisher).Take(5))
+ {
+ Console.WriteLine($"\tType:\t{t.Name}");
+
+ foreach (var v in subscription.GetVmExtensionImages().ListVersions(defaultLocation, defaultPublisher, t.Name).Take(5))
+ {
+ Console.WriteLine($"\t\tOffer:\t{v.Name}");
+ }
+ }
+
+ if (!subscription.GetVmExtensionImages().DoesExist(defaultLocation, "Microsoft.Azure.Extensions", "DockerExtension", "1.2.0")
+ || subscription.GetVmExtensionImages().DoesExist(defaultLocation, "Microsoft.Azure.Extensions", "DockerExtension", "0.0.0"))
+ {
+ Console.WriteLine("!!!!!!! DoesExist check failed!");
+ }
+
+ if (subscription.GetVmExtensionImages().TryGet(defaultLocation, "Microsoft.Azure.Extensions", "DockerExtension", "1.2.0") == null
+ || subscription.GetVmExtensionImages().TryGet(defaultLocation, "Microsoft.Azure.Extensions", "DockerExtension", "0.0.0") != null)
+ {
+ Console.WriteLine("!!!!!!! DoesExist check failed!");
+ }
+
+ Console.WriteLine($"-------- All Sync VM image API test passed.--------");
+ }
+
+ private async Task ExecuteAsync (ArmClient client)
+ {
+ var subscription = client.DefaultSubscription;
+
+ var defaultLocation = ((LocationData)Context.Loc).Name;
+ var defaultPublisher = "redhat";
+
+ Console.WriteLine($"--------Start listing all VMImage publishers at {defaultLocation}--------");
+ foreach (var p in (await subscription.GetVmImages().ListPublishersAsync(defaultLocation)).Take(50))
+ {
+ Console.WriteLine(p.Name);
+ }
+
+ Console.WriteLine($"--------Start listing all VMImage offers for Publisher {defaultPublisher}--------");
+ foreach (var o in (await subscription.GetVmImages().ListOffersAsync(defaultLocation, defaultPublisher)).Take(3))
+ {
+ Console.WriteLine($"offer:\t{o.Name}");
+
+ foreach (var s in (await subscription.GetVmImages().ListSkusAsync(defaultLocation, defaultPublisher, o.Name)).Take(3))
+ {
+ Console.WriteLine($"\tsku:\t{s.Name}");
+
+ foreach (var v in (await subscription.GetVmImages().ListVersionsAsync(defaultLocation, defaultPublisher, o.Name, s.Name)).Take(2))
+ {
+ Console.WriteLine($"\t\tversion:\t{v.Name}");
+
+ var vmImage = await subscription.GetVmImages().GetAsync(
+ defaultLocation,
+ defaultPublisher,
+ o.Name,
+ s.Name,
+ v.Name);
+ Console.WriteLine($"vmImage:\t\t\tVM Image:\t{vmImage.Value.Id}");
+ }
+ }
+ }
+
+ Console.WriteLine($"--------Start listing all VMExtensionImage offers for Publisher {defaultPublisher}--------");
+ foreach (var t in (await subscription.GetVmExtensionImages().ListTypesAsync(defaultLocation, defaultPublisher)).Take(5))
+ {
+ Console.WriteLine($"\tType:\t{t.Name}");
+
+ foreach (var v in (await subscription.GetVmExtensionImages().ListVersionsAsync(defaultLocation, defaultPublisher, t.Name)).Take(5))
+ {
+ Console.WriteLine($"\t\tOffer:\t{v.Name}");
+ }
+ }
+
+ if (!await subscription.GetVmExtensionImages().DoesExistAsync(defaultLocation, "Microsoft.Azure.Extensions", "DockerExtension", "1.2.0")
+ || await subscription.GetVmExtensionImages().DoesExistAsync(defaultLocation, "Microsoft.Azure.Extensions", "DockerExtension", "0.0.0"))
+ {
+ Console.WriteLine("!!!!!!! DoesExist check failed!");
+ }
+
+ if (await subscription.GetVmExtensionImages().TryGetAsync(defaultLocation, "Microsoft.Azure.Extensions", "DockerExtension", "1.2.0") == null
+ || await subscription.GetVmExtensionImages().TryGetAsync(defaultLocation, "Microsoft.Azure.Extensions", "DockerExtension", "0.0.0") != null)
+ {
+ Console.WriteLine("!!!!!!! DoesExist check failed!");
+ }
+
+ Console.WriteLine($"-------- All Async VM image API test passed.--------");
+ }
+ }
+}