/// <summary>
        /// Initialize VM's identity property.
        /// </summary>
        /// <param name="identityType">The identity type to set.</param>
        private void InitVMIdentity(Fluent.Models.ResourceIdentityType identityType)
        {
            if (!identityType.Equals(Models.ResourceIdentityType.UserAssigned) &&
                !identityType.Equals(Models.ResourceIdentityType.SystemAssigned))
            {
                throw new ArgumentException("Invalid argument: " + identityType);
            }

            var virtualMachineInner = this.virtualMachine.Inner;

            if (virtualMachineInner.Identity == null)
            {
                virtualMachineInner.Identity = new VirtualMachineIdentity();
            }

            if (virtualMachineInner.Identity.Type == null ||
                virtualMachineInner.Identity.Type.Equals(Models.ResourceIdentityType.None) ||
                virtualMachineInner.Identity.Type.Equals(identityType))
            {
                virtualMachineInner.Identity.Type = identityType;
            }
            else
            {
                virtualMachineInner.Identity.Type = Models.ResourceIdentityType.SystemAssignedUserAssigned;
            }
        }
예제 #2
0
        /// <summary>
        /// Initialize VM's identity property.
        /// </summary>
        /// <param name="identityType">The identity type to set.</param>
        private void InitVMIdentity(Fluent.Models.ResourceIdentityType identityType)
        {
            if (!identityType.Equals(Models.ResourceIdentityType.UserAssigned) &&
                !identityType.Equals(Models.ResourceIdentityType.SystemAssigned))
            {
                throw new ArgumentException("Invalid argument: " + identityType);
            }

            var virtualMachineInner = this.virtualMachine.Inner;

            if (virtualMachineInner.Identity == null)
            {
                virtualMachineInner.Identity = new VirtualMachineIdentity();
            }

            if (virtualMachineInner.Identity.Type == null ||
                virtualMachineInner.Identity.Type.Equals(ResourceIdentityTypeEnumExtension.ToSerializedValue(Models.ResourceIdentityType.None), StringComparison.OrdinalIgnoreCase) ||
                virtualMachineInner.Identity.Type.Equals(ResourceIdentityTypeEnumExtension.ToSerializedValue(identityType), StringComparison.OrdinalIgnoreCase))
            {
                virtualMachineInner.Identity.Type = ResourceIdentityTypeEnumExtension.ToSerializedValue(identityType);
            }
            else
            {
                virtualMachineInner.Identity.Type = ResourceIdentityTypeEnumExtension.ToSerializedValue(Models.ResourceIdentityType.SystemAssignedUserAssigned);
            }
        }