Пример #1
0
        private void CreateConfiguration()
        {
            var publicSettings  = new DscExtensionPublicSettings();
            var privateSettings = new DscExtensionPrivateSettings();

            if (!string.IsNullOrEmpty(ConfigurationArchive))
            {
                ConfigurationUris configurationUris = UploadConfigurationDataToBlob();

                publicSettings.SasToken              = configurationUris.SasToken;
                publicSettings.ModulesUrl            = configurationUris.ModulesUrl;
                publicSettings.ConfigurationFunction = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}\\{1}",
                    Path.GetFileNameWithoutExtension(ConfigurationArchive),
                    ConfigurationName);
                Tuple <DscExtensionPublicSettings.Property[], Hashtable> settings =
                    DscExtensionSettingsSerializer.SeparatePrivateItems(ConfigurationArgument);
                publicSettings.Properties = settings.Item1;
                privateSettings.Items     = settings.Item2;

                privateSettings.DataBlobUri = configurationUris.DataBlobUri;
            }

            //
            // Define the public and private property bags that will be passed to the extension.
            //
            PublicConfiguration = DscExtensionSettingsSerializer.SerializePublicSettings(publicSettings);
            //
            // PrivateConfuguration contains sensitive data in a plain text.
            //
            PrivateConfiguration = DscExtensionSettingsSerializer.SerializePrivateSettings(privateSettings);
        }
Пример #2
0
        /// <summary>
        /// Helper function for tests.
        /// </summary>
        /// <param name="configurationArguments"></param>
        /// <param name="privateSettings"></param>
        /// <returns></returns>
        private static DscExtensionPublicSettings GetPublicPrivateAfterDeseriazlization(
            Hashtable configurationArguments,
            out DscExtensionPrivateSettings privateSettings)
        {
            Tuple <DscExtensionPublicSettings.Property[], Hashtable> separatedSettings =
                DscExtensionSettingsSerializer.SeparatePrivateItems(configurationArguments);
            DscExtensionPublicSettings extensionPublicSettings = new DscExtensionPublicSettings();

            privateSettings = new DscExtensionPrivateSettings();
            extensionPublicSettings.Properties = separatedSettings.Item1;
            privateSettings.Items = separatedSettings.Item2;

            string serializedPublic  = DscExtensionSettingsSerializer.SerializePublicSettings(extensionPublicSettings);
            string serializedPrivate = DscExtensionSettingsSerializer.SerializePrivateSettings(privateSettings);

            extensionPublicSettings = DscExtensionSettingsSerializer.DeserializePublicSettings(serializedPublic);
            privateSettings         = DeserializePrivateSettings(serializedPrivate);
            return(extensionPublicSettings);
        }
Пример #3
0
        private void CreateConfiguration()
        {
            var publicSettings  = new DscExtensionPublicSettings();
            var privateSettings = new DscExtensionPrivateSettings();

            publicSettings.WmfVersion = string.IsNullOrEmpty(WmfVersion) ? "latest" : WmfVersion;

            if (!string.IsNullOrEmpty(ArchiveBlobName))
            {
                ConfigurationUris configurationUris = UploadConfigurationDataToBlob();

                publicSettings.SasToken              = configurationUris.SasToken;
                publicSettings.ModulesUrl            = configurationUris.ModulesUrl;
                publicSettings.ConfigurationFunction = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}\\{1}",
                    Path.GetFileNameWithoutExtension(ArchiveBlobName),
                    ConfigurationName);
                Tuple <DscExtensionPublicSettings.Property[], Hashtable> settings =
                    DscExtensionSettingsSerializer.SeparatePrivateItems(ConfigurationArgument);
                publicSettings.Properties = settings.Item1;
                privateSettings.Items     = settings.Item2;

                privateSettings.DataBlobUri = configurationUris.DataBlobUri;
            }

            if (string.IsNullOrEmpty(this.Location))
            {
                this.Location = GetLocationFromVm(this.ResourceGroupName, this.VMName);
            }

            var parameters = new VirtualMachineExtension
            {
                Location           = this.Location,
                Name               = Name ?? DscExtensionCmdletConstants.ExtensionPublishedNamespace + "." + DscExtensionCmdletConstants.ExtensionPublishedName,
                Type               = VirtualMachineExtensionType,
                Publisher          = DscExtensionCmdletConstants.ExtensionPublishedNamespace,
                ExtensionType      = DscExtensionCmdletConstants.ExtensionPublishedName,
                TypeHandlerVersion = Version,
                // Define the public and private property bags that will be passed to the extension.
                Settings = DscExtensionSettingsSerializer.SerializePublicSettings(publicSettings),
                //PrivateConfuguration contains sensitive data in a plain text
                ProtectedSettings       = DscExtensionSettingsSerializer.SerializePrivateSettings(privateSettings),
                AutoUpgradeMinorVersion = AutoUpdate.IsPresent
            };

            //Add retry logic due to CRP service restart known issue CRP bug: 3564713
            var count = 1;
            ComputeLongRunningOperationResponse op = null;

            while (count <= 2)
            {
                op = VirtualMachineExtensionClient.CreateOrUpdate(
                    ResourceGroupName,
                    VMName,
                    parameters);

                if (ComputeOperationStatus.Failed.Equals(op.Status) && op.Error != null && "InternalExecutionError".Equals(op.Error.Code))
                {
                    count++;
                }
                else
                {
                    break;
                }
            }
            var result = Mapper.Map <PSComputeLongRunningOperation>(op);

            WriteObject(result);
        }