Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
        private void CreateConfiguration()
        {
            var publicSettings = new DscExtensionPublicSettings();
            var privateSettings = new DscExtensionPrivateSettings();

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

                publicSettings.SasToken = configurationUris.SasToken;
                publicSettings.ModulesUrl = configurationUris.ModulesUrl;

                Hashtable privacySetting = new Hashtable();
                privacySetting.Add("DataCollection", DataCollection);
                publicSettings.Privacy = privacySetting;

                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(WmfVersion))
                {
                    publicSettings.WmfVersion = WmfVersion;
                }
            }

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

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

            //Add retry logic due to CRP service restart known issue CRP bug: 3564713
            var count = 1;
            Rest.Azure.AzureOperationResponse<VirtualMachineExtension> op = null;

            while (true)
            {
                try
                {
                    op = VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
                        ResourceGroupName,
                        VMName,
                        Name ?? DscExtensionCmdletConstants.ExtensionPublishedNamespace + "." + DscExtensionCmdletConstants.ExtensionPublishedName,
                        parameters).GetAwaiter().GetResult();

                    break;
                }
                catch (Rest.Azure.CloudException ex)
                {
                    var errorReturned = JsonConvert.DeserializeObject<ComputeLongRunningOperationError>(
                        ex.Response.Content);

                    if (ComputeOperationStatus.Failed.Equals(errorReturned.Status)
                        && errorReturned.Error != null && "InternalExecutionError".Equals(errorReturned.Error.Code))
                    {
                        count++;
                        if (count <= 2)
                        {
                            continue;
                        }
                    }

                    ThrowTerminatingError(new ErrorRecord(ex, "InvalidResult", ErrorCategory.InvalidResult, null));
                }
            }

            var result = Mapper.Map<PSAzureOperationResponse>(op);
            WriteObject(result);
        }
        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);
        }