From e4a19d488015e27efb5aae46e2996a1ad884ccaa Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Thu, 22 Apr 2021 10:19:08 -0700 Subject: [PATCH 1/9] adding initial singleton base classs and proto code --- .../src/SingletonOperationsBase.cs | 64 ++++ .../Placeholder/RollingUpgradeStatusInfo.cs | 41 +++ .../Placeholder/VirtualMachineScaleSetData.cs | 78 +++++ .../compute/VirtualMachineScaleSet.cs | 40 +++ .../VirtualMachineScaleSetContainer.cs | 203 +++++++++++ .../VirtualMachineScaleSetOperations.cs | 314 ++++++++++++++++++ .../VirtualMachineScaleSetRollingUpgrade.cs | 33 ++ ...MachineScaleSetRollingUpgradeOperations.cs | 58 ++++ 8 files changed, 831 insertions(+) create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs create mode 100644 sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs create mode 100644 sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineScaleSetData.cs create mode 100644 sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSet.cs create mode 100644 sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs create mode 100644 sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs create mode 100644 sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgrade.cs create mode 100644 sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgradeOperations.cs diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs new file mode 100644 index 0000000000000..58e4823849b31 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs @@ -0,0 +1,64 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace Azure.ResourceManager.Core +{ + /// + /// A class representing the operations that can be performed over a specific resource. + /// + public abstract class SingletonOperationsBase : OperationsBase + { + /// + /// Initializes a new instance of the class for mocking. + /// + protected SingletonOperationsBase() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// + internal SingletonOperationsBase(ClientContext clientContext, ResourceIdentifier id) + : base(clientContext, id) + { + } + } + + /// + /// Base class representing a singleton operation + /// + /// The type of the class containing operations for the underlying resource. + /// The type of the resource identifier. + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "")] + public abstract class SingletonOperationsBase : OperationsBase + where TOperations : SingletonOperationsBase + where TIdentifier : ResourceIdentifier + { + /// + /// Initializes a new instance of the class for mocking. + /// + protected SingletonOperationsBase() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The resource representing the parent resource. + /// The identifier of the resource that is the target of operations. + protected SingletonOperationsBase(OperationsBase parent, ResourceIdentifier id) + : base(new ClientContext(parent.ClientOptions, parent.Credential, parent.BaseUri), id) + { + } + + /// + /// The typed resource identifier for the underlying resource + /// + public new virtual TIdentifier Id + { + get { return base.Id as TIdentifier; } + } + } +} diff --git a/sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs b/sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs new file mode 100644 index 0000000000000..a47dd6930a00b --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure.ResourceManager.Compute.Models; +using Azure.ResourceManager.Core; + +namespace Proto.Compute +{ + /// The status of the latest virtual machine scale set rolling upgrade. + public partial class RollingUpgradeStatusInfo : ProxyResource + { + /// + /// Initializes a new instance of the class. + /// + public RollingUpgradeStatusInfo(Azure.ResourceManager.Compute.Models.RollingUpgradeStatusInfo rollingUpgradeStatusInfo) + : base(rollingUpgradeStatusInfo.Id, rollingUpgradeStatusInfo) + { + } + + /// + /// Gets the subnet id. + /// + public override string Name => Model.Name; + + /// The rolling upgrade policies applied for this upgrade. + public RollingUpgradePolicy Policy => Model.Policy; + + /// Information about the current running state of the overall upgrade. + public RollingUpgradeRunningStatus RunningStatus => Model.RunningStatus; + + /// Information about the number of virtual machine instances in each upgrade state. + public RollingUpgradeProgressInfo Progress => Model.Progress; + + /// Error details for this upgrade, if there are any. + public ApiError Error => Model.Error; + } +} \ No newline at end of file diff --git a/sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineScaleSetData.cs b/sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineScaleSetData.cs new file mode 100644 index 0000000000000..66231a6ef7653 --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineScaleSetData.cs @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure.ResourceManager.Compute.Models; +using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Adapters; +using System.Collections.Generic; + +namespace Proto.Compute +{ + /// A class representing the VirtualMachineScaleSet data model. + public partial class VirtualMachineScaleSetData : TrackedResource + { + /// Initializes a new instance of VirtualMachineScaleSetData. + public VirtualMachineScaleSetData(Azure.ResourceManager.Compute.Models.VirtualMachineScaleSet vmScaleSet) + : base(vmScaleSet.Id, vmScaleSet.Location, vmScaleSet) + { + Sku = vmScaleSet.Sku; + Plan = vmScaleSet.Plan; + Identity = vmScaleSet.Identity; + Zones = vmScaleSet.Zones; + UpgradePolicy = vmScaleSet.UpgradePolicy; + AutomaticRepairsPolicy = vmScaleSet.AutomaticRepairsPolicy; + VirtualMachineProfile = vmScaleSet.VirtualMachineProfile; + ProvisioningState = vmScaleSet.ProvisioningState; + Overprovision = vmScaleSet.Overprovision; + DoNotRunExtensionsOnOverprovisionedVMs = vmScaleSet.DoNotRunExtensionsOnOverprovisionedVMs; + UniqueId = vmScaleSet.UniqueId; + SinglePlacementGroup = vmScaleSet.SinglePlacementGroup; + ZoneBalance = vmScaleSet.ZoneBalance; + PlatformFaultDomainCount = vmScaleSet.PlatformFaultDomainCount; + ProximityPlacementGroup = vmScaleSet.ProximityPlacementGroup; + AdditionalCapabilities = vmScaleSet.AdditionalCapabilities; + ScaleInPolicy = vmScaleSet.ScaleInPolicy; + } + + /// The virtual machine scale set sku. + public Azure.ResourceManager.Compute.Models.Sku Sku { get; set; } + /// Specifies information about the marketplace image used to create the virtual machine. This element is only used for marketplace images. Before you can use a marketplace image from an API, you must enable the image for programmatic use. In the Azure portal, find the marketplace image that you want to use and then click **Want to deploy programmatically, Get Started ->**. Enter any required information and then click **Save**. + public Azure.ResourceManager.Compute.Models.Plan Plan { get; set; } + /// The identity of the virtual machine scale set, if configured. + public VirtualMachineScaleSetIdentity Identity { get; set; } + /// The virtual machine scale set zones. NOTE: Availability zones can only be set when you create the scale set. + public IList Zones { get; } + /// The upgrade policy. + public UpgradePolicy UpgradePolicy { get; set; } + /// Policy for automatic repairs. + public AutomaticRepairsPolicy AutomaticRepairsPolicy { get; set; } + /// The virtual machine profile. + public VirtualMachineScaleSetVMProfile VirtualMachineProfile { get; set; } + /// The provisioning state, which only appears in the response. + public string ProvisioningState { get; } + /// Specifies whether the Virtual Machine Scale Set should be overprovisioned. + public bool? Overprovision { get; set; } + /// When Overprovision is enabled, extensions are launched only on the requested number of VMs which are finally kept. This property will hence ensure that the extensions do not run on the extra overprovisioned VMs. + public bool? DoNotRunExtensionsOnOverprovisionedVMs { get; set; } + /// Specifies the ID which uniquely identifies a Virtual Machine Scale Set. + public string UniqueId { get; } + /// When true this limits the scale set to a single placement group, of max size 100 virtual machines. NOTE: If singlePlacementGroup is true, it may be modified to false. However, if singlePlacementGroup is false, it may not be modified to true. + public bool? SinglePlacementGroup { get; set; } + /// Whether to force strictly even Virtual Machine distribution cross x-zones in case there is zone outage. + public bool? ZoneBalance { get; set; } + /// Fault Domain count for each placement group. + public int? PlatformFaultDomainCount { get; set; } + /// Specifies information about the proximity placement group that the virtual machine scale set should be assigned to. <br><br>Minimum api-version: 2018-04-01. + public SubResource ProximityPlacementGroup { get; set; } + /// Specifies information about the dedicated host group that the virtual machine scale set resides in. <br><br>Minimum api-version: 2020-06-01. + public SubResource HostGroup { get; set; } + /// Specifies additional capabilities enabled or disabled on the Virtual Machines in the Virtual Machine Scale Set. For instance: whether the Virtual Machines have the capability to support attaching managed data disks with UltraSSD_LRS storage account type. + public AdditionalCapabilities AdditionalCapabilities { get; set; } + /// Specifies the scale-in policy that decides which virtual machines are chosen for removal when a Virtual Machine Scale Set is scaled-in. + public ScaleInPolicy ScaleInPolicy { get; set; } + } +} diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSet.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSet.cs new file mode 100644 index 0000000000000..1b1773b3959b5 --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSet.cs @@ -0,0 +1,40 @@ +using System.Threading; +using System.Threading.Tasks; +using Azure.ResourceManager.Core; + +namespace Proto.Compute +{ + /// + /// Class representing a VirtualMachineScaleSet along with the instance operations that can be performed on it. + /// + public class VirtualMachineScaleSet : VirtualMachineScaleSetOperations + { + /// + /// Gets the data representing this VirtualMachineScaleSet. + /// + public VirtualMachineScaleSetData Data { get; private set; } + + /// + /// Initializes a new instance of the class. + /// + /// The client parameters to use in these operations. + /// The resource that is the target of operations. + internal VirtualMachineScaleSet(ResourceOperationsBase operations, VirtualMachineScaleSetData resource) + : base(operations, resource.Id) + { + Data = resource; + } + + /// + protected override VirtualMachineScaleSet GetResource(CancellationToken cancellation = default) + { + return this; + } + + /// + protected override Task GetResourceAsync(CancellationToken cancellationToken = default) + { + return Task.FromResult(this); + } + } +} diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs new file mode 100644 index 0000000000000..14e54129c242b --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs @@ -0,0 +1,203 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.ResourceManager.Compute; +using Azure.ResourceManager.Core; +using Azure.ResourceManager.Core.Resources; + +namespace Proto.Compute +{ + /// + /// A class representing collection of VirtualMachineScaleSet and their operations over a ResourceGroup. + /// + public class VirtualMachineScaleSetContainer : ResourceContainerBase + { + /// + /// Initializes a new instance of the class. + /// + /// The ResourceGroup that is the parent of the VirtualMachineScaleSets. + internal VirtualMachineScaleSetContainer(ResourceGroupOperations resourceGroup) + : base(resourceGroup) + { + } + + /// + /// Typed Resource Identifier for the container. + /// + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + + private VirtualMachineScaleSetsOperations Operations => new ComputeManagementClient( + BaseUri, + Id.SubscriptionId, + Credential, + ClientOptions.Convert()).VirtualMachineScaleSets; + + /// + /// Gets the valid resource type for this object + /// + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + /// + /// The operation to create a virtual machine. + /// + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// 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. + public override ArmResponse CreateOrUpdate(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) + { + var operation = Operations.StartCreateOrUpdate(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken); + return new PhArmResponse( + operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(), + v => new VirtualMachineScaleSet(Parent, new VirtualMachineScaleSetData(v))); + } + + /// + /// The operation to create a virtual machine. + /// + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// 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. + public async override Task> CreateOrUpdateAsync(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) + { + var operation = await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken).ConfigureAwait(false); + return new PhArmResponse( + await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false), + v => new VirtualMachineScaleSet(Parent, new VirtualMachineScaleSetData(v))); + } + + /// + public override ArmResponse Get(string VirtualMachineScaleSetName, CancellationToken cancellationToken = default) + { + return new PhArmResponse(Operations.Get(Id.ResourceGroupName, VirtualMachineScaleSetName, cancellationToken), + v => new VirtualMachineScaleSet(Parent, new VirtualMachineScaleSetData(v))); + } + + /// + public override async Task> GetAsync(string VirtualMachineScaleSetName, CancellationToken cancellationToken = default) + { + return new PhArmResponse(await Operations.GetAsync(Id.ResourceGroupName, VirtualMachineScaleSetName, cancellationToken), + v => new VirtualMachineScaleSet(Parent, new VirtualMachineScaleSetData(v))); + } + + /// + /// List the virtual machines for this resource group. + /// + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(CancellationToken cancellationToken = default) + { + var result = Operations.List(Id.Name, cancellationToken); + return new PhWrappingPageable( + result, + s => new VirtualMachineScaleSet(Parent, new VirtualMachineScaleSetData(s))); + } + + /// + /// Filters the list of virtual machines for this resource group represented as generic resources. + /// Makes an additional network call to retrieve the full data model for each virtual machine. + /// + /// The substring to filter by. + /// The number of items to truncate by. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable List(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResource(nameFilter, top, cancellationToken); + return new PhWrappingPageable(results, s => (new VirtualMachineScaleSetOperations(s)).Get().Value); + } + + /// + /// Filters the list of virtual machines for this resource group represented as generic resources. + /// + /// The substring to filter by. + /// The number of items to truncate by. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of that may take multiple service requests to iterate over. + public Pageable ListAsGenericResource(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + ResourceFilterCollection filters = new ResourceFilterCollection(VirtualMachineScaleSetOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContext(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + + /// + /// Filters the list of virtual machines for this resource group represented as generic resources. + /// + /// The substring to filter by. + /// The number of items to truncate by. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsGenericResourceAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + ResourceFilterCollection filters = new ResourceFilterCollection(VirtualMachineScaleSetOperations.ResourceType); + filters.SubstringFilter = nameFilter; + return ResourceListOperations.ListAtContextAsync(Parent as ResourceGroupOperations, filters, top, cancellationToken); + } + + /// + /// List the virtual machines for this resource group. + /// + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(CancellationToken cancellationToken = default) + { + var result = Operations.ListAsync(Id.Name, cancellationToken); + return new PhWrappingAsyncPageable( + result, + s => new VirtualMachineScaleSet(Parent, new VirtualMachineScaleSetData(s))); + } + + /// + /// Filters the list of virtual machines for this resource group represented as generic resources. + /// Makes an additional network call to retrieve the full data model for each virtual machine. + /// + /// The substring to filter by. + /// The number of items to truncate by. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(string nameFilter, int? top = null, CancellationToken cancellationToken = default) + { + var results = ListAsGenericResourceAsync(nameFilter, top, cancellationToken); + return new PhWrappingAsyncPageable(results, s => (new VirtualMachineScaleSetOperations(s)).Get().Value); + } + + /// + /// The operation to create a virtual machine. + /// + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// + /// Details on long running operation object. + /// + /// An that allows polling for completion of the operation. + public override ArmOperation StartCreateOrUpdate(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) + { + return new PhArmOperation( + Operations.StartCreateOrUpdate(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken), + v => new VirtualMachineScaleSet(Parent, new VirtualMachineScaleSetData(v))); + } + + /// + /// The operation to create a virtual machine. + /// + /// The name of the virtual machine. + /// Parameters supplied to the Create Virtual Machine operation. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// + /// Details on long running operation object. + /// + /// A that on completion returns an that allows polling for completion of the operation. + public async override Task> StartCreateOrUpdateAsync(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) + { + return new PhArmOperation( + await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken).ConfigureAwait(false), + v => new VirtualMachineScaleSet(Parent, new VirtualMachineScaleSetData(v))); + } + } +} diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs new file mode 100644 index 0000000000000..3d38ab412cfd9 --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs @@ -0,0 +1,314 @@ +using Azure; +using Azure.ResourceManager.Compute; +using Azure.ResourceManager.Compute.Models; +using Azure.ResourceManager.Core; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Proto.Compute +{ + /// + /// A class representing the operations that can be performed over a specific VirtualMachineScaleSet. + /// + public class VirtualMachineScaleSetOperations : ResourceOperationsBase, ITaggableResource, IDeletableResource + { + /// + /// Initializes a new instance of the class. + /// + /// An instance of that has an id for a virtual machine. + internal VirtualMachineScaleSetOperations(GenericResourceOperations genericOperations) + : base(genericOperations, genericOperations.Id) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The client parameters to use in these operations. + /// The identifier of the resource that is the target of operations. + internal VirtualMachineScaleSetOperations(ResourceGroupOperations resourceGroup, string vmName) + : base(resourceGroup, resourceGroup.Id.AppendProviderResource(ResourceType.Namespace, ResourceType.Type, vmName)) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The client parameters to use in these operations. + /// The identifier of the resource that is the target of operations. + protected VirtualMachineScaleSetOperations(ResourceOperationsBase operation, ResourceGroupResourceIdentifier id) + : base(operation, id) + { + } + + /// + /// Gets the resource type definition for a virtual machine. + /// + public static readonly ResourceType ResourceType = "Microsoft.Compute/VirtualMachineScaleSets"; + + /// + /// Gets the valid resources for virtual machines. + /// + protected override ResourceType ValidResourceType => ResourceType; + + private VirtualMachineScaleSetsOperations Operations => new ComputeManagementClient( + BaseUri, + Id.SubscriptionId, + Credential, + ClientOptions.Convert()).VirtualMachineScaleSets; + + /// + /// Initializes a new instance of the class from a . + /// + /// An instance of that has an id for a virtual machine. + /// A new instance of the class. + public static VirtualMachineScaleSetOperations FromGeneric(GenericResourceOperations genericOperations) + { + return new VirtualMachineScaleSetOperations(genericOperations); + } + + /// + public ArmResponse Delete(CancellationToken cancellationToken = default) + { + return new ArmResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + } + + /// + public async Task> DeleteAsync(CancellationToken cancellationToken = default) + { + return new ArmResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + } + + /// + public ArmOperation StartDelete(CancellationToken cancellationToken = default) + { + return new ArmVoidOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); + } + + /// + public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + { + return new ArmVoidOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); + } + + /// + public override ArmResponse Get(CancellationToken cancellationToken = default) + { + return new PhArmResponse( + Operations.Get(Id.ResourceGroupName, Id.Name, cancellationToken), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public override async Task> GetAsync(CancellationToken cancellationToken = default) + { + return new PhArmResponse( + await Operations.GetAsync(Id.ResourceGroupName, Id.Name, cancellationToken), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + /// The operation to update a virtual machine. Please note some properties can be set only during virtual machine creation. + /// + /// The parameters to update. + /// An that allows polling for completion of the operation. + public ArmOperation StartUpdate(VirtualMachineScaleSetUpdate patchable, CancellationToken cancellationToken = default) + { + return new PhArmOperation( + Operations.StartUpdate(Id.ResourceGroupName, Id.Name, patchable, cancellationToken), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + /// The operation to update a virtual machine. Please note some properties can be set only during virtual machine creation. + /// + /// The parameters to update. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A that on completion returns an that allows polling for completion of the operation. + public async Task> StartUpdateAsync(VirtualMachineScaleSetUpdate patchable, CancellationToken cancellationToken = default) + { + return new PhArmOperation( + await Operations.StartUpdateAsync(Id.ResourceGroupName, Id.Name, patchable, cancellationToken), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public ArmResponse AddTag(string key, string value, CancellationToken cancellationToken = default) + { + var vm = GetResource(); + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(vm.Data.Tags); + patchable.Tags[key] = value; + + return new PhArmResponse( + Operations.StartUpdate(Id.ResourceGroupName, Id.Name, patchable, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public async Task> AddTagAsync(string key, string value, CancellationToken cancellationToken = default) + { + var vm = await GetResourceAsync(cancellationToken); + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(vm.Data.Tags); + patchable.Tags[key] = value; + + return new PhArmResponse( + await Operations.StartUpdateAsync(Id.ResourceGroupName, Id.Name, patchable, cancellationToken).Result.WaitForCompletionAsync(), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public ArmOperation StartAddTag(string key, string value, CancellationToken cancellationToken = default) + { + var vm = GetResource(); + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(vm.Data.Tags); + patchable.Tags[key] = value; + + return new PhArmOperation( + Operations.StartUpdate(Id.ResourceGroupName, Id.Name, patchable, cancellationToken), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public async Task> StartAddTagAsync(string key, string value, CancellationToken cancellationToken = default) + { + var vm = await GetResourceAsync(cancellationToken); + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(vm.Data.Tags); + patchable.Tags[key] = value; + + return new PhArmOperation( + await Operations.StartUpdateAsync(Id.ResourceGroupName, Id.Name, patchable, cancellationToken), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public ArmResponse SetTags(IDictionary tags, CancellationToken cancellationToken = default) + { + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(tags); + + return new PhArmResponse( + Operations.StartUpdate(Id.ResourceGroupName, Id.Name, patchable, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public async Task> SetTagsAsync(IDictionary tags, CancellationToken cancellationToken = default) + { + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(tags); + + return new PhArmResponse( + await Operations.StartUpdateAsync(Id.ResourceGroupName, Id.Name, patchable, cancellationToken).Result.WaitForCompletionAsync(cancellationToken), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public ArmOperation StartSetTags(IDictionary tags, CancellationToken cancellationToken = default) + { + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(tags); + + return new PhArmOperation( + Operations.StartUpdate(Id.ResourceGroupName, Id.Name, patchable, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public async Task> StartSetTagsAsync(IDictionary tags, CancellationToken cancellationToken = default) + { + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(tags); + + return new PhArmOperation( + await Operations.StartUpdateAsync(Id.ResourceGroupName, Id.Name, patchable, cancellationToken).Result.WaitForCompletionAsync(cancellationToken), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public ArmResponse RemoveTag(string key, CancellationToken cancellationToken = default) + { + var vm = GetResource(); + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(vm.Data.Tags); + patchable.Tags.Remove(key); + + return new PhArmResponse( + Operations.StartUpdate(Id.ResourceGroupName, Id.Name, patchable, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public async Task> RemoveTagAsync(string key, CancellationToken cancellationToken = default) + { + var vm = await GetResourceAsync(cancellationToken); + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(vm.Data.Tags); + patchable.Tags.Remove(key); + + return new PhArmResponse( + await Operations.StartUpdateAsync(Id.ResourceGroupName, Id.Name, patchable, cancellationToken).Result.WaitForCompletionAsync(cancellationToken), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public ArmOperation StartRemoveTag(string key, CancellationToken cancellationToken = default) + { + var vm = GetResource(); + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(vm.Data.Tags); + patchable.Tags.Remove(key); + + return new PhArmOperation( + Operations.StartUpdate(Id.ResourceGroupName, Id.Name, patchable, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + public async Task> StartRemoveTagAsync(string key, CancellationToken cancellationToken = default) + { + var vm = await GetResourceAsync(cancellationToken); + var patchable = new VirtualMachineScaleSetUpdate(); + patchable.Tags.ReplaceWith(vm.Data.Tags); + patchable.Tags.Remove(key); + + return new PhArmOperation( + await Operations.StartUpdateAsync(Id.ResourceGroupName, Id.Name, patchable, cancellationToken).Result.WaitForCompletionAsync(cancellationToken), + v => new VirtualMachineScaleSet(this, new VirtualMachineScaleSetData(v))); + } + + /// + /// Lists all available geo-locations. + /// + /// A collection of location that may take multiple service requests to iterate over. + public IEnumerable ListAvailableLocations(CancellationToken cancellationToken = default) + { + return ListAvailableLocations(ResourceType, cancellationToken); + } + + /// + /// Lists all available geo-locations. + /// + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of location that may take multiple service requests to iterate over. + /// The default subscription id is null. + public async Task> ListAvailableLocationsAsync(CancellationToken cancellationToken = default) + { + return await ListAvailableLocationsAsync(ResourceType, cancellationToken); + } + + /// + /// Gets a list of subnet in the virtual nerwork. + /// + /// An object representing collection of subnets and their operations over a virtual network. + public VirtualMachineScaleSetRollingUpgradeOperations GetRollingUpgrade() + { + return new VirtualMachineScaleSetRollingUpgradeOperations(this, Id); + } + } +} diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgrade.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgrade.cs new file mode 100644 index 0000000000000..7b2e2cc6e8756 --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgrade.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +using System.Threading; +using System.Threading.Tasks; +using Azure.ResourceManager.Core; + +#nullable disable + +namespace Proto.Compute +{ + /// A Class representing a VirtualMachineScaleSetRollingUpgrade along with the instance operations that can be performed on it. + public class VirtualMachineScaleSetRollingUpgrade : VirtualMachineScaleSetRollingUpgradeOperations + { + /// + /// Gets the data representing this VirtualMachine. + /// + public RollingUpgradeStatusInfo Data { get; private set; } + + /// + /// Initializes a new instance of the class. + /// + /// The client parameters to use in these operations. + /// The resource that is the target of operations. + internal VirtualMachineScaleSetRollingUpgrade(OperationsBase operations, RollingUpgradeStatusInfo resource) + : base(operations, resource.Id) + { + Data = resource; + } + } +} diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgradeOperations.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgradeOperations.cs new file mode 100644 index 0000000000000..d13f681c22865 --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgradeOperations.cs @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.ResourceManager.Compute; +using Azure.ResourceManager.Core; + +namespace Proto.Compute +{ + /// A class representing the operations that can be performed over a specific VirtualMachineScaleSetRollingUpgrade. + public partial class VirtualMachineScaleSetRollingUpgradeOperations : SingletonOperationsBase + { + /// Initializes a new instance of VirtualMachineScaleSetRollingUpgradeOperations for mocking. + protected VirtualMachineScaleSetRollingUpgradeOperations() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The client parameters to use in these operations. + /// The identifier of the resource that is the target of operations. + protected internal VirtualMachineScaleSetRollingUpgradeOperations(OperationsBase operation, ResourceGroupResourceIdentifier id) + : base(operation, id) + { + } + + public static readonly ResourceType ResourceType = "Proto.Compute/VirtualMachineScaleSet/VirtualMachineScaleSetRollingUpgradeOperations"; + + protected override ResourceType ValidResourceType => ResourceType; + + private VirtualMachineScaleSetRollingUpgradesOperations Operations => new ComputeManagementClient( + BaseUri, + Id.SubscriptionId, + Credential, + ClientOptions.Convert()).VirtualMachineScaleSetRollingUpgrades; + + // Note: Singleton may have different operations such as GET/PUT/PATCH/POST or a combination of these + // Individual methods will be generated as they are declared + public ArmResponse Get(CancellationToken cancellationToken = default) + { + return new PhArmResponse( + Operations.GetLatest(Id.ResourceGroupName, "", cancellationToken), + v => new VirtualMachineScaleSetRollingUpgrade(this, new RollingUpgradeStatusInfo(v))); + } + + public Task> GetAsync(CancellationToken cancellationToken = default) + { + throw new NotImplementedException(); + } + } +} From 7e0c3bdf13702b5ad6abaaa87311f69a80b69129 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Fri, 23 Apr 2021 14:19:20 -0700 Subject: [PATCH 2/9] PR comment fix. --- .../compute/Placeholder/RollingUpgradeStatusInfo.cs | 12 +++++++++--- .../Placeholder/VirtualMachineScaleSetData.cs | 4 ++-- .../Proto.Client/network/Placeholder/SubnetData.cs | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs b/sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs index a47dd6930a00b..b336bb49916b5 100644 --- a/sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs +++ b/sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs @@ -11,16 +11,22 @@ namespace Proto.Compute { /// The status of the latest virtual machine scale set rolling upgrade. - public partial class RollingUpgradeStatusInfo : ProxyResource + public partial class RollingUpgradeStatusInfo : Resource { /// /// Initializes a new instance of the class. /// public RollingUpgradeStatusInfo(Azure.ResourceManager.Compute.Models.RollingUpgradeStatusInfo rollingUpgradeStatusInfo) - : base(rollingUpgradeStatusInfo.Id, rollingUpgradeStatusInfo) + : base(rollingUpgradeStatusInfo.Id, rollingUpgradeStatusInfo.Name, VirtualMachineScaleSetRollingUpgradeOperations.ResourceType) { + Model = rollingUpgradeStatusInfo; } + /// + /// Gets or sets the Model this resource is based of. + /// + public virtual Azure.ResourceManager.Compute.Models.RollingUpgradeStatusInfo Model { get; } + /// /// Gets the subnet id. /// @@ -38,4 +44,4 @@ public RollingUpgradeStatusInfo(Azure.ResourceManager.Compute.Models.RollingUpgr /// Error details for this upgrade, if there are any. public ApiError Error => Model.Error; } -} \ No newline at end of file +} diff --git a/sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineScaleSetData.cs b/sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineScaleSetData.cs index 66231a6ef7653..9112bb437bade 100644 --- a/sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineScaleSetData.cs +++ b/sdk/resourcemanager/Proto.Client/compute/Placeholder/VirtualMachineScaleSetData.cs @@ -67,9 +67,9 @@ public VirtualMachineScaleSetData(Azure.ResourceManager.Compute.Models.VirtualMa /// Fault Domain count for each placement group. public int? PlatformFaultDomainCount { get; set; } /// Specifies information about the proximity placement group that the virtual machine scale set should be assigned to. <br><br>Minimum api-version: 2018-04-01. - public SubResource ProximityPlacementGroup { get; set; } + public Azure.ResourceManager.Compute.Models.SubResource ProximityPlacementGroup { get; set; } /// Specifies information about the dedicated host group that the virtual machine scale set resides in. <br><br>Minimum api-version: 2020-06-01. - public SubResource HostGroup { get; set; } + public Azure.ResourceManager.Compute.Models.SubResource HostGroup { get; set; } /// Specifies additional capabilities enabled or disabled on the Virtual Machines in the Virtual Machine Scale Set. For instance: whether the Virtual Machines have the capability to support attaching managed data disks with UltraSSD_LRS storage account type. public AdditionalCapabilities AdditionalCapabilities { get; set; } /// Specifies the scale-in policy that decides which virtual machines are chosen for removal when a Virtual Machine Scale Set is scaled-in. diff --git a/sdk/resourcemanager/Proto.Client/network/Placeholder/SubnetData.cs b/sdk/resourcemanager/Proto.Client/network/Placeholder/SubnetData.cs index 9a7cefb7c9377..48ef7dd88b3f7 100644 --- a/sdk/resourcemanager/Proto.Client/network/Placeholder/SubnetData.cs +++ b/sdk/resourcemanager/Proto.Client/network/Placeholder/SubnetData.cs @@ -21,7 +21,7 @@ public SubnetData(Azure.ResourceManager.Network.Models.Subnet sub) /// /// Gets or sets the Model this resource is based of. /// - public virtual Azure.ResourceManager.Network.Models.Subnet Model { get; set; } + public virtual Azure.ResourceManager.Network.Models.Subnet Model { get; } /// /// Gets the subnet id. From b9af9924fff29dbb94d32ca6a09c1e90c0a8d0f7 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Thu, 29 Apr 2021 01:27:27 -0700 Subject: [PATCH 3/9] Completed singleton VMSS test case. --- .../src/ArmClient.cs | 2 +- .../src/SingletonOperationsBase.cs | 30 +++-- .../VirtualMachineScaleSetModelBuilder.cs | 95 +++++++++++++++ .../VirtualMachineScaleSetModelBuilderBase.cs | 58 +++++++++ .../Extensions/ResourceGroupExtensions.cs | 10 ++ .../Placeholder/RollingUpgradeStatusInfo.cs | 2 +- ...SetRollingUpgrade.cs => RollingUpgrade.cs} | 8 +- ...rations.cs => RollingUpgradeOperations.cs} | 30 +++-- .../VirtualMachineScaleSetContainer.cs | 64 +++++++++- .../VirtualMachineScaleSetOperations.cs | 6 +- .../Extensions/ResourceGroupExtensions.cs | 10 ++ .../Proto.Client/network/LoadBalancer.cs | 38 ++++++ .../network/LoadBalancerContainer.cs | 115 ++++++++++++++++++ .../network/LoadBalancerOperations.cs | 92 ++++++++++++++ .../network/Placeholder/LoadBalancerData.cs | 70 +++++++++++ .../Proto.Client/src/ScenarioFactory.cs | 3 +- .../Proto.Client/src/Scenarios/CreateVMSS.cs | 80 ++++++++++++ .../src/Scenarios/SingletonVmssUpgrade.cs | 55 +++++++++ 18 files changed, 734 insertions(+), 34 deletions(-) create mode 100644 sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilder.cs create mode 100644 sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs rename sdk/resourcemanager/Proto.Client/compute/{VirtualMachineScaleSetRollingUpgrade.cs => RollingUpgrade.cs} (70%) rename sdk/resourcemanager/Proto.Client/compute/{VirtualMachineScaleSetRollingUpgradeOperations.cs => RollingUpgradeOperations.cs} (52%) create mode 100644 sdk/resourcemanager/Proto.Client/network/LoadBalancer.cs create mode 100644 sdk/resourcemanager/Proto.Client/network/LoadBalancerContainer.cs create mode 100644 sdk/resourcemanager/Proto.Client/network/LoadBalancerOperations.cs create mode 100644 sdk/resourcemanager/Proto.Client/network/Placeholder/LoadBalancerData.cs create mode 100644 sdk/resourcemanager/Proto.Client/src/Scenarios/CreateVMSS.cs create mode 100644 sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs index 6f8568f20475a..5b8b708460919 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs @@ -86,7 +86,6 @@ private ArmClient( TokenCredential credential, ArmClientOptions options) { - Pipeline = ManagementPipelineBuilder.Build(credential, baseUri, options); Credential = credential; BaseUri = baseUri; if (credential is null) @@ -97,6 +96,7 @@ private ArmClient( ? GetDefaultSubscription() : GetSubscriptions().TryGet(defaultSubscriptionId); ClientOptions.ApiVersions.SetProviderClient(credential, baseUri, DefaultSubscription.Id.SubscriptionId); + Pipeline = ManagementPipelineBuilder.Build(Credential, baseUri, ClientOptions); } /// diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs index 58e4823849b31..59780c562658f 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs @@ -21,8 +21,17 @@ protected SingletonOperationsBase() /// /// internal SingletonOperationsBase(ClientContext clientContext, ResourceIdentifier id) - : base(clientContext, id) + : base(clientContext, ResourceIdentifier.RootResourceIdentifier) { + ParentId = id; + } + + /// + /// The typed resource identifier for the underlying resource + /// + public ResourceIdentifier ParentId + { + get; } } @@ -32,7 +41,7 @@ internal SingletonOperationsBase(ClientContext clientContext, ResourceIdentifier /// The type of the class containing operations for the underlying resource. /// The type of the resource identifier. [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "")] - public abstract class SingletonOperationsBase : OperationsBase + public abstract class SingletonOperationsBase : SingletonOperationsBase where TOperations : SingletonOperationsBase where TIdentifier : ResourceIdentifier { @@ -47,18 +56,25 @@ protected SingletonOperationsBase() /// Initializes a new instance of the class. /// /// The resource representing the parent resource. - /// The identifier of the resource that is the target of operations. - protected SingletonOperationsBase(OperationsBase parent, ResourceIdentifier id) - : base(new ClientContext(parent.ClientOptions, parent.Credential, parent.BaseUri), id) + /// The identifier of the resource that is the target of operations. + protected SingletonOperationsBase(OperationsBase parent, TIdentifier parentId) + : base(new ClientContext(parent.ClientOptions, parent.Credential, parent.BaseUri, parent.Pipeline), parentId) { + Parent = parent; + ParentId = parentId; } + /// + /// Gets the parent resource of this resource. + /// + protected OperationsBase Parent { get; } + /// /// The typed resource identifier for the underlying resource /// - public new virtual TIdentifier Id + protected new TIdentifier ParentId { - get { return base.Id as TIdentifier; } + get; } } } diff --git a/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilder.cs b/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilder.cs new file mode 100644 index 0000000000000..e5d98ae4b0e4a --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilder.cs @@ -0,0 +1,95 @@ +using Azure.ResourceManager.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.ResourceManager.Compute.Models; + +namespace Proto.Compute.Convenience +{ + /// + /// A class representing a builder object to help create a virtual machine. + /// + public class VirtualMachineScaleSetModelBuilder : VirtualMachineScaleSetModelBuilderBase + { + private VirtualMachineScaleSetData _model; + + /// + /// Initializes a new instance of the class. + /// + /// The container to create the virtual machine in. + /// The data model representing the virtual machine to create. + public VirtualMachineScaleSetModelBuilder(VirtualMachineScaleSetContainer containerOperations, VirtualMachineScaleSetData model) + : base(containerOperations, model) + { + // TODO: GENERATOR Update Builder after models are incorporated in generated models + _model = model; + } + + public override VirtualMachineScaleSetModelBuilderBase WithUseWindowsImage(string computerNamePrefix, string adminUser, string password) + { + _model.VirtualMachineProfile.OsProfile = new VirtualMachineScaleSetOSProfile() + { + ComputerNamePrefix = computerNamePrefix, + AdminUsername = adminUser, + AdminPassword = password, + WindowsConfiguration = new WindowsConfiguration { TimeZone = "Pacific Standard Time", ProvisionVMAgent = true } + }; + + return this; + } + + public override VirtualMachineScaleSetModelBuilderBase WithUseLinuxImage(string computerNamePrefix, string adminUser, string password) + { + _model.VirtualMachineProfile.OsProfile = new VirtualMachineScaleSetOSProfile() + { + ComputerNamePrefix = computerNamePrefix, + AdminUsername = adminUser, + AdminPassword = password, + LinuxConfiguration = new LinuxConfiguration + { + DisablePasswordAuthentication = false, + ProvisionVMAgent = true + } + }; + + return this; + } + + public override VirtualMachineScaleSetModelBuilderBase WithRequiredPrimaryNetworkInterface( + string name, + ResourceIdentifier subNetResourceId, + ICollection backendAddressPoolResourceIds, + ICollection inboundNatPoolResourceIds) + { + var ipconfig = new VirtualMachineScaleSetIPConfiguration($"{name}PrimaryIPConfig") + { + Subnet = new ApiEntityReference() { Id = subNetResourceId }, + }; + foreach (var id in backendAddressPoolResourceIds) + { + ipconfig.LoadBalancerBackendAddressPools.Add( + new Azure.ResourceManager.Compute.Models.SubResource { Id = id }); + } + foreach (var id in inboundNatPoolResourceIds) + { + ipconfig.LoadBalancerInboundNatPools.Add( + new Azure.ResourceManager.Compute.Models.SubResource { Id = id }); + } + + var nicConfig = new VirtualMachineScaleSetNetworkConfiguration(name) + { + Primary = true, + }; + nicConfig.IpConfigurations.Add(ipconfig); + + _model.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Add(nicConfig); + + return this; + } + + public override VirtualMachineScaleSetModelBuilderBase WithRequiredLoadBalancer(ResourceIdentifier asetResourceId) + { + return this; + } + } +} diff --git a/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs b/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs new file mode 100644 index 0000000000000..72d98a23940c5 --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs @@ -0,0 +1,58 @@ +using Azure.ResourceManager.Core; +using System; +using System.Collections.Generic; + +namespace Proto.Compute.Convenience +{ + /// + /// A class representing a builder object to help create a virtual machine scale set. + /// + public abstract class VirtualMachineScaleSetModelBuilderBase : ArmBuilder + { + /// + /// Initializes a new instance of the class. + /// + /// The container to create the virtual machine in. + /// The data model representing the virtual machine to create. + protected VirtualMachineScaleSetModelBuilderBase(VirtualMachineScaleSetContainer containerOperations, VirtualMachineScaleSetData vm) + : base(containerOperations, vm) + { + } + + /// + /// Tells the builder to use a windows image. + /// + /// The admin username for the virtual machine. + /// The asmin password for the virtual machine. + /// An instance of . + public abstract VirtualMachineScaleSetModelBuilderBase WithUseWindowsImage(string computerNamePrefix, string adminUser, string password); + + /// + /// Tells the builder to use a linux image. + /// + /// The admin username for the virtual machine. + /// The asmin password for the virtual machine. + /// An instance of . + public abstract VirtualMachineScaleSetModelBuilderBase WithUseLinuxImage(string computerNamePrefix, string adminUser, string password); + + /// + /// Tells the builder to use a specific network interface. + /// + /// name of the network interface configuration + /// The network interface identifier. + /// The list of backend address pool resource id + /// The list of inbound Nat pool resource id. + /// An instance of . + public abstract VirtualMachineScaleSetModelBuilderBase WithRequiredPrimaryNetworkInterface( + string name, ResourceIdentifier subNetResourceId, + ICollection backendAddressPoolResourceIds, + ICollection inboundNatPoolResourceIds); + + /// + /// Tells the builder to use a specific load balancer. + /// + /// The availability set identifier. + /// An instance of . + public abstract VirtualMachineScaleSetModelBuilderBase WithRequiredLoadBalancer(ResourceIdentifier asetResourceId); + } +} diff --git a/sdk/resourcemanager/Proto.Client/compute/Extensions/ResourceGroupExtensions.cs b/sdk/resourcemanager/Proto.Client/compute/Extensions/ResourceGroupExtensions.cs index c91d8000f2e71..dd3190efe995b 100644 --- a/sdk/resourcemanager/Proto.Client/compute/Extensions/ResourceGroupExtensions.cs +++ b/sdk/resourcemanager/Proto.Client/compute/Extensions/ResourceGroupExtensions.cs @@ -18,6 +18,16 @@ public static VirtualMachineContainer GetVirtualMachines(this ResourceGroupOpera return new VirtualMachineContainer(resourceGroup); } + /// + /// Gets an object representing a VirtualMachineScaleSetContainer along with the instance operations that can be performed on it. + /// + /// The instance the method will execute against. + /// Returns a object. + public static VirtualMachineScaleSetContainer GetVirtualMachineScaleSet(this ResourceGroupOperations resourceGroup) + { + return new VirtualMachineScaleSetContainer(resourceGroup); + } + /// /// Gets an object representing a AvailabilitySetContainer along with the instance operations that can be performed on it. /// diff --git a/sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs b/sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs index b336bb49916b5..dcbe732f5af65 100644 --- a/sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs +++ b/sdk/resourcemanager/Proto.Client/compute/Placeholder/RollingUpgradeStatusInfo.cs @@ -17,7 +17,7 @@ public partial class RollingUpgradeStatusInfo : Resource class. /// public RollingUpgradeStatusInfo(Azure.ResourceManager.Compute.Models.RollingUpgradeStatusInfo rollingUpgradeStatusInfo) - : base(rollingUpgradeStatusInfo.Id, rollingUpgradeStatusInfo.Name, VirtualMachineScaleSetRollingUpgradeOperations.ResourceType) + : base(rollingUpgradeStatusInfo.Id, rollingUpgradeStatusInfo.Name, RollingUpgradeOperations.ResourceType) { Model = rollingUpgradeStatusInfo; } diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgrade.cs b/sdk/resourcemanager/Proto.Client/compute/RollingUpgrade.cs similarity index 70% rename from sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgrade.cs rename to sdk/resourcemanager/Proto.Client/compute/RollingUpgrade.cs index 7b2e2cc6e8756..81a31e82f19eb 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgrade.cs +++ b/sdk/resourcemanager/Proto.Client/compute/RollingUpgrade.cs @@ -12,7 +12,7 @@ namespace Proto.Compute { /// A Class representing a VirtualMachineScaleSetRollingUpgrade along with the instance operations that can be performed on it. - public class VirtualMachineScaleSetRollingUpgrade : VirtualMachineScaleSetRollingUpgradeOperations + public class RollingUpgrade : RollingUpgradeOperations { /// /// Gets the data representing this VirtualMachine. @@ -20,12 +20,12 @@ public class VirtualMachineScaleSetRollingUpgrade : VirtualMachineScaleSetRollin public RollingUpgradeStatusInfo Data { get; private set; } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The client parameters to use in these operations. /// The resource that is the target of operations. - internal VirtualMachineScaleSetRollingUpgrade(OperationsBase operations, RollingUpgradeStatusInfo resource) - : base(operations, resource.Id) + internal RollingUpgrade(OperationsBase operations, RollingUpgradeStatusInfo resource) + : base(operations, operations.Id as ResourceGroupResourceIdentifier) { Data = resource; } diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgradeOperations.cs b/sdk/resourcemanager/Proto.Client/compute/RollingUpgradeOperations.cs similarity index 52% rename from sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgradeOperations.cs rename to sdk/resourcemanager/Proto.Client/compute/RollingUpgradeOperations.cs index d13f681c22865..80ffda87e7eff 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetRollingUpgradeOperations.cs +++ b/sdk/resourcemanager/Proto.Client/compute/RollingUpgradeOperations.cs @@ -8,16 +8,17 @@ using System; using System.Threading; using System.Threading.Tasks; +using Azure; using Azure.ResourceManager.Compute; using Azure.ResourceManager.Core; namespace Proto.Compute { /// A class representing the operations that can be performed over a specific VirtualMachineScaleSetRollingUpgrade. - public partial class VirtualMachineScaleSetRollingUpgradeOperations : SingletonOperationsBase + public partial class RollingUpgradeOperations : SingletonOperationsBase { /// Initializes a new instance of VirtualMachineScaleSetRollingUpgradeOperations for mocking. - protected VirtualMachineScaleSetRollingUpgradeOperations() + protected RollingUpgradeOperations() { } @@ -26,33 +27,40 @@ protected VirtualMachineScaleSetRollingUpgradeOperations() /// /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. - protected internal VirtualMachineScaleSetRollingUpgradeOperations(OperationsBase operation, ResourceGroupResourceIdentifier id) + protected internal RollingUpgradeOperations(OperationsBase operation, ResourceGroupResourceIdentifier id) : base(operation, id) { } - public static readonly ResourceType ResourceType = "Proto.Compute/VirtualMachineScaleSet/VirtualMachineScaleSetRollingUpgradeOperations"; + public static readonly ResourceType ResourceType = "Microsoft.Compute/virtualMachineScaleSets"; - protected override ResourceType ValidResourceType => ResourceType; + protected override ResourceType ValidResourceType => ResourceType.RootResourceType; private VirtualMachineScaleSetRollingUpgradesOperations Operations => new ComputeManagementClient( BaseUri, - Id.SubscriptionId, + ParentId.SubscriptionId, Credential, ClientOptions.Convert()).VirtualMachineScaleSetRollingUpgrades; // Note: Singleton may have different operations such as GET/PUT/PATCH/POST or a combination of these // Individual methods will be generated as they are declared - public ArmResponse Get(CancellationToken cancellationToken = default) + public ArmResponse Get(CancellationToken cancellationToken = default) { - return new PhArmResponse( - Operations.GetLatest(Id.ResourceGroupName, "", cancellationToken), - v => new VirtualMachineScaleSetRollingUpgrade(this, new RollingUpgradeStatusInfo(v))); + return new PhArmResponse( + Operations.GetLatest(ParentId.ResourceGroupName, ParentId.Name, cancellationToken), + v => new RollingUpgrade(Parent, new RollingUpgradeStatusInfo(v))); } - public Task> GetAsync(CancellationToken cancellationToken = default) + public Task> GetAsync(CancellationToken cancellationToken = default) { throw new NotImplementedException(); } + + // Note: Singleton may have different operations such as GET/PUT/PATCH/POST or a combination of these + // Individual methods will be generated as they are declared + public ArmResponse Cancel(CancellationToken cancellationToken = default) + { + return new ArmResponse(Operations.StartCancel(ParentId.ResourceGroupName, ParentId.Name, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + } } } diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs index 14e54129c242b..76a02b72c0009 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs @@ -1,12 +1,15 @@ // 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; using Azure.ResourceManager.Core.Resources; +using Proto.Compute.Convenience; namespace Proto.Compute { @@ -62,7 +65,7 @@ public override ArmResponse CreateOrUpdate(string name, /// Parameters supplied to the Create Virtual Machine operation. /// 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. - public async override Task> CreateOrUpdateAsync(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) + public override async Task> CreateOrUpdateAsync(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) { var operation = await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken).ConfigureAwait(false); return new PhArmResponse( @@ -71,16 +74,16 @@ await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false), } /// - public override ArmResponse Get(string VirtualMachineScaleSetName, CancellationToken cancellationToken = default) + public override ArmResponse Get(string virtualMachineScaleSetName, CancellationToken cancellationToken = default) { - return new PhArmResponse(Operations.Get(Id.ResourceGroupName, VirtualMachineScaleSetName, cancellationToken), + return new PhArmResponse(Operations.Get(Id.ResourceGroupName, virtualMachineScaleSetName, cancellationToken), v => new VirtualMachineScaleSet(Parent, new VirtualMachineScaleSetData(v))); } /// - public override async Task> GetAsync(string VirtualMachineScaleSetName, CancellationToken cancellationToken = default) + public override async Task> GetAsync(string virtualMachineScaleSetName, CancellationToken cancellationToken = default) { - return new PhArmResponse(await Operations.GetAsync(Id.ResourceGroupName, VirtualMachineScaleSetName, cancellationToken), + return new PhArmResponse(await Operations.GetAsync(Id.ResourceGroupName, virtualMachineScaleSetName, cancellationToken), v => new VirtualMachineScaleSet(Parent, new VirtualMachineScaleSetData(v))); } @@ -193,11 +196,60 @@ public override ArmOperation StartCreateOrUpdate(string /// Details on long running operation object. /// /// A that on completion returns an that allows polling for completion of the operation. - public async override Task> StartCreateOrUpdateAsync(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) + public override async Task> StartCreateOrUpdateAsync(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) { return new PhArmOperation( await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken).ConfigureAwait(false), v => new VirtualMachineScaleSet(Parent, new VirtualMachineScaleSetData(v))); } + + /// + /// Construct an object used to create a VirtualMachine. + /// + /// The hostname for the virtual machine. + /// The location to create the Virtual Machine. + /// Object used to create a . + public VirtualMachineScaleSetModelBuilder Construct(string hostName, LocationData location = null) + { + var parent = GetParentResource(); + var vmss = new Azure.ResourceManager.Compute.Models.VirtualMachineScaleSet(location ?? parent.Data.Location) + { + // TODO SKU should not be hardcoded + Sku = new Azure.ResourceManager.Compute.Models.Sku() { Name = "Standard_DS1_v2", Capacity = 2 }, + Overprovision = false, + VirtualMachineProfile = new Azure.ResourceManager.Compute.Models.VirtualMachineScaleSetVMProfile() + { + NetworkProfile = new VirtualMachineScaleSetNetworkProfile(), + StorageProfile = new VirtualMachineScaleSetStorageProfile() + { + OsDisk = new VirtualMachineScaleSetOSDisk(DiskCreateOptionTypes.FromImage), + ImageReference = new ImageReference() + { + Offer = "WindowsServer", + Publisher = "MicrosoftWindowsServer", + Sku = "2019-Datacenter", + Version = "latest" + }, + } + }, + UpgradePolicy = new UpgradePolicy() { Mode = UpgradeMode.Automatic }, + }; + + var nicConfig = new VirtualMachineScaleSetNetworkConfiguration("scaleSetNic") + { + Primary = true, + }; + var ipconfig = new VirtualMachineScaleSetIPConfiguration("scaleSetIPConfig") + { + Subnet = new ApiEntityReference() { Id = "" }, + }; + ipconfig.LoadBalancerBackendAddressPools.Add(null); + ipconfig.LoadBalancerInboundNatPools.Add(null); + nicConfig.IpConfigurations.Add(ipconfig); + + vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Add(nicConfig); + + return new VirtualMachineScaleSetModelBuilder(this, new VirtualMachineScaleSetData(vmss)); + } } } diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs index 3d38ab412cfd9..5a40d1d90a2de 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs @@ -46,7 +46,7 @@ protected VirtualMachineScaleSetOperations(ResourceOperationsBase operation, Res /// /// Gets the resource type definition for a virtual machine. /// - public static readonly ResourceType ResourceType = "Microsoft.Compute/VirtualMachineScaleSets"; + public static readonly ResourceType ResourceType = "Microsoft.Compute/virtualMachineScaleSets"; /// /// Gets the valid resources for virtual machines. @@ -306,9 +306,9 @@ public async Task> ListAvailableLocationsAsync(Cancell /// Gets a list of subnet in the virtual nerwork. /// /// An object representing collection of subnets and their operations over a virtual network. - public VirtualMachineScaleSetRollingUpgradeOperations GetRollingUpgrade() + public RollingUpgradeOperations GetRollingUpgrade() { - return new VirtualMachineScaleSetRollingUpgradeOperations(this, Id); + return new RollingUpgradeOperations(this, Id); } } } diff --git a/sdk/resourcemanager/Proto.Client/network/Extensions/ResourceGroupExtensions.cs b/sdk/resourcemanager/Proto.Client/network/Extensions/ResourceGroupExtensions.cs index eabef4015913f..0975ca3446dbe 100644 --- a/sdk/resourcemanager/Proto.Client/network/Extensions/ResourceGroupExtensions.cs +++ b/sdk/resourcemanager/Proto.Client/network/Extensions/ResourceGroupExtensions.cs @@ -50,5 +50,15 @@ public static NetworkSecurityGroupContainer GetNetworkSecurityGroups(this Resour { return new NetworkSecurityGroupContainer(resourceGroup); } + + /// + /// Gets a under a . + /// + /// The instance the method will execute against. + /// An instance of . + public static LoadBalancerContainer GetLoadBalancers(this ResourceGroupOperations resourceGroup) + { + return new LoadBalancerContainer(resourceGroup); + } } } diff --git a/sdk/resourcemanager/Proto.Client/network/LoadBalancer.cs b/sdk/resourcemanager/Proto.Client/network/LoadBalancer.cs new file mode 100644 index 0000000000000..db9bbf280a833 --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/network/LoadBalancer.cs @@ -0,0 +1,38 @@ +using System.Threading; +using System.Threading.Tasks; +using Azure.ResourceManager.Core; + +namespace Proto.Network +{ + /// + /// A class representing a LoadBalancer along with the instance operations that can be performed on it. + /// + public class LoadBalancer : LoadBalancerOperations + { + /// + /// Initializes a new instance of the class. + /// + internal LoadBalancer(ResourceOperationsBase options, LoadBalancerData resource) + : base(options, resource.Id) + { + Data = resource; + } + + /// + /// Gets the data representing the LoadBalancer + /// + public LoadBalancerData Data { get; private set; } + + /// + protected override LoadBalancer GetResource(CancellationToken cancellation = default) + { + return this; + } + + /// + protected override Task GetResourceAsync(CancellationToken cancellationToken = default) + { + return Task.FromResult(this); + } + } +} diff --git a/sdk/resourcemanager/Proto.Client/network/LoadBalancerContainer.cs b/sdk/resourcemanager/Proto.Client/network/LoadBalancerContainer.cs new file mode 100644 index 0000000000000..7ef8906bfce25 --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/network/LoadBalancerContainer.cs @@ -0,0 +1,115 @@ +using Azure; +using Azure.ResourceManager.Core; +using Azure.ResourceManager.Network; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Proto.Network +{ + /// + /// A class representing collection of LoadBalancers and their operations over a VirtualNetwork. + /// + public class LoadBalancerContainer : ResourceContainerBase + { + /// + /// Initializes a new instance of the class. + /// + /// The parent resource group. + internal LoadBalancerContainer(ResourceGroupOperations resourceGroup) + : base(resourceGroup) + { + } + + /// + /// Typed Resource Identifier for the container. + /// + public new ResourceGroupResourceIdentifier Id => base.Id as ResourceGroupResourceIdentifier; + + /// + protected override ResourceType ValidResourceType => ResourceGroupOperations.ResourceType; + + private LoadBalancersOperations Operations => new NetworkManagementClient( + Id.SubscriptionId, + BaseUri, + Credential, + ClientOptions.Convert()).LoadBalancers; + + /// + public override ArmResponse CreateOrUpdate(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) + { + var operation = Operations.StartCreateOrUpdate(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken); + return new PhArmResponse( + operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(), + s => new LoadBalancer(Parent, new LoadBalancerData(s))); + } + + /// + public override async Task> CreateOrUpdateAsync(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) + { + var operation = await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken).ConfigureAwait(false); + return new PhArmResponse( + await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false), + s => new LoadBalancer(Parent, new LoadBalancerData(s))); + } + + /// + public override ArmOperation StartCreateOrUpdate(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) + { + return new PhArmOperation( + Operations.StartCreateOrUpdate(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken), + s => new LoadBalancer(Parent, new LoadBalancerData(s))); + } + + /// + public async override Task> StartCreateOrUpdateAsync(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) + { + return new PhArmOperation( + await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken).ConfigureAwait(false), + s => new LoadBalancer(Parent, new LoadBalancerData(s))); + } + + /// + /// Lists the LoadBalancers for this LoadBalancer. + /// + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A collection of resource operations that may take multiple service requests to iterate over. + public Pageable List(CancellationToken cancellationToken = default) + { + return new PhWrappingPageable( + Operations.List(Id.ResourceGroupName, cancellationToken), + convertor()); + } + + /// + /// Lists the LoadBalancers for this LoadBalancer. + /// + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An async collection of resource operations that may take multiple service requests to iterate over. + public AsyncPageable ListAsync(CancellationToken cancellationToken = default) + { + return new PhWrappingAsyncPageable( + Operations.ListAsync(Id.ResourceGroupName, cancellationToken), + convertor()); + } + + private Func convertor() + { + return s => new LoadBalancer(Parent, new LoadBalancerData(s)); + } + + /// + public override ArmResponse Get(string loadBalancerName, CancellationToken cancellationToken = default) + { + return new PhArmResponse(Operations.Get(Id.ResourceGroupName, loadBalancerName, null, cancellationToken: cancellationToken), + n => new LoadBalancer(Parent, new LoadBalancerData(n))); + } + + /// + public override async Task> GetAsync(string loadBalancerName, CancellationToken cancellationToken = default) + { + return new PhArmResponse(await Operations.GetAsync(Id.ResourceGroupName, loadBalancerName, null, cancellationToken), + n => new LoadBalancer(Parent, new LoadBalancerData(n))); + } + } +} diff --git a/sdk/resourcemanager/Proto.Client/network/LoadBalancerOperations.cs b/sdk/resourcemanager/Proto.Client/network/LoadBalancerOperations.cs new file mode 100644 index 0000000000000..2994fa8f1e50e --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/network/LoadBalancerOperations.cs @@ -0,0 +1,92 @@ +using Azure; +using Azure.ResourceManager.Network; +using Azure.ResourceManager.Core; +using System.Threading; +using System.Threading.Tasks; + +namespace Proto.Network +{ + /// + /// A class representing the operations that can be performed over a specific LoadBalancer. + /// + // TODO, ITaggable was not added. + public class LoadBalancerOperations : ResourceOperationsBase, IDeletableResource + { + /// + /// Initializes a new instance of the class. + /// + /// The client parameters to use in these operations. + /// The name of the LoadBalancer. + internal LoadBalancerOperations(VirtualNetworkOperations virtualNetwork, string loadBalancerName) + : base(virtualNetwork, virtualNetwork.Id.AppendChildResource( "loadBalancers", loadBalancerName)) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The client parameters to use in these operations. + /// The identifier of the resource that is the target of operations. + protected LoadBalancerOperations(ResourceOperationsBase options, ResourceIdentifier id) + : base(options, id) + { + } + + /// + /// Gets the resource type definition for a LoadBalancer. + /// + public static readonly ResourceType ResourceType = "Microsoft.Network/loadBalancers"; + + /// + /// Gets the valid resource type definition for a LoadBalancer. + /// + protected override ResourceType ValidResourceType => ResourceType; + + private LoadBalancersOperations Operations => new NetworkManagementClient( + Id.SubscriptionId, + BaseUri, + Credential, + ClientOptions.Convert()).LoadBalancers; + + /// + public ArmResponse Delete(CancellationToken cancellationToken = default) + { + return new ArmResponse(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken) + .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + } + + /// + public async Task> DeleteAsync(CancellationToken cancellationToken = default) + { + return new ArmResponse((await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)) + .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + } + + + /// + public ArmOperation StartDelete(CancellationToken cancellationToken = default) + { + return new ArmVoidOperation(Operations.StartDelete(Id.ResourceGroupName, Id.Name, cancellationToken)); + } + + /// + public async Task> StartDeleteAsync(CancellationToken cancellationToken = default) + { + return new ArmVoidOperation(await Operations.StartDeleteAsync(Id.ResourceGroupName, Id.Name, cancellationToken)); + } + + /// + public override ArmResponse Get(CancellationToken cancellationToken = default) + { + return new PhArmResponse(Operations.Get(Id.ResourceGroupName, Id.Parent.Name, Id.Name, cancellationToken: cancellationToken), + n => new LoadBalancer(this, new LoadBalancerData(n))); + } + + /// + public override async Task> GetAsync(CancellationToken cancellationToken = default) + { + return new PhArmResponse(await Operations.GetAsync(Id.ResourceGroupName, Id.Name, null, cancellationToken), + n => new LoadBalancer(this, new LoadBalancerData(n))); + } + } +} diff --git a/sdk/resourcemanager/Proto.Client/network/Placeholder/LoadBalancerData.cs b/sdk/resourcemanager/Proto.Client/network/Placeholder/LoadBalancerData.cs new file mode 100644 index 0000000000000..8b0850825ffb1 --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/network/Placeholder/LoadBalancerData.cs @@ -0,0 +1,70 @@ +using Azure.ResourceManager.Network.Models; +using Azure.ResourceManager.Core; +using System.Collections.Generic; + +namespace Proto.Network +{ + /// + /// A class representing the LoadBalancer data model. + /// + public class LoadBalancerData : Resource + { + /// + /// Initializes a new instance of the class. + /// + public LoadBalancerData(Azure.ResourceManager.Network.Models.LoadBalancer loadBalancer) + : base(loadBalancer.Id, loadBalancer.Name, LoadBalancerOperations.ResourceType) + { + Model = loadBalancer; + } + + /// + /// Gets or sets the Model this resource is based of. + /// + public virtual Azure.ResourceManager.Network.Models.LoadBalancer Model { get; } + + /// + /// Gets the LoadBalancer id. + /// + public override string Name => Model.Name; + + /// + /// The provisioning state of the LoadBalancer resource. + /// + public ProvisioningState? ProvisioningState => Model.ProvisioningState; + + /// The load balancer SKU. + public LoadBalancerSku Sku + { + get => Model.Sku; + set => Model.Sku = value; + } + + /// A unique read-only string that changes whenever the resource is updated. + public string Etag => Model.Etag; + + /// Object representing the frontend IPs to be used for the load balancer. + public IList FrontendIPConfigurations => Model.FrontendIPConfigurations; + + /// Collection of backend address pools used by a load balancer. + public IList BackendAddressPools => Model.BackendAddressPools; + + /// Object collection representing the load balancing rules Gets the provisioning. + public IList LoadBalancingRules => Model.LoadBalancingRules; + + /// Collection of probe objects used in the load balancer. + public IList Probes => Model.Probes; + + /// Collection of inbound NAT Rules used by a load balancer. Defining inbound NAT rules on your load balancer is mutually exclusive with defining an inbound NAT pool. Inbound NAT pools are referenced from virtual machine scale sets. NICs that are associated with individual virtual machines cannot reference an Inbound NAT pool. They have to reference individual inbound NAT rules. + public IList InboundNatRules => Model.InboundNatRules; + + /// Defines an external port range for inbound NAT to a single backend port on NICs associated with a load balancer. Inbound NAT rules are created automatically for each NIC associated with the Load Balancer using an external port from this range. Defining an Inbound NAT pool on your Load Balancer is mutually exclusive with defining inbound Nat rules. Inbound NAT pools are referenced from virtual machine scale sets. NICs that are associated with individual virtual machines cannot reference an inbound NAT pool. They have to reference individual inbound NAT rules. + public IList InboundNatPools => Model.InboundNatPools; + + /// The outbound rules. + public IList OutboundRules => Model.OutboundRules; + + /// The resource GUID property of the load balancer resource. + public string ResourceGuid => Model.ResourceGuid; + } +} diff --git a/sdk/resourcemanager/Proto.Client/src/ScenarioFactory.cs b/sdk/resourcemanager/Proto.Client/src/ScenarioFactory.cs index afa100e1112bf..6f094ee6b67df 100644 --- a/sdk/resourcemanager/Proto.Client/src/ScenarioFactory.cs +++ b/sdk/resourcemanager/Proto.Client/src/ScenarioFactory.cs @@ -40,7 +40,8 @@ enum Scenarios CheckResourceGroupOpsAsync, TenantResource, CheckResourceGroupContainerAsync, - GenericResourceOperationsExample + GenericResourceOperationsExample, + SingletonVmssUpgrade, } class ScenarioFactory diff --git a/sdk/resourcemanager/Proto.Client/src/Scenarios/CreateVMSS.cs b/sdk/resourcemanager/Proto.Client/src/Scenarios/CreateVMSS.cs new file mode 100644 index 0000000000000..7043318d55df6 --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/src/Scenarios/CreateVMSS.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading.Tasks; +using Azure.Identity; +using Azure.ResourceManager.Core; +using Proto.Compute; +using Proto.Network; + +namespace Proto.Client +{ + class CreateVMSS : Scenario + { + public override void Execute() + { + // TODO Not fully debugged yet around LoadBalancer + // ExecuteAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + } + + private async Task ExecuteAsync() + { + var client = new ArmClient(ScenarioContext.AzureSdkSandboxId, new DefaultAzureCredential()); + + // Create Resource Group + Console.WriteLine($"--------Start StartCreate group {Context.RgName}--------"); + ResourceGroup resourceGroup = await client + .DefaultSubscription + .GetResourceGroups() + .Construct(Context.Loc) + .StartCreateOrUpdate(Context.RgName) + .WaitForCompletionAsync() + ; + CleanUp.Add(resourceGroup.Id); + + // Create VNet + Console.WriteLine("--------Start create VNet--------"); + string vnetName = Context.VmName + "_vnet"; + var vnet = resourceGroup.GetVirtualNetworks().Construct("10.0.0.0/16").CreateOrUpdate(vnetName).Value; + + //create subnet + Console.WriteLine("--------Start create Subnet async--------"); + var subnet = vnet.GetSubnets().Construct("10.0.0.0/24").CreateOrUpdate(Context.SubnetName).Value; + + //create network security group + Console.WriteLine("--------Start create NetworkSecurityGroup--------"); + _ = resourceGroup.GetNetworkSecurityGroups().Construct(80).CreateOrUpdate(Context.NsgName).Value; + + // Create Network Interface + Console.WriteLine("--------Start create Network Interface--------"); + var nic = resourceGroup.GetNetworkInterfaces().Construct(subnet.Id).CreateOrUpdate($"{Context.VmName}_nic").Value; + + + // Create Network Interface + Console.WriteLine("--------Start create Public IP--------"); + var publicIP = resourceGroup.GetPublicIpAddresss().Construct(resourceGroup.Data.Location).CreateOrUpdate($"{Context.VmName}_publicip").Value; + + // Create Network Interface + Console.WriteLine("--------Start create Load Balancer--------"); + var lbData = new LoadBalancerData(new Azure.ResourceManager.Network.Models.LoadBalancer() + { + Location = resourceGroup.Data.Location, + }); + var lb = resourceGroup.GetLoadBalancers().CreateOrUpdate($"{Context.VmName}_lb", lbData).Value; + + // Create VMSS + VirtualMachineScaleSet vmss = resourceGroup + .GetVirtualMachineScaleSet() + .Construct($"{Context.VmName}ScaleSet") + .WithRequiredLoadBalancer(lb.Id) + .WithRequiredPrimaryNetworkInterface("default", nic.Id, null, null) + //.WithUseLinuxImage("testvmss", "azureuser", "") + .WithUseWindowsImage($"{Context.VmName}Prefix", "azureuser", "") + .CreateOrUpdate($"{Context.VmName}ScaleSet"); + CleanUp.Add(vmss.Id); + + Console.WriteLine("\nDone all asserts passed ..."); + } + } +} diff --git a/sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs b/sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs new file mode 100644 index 0000000000000..cbaefe2599b37 --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Diagnostics; +using System.Threading.Tasks; +using Azure; +using Azure.Identity; +using Azure.ResourceManager.Core; +using Proto.Compute; +using Proto.Network; + +namespace Proto.Client +{ + class SingletonVmssUpgrade : Scenario + { + public override void Execute() + { + ExecuteAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + } + + private async Task ExecuteAsync() + { + var client = new ArmClient(ScenarioContext.AzureSdkSandboxId, new DefaultAzureCredential()); + + // NOTE: due to full test involves creating LB which have another 3-5 resources needs to be in + // proto, this test relies on pre-created VMSS. + // 1. Follow instruction here (CLI), https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/quick-create-cli + // 2. Initiate a rolling upgrade az vmss rolling-upgrade start -g [RG] -n myScaleSet --debug + var vmss1 = client.DefaultSubscription + .GetResourceGroups().Get("azhang-test").Value + .GetVirtualMachineScaleSet().Get("myScaleSet").Value; + + var ru = vmss1.GetRollingUpgrade().Get().Value; + Debug.Assert(ru.Data.Model != null); + + ru = ru.Get().Value; + Debug.Assert(ru.Data.Model != null); + + try + { + vmss1.GetRollingUpgrade().Cancel(); + } + catch (RequestFailedException e) when (e.Status == 409) + { + } + catch + { + throw; + } + + Console.WriteLine("Test case SingletonVmssUpgrade passed."); + } + } +} From 4b7999b5fc6388799676ae01ca041701d8bef6aa Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Thu, 29 Apr 2021 01:47:48 -0700 Subject: [PATCH 4/9] Fix merge issue around ArmBuilder removal --- .../VirtualMachineScaleSetModelBuilderBase.cs | 2 +- .../compute/VirtualMachineScaleSetBuilder.cs | 176 ++++++++++++++++++ .../VirtualMachineScaleSetContainer.cs | 8 +- .../network/LoadBalancerContainer.cs | 8 +- 4 files changed, 185 insertions(+), 9 deletions(-) create mode 100644 sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs diff --git a/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs b/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs index 72d98a23940c5..7af06cb69683d 100644 --- a/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs +++ b/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs @@ -7,7 +7,7 @@ namespace Proto.Compute.Convenience /// /// A class representing a builder object to help create a virtual machine scale set. /// - public abstract class VirtualMachineScaleSetModelBuilderBase : ArmBuilder + public abstract class VirtualMachineScaleSetModelBuilderBase : VirtualMachineScaleSetBuilder { /// /// Initializes a new instance of the class. diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs new file mode 100644 index 0000000000000..a4ed9c926cd0b --- /dev/null +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs @@ -0,0 +1,176 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.ResourceManager.Core; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Proto.Compute +{ + /// + /// A class representing a builder object used to create Azure resources. + /// + public class VirtualMachineScaleSetBuilder + { + /// + /// Initializes a new instance of the class. + /// + /// The container object to create the resource in. + /// The resource to create. + public VirtualMachineScaleSetBuilder(VirtualMachineScaleSetContainer container, VirtualMachineScaleSetData resource) + { + Resource = resource; + UnTypedContainer = container; + } + + /// + /// Gets the resource object to create. + /// + protected VirtualMachineScaleSetData Resource { get; private set; } + + /// + /// Gets the resource name. + /// + protected string ResourceName { get; private set; } + + /// + /// Gets the container object to create the resource in. + /// + protected VirtualMachineScaleSetContainer UnTypedContainer { get; private set; } + + /// + /// Creates the resource object to send to the Azure API. + /// + /// The resource to create. + public VirtualMachineScaleSetData Build() + { + ThrowIfNotValid(); + OnBeforeBuild(); + InternalBuild(); + OnAfterBuild(); + + return Resource; + } + + /// + /// The operation to create or update a resource. Please note some properties can be set only during creation. + /// + /// The name of the new resource to create. + /// 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. + /// Name cannot be null or a whitespace. + public ArmResponse CreateOrUpdate(string name, CancellationToken cancellationToken = default) + { + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentException("Name cannot be null or whitespace.", nameof(name)); + + ResourceName = name; + Resource = Build(); + + return UnTypedContainer.CreateOrUpdate(name, Resource, cancellationToken); + } + + /// + /// The operation to create or update a resource. Please note some properties can be set only during creation. + /// + /// The name of the new resource to create. + /// 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. + /// Name cannot be null or a whitespace. + public async Task> CreateOrUpdateAsync( + string name, + CancellationToken cancellationToken = default) + { + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentException("Name cannot be null or whitespace.", nameof(name)); + + ResourceName = name; + Resource = Build(); + + return await UnTypedContainer.CreateOrUpdateAsync(name, Resource, cancellationToken).ConfigureAwait(false); + } + + /// + /// The operation to create or update a resource. Please note some properties can be set only during creation. + /// + /// The name of the new resource to create. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// An that allows polling for completion of the operation. + /// + /// Details on long running operation object. + /// + /// Name cannot be null or a whitespace. + public ArmOperation StartCreateOrUpdate(string name, CancellationToken cancellationToken = default) + { + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentException("Name cannot be null or whitespace.", nameof(name)); + + ResourceName = name; + Resource = Build(); + + return UnTypedContainer.StartCreateOrUpdate(name, Resource, cancellationToken); + } + + /// + /// The operation to create or update a resource. Please note some properties can be set only during creation. + /// + /// The name of the new resource to create. + /// A token to allow the caller to cancel the call to the service. The default value is . + /// A that on completion returns an that allows polling for completion of the operation. + /// + /// Details on long running operation object. + /// + /// Name cannot be null or a whitespace. + public async Task> StartCreateOrUpdateAsync( + string name, + CancellationToken cancellationToken = default) + { + if (string.IsNullOrWhiteSpace(name)) + throw new ArgumentException("Name cannot be null or whitespace.", nameof(name)); + + ResourceName = name; + Resource = Build(); + + return await UnTypedContainer.StartCreateOrUpdateAsync(name, Resource, cancellationToken).ConfigureAwait(false); + } + + /// + /// Determines whether or not the resource is valid. + /// + /// The message indicating what is wrong with the resource. + /// Whether or not the resource is valid. + protected virtual bool IsValid(out string message) + { + message = string.Empty; + + return true; + } + + /// + /// Perform any tasks necessary after the resource is built + /// + protected virtual void OnAfterBuild() + { + } + + /// + /// Perform any tasks necessary before the resource is built + /// + protected virtual void OnBeforeBuild() + { + } + + private static void InternalBuild() + { + } + + private void ThrowIfNotValid() + { + if (!IsValid(out var message)) + { + throw new InvalidOperationException(message); + } + } + } +} diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs index 76a02b72c0009..31849943f40d4 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs @@ -50,7 +50,7 @@ internal VirtualMachineScaleSetContainer(ResourceGroupOperations resourceGroup) /// Parameters supplied to the Create Virtual Machine operation. /// 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. - public override ArmResponse CreateOrUpdate(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) + public ArmResponse CreateOrUpdate(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) { var operation = Operations.StartCreateOrUpdate(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken); return new PhArmResponse( @@ -65,7 +65,7 @@ public override ArmResponse CreateOrUpdate(string name, /// Parameters supplied to the Create Virtual Machine operation. /// 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. - public override async Task> CreateOrUpdateAsync(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) + public async Task> CreateOrUpdateAsync(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) { var operation = await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken).ConfigureAwait(false); return new PhArmResponse( @@ -179,7 +179,7 @@ public AsyncPageable ListAsync(string nameFilter, int? t /// Details on long running operation object. /// /// An that allows polling for completion of the operation. - public override ArmOperation StartCreateOrUpdate(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) + public ArmOperation StartCreateOrUpdate(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) { return new PhArmOperation( Operations.StartCreateOrUpdate(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken), @@ -196,7 +196,7 @@ public override ArmOperation StartCreateOrUpdate(string /// Details on long running operation object. /// /// A that on completion returns an that allows polling for completion of the operation. - public override async Task> StartCreateOrUpdateAsync(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) + public async Task> StartCreateOrUpdateAsync(string name, VirtualMachineScaleSetData resourceDetails, CancellationToken cancellationToken = default) { return new PhArmOperation( await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken).ConfigureAwait(false), diff --git a/sdk/resourcemanager/Proto.Client/network/LoadBalancerContainer.cs b/sdk/resourcemanager/Proto.Client/network/LoadBalancerContainer.cs index 7ef8906bfce25..c19473a541f4e 100644 --- a/sdk/resourcemanager/Proto.Client/network/LoadBalancerContainer.cs +++ b/sdk/resourcemanager/Proto.Client/network/LoadBalancerContainer.cs @@ -36,7 +36,7 @@ internal LoadBalancerContainer(ResourceGroupOperations resourceGroup) ClientOptions.Convert()).LoadBalancers; /// - public override ArmResponse CreateOrUpdate(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) + public ArmResponse CreateOrUpdate(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) { var operation = Operations.StartCreateOrUpdate(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken); return new PhArmResponse( @@ -45,7 +45,7 @@ public override ArmResponse CreateOrUpdate(string name, LoadBalanc } /// - public override async Task> CreateOrUpdateAsync(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) + public async Task> CreateOrUpdateAsync(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) { var operation = await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken).ConfigureAwait(false); return new PhArmResponse( @@ -54,7 +54,7 @@ await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false), } /// - public override ArmOperation StartCreateOrUpdate(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) + public ArmOperation StartCreateOrUpdate(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) { return new PhArmOperation( Operations.StartCreateOrUpdate(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken), @@ -62,7 +62,7 @@ public override ArmOperation StartCreateOrUpdate(string name, Load } /// - public async override Task> StartCreateOrUpdateAsync(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) + public async Task> StartCreateOrUpdateAsync(string name, LoadBalancerData resourceDetails, CancellationToken cancellationToken = default) { return new PhArmOperation( await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDetails.Model, cancellationToken).ConfigureAwait(false), From ae1327909d2972da8bf9fbad5adc9d296a8123bd Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Thu, 29 Apr 2021 02:05:10 -0700 Subject: [PATCH 5/9] Fix build issue. --- .../Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs b/sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs index cbaefe2599b37..eb2edd3ade292 100644 --- a/sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs +++ b/sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs @@ -27,9 +27,9 @@ private async Task ExecuteAsync() // proto, this test relies on pre-created VMSS. // 1. Follow instruction here (CLI), https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/quick-create-cli // 2. Initiate a rolling upgrade az vmss rolling-upgrade start -g [RG] -n myScaleSet --debug - var vmss1 = client.DefaultSubscription + VirtualMachineScaleSet vmss1 = await client.DefaultSubscription .GetResourceGroups().Get("azhang-test").Value - .GetVirtualMachineScaleSet().Get("myScaleSet").Value; + .GetVirtualMachineScaleSet().GetAsync("myScaleSet"); var ru = vmss1.GetRollingUpgrade().Get().Value; Debug.Assert(ru.Data.Model != null); From 3980213d8aa91a770c0a1ff1b54c82ecf5a1a15b Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Thu, 29 Apr 2021 02:32:53 -0700 Subject: [PATCH 6/9] Fixing test failure --- .../Azure.ResourceManager.Core/src/ArmClient.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs index 5b8b708460919..d695e8c05035f 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs @@ -86,17 +86,18 @@ private ArmClient( TokenCredential credential, ArmClientOptions options) { - Credential = credential; - BaseUri = baseUri; if (credential is null) throw new ArgumentNullException(nameof(credential)); + Credential = credential; + BaseUri = baseUri; ClientOptions = options?.Clone() ?? new ArmClientOptions(); + Pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, ClientOptions); + DefaultSubscription = string.IsNullOrWhiteSpace(defaultSubscriptionId) ? GetDefaultSubscription() : GetSubscriptions().TryGet(defaultSubscriptionId); ClientOptions.ApiVersions.SetProviderClient(credential, baseUri, DefaultSubscription.Id.SubscriptionId); - Pipeline = ManagementPipelineBuilder.Build(Credential, baseUri, ClientOptions); } /// From 796a16f831f874bb7e2ece63f7da685635ce1af7 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Mon, 3 May 2021 15:58:18 -0700 Subject: [PATCH 7/9] CR comment. --- .../src/SingletonOperationsBase.cs | 34 +++++++++++-------- .../Proto.Client/compute/RollingUpgrade.cs | 2 +- .../compute/RollingUpgradeOperations.cs | 21 +++++++++--- .../compute/VirtualMachineScaleSetBuilder.cs | 12 +++---- .../VirtualMachineScaleSetOperations.cs | 2 +- .../src/Scenarios/SingletonVmssUpgrade.cs | 4 ++- 6 files changed, 46 insertions(+), 29 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs index 59780c562658f..35579279581df 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; + namespace Azure.ResourceManager.Core { /// @@ -18,14 +20,19 @@ protected SingletonOperationsBase() /// /// Initializes a new instance of the class. /// - /// - /// - internal SingletonOperationsBase(ClientContext clientContext, ResourceIdentifier id) - : base(clientContext, ResourceIdentifier.RootResourceIdentifier) + /// + internal SingletonOperationsBase(OperationsBase parent) + : base(new ClientContext(parent.ClientOptions, parent.Credential, parent.BaseUri, parent.Pipeline), ResourceIdentifier.RootResourceIdentifier) { - ParentId = id; + Parent = parent; + ParentId = parent.Id; } + /// + /// Gets the parent resource of this resource. + /// + protected OperationsBase Parent { get; set; } + /// /// The typed resource identifier for the underlying resource /// @@ -56,19 +63,16 @@ protected SingletonOperationsBase() /// Initializes a new instance of the class. /// /// The resource representing the parent resource. - /// The identifier of the resource that is the target of operations. - protected SingletonOperationsBase(OperationsBase parent, TIdentifier parentId) - : base(new ClientContext(parent.ClientOptions, parent.Credential, parent.BaseUri, parent.Pipeline), parentId) + protected SingletonOperationsBase(OperationsBase parent) + : base(parent) { - Parent = parent; - ParentId = parentId; + ParentId = parent.Id as TIdentifier; + if (string.IsNullOrWhiteSpace(ParentId)) + { + throw new InvalidOperationException(); + } } - /// - /// Gets the parent resource of this resource. - /// - protected OperationsBase Parent { get; } - /// /// The typed resource identifier for the underlying resource /// diff --git a/sdk/resourcemanager/Proto.Client/compute/RollingUpgrade.cs b/sdk/resourcemanager/Proto.Client/compute/RollingUpgrade.cs index 81a31e82f19eb..de0f42b4e991c 100644 --- a/sdk/resourcemanager/Proto.Client/compute/RollingUpgrade.cs +++ b/sdk/resourcemanager/Proto.Client/compute/RollingUpgrade.cs @@ -25,7 +25,7 @@ public class RollingUpgrade : RollingUpgradeOperations /// The client parameters to use in these operations. /// The resource that is the target of operations. internal RollingUpgrade(OperationsBase operations, RollingUpgradeStatusInfo resource) - : base(operations, operations.Id as ResourceGroupResourceIdentifier) + : base(operations) { Data = resource; } diff --git a/sdk/resourcemanager/Proto.Client/compute/RollingUpgradeOperations.cs b/sdk/resourcemanager/Proto.Client/compute/RollingUpgradeOperations.cs index 80ffda87e7eff..8d6dbc2c239dd 100644 --- a/sdk/resourcemanager/Proto.Client/compute/RollingUpgradeOperations.cs +++ b/sdk/resourcemanager/Proto.Client/compute/RollingUpgradeOperations.cs @@ -27,8 +27,8 @@ protected RollingUpgradeOperations() /// /// The client parameters to use in these operations. /// The identifier of the resource that is the target of operations. - protected internal RollingUpgradeOperations(OperationsBase operation, ResourceGroupResourceIdentifier id) - : base(operation, id) + protected internal RollingUpgradeOperations(OperationsBase operation) + : base(operation) { } @@ -51,16 +51,27 @@ public ArmResponse Get(CancellationToken cancellationToken = def v => new RollingUpgrade(Parent, new RollingUpgradeStatusInfo(v))); } - public Task> GetAsync(CancellationToken cancellationToken = default) + public async Task> GetAsync(CancellationToken cancellationToken = default) { - throw new NotImplementedException(); + return new PhArmResponse( + await Operations.GetLatestAsync(ParentId.ResourceGroupName, ParentId.Name, cancellationToken), + v => new RollingUpgrade(Parent, new RollingUpgradeStatusInfo(v))); } // Note: Singleton may have different operations such as GET/PUT/PATCH/POST or a combination of these // Individual methods will be generated as they are declared public ArmResponse Cancel(CancellationToken cancellationToken = default) { - return new ArmResponse(Operations.StartCancel(ParentId.ResourceGroupName, ParentId.Name, cancellationToken).WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + return new ArmResponse(Operations + .StartCancel(ParentId.ResourceGroupName, ParentId.Name, cancellationToken) + .WaitForCompletionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult()); + } + + public async Task> CancelAsync(CancellationToken cancellationToken = default) + { + return new ArmResponse((await Operations + .StartCancel(ParentId.ResourceGroupName, ParentId.Name, cancellationToken) + .WaitForCompletionAsync(cancellationToken))); } } } diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs index a4ed9c926cd0b..ace5304bf157a 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs @@ -21,7 +21,7 @@ public class VirtualMachineScaleSetBuilder public VirtualMachineScaleSetBuilder(VirtualMachineScaleSetContainer container, VirtualMachineScaleSetData resource) { Resource = resource; - UnTypedContainer = container; + VirtualMachineScaleSetContainer = container; } /// @@ -37,7 +37,7 @@ public VirtualMachineScaleSetBuilder(VirtualMachineScaleSetContainer container, /// /// Gets the container object to create the resource in. /// - protected VirtualMachineScaleSetContainer UnTypedContainer { get; private set; } + protected VirtualMachineScaleSetContainer VirtualMachineScaleSetContainer { get; private set; } /// /// Creates the resource object to send to the Azure API. @@ -68,7 +68,7 @@ public ArmResponse CreateOrUpdate(string name, Cancellat ResourceName = name; Resource = Build(); - return UnTypedContainer.CreateOrUpdate(name, Resource, cancellationToken); + return VirtualMachineScaleSetContainer.CreateOrUpdate(name, Resource, cancellationToken); } /// @@ -88,7 +88,7 @@ public async Task> CreateOrUpdateAsync( ResourceName = name; Resource = Build(); - return await UnTypedContainer.CreateOrUpdateAsync(name, Resource, cancellationToken).ConfigureAwait(false); + return await VirtualMachineScaleSetContainer.CreateOrUpdateAsync(name, Resource, cancellationToken).ConfigureAwait(false); } /// @@ -109,7 +109,7 @@ public ArmOperation StartCreateOrUpdate(string name, Can ResourceName = name; Resource = Build(); - return UnTypedContainer.StartCreateOrUpdate(name, Resource, cancellationToken); + return VirtualMachineScaleSetContainer.StartCreateOrUpdate(name, Resource, cancellationToken); } /// @@ -132,7 +132,7 @@ public async Task> StartCreateOrUpdateAsync ResourceName = name; Resource = Build(); - return await UnTypedContainer.StartCreateOrUpdateAsync(name, Resource, cancellationToken).ConfigureAwait(false); + return await VirtualMachineScaleSetContainer.StartCreateOrUpdateAsync(name, Resource, cancellationToken).ConfigureAwait(false); } /// diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs index 5a40d1d90a2de..d7425a1130c03 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetOperations.cs @@ -308,7 +308,7 @@ public async Task> ListAvailableLocationsAsync(Cancell /// An object representing collection of subnets and their operations over a virtual network. public RollingUpgradeOperations GetRollingUpgrade() { - return new RollingUpgradeOperations(this, Id); + return new RollingUpgradeOperations(this); } } } diff --git a/sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs b/sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs index eb2edd3ade292..00fd9c7c981a3 100644 --- a/sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs +++ b/sdk/resourcemanager/Proto.Client/src/Scenarios/SingletonVmssUpgrade.cs @@ -26,7 +26,9 @@ private async Task ExecuteAsync() // NOTE: due to full test involves creating LB which have another 3-5 resources needs to be in // proto, this test relies on pre-created VMSS. // 1. Follow instruction here (CLI), https://docs.microsoft.com/en-us/azure/virtual-machine-scale-sets/quick-create-cli - // 2. Initiate a rolling upgrade az vmss rolling-upgrade start -g [RG] -n myScaleSet --debug + // az group create --name azhang-test --location eastus + // az vmss create --resource-group azhang-test --name myScaleSet --image UbuntuLTS --upgrade-policy-mode automatic --admin-username azureuser --generate-ssh-keys + // 2. Initiate a rolling upgrade az vmss rolling-upgrade start -g azhang-test -n myScaleSet --debug VirtualMachineScaleSet vmss1 = await client.DefaultSubscription .GetResourceGroups().Get("azhang-test").Value .GetVirtualMachineScaleSet().GetAsync("myScaleSet"); From 35af52390ef4f57f12c0b9f2729df4a5ff6238f3 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Mon, 3 May 2021 16:11:02 -0700 Subject: [PATCH 8/9] Flattend the builder to partial classes. --- ...er.cs => VirtualMachineScaleSetBuilder.cs} | 26 ++------- .../VirtualMachineScaleSetModelBuilderBase.cs | 58 ------------------- .../compute/VirtualMachineScaleSetBuilder.cs | 5 +- .../VirtualMachineScaleSetContainer.cs | 4 +- 4 files changed, 12 insertions(+), 81 deletions(-) rename sdk/resourcemanager/Proto.Client/compute/Convenience/{VirtualMachineScaleSetModelBuilder.cs => VirtualMachineScaleSetBuilder.cs} (64%) delete mode 100644 sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs diff --git a/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilder.cs b/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetBuilder.cs similarity index 64% rename from sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilder.cs rename to sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetBuilder.cs index e5d98ae4b0e4a..64e2342dd4bd3 100644 --- a/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilder.cs +++ b/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetBuilder.cs @@ -4,28 +4,14 @@ using System.Linq; using Azure.ResourceManager.Compute.Models; -namespace Proto.Compute.Convenience +namespace Proto.Compute { /// /// A class representing a builder object to help create a virtual machine. /// - public class VirtualMachineScaleSetModelBuilder : VirtualMachineScaleSetModelBuilderBase + public partial class VirtualMachineScaleSetBuilder { - private VirtualMachineScaleSetData _model; - - /// - /// Initializes a new instance of the class. - /// - /// The container to create the virtual machine in. - /// The data model representing the virtual machine to create. - public VirtualMachineScaleSetModelBuilder(VirtualMachineScaleSetContainer containerOperations, VirtualMachineScaleSetData model) - : base(containerOperations, model) - { - // TODO: GENERATOR Update Builder after models are incorporated in generated models - _model = model; - } - - public override VirtualMachineScaleSetModelBuilderBase WithUseWindowsImage(string computerNamePrefix, string adminUser, string password) + public VirtualMachineScaleSetBuilder WithUseWindowsImage(string computerNamePrefix, string adminUser, string password) { _model.VirtualMachineProfile.OsProfile = new VirtualMachineScaleSetOSProfile() { @@ -38,7 +24,7 @@ public override VirtualMachineScaleSetModelBuilderBase WithUseWindowsImage(strin return this; } - public override VirtualMachineScaleSetModelBuilderBase WithUseLinuxImage(string computerNamePrefix, string adminUser, string password) + public VirtualMachineScaleSetBuilder WithUseLinuxImage(string computerNamePrefix, string adminUser, string password) { _model.VirtualMachineProfile.OsProfile = new VirtualMachineScaleSetOSProfile() { @@ -55,7 +41,7 @@ public override VirtualMachineScaleSetModelBuilderBase WithUseLinuxImage(string return this; } - public override VirtualMachineScaleSetModelBuilderBase WithRequiredPrimaryNetworkInterface( + public VirtualMachineScaleSetBuilder WithRequiredPrimaryNetworkInterface( string name, ResourceIdentifier subNetResourceId, ICollection backendAddressPoolResourceIds, @@ -87,7 +73,7 @@ public override VirtualMachineScaleSetModelBuilderBase WithRequiredPrimaryNetwor return this; } - public override VirtualMachineScaleSetModelBuilderBase WithRequiredLoadBalancer(ResourceIdentifier asetResourceId) + public VirtualMachineScaleSetBuilder WithRequiredLoadBalancer(ResourceIdentifier asetResourceId) { return this; } diff --git a/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs b/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs deleted file mode 100644 index 7af06cb69683d..0000000000000 --- a/sdk/resourcemanager/Proto.Client/compute/Convenience/VirtualMachineScaleSetModelBuilderBase.cs +++ /dev/null @@ -1,58 +0,0 @@ -using Azure.ResourceManager.Core; -using System; -using System.Collections.Generic; - -namespace Proto.Compute.Convenience -{ - /// - /// A class representing a builder object to help create a virtual machine scale set. - /// - public abstract class VirtualMachineScaleSetModelBuilderBase : VirtualMachineScaleSetBuilder - { - /// - /// Initializes a new instance of the class. - /// - /// The container to create the virtual machine in. - /// The data model representing the virtual machine to create. - protected VirtualMachineScaleSetModelBuilderBase(VirtualMachineScaleSetContainer containerOperations, VirtualMachineScaleSetData vm) - : base(containerOperations, vm) - { - } - - /// - /// Tells the builder to use a windows image. - /// - /// The admin username for the virtual machine. - /// The asmin password for the virtual machine. - /// An instance of . - public abstract VirtualMachineScaleSetModelBuilderBase WithUseWindowsImage(string computerNamePrefix, string adminUser, string password); - - /// - /// Tells the builder to use a linux image. - /// - /// The admin username for the virtual machine. - /// The asmin password for the virtual machine. - /// An instance of . - public abstract VirtualMachineScaleSetModelBuilderBase WithUseLinuxImage(string computerNamePrefix, string adminUser, string password); - - /// - /// Tells the builder to use a specific network interface. - /// - /// name of the network interface configuration - /// The network interface identifier. - /// The list of backend address pool resource id - /// The list of inbound Nat pool resource id. - /// An instance of . - public abstract VirtualMachineScaleSetModelBuilderBase WithRequiredPrimaryNetworkInterface( - string name, ResourceIdentifier subNetResourceId, - ICollection backendAddressPoolResourceIds, - ICollection inboundNatPoolResourceIds); - - /// - /// Tells the builder to use a specific load balancer. - /// - /// The availability set identifier. - /// An instance of . - public abstract VirtualMachineScaleSetModelBuilderBase WithRequiredLoadBalancer(ResourceIdentifier asetResourceId); - } -} diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs index ace5304bf157a..e81b855046f2b 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetBuilder.cs @@ -11,8 +11,10 @@ namespace Proto.Compute /// /// A class representing a builder object used to create Azure resources. /// - public class VirtualMachineScaleSetBuilder + public partial class VirtualMachineScaleSetBuilder { + private VirtualMachineScaleSetData _model; + /// /// Initializes a new instance of the class. /// @@ -22,6 +24,7 @@ public VirtualMachineScaleSetBuilder(VirtualMachineScaleSetContainer container, { Resource = resource; VirtualMachineScaleSetContainer = container; + _model = resource; } /// diff --git a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs index 31849943f40d4..b444c7a48ec26 100644 --- a/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs +++ b/sdk/resourcemanager/Proto.Client/compute/VirtualMachineScaleSetContainer.cs @@ -209,7 +209,7 @@ await Operations.StartCreateOrUpdateAsync(Id.ResourceGroupName, name, resourceDe /// The hostname for the virtual machine. /// The location to create the Virtual Machine. /// Object used to create a . - public VirtualMachineScaleSetModelBuilder Construct(string hostName, LocationData location = null) + public VirtualMachineScaleSetBuilder Construct(string hostName, LocationData location = null) { var parent = GetParentResource(); var vmss = new Azure.ResourceManager.Compute.Models.VirtualMachineScaleSet(location ?? parent.Data.Location) @@ -249,7 +249,7 @@ public VirtualMachineScaleSetModelBuilder Construct(string hostName, LocationDat vmss.VirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations.Add(nicConfig); - return new VirtualMachineScaleSetModelBuilder(this, new VirtualMachineScaleSetData(vmss)); + return new VirtualMachineScaleSetBuilder(this, new VirtualMachineScaleSetData(vmss)); } } } From c7041a14f5d221fb5af9780d6689a10b25518955 Mon Sep 17 00:00:00 2001 From: Allen Zhang Date: Mon, 3 May 2021 16:26:55 -0700 Subject: [PATCH 9/9] CR fix --- .../Azure.ResourceManager.Core/src/SingletonOperationsBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs index 35579279581df..5a422406ebd3e 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/SingletonOperationsBase.cs @@ -31,7 +31,7 @@ internal SingletonOperationsBase(OperationsBase parent) /// /// Gets the parent resource of this resource. /// - protected OperationsBase Parent { get; set; } + protected OperationsBase Parent { get; } /// /// The typed resource identifier for the underlying resource