Inheritance: Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineExtension
Esempio n. 1
0
        private VirtualMachineDscExtensionContext GetDscExtensionContext(PSVirtualMachineExtension extension)
        {
            var context = new VirtualMachineDscExtensionContext
            {
                ResourceGroupName = extension.ResourceGroupName,
                Name               = extension.Name,
                Location           = extension.Location,
                Etag               = extension.Etag,
                Publisher          = extension.Publisher,
                ExtensionType      = extension.ExtensionType,
                TypeHandlerVersion = extension.TypeHandlerVersion,
                Id                = extension.Id,
                PublicSettings    = extension.PublicSettings,
                ProtectedSettings = extension.ProtectedSettings,
                ProvisioningState = extension.ProvisioningState,
                Statuses          = extension.Statuses
            };

            DscExtensionPublicSettings extensionPublicSettings = null;

            try
            {
                extensionPublicSettings = DscExtensionSettingsSerializer.DeserializePublicSettings(extension.PublicSettings);
            }
            catch (JsonException e)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new JsonException(
                            String.Format(
                                CultureInfo.CurrentUICulture,
                                Microsoft.Azure.Commands.Compute.Properties.Resources.AzureVMDscWrongSettingsFormat,
                                extension.PublicSettings),
                            e),
                        string.Empty,
                        ErrorCategory.ParserError,
                        null));
            }

            if (extensionPublicSettings == null)
            {
                context.ModulesUrl            = string.Empty;
                context.ConfigurationFunction = string.Empty;
                context.Properties            = null;
            }
            else
            {
                context.ModulesUrl            = extensionPublicSettings.ModulesUrl;
                context.ConfigurationFunction = extensionPublicSettings.ConfigurationFunction;
                if (extensionPublicSettings.Properties != null)
                {
                    context.Properties =
                        new Hashtable(extensionPublicSettings.Properties.ToDictionary(x => x.Name, x => x.Value));
                }
            }

            return(context);
        }
        private VirtualMachineDscExtensionContext GetDscExtensionContext(PSVirtualMachineExtension extension)
        {
            var context = new VirtualMachineDscExtensionContext
            {
                ResourceGroupName = extension.ResourceGroupName,
                Name               = extension.Name,
                Location           = extension.Location,
                Etag               = extension.Etag,
                Publisher          = extension.Publisher,
                ExtensionType      = extension.ExtensionType,
                TypeHandlerVersion = extension.TypeHandlerVersion,
                Id                = extension.Id,
                PublicSettings    = extension.PublicSettings,
                ProtectedSettings = extension.ProtectedSettings,
                ProvisioningState = extension.ProvisioningState,
                Statuses          = extension.Statuses
            };

            DscExtensionPublicSettings publicSettings;

            try
            {
                publicSettings = string.IsNullOrEmpty(extension.PublicSettings) ? null
                                    : JsonConvert.DeserializeObject <DscExtensionPublicSettings>(extension.PublicSettings);
            }
            catch (Exception)
            {
                // Try deserialize as version 1.0
                try
                {
                    var publicSettingsV1 =
                        JsonConvert.DeserializeObject <DscExtensionPublicSettings.Version1>(extension.PublicSettings);
                    publicSettings = publicSettingsV1.ToCurrentVersion();
                }
                catch (JsonException)
                {
                    throw;
                }
            }

            if (publicSettings == null)
            {
                context.ModulesUrl            = string.Empty;
                context.ConfigurationFunction = string.Empty;
                context.Properties            = null;
            }
            else
            {
                context.ModulesUrl            = publicSettings.ModulesUrl;
                context.ConfigurationFunction = publicSettings.ConfigurationFunction;
                context.Properties            = new Hashtable(publicSettings.Properties.ToDictionary(x => x.Name, x => x.Value));
            }

            return(context);
        }
        private VirtualMachineDscExtensionContext GetDscExtensionContext(PSVirtualMachineExtension extension)
        {
            var context = new VirtualMachineDscExtensionContext
            {
                ResourceGroupName = extension.ResourceGroupName,
                Name = extension.Name,
                Location = extension.Location,
                Etag = extension.Etag,
                Publisher = extension.Publisher,
                ExtensionType = extension.ExtensionType,
                TypeHandlerVersion = extension.TypeHandlerVersion,
                Id = extension.Id,
                PublicSettings = extension.PublicSettings,
                ProtectedSettings = extension.ProtectedSettings,
                ProvisioningState = extension.ProvisioningState,
                Statuses = extension.Statuses
            };

            DscExtensionPublicSettings extensionPublicSettings = null;
            try
            {
                extensionPublicSettings = DscExtensionSettingsSerializer.DeserializePublicSettings(extension.PublicSettings);
            }
            catch (JsonException e)
            {
                ThrowTerminatingError(
                    new ErrorRecord(
                        new JsonException(
                            String.Format(
                                CultureInfo.CurrentUICulture,
                                Properties.Resources.AzureVMDscWrongSettingsFormat,
                                extension.PublicSettings),
                            e),
                        string.Empty,
                        ErrorCategory.ParserError,
                        null));
            }

            if (extensionPublicSettings == null)
            {
                context.ModulesUrl = string.Empty;
                context.ConfigurationFunction = string.Empty;
                context.Properties = null;
            }
            else
            {
                context.ModulesUrl = extensionPublicSettings.ModulesUrl;
                context.ConfigurationFunction = extensionPublicSettings.ConfigurationFunction;
                context.Properties = new Hashtable(extensionPublicSettings.Properties.ToDictionary(x => x.Name, x => x.Value));
            }

            return context;
        }
        private VirtualMachineDscExtensionContext GetDscExtensionContext(PSVirtualMachineExtension extension)
        {
            var context = new VirtualMachineDscExtensionContext
            {
                ResourceGroupName = extension.ResourceGroupName,
                Name = extension.Name,
                Location = extension.Location,
                Etag = extension.Etag,
                Publisher = extension.Publisher,
                ExtensionType = extension.ExtensionType,
                TypeHandlerVersion = extension.TypeHandlerVersion,
                Id = extension.Id,
                PublicSettings = extension.PublicSettings,
                ProtectedSettings = extension.ProtectedSettings,
                ProvisioningState = extension.ProvisioningState,
                Statuses = extension.Statuses
            };

            DscExtensionPublicSettings publicSettings;
            try
            {
                publicSettings = string.IsNullOrEmpty(extension.PublicSettings) ? null
                                    : JsonConvert.DeserializeObject<DscExtensionPublicSettings>(extension.PublicSettings);
            }
            catch (Exception)
            {
                // Try deserialize as version 1.0
                try
                {
                    var publicSettingsV1 =
                        JsonConvert.DeserializeObject<DscExtensionPublicSettings.Version1>(extension.PublicSettings);
                    publicSettings = publicSettingsV1.ToCurrentVersion();
                }
                catch (JsonException)
                {
                    throw;
                } 
            }
            
            if (publicSettings == null)
            {
                context.ModulesUrl = string.Empty;
                context.ConfigurationFunction = string.Empty;
                context.Properties = null;
            }
            else
            {
                context.ModulesUrl = publicSettings.ModulesUrl;
                context.ConfigurationFunction = publicSettings.ConfigurationFunction;
                context.Properties = new Hashtable(publicSettings.Properties.ToDictionary( x => x.Name, x => x.Value ));
            }

            return context;
        }