Exemplo n.º 1
0
        private static void InitVMIdentity(VirtualMachineScaleSetInner vmssInner, ResourceIdentityType identityType)
        {
            if (!identityType.Equals(ResourceIdentityType.UserAssigned)
                    && !identityType.Equals(ResourceIdentityType.SystemAssigned))
            {
                throw new ArgumentException("Invalid argument: " + identityType);
            }
            if (vmssInner.Identity == null)
            {
                vmssInner.Identity = new VirtualMachineScaleSetIdentity();
            }

            ResourceIdentityType? parsedIdentityType = vmssInner.Identity.Type;
            if (parsedIdentityType == null
                    || parsedIdentityType.Equals(ResourceIdentityType.None)
                    || parsedIdentityType.Equals(identityType))
            {
                vmssInner.Identity.Type = identityType;
            }
            else
            {
                vmssInner.Identity.Type = ResourceIdentityType.SystemAssignedUserAssigned;
            }
            if (vmssInner.Identity.IdentityIds == null)
            {
                if (identityType.Equals(ResourceIdentityType.UserAssigned)
                        || identityType.Equals(ResourceIdentityType.SystemAssignedUserAssigned))
                {
                    vmssInner.Identity.IdentityIds = new List<string>();
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Gets the MSI identity type.
 /// </summary>
 /// <param name="inner">the virtual machine scale set inner</param>
 /// <returns>the MSI identity type</returns>
 internal static ResourceIdentityType? ManagedServiceIdentityType(VirtualMachineScaleSetInner inner)
 {
     if (inner.Identity != null)
     {
         return inner.Identity.Type;
     }
     return null;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the MSI identity type.
 /// </summary>
 /// <param name="inner">the virtual machine scale set inner</param>
 /// <returns>the MSI identity type</returns>
 internal static ResourceIdentityType?ManagedServiceIdentityType(VirtualMachineScaleSetInner inner)
 {
     if (inner.Identity != null)
     {
         return(ResourceIdentityTypeEnumExtension.ParseResourceIdentityType(inner.Identity.Type));
     }
     return(null);
 }
 /// <summary>
 /// Gets the MSI identity type.
 /// </summary>
 /// <param name="inner">the virtual machine scale set inner</param>
 /// <returns>the MSI identity type</returns>
 internal static ResourceIdentityType?ManagedServiceIdentityType(VirtualMachineScaleSetInner inner)
 {
     if (inner.Identity != null)
     {
         //ResourceIdentityTypeEnumExtension.ToSerializedValue(ResourceIdentityType.SystemAssigned);
         return(inner.Identity.Type);
     }
     return(null);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Set user assigned identity ids to the given VMSS inner model
        /// </summary>
        /// <param name="vmssInner">the VMSS inner model</param>
        /// <param name="vmTaskGroup">the VMSS task group</param>
        internal void HandleUserAssignedIdentities(VirtualMachineScaleSetInner vmssInner, CreatorTaskGroup<IHasId> vmTaskGroup)
        {
            try
            {
                if (vmssInner.Identity == null || vmssInner.Identity.Type == null)
                {
                    return;
                }
                var parsedIdentityType = vmssInner.Identity.Type;
                if (parsedIdentityType.Equals(ResourceIdentityType.None)
                    || parsedIdentityType.Equals(ResourceIdentityType.SystemAssigned))
                {
                    return;
                }
                foreach (var key in this.userAssignedIdentityCreatableKeys)
                {
                    var identity = (IIdentity)vmTaskGroup.CreatedResource(key);
                    if (!this.userAssignedIdentityIdsToAssociate.Contains(identity.Id))
                    {
                        this.userAssignedIdentityIdsToAssociate.Add(identity.Id);
                    }
                }
                if (vmssInner.Identity.IdentityIds == null)
                {
                    vmssInner.Identity.IdentityIds = new List<string>();
                }
                foreach (var identityId in this.userAssignedIdentityIdsToAssociate)
                {
                    if (!vmssInner.Identity.IdentityIds.Contains(identityId))
                    {
                        vmssInner.Identity.IdentityIds.Add(identityId);
                    }
                }
                foreach (var identityId in this.userAssignedIdentityIdsToRemove)
                {
                    if (vmssInner.Identity.IdentityIds.Contains(identityId))
                    {
                        vmssInner.Identity.IdentityIds.Remove(identityId);
                    }
                }
            }
            finally
            {
                this.userAssignedIdentityCreatableKeys.Clear();
                this.userAssignedIdentityIdsToAssociate.Clear();
                this.userAssignedIdentityIdsToRemove.Clear();
            }

        }
 /// <summary>
 /// Create or update a VM scale set.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='vmScaleSetName'>
 /// The name of the VM scale set to create or update.
 /// </param>
 /// <param name='parameters'>
 /// The scale set object.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <VirtualMachineScaleSetInner> BeginCreateOrUpdateAsync(this IVirtualMachineScaleSetsOperations operations, string resourceGroupName, string vmScaleSetName, VirtualMachineScaleSetInner parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.BeginCreateOrUpdateWithHttpMessagesAsync(resourceGroupName, vmScaleSetName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Specifies the definition of a not-yet-created user assigned identity to be associated with the VMSS.
 /// </summary>
 /// <param name="vmssInner">The VMSS to set the identity.</param>
 /// <param name="vmTaskGroup">the task group of the virtual machine</param>
 /// <param name="creatableIdentity">the creatable user assigned identity</param>
 /// <returns>VirtualMachineScaleSetMsiHelper.</returns>
 internal VirtualMachineScaleSetMsiHelper WithNewUserAssignedManagedServiceIdentity(VirtualMachineScaleSetInner vmssInner, CreatorTaskGroup<IHasId> vmTaskGroup, ICreatable<IIdentity> creatableIdentity)
 {
     if (!this.userAssignedIdentityCreatableKeys.Contains(creatableIdentity.Key))
     {
         this.installExtensionIfNotInstalled = true;
         InitVMIdentity(vmssInner, ResourceIdentityType.UserAssigned);
         this.userAssignedIdentityCreatableKeys.Add(creatableIdentity.Key);
         ((creatableIdentity as IResourceCreator<IHasId>).CreatorTaskGroup).Merge(vmTaskGroup);
     }
     return this;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Specifies that System Assigned Managed Service Identity needs to be enabled in the virtual machine scale set.
 /// </summary>
 /// <param name="port">The port in the virtual machine scale set instance to get the access token from.</param>
 /// <param name="vmssInner">The virtual machine scale set to enable System Assigned MSI.</param>
 /// <return>VirtualMachineScaleSetMsiHelper.</return>
 internal VirtualMachineScaleSetMsiHelper WithSystemAssignedManagedServiceIdentity(int? port, VirtualMachineScaleSetInner vmssInner)
 {
     this.installExtensionIfNotInstalled = true;
     this.tokenPort = port;
     InitVMIdentity(vmssInner, ResourceIdentityType.SystemAssigned);
     return this;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Specifies that System Assigned Managed Service Identity needs to be enabled in the virtual machine scale set.
 /// </summary>
 /// <param name="scaleSetInner">The virtual machine scale set to enable System Assigned MSI.</param>
 /// <return>VirtualMachineScaleSetMsiHelper.</return>
 internal VirtualMachineScaleSetMsiHelper WithSystemAssignedManagedServiceIdentity(VirtualMachineScaleSetInner scaleSetInner)
 {
     return WithSystemAssignedManagedServiceIdentity(null, scaleSetInner);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Specifies an existing user assigned identity to be associated with the VMSS.
 /// </summary>
 /// <param name="identity">an existing user assigned identity</param>
 /// <returns>VirtualMachineScaleSetMsiHelper.</returns>
 internal VirtualMachineScaleSetMsiHelper WithExistingUserAssignedManagedServiceIdentity(VirtualMachineScaleSetInner vmssInner, IIdentity identity)
 {
     if (!this.userAssignedIdentityIdsToAssociate.Contains(identity.Id))
     {
         this.installExtensionIfNotInstalled = true;
         InitVMIdentity(vmssInner, ResourceIdentityType.UserAssigned);
         this.userAssignedIdentityIdsToAssociate.Add(identity.Id);
     }
     return this;
 }
 /// <summary>
 /// Specifies that Managed Service Identity property needs to be set in the virtual machine scale set.
 /// The access token will be available in the virtual machine at given port.
 /// </summary>
 /// <param name="port">The port in the virtual machine scale set instance to get the access token from.</param>
 /// <param name="scaleSetInner">The virtual machine scale set to set the identity.</param>
 /// <return>VirtualMachineScaleSetMsiHelper.</return>
 ///GENMHASH:5241398EC0DF56AB83CB75D6856D17A8:B16DB3B1494A86E6266A914618A6D036
 internal VirtualMachineScaleSetMsiHelper WithManagedServiceIdentity(int?port, VirtualMachineScaleSetInner scaleSetInner)
 {
     this.requireSetup = true;
     this.tokenPort    = port;
     if (scaleSetInner.Identity == null)
     {
         scaleSetInner.Identity = new VirtualMachineScaleSetIdentity();
     }
     if (scaleSetInner.Identity.Type == null)
     {
         scaleSetInner.Identity.Type = ResourceIdentityType.SystemAssigned;
     }
     return(this);
 }
 /// <summary>
 /// Specifies that Managed Service Identity property needs to be set in the virtual machine scale set.
 /// If MSI extension is already installed then the access token will be available in the virtual machine
 /// scale set instance at port specified in the extension public setting, otherwise the port for
 /// new extension will be 50342.
 /// </summary>
 /// <param name="scaleSetInner">The virtual machine scale set to set the identity.</param>
 /// <return>VirtualMachineScaleSetMsiHelper.</return>
 ///GENMHASH:1D02816AA567687856A358E81DB99773:E64D1862840D63C171CB834051EF21E8
 internal VirtualMachineScaleSetMsiHelper WithManagedServiceIdentity(VirtualMachineScaleSetInner scaleSetInner)
 {
     return(WithManagedServiceIdentity(null, scaleSetInner));
 }