/// <summary>
 /// Creates VirtualMachineScaleSetMsiHandler.
 /// </summary>
 /// <param name="rbacManager">The graph rbac manager.</param>
 internal VirtualMachineScaleSetMsiHelper(IGraphRbacManager rbacManager, VirtualMachineScaleSetImpl scaleSet)
     : base(rbacManager, new VmssIdProvider(scaleSet))
 {
     this.scaleSet = scaleSet;
     this.creatableIdentityKeys  = new HashSet <string>();
     this.userAssignedIdentities = new Dictionary <string, VirtualMachineScaleSetIdentityUserAssignedIdentitiesValue>();
 }
Beispiel #2
0
        /// <summary>
        /// Add or update the Managed Service Identity extension for the given virtual machine scale set.
        /// </summary>
        /// <param name="scaleSetImpl">The scale set.</param>
        internal void AddOrUpdateMSIExtension(VirtualMachineScaleSetImpl scaleSetImpl)
        {
            if (!this.installExtensionIfNotInstalled)
            {
                return;
            }

            // To add or update MSI extension, we relay on methods exposed from interfaces instead of from
            // impl so that any breaking change in the contract cause a compile time error here. So do not
            // change the below 'updateExtension' or 'defineNewExtension' to use impls.
            //
            String msiExtensionType = scaleSetImpl.OSTypeIntern() == OperatingSystemTypes.Linux ? "ManagedIdentityExtensionForLinux" : "ManagedIdentityExtensionForWindows";
            IVirtualMachineScaleSetExtension msiExtension = GetMSIExtension(scaleSetImpl.Extensions(), msiExtensionType);
            if (msiExtension != null)
            {
                Object currentTokenPortObj = msiExtension.PublicSettings["port"];
                int? currentTokenPort = ComputeUtils.ObjectToInteger(currentTokenPortObj);
                int? newPort;
                if (this.tokenPort != null)
                {
                    // user specified a port
                    newPort = this.tokenPort;
                }
                else if (currentTokenPort != null)
                {
                    // user didn't specify a port and currently there is a port
                    newPort = currentTokenPort;
                }
                else
                {
                    // user didn't specify a port and currently there is no port
                    newPort = DEFAULT_TOKEN_PORT;
                }
                VirtualMachineScaleSet.Update.IUpdate appliableVMSS = scaleSetImpl;
                appliableVMSS.UpdateExtension(msiExtension.Name)
                    .WithPublicSetting("port", newPort)
                    .Parent();
            }
            else
            {
                int? port;
                if (this.tokenPort != null)
                {
                    port = this.tokenPort;
                }
                else
                {
                    port = DEFAULT_TOKEN_PORT;
                }
                if (scaleSetImpl.Inner.Id == null) // InCreateMode
                {
                    VirtualMachineScaleSet.Definition.IWithCreate creatableVMSS = scaleSetImpl;
                    creatableVMSS.DefineNewExtension(msiExtensionType)
                        .WithPublisher(MSI_EXTENSION_PUBLISHER_NAME)
                        .WithType(msiExtensionType)
                        .WithVersion("1.0")
                        .WithMinorVersionAutoUpgrade()
                        .WithPublicSetting("port", port)
                        .Attach();
                }
                else
                {
                    VirtualMachineScaleSet.Update.IUpdate appliableVMSS = scaleSetImpl;
                    appliableVMSS.DefineNewExtension(msiExtensionType)
                        .WithPublisher(MSI_EXTENSION_PUBLISHER_NAME)
                        .WithType(msiExtensionType)
                        .WithVersion("1.0")
                        .WithMinorVersionAutoUpgrade()
                        .WithPublicSetting("port", port)
                        .Attach();
                }
            }

            this.installExtensionIfNotInstalled = false;
            this.tokenPort = null;
        }
 internal VmssIdProvider(VirtualMachineScaleSetImpl vmss)
 {
     this.vmss = vmss;
 }
 ///GENMHASH:2F547EF235083E7C24F2AAD75FCE9FFC:C140D4869BF21B82D034CCD0BC161B59
 internal VirtualMachineScaleSetVMsImpl(VirtualMachineScaleSetImpl scaleSet, IComputeManager computeManager)
 {
     this.scaleSet = scaleSet;
     Manager       = computeManager;
 }