internal void ExecuteCommand()
        {
            var extensionRefs = GetPredicateExtensionList();

            WriteObject(
                extensionRefs == null ? null : extensionRefs.Select(
                    r =>
            {
                GetVMAccessExtensionValues(r);
                return(new VirtualMachineAccessExtensionContext
                {
                    ExtensionName = r.Name,
                    Publisher = r.Publisher,
                    ReferenceName = r.ReferenceName,
                    Version = r.Version,
                    State = r.State,
                    Enabled = !Disable,
                    UserName = UserName,
                    Password = SecureStringHelper.GetSecureString(Password),
                    PublicConfiguration = PublicConfiguration,
                    PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration),
                    RoleName = VM.GetInstance().RoleName
                });
            }), true);
        }
示例#2
0
        internal void ExecuteCommand()
        {
            var extensionRefs = GetPredicateExtensionList();

            WriteObject(
                extensionRefs == null ? null : extensionRefs.Select(
                    r =>
            {
                GetExtensionValues(r);
                var pubSettings = string.IsNullOrEmpty(PublicConfiguration) ? null
                                    : JsonConvert.DeserializeObject <PublicSettings>(PublicConfiguration);

                return(new VirtualMachineCustomScriptExtensionContext
                {
                    ExtensionName = r.Name,
                    Publisher = r.Publisher,
                    ReferenceName = r.ReferenceName,
                    Version = r.Version,
                    State = r.State,
                    PublicConfiguration = PublicConfiguration,
                    PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration),
                    CommandToExecute = pubSettings == null ? string.Empty : pubSettings.commandToExecute,
                    Uri = pubSettings == null ? null : pubSettings.fileUris,
                    RoleName = VM.GetInstance().RoleName
                });
            }), true);
        }
        protected void SetProvisioningConfiguration(WindowsProvisioningConfigurationSet provisioningConfiguration)
        {
            provisioningConfiguration.AdminUsername             = AdminUsername;
            provisioningConfiguration.AdminPassword             = SecureStringHelper.GetSecureString(Password);
            provisioningConfiguration.ResetPasswordOnFirstLogon = ResetPasswordOnFirstLogon.IsPresent;
            provisioningConfiguration.StoredCertificateSettings = CertUtilsNewSM.GetCertificateSettings(Certificates, X509Certificates);
            provisioningConfiguration.EnableAutomaticUpdates    = !DisableAutomaticUpdates.IsPresent;

            if (provisioningConfiguration.StoredCertificateSettings == null)
            {
                provisioningConfiguration.StoredCertificateSettings = new CertificateSettingList();
            }

            if (!string.IsNullOrEmpty(TimeZone))
            {
                provisioningConfiguration.TimeZone = TimeZone;
            }

            if (WindowsDomainParameterSetName.Equals(ParameterSetName, StringComparison.OrdinalIgnoreCase))
            {
                provisioningConfiguration.DomainJoin = new WindowsProvisioningConfigurationSet.DomainJoinSettings
                {
                    Credentials = new WindowsProvisioningConfigurationSet.DomainJoinCredentials
                    {
                        Username = DomainUserName,
                        Password = SecureStringHelper.GetSecureString(DomainPassword),
                        Domain   = Domain
                    },
                    MachineObjectOU = MachineObjectOU,
                    JoinDomain      = JoinDomain
                };
            }
        }
        protected void SetProvisioningConfiguration(LinuxProvisioningConfigurationSet provisioningConfiguration)
        {
            provisioningConfiguration.UserName     = LinuxUser;
            provisioningConfiguration.UserPassword = SecureStringHelper.GetSecureString(Password);
            if (NoSSHPassword.IsPresent)
            {
                provisioningConfiguration.UserPassword = SecureStringHelper.GetSecureString(String.Empty);
            }

            if (DisableSSH.IsPresent || NoSSHPassword.IsPresent)
            {
                provisioningConfiguration.DisableSshPasswordAuthentication = true;
            }
            else
            {
                provisioningConfiguration.DisableSshPasswordAuthentication = false;
            }

            if (SSHKeyPairs != null && SSHKeyPairs.Count > 0 || SSHPublicKeys != null && SSHPublicKeys.Count > 0)
            {
                provisioningConfiguration.SSH = new LinuxProvisioningConfigurationSet.SSHSettings {
                    PublicKeys = SSHPublicKeys, KeyPairs = SSHKeyPairs
                };
            }

            if (!string.IsNullOrEmpty(CustomDataFile))
            {
                string fileName = this.TryResolvePath(this.CustomDataFile);
                provisioningConfiguration.CustomData = PersistentVMHelper.ConvertCustomDataFileToBase64(fileName);
            }
        }
        protected void SetProvisioningConfiguration(LinuxProvisioningConfigurationSet provisioningConfiguration)
        {
            provisioningConfiguration.UserName     = LinuxUser;
            provisioningConfiguration.UserPassword = SecureStringHelper.GetSecureString(Password);
            if (NoSSHPassword.IsPresent)
            {
                provisioningConfiguration.UserPassword = SecureStringHelper.GetSecureString(String.Empty);
            }

            if (DisableSSH.IsPresent || NoSSHPassword.IsPresent)
            {
                provisioningConfiguration.DisableSshPasswordAuthentication = true;
            }
            else
            {
                provisioningConfiguration.DisableSshPasswordAuthentication = false;
            }

            if (SSHKeyPairs != null && SSHKeyPairs.Count > 0 || SSHPublicKeys != null && SSHPublicKeys.Count > 0)
            {
                provisioningConfiguration.SSH = new LinuxProvisioningConfigurationSet.SSHSettings {
                    PublicKeys = SSHPublicKeys, KeyPairs = SSHKeyPairs
                };
            }
        }
示例#6
0
        public ShellApplication(object password, UserSessionService userSessionService, EventWaitHandle loadedEvent, string securityTokenXml)
        {
            if (password != null)
            {
                _password = SecureStringHelper.GetSecureString(Marshal.PtrToStringBSTR((IntPtr)password));
                SecureStringHelper.FreeString((IntPtr)password);
            }

            _userSessionService = userSessionService;
            _loadedEvent        = loadedEvent;

            if (securityTokenXml != null)
            {
                _tokenCache = Imi.Framework.UX.Identity.SecurityTokenCache.Deserialize(securityTokenXml);
            }
            else
            {
                _tokenCache = new Imi.Framework.UX.Identity.SecurityTokenCache();
            }

            _settingsLoadedEvent = new EventWaitHandle(false, EventResetMode.AutoReset);

            Thread.CurrentThread.CurrentUICulture = userSessionService.UICulture;

            Run();
        }
        internal void ExecuteCommand()
        {
            List <ResourceExtensionReference> extensionRefs = GetPredicateExtensionList();

            WriteObject(
                extensionRefs == null ? null : extensionRefs.Select(
                    r =>
            {
                GetExtensionValues(r);
                DscPublicSettings publicSettings = null;
                try
                {
                    publicSettings = DscSettingsSerializer.DeserializePublicSettings(PublicConfiguration);
                }
                catch (JsonException e)
                {
                    this.ThrowTerminatingError(
                        new ErrorRecord(
                            new JsonException(
                                String.Format(
                                    CultureInfo.CurrentUICulture,
                                    Properties.Resources.AzureVMDscWrongSettingsFormat,
                                    PublicConfiguration),
                                e),
                            string.Empty,
                            ErrorCategory.ParserError,
                            null));
                }
                var context = new VirtualMachineDscExtensionContext
                {
                    ExtensionName        = r.Name,
                    Publisher            = r.Publisher,
                    ReferenceName        = r.ReferenceName,
                    Version              = r.Version,
                    State                = r.State,
                    RoleName             = VM.GetInstance().RoleName,
                    PublicConfiguration  = PublicConfiguration,
                    PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration)
                };

                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);
            }

                    ).FirstOrDefault());
        }
        protected ResourceExtensionReference NewResourceExtension()
        {
            var extensionRef = new ResourceExtensionReference();

            extensionRef.Name      = this.ExtensionName;
            extensionRef.Publisher = this.Publisher;
            extensionRef.Version   = this.Version;
            extensionRef.State     = IsLegacyExtension() ? null :
                                     this.Uninstall.IsPresent ? ReferenceUninstallStateStr :
                                     this.Disable.IsPresent ? ReferenceDisableStateStr : ReferenceEnableStateStr;
            extensionRef.ResourceExtensionParameterValues = new ResourceExtensionParameterValueList();

            if (!string.IsNullOrEmpty(this.ReferenceName))
            {
                extensionRef.ReferenceName = this.ReferenceName;
            }
            else
            {
                extensionRef.ReferenceName = extensionRef.Name;
            }

            if (!string.IsNullOrEmpty(this.PublicConfigPath))
            {
                this.PublicConfiguration = FileUtilities.DataStore.ReadFileAsText(this.PublicConfigPath);
            }

            if (!string.IsNullOrEmpty(this.PublicConfiguration))
            {
                extensionRef.ResourceExtensionParameterValues.Add(
                    new ResourceExtensionParameterValue
                {
                    Key = !string.IsNullOrEmpty(this.PublicConfigKey) ? this.PublicConfigKey
                            : ExtensionName + (IsLegacyExtension() ? string.Empty : PublicTypeStr) + "ConfigParameter",
                    Type  = IsLegacyExtension() ? null : PublicTypeStr,
                    Value = PublicConfiguration
                });
            }

            if (!string.IsNullOrEmpty(this.PrivateConfigPath))
            {
                this.PrivateConfiguration = FileUtilities.DataStore.ReadFileAsText(this.PrivateConfigPath);
            }

            if (!string.IsNullOrEmpty(this.PrivateConfiguration))
            {
                extensionRef.ResourceExtensionParameterValues.Add(
                    new ResourceExtensionParameterValue
                {
                    Key = !string.IsNullOrEmpty(this.PrivateConfigKey) ? this.PrivateConfigKey
                            : ExtensionName + (IsLegacyExtension() ? string.Empty : PrivateTypeStr) + "ConfigParameter",
                    Type        = IsLegacyExtension() ? null : PrivateTypeStr,
                    SecureValue = SecureStringHelper.GetSecureString(PrivateConfiguration)
                });
            }

            return(extensionRef);
        }
示例#9
0
        private static Credential ReadCredential(PrivateCredential credential)
        {
            var    applicationName = Marshal.PtrToStringUni(credential.TargetName);
            var    userName        = Marshal.PtrToStringUni(credential.UserName);
            string insecureSecret  = null;

            if (credential.CredentialBlob != IntPtr.Zero)
            {
                insecureSecret = Marshal.PtrToStringUni(credential.CredentialBlob, (int)credential.CredentialBlobSize / 2);
            }

            var secret = SecureStringHelper.GetSecureString(insecureSecret);

            return(new Credential(credential.Type, applicationName, userName, secret));
        }
示例#10
0
        internal void ExecuteCommand()
        {
            List <ResourceExtensionReference> extensionRefs = GetPredicateExtensionList();

            WriteObject(
                extensionRefs == null ? null : extensionRefs.Select(
                    r =>
            {
                GetExtensionValues(r);

                var publicSettings = string.IsNullOrEmpty(PublicConfiguration) ? null : JsonConvert.DeserializeObject <DscPublicSettings>(PublicConfiguration);

                var context = new VirtualMachineDscExtensionContext
                {
                    ExtensionName        = r.Name,
                    Publisher            = r.Publisher,
                    ReferenceName        = r.ReferenceName,
                    Version              = r.Version,
                    State                = r.State,
                    RoleName             = VM.GetInstance().RoleName,
                    PublicConfiguration  = PublicConfiguration,
                    PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration),
                };

                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            = publicSettings.Properties;
                }

                return(context);
            }

                    ).FirstOrDefault());
        }
示例#11
0
        internal void ExecuteCommand()
        {
            var extensionRefs =
                string.IsNullOrEmpty(ReferenceName) && string.IsNullOrEmpty(ExtensionName) ?
                ResourceExtensionReferences : GetPredicateExtensionList();

            var extensions = extensionRefs == null ? null : extensionRefs.Select(
                r => new VirtualMachineExtensionContext
            {
                ExtensionName       = r.Name,
                ReferenceName       = r.ReferenceName,
                Publisher           = r.Publisher,
                Version             = r.Version,
                State               = r.State,
                PublicConfiguration = IsLegacyExtension(r.Name, r.Publisher, r.Version)
                                        ? GetConfiguration(r) : GetConfiguration(r, PublicTypeStr),
                PrivateConfiguration = SecureStringHelper.GetSecureString(GetConfiguration(r, PrivateTypeStr)),
                RoleName             = VM.GetInstance().RoleName
            });

            WriteObject(extensions, true);
        }
        protected override void Configure()
        {
            // Service Extension Image
            Mapper.CreateMap <OperationStatusResponse, ExtensionImageContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            Mapper.CreateMap <ExtensionImage, ExtensionImageContext>()
            .ForMember(c => c.ThumbprintAlgorithm, o => o.MapFrom(r => r.Certificate.ThumbprintAlgorithm))
            .ForMember(c => c.ExtensionName, o => o.MapFrom(r => r.Type));

            // VM Extension Image
            Mapper.CreateMap <OperationStatusResponse, VirtualMachineExtensionImageContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            Mapper.CreateMap <VirtualMachineExtensionListResponse.ResourceExtension, VirtualMachineExtensionImageContext>()
            .ForMember(c => c.ExtensionName, o => o.MapFrom(r => r.Name));

            //Image mapping
            Mapper.CreateMap <VirtualMachineOSImageListResponse.VirtualMachineOSImage, OSImageContext>()
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.ImageName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystemType))
            .ForMember(c => c.PublishedDate, o => o.MapFrom(r => new DateTime?(r.PublishedDate)))
            .ForMember(c => c.IconUri, o => o.MapFrom(r => r.SmallIconUri))
            .ForMember(c => c.LogicalSizeInGB, o => o.MapFrom(r => (int)r.LogicalSizeInGB));

            Mapper.CreateMap <VirtualMachineOSImageGetResponse, OSImageContext>()
            .ForMember(c => c.ImageName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystemType))
            .ForMember(c => c.PublishedDate, o => o.MapFrom(r => new DateTime?(r.PublishedDate)))
            .ForMember(c => c.LogicalSizeInGB, o => o.MapFrom(r => (int)r.LogicalSizeInGB));

            Mapper.CreateMap <VirtualMachineOSImageCreateResponse, OSImageContext>()
            .ForMember(c => c.ImageName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.IconUri, o => o.MapFrom(r => r.SmallIconUri))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystemType))
            .ForMember(c => c.PublishedDate, o => o.MapFrom(r => r.PublishedDate))
            .ForMember(c => c.LogicalSizeInGB, o => o.MapFrom(r => (int)r.LogicalSizeInGB));

            Mapper.CreateMap <VirtualMachineOSImageUpdateResponse, OSImageContext>()
            .ForMember(c => c.ImageName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.IconUri, o => o.MapFrom(r => r.SmallIconUri))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystemType))
            .ForMember(c => c.PublishedDate, o => o.MapFrom(r => r.PublishedDate))
            .ForMember(c => c.LogicalSizeInGB, o => o.MapFrom(r => (int)r.LogicalSizeInGB));

            Mapper.CreateMap <OperationStatusResponse, OSImageContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            Mapper.CreateMap <VirtualMachineDiskCreateResponse, OSImageContext>()
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.ImageName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystem));

            // VM Image mapping
            Mapper.CreateMap <VirtualMachineOSImageListResponse.VirtualMachineOSImage, VMImageContext>()
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.ImageName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystemType))
            .ForMember(c => c.PublishedDate, o => o.MapFrom(r => new DateTime?(r.PublishedDate)))
            .ForMember(c => c.IconUri, o => o.MapFrom(r => r.SmallIconUri))
            .ForMember(c => c.LogicalSizeInGB, o => o.MapFrom(r => (int)r.LogicalSizeInGB));

            Mapper.CreateMap <VirtualMachineOSImageGetResponse, VMImageContext>()
            .ForMember(c => c.ImageName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystemType))
            .ForMember(c => c.PublishedDate, o => o.MapFrom(r => new DateTime?(r.PublishedDate)))
            .ForMember(c => c.LogicalSizeInGB, o => o.MapFrom(r => (int)r.LogicalSizeInGB));

            Mapper.CreateMap <VirtualMachineOSImageCreateResponse, VMImageContext>()
            .ForMember(c => c.ImageName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.IconUri, o => o.MapFrom(r => r.SmallIconUri))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystemType))
            .ForMember(c => c.PublishedDate, o => o.MapFrom(r => r.PublishedDate))
            .ForMember(c => c.LogicalSizeInGB, o => o.MapFrom(r => (int)r.LogicalSizeInGB));

            Mapper.CreateMap <VirtualMachineOSImageUpdateResponse, VMImageContext>()
            .ForMember(c => c.ImageName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.IconUri, o => o.MapFrom(r => r.SmallIconUri))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystemType))
            .ForMember(c => c.PublishedDate, o => o.MapFrom(r => r.PublishedDate))
            .ForMember(c => c.LogicalSizeInGB, o => o.MapFrom(r => (int)r.LogicalSizeInGB));

            Mapper.CreateMap <OperationStatusResponse, VMImageContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            Mapper.CreateMap <VirtualMachineDiskCreateResponse, VMImageContext>()
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.ImageName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystem));

            // VM Image Disk Mapping
            Mapper.CreateMap <VirtualMachineVMImageListResponse.OSDiskConfiguration, PVM.OSDiskConfiguration>()
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystem));
            Mapper.CreateMap <VirtualMachineVMImageListResponse.DataDiskConfiguration, PVM.DataDiskConfiguration>()
            .ForMember(c => c.Lun, o => o.MapFrom(r => r.LogicalUnitNumber));

            Mapper.CreateMap <IList <NSM.DataDiskConfigurationUpdateParameters>, List <PVM.DataDiskConfiguration> >();
            Mapper.CreateMap <List <NSM.DataDiskConfigurationUpdateParameters>, List <PVM.DataDiskConfiguration> >();
            Mapper.CreateMap <IList <NSM.DataDiskConfigurationUpdateParameters>, PVM.DataDiskConfigurationList>();

            Mapper.CreateMap <PVM.OSDiskConfiguration, NSM.OSDiskConfigurationUpdateParameters>();
            Mapper.CreateMap <PVM.DataDiskConfiguration, NSM.DataDiskConfigurationUpdateParameters>()
            .ForMember(c => c.LogicalUnitNumber, o => o.MapFrom(r => r.Lun));

            Mapper.CreateMap <IList <PVM.DataDiskConfiguration>, IList <NSM.DataDiskConfigurationUpdateParameters> >();
            Mapper.CreateMap <List <PVM.DataDiskConfiguration>, List <NSM.DataDiskConfigurationUpdateParameters> >();
            Mapper.CreateMap <PVM.DataDiskConfigurationList, Collection <PVM.DataDiskConfiguration> >();
            Mapper.CreateMap <Collection <PVM.DataDiskConfiguration>, IList <NSM.DataDiskConfigurationUpdateParameters> >();
            Mapper.CreateMap <Collection <PVM.DataDiskConfiguration>, List <NSM.DataDiskConfigurationUpdateParameters> >();
            Mapper.CreateMap <PVM.DataDiskConfigurationList, IList <NSM.DataDiskConfigurationUpdateParameters> >();
            Mapper.CreateMap <PVM.DataDiskConfigurationList, List <NSM.DataDiskConfigurationUpdateParameters> >();

            Mapper.CreateMap <VirtualMachineVMImageListResponse.VirtualMachineVMImage, VMImageContext>()
            .ForMember(c => c.ImageName, o => o.MapFrom(r => r.Name));

            Mapper.CreateMap <OperationStatusResponse, VMImageContext>()
            .ForMember(c => c.OS, o => o.Ignore())
            .ForMember(c => c.LogicalSizeInGB, o => o.Ignore())
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            // VM Resource Extensions
            Mapper.CreateMap <NSM.GuestAgentMessage, PVM.GuestAgentMessage>();
            Mapper.CreateMap <NSM.GuestAgentFormattedMessage, PVM.GuestAgentFormattedMessage>();
            Mapper.CreateMap <NSM.GuestAgentStatus, PVM.GuestAgentStatus>()
            .ForMember(c => c.TimestampUtc, o => o.MapFrom(r => r.Timestamp));

            Mapper.CreateMap <NSM.ResourceExtensionConfigurationStatus, PVM.ResourceExtensionConfigurationStatus>()
            .ForMember(c => c.TimestampUtc, o => o.MapFrom(r => r.Timestamp))
            .ForMember(c => c.ConfigurationAppliedTimeUtc, o => o.MapFrom(r => r.ConfigurationAppliedTime));

            Mapper.CreateMap <NSM.ResourceExtensionSubStatus, PVM.ResourceExtensionSubStatus>();
            Mapper.CreateMap <IList <NSM.ResourceExtensionSubStatus>, PVM.ResourceExtensionStatusList>();
            Mapper.CreateMap <IEnumerable <NSM.ResourceExtensionSubStatus>, PVM.ResourceExtensionStatusList>();
            Mapper.CreateMap <List <NSM.ResourceExtensionSubStatus>, PVM.ResourceExtensionStatusList>();

            Mapper.CreateMap <NSM.ResourceExtensionStatus, PVM.ResourceExtensionStatus>();
            Mapper.CreateMap <IList <NSM.ResourceExtensionStatus>, PVM.ResourceExtensionStatusList>();
            Mapper.CreateMap <IEnumerable <NSM.ResourceExtensionStatus>, PVM.ResourceExtensionStatusList>();
            Mapper.CreateMap <List <NSM.ResourceExtensionStatus>, PVM.ResourceExtensionStatusList>();

            //SM to NewSM mapping
            Mapper.CreateMap <PVM.LoadBalancerProbe, NSM.LoadBalancerProbe>()
            .ForMember(c => c.Protocol, o => o.MapFrom(r => r.Protocol));
            Mapper.CreateMap <PVM.AccessControlListRule, NSM.AccessControlListRule>();
            Mapper.CreateMap <PVM.EndpointAccessControlList, NSM.EndpointAcl>()
            .ForMember(c => c.Rules, o => o.MapFrom(r => r.Rules.ToList()));
            Mapper.CreateMap <PVM.InputEndpoint, NSM.InputEndpoint>()
            .ForMember(c => c.VirtualIPAddress, o => o.MapFrom(r => r.Vip != null ? IPAddress.Parse(r.Vip) : null))
            .ForMember(c => c.EndpointAcl, o => o.MapFrom(r => r.EndpointAccessControlList))
            .ForMember(c => c.LoadBalancerName, o => o.MapFrom(r => r.LoadBalancerName));
            Mapper.CreateMap <PVM.DataVirtualHardDisk, NSM.DataVirtualHardDisk>()
            .ForMember(c => c.Name, o => o.MapFrom(r => r.DiskName))
            .ForMember(c => c.Label, o => o.MapFrom(r => r.DiskLabel))
            .ForMember(c => c.LogicalUnitNumber, o => o.MapFrom(r => r.Lun));
            Mapper.CreateMap <PVM.OSVirtualHardDisk, NSM.OSVirtualHardDisk>()
            .ForMember(c => c.Name, o => o.MapFrom(r => r.DiskName))
            .ForMember(c => c.Label, o => o.MapFrom(r => r.DiskLabel))
            .ForMember(c => c.OperatingSystem, o => o.MapFrom(r => r.OS));
            Mapper.CreateMap <PVM.NetworkConfigurationSet, NSM.ConfigurationSet>()
            .ForMember(c => c.InputEndpoints, o => o.MapFrom(r => r.InputEndpoints != null ? r.InputEndpoints.ToList() : null))
            .ForMember(c => c.SubnetNames, o => o.MapFrom(r => r.SubnetNames != null ? r.SubnetNames.ToList() : null))
            .ForMember(c => c.PublicIPs, o => o.MapFrom(r => r.PublicIPs != null ? r.PublicIPs.ToList() : null));

            Mapper.CreateMap <PVM.LinuxProvisioningConfigurationSet.SSHKeyPair, NSM.SshSettingKeyPair>();
            Mapper.CreateMap <PVM.LinuxProvisioningConfigurationSet.SSHPublicKey, NSM.SshSettingPublicKey>();
            Mapper.CreateMap <PVM.LinuxProvisioningConfigurationSet.SSHSettings, NSM.SshSettings>();
            Mapper.CreateMap <PVM.LinuxProvisioningConfigurationSet, NSM.ConfigurationSet>()
            .ForMember(c => c.PublicIPs, o => o.Ignore())
            .ForMember(c => c.UserPassword, o => o.MapFrom(r => r.UserPassword == null ? null : r.UserPassword.ConvertToUnsecureString()))
            .ForMember(c => c.SshSettings, o => o.MapFrom(r => r.SSH));
            Mapper.CreateMap <PVM.WindowsProvisioningConfigurationSet, NSM.ConfigurationSet>()
            .ForMember(c => c.PublicIPs, o => o.Ignore())
            .ForMember(c => c.AdminPassword, o => o.MapFrom(r => r.AdminPassword == null ? null : r.AdminPassword.ConvertToUnsecureString()));
            Mapper.CreateMap <PVM.ProvisioningConfigurationSet, NSM.ConfigurationSet>()
            .ForMember(c => c.PublicIPs, o => o.Ignore());
            Mapper.CreateMap <PVM.ConfigurationSet, NSM.ConfigurationSet>()
            .ForMember(c => c.PublicIPs, o => o.Ignore());
            Mapper.CreateMap <PVM.InstanceEndpoint, NSM.InstanceEndpoint>()
            .ForMember(c => c.VirtualIPAddress, o => o.MapFrom(r => r.Vip != null ? IPAddress.Parse(r.Vip) : null))
            .ForMember(c => c.Port, o => o.MapFrom(r => r.PublicPort));

            Mapper.CreateMap <PVM.WindowsProvisioningConfigurationSet.WinRmConfiguration, NSM.WindowsRemoteManagementSettings>();
            Mapper.CreateMap <PVM.WindowsProvisioningConfigurationSet.WinRmListenerProperties, NSM.WindowsRemoteManagementListener>()
            .ForMember(c => c.ListenerType, o => o.MapFrom(r => r.Protocol));
            Mapper.CreateMap <PVM.WindowsProvisioningConfigurationSet.WinRmListenerCollection, IList <NSM.WindowsRemoteManagementListener> >();

            //NewSM to SM mapping
            Mapper.CreateMap <NSM.LoadBalancerProbe, PVM.LoadBalancerProbe>()
            .ForMember(c => c.Protocol, o => o.MapFrom(r => r.Protocol.ToString().ToLower()));
            Mapper.CreateMap <NSM.AccessControlListRule, PVM.AccessControlListRule>();
            Mapper.CreateMap <NSM.EndpointAcl, PVM.EndpointAccessControlList>()
            .ForMember(c => c.Rules, o => o.MapFrom(r => r.Rules));
            Mapper.CreateMap <NSM.InputEndpoint, PVM.InputEndpoint>()
            .ForMember(c => c.LoadBalancerName, o => o.MapFrom(r => r.LoadBalancerName))
            .ForMember(c => c.Vip, o => o.MapFrom(r => r.VirtualIPAddress != null ? r.VirtualIPAddress.ToString() : null))
            .ForMember(c => c.EndpointAccessControlList, o => o.MapFrom(r => r.EndpointAcl));
            Mapper.CreateMap <NSM.DataVirtualHardDisk, PVM.DataVirtualHardDisk>()
            .ForMember(c => c.DiskName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.DiskLabel, o => o.MapFrom(r => r.Label))
            .ForMember(c => c.Lun, o => o.MapFrom(r => r.LogicalUnitNumber));
            Mapper.CreateMap <NSM.OSVirtualHardDisk, PVM.OSVirtualHardDisk>()
            .ForMember(c => c.DiskName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.DiskLabel, o => o.MapFrom(r => r.Label))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystem));
            Mapper.CreateMap <NSM.ConfigurationSet, PVM.ConfigurationSet>();
            Mapper.CreateMap <NSM.ConfigurationSet, PVM.NetworkConfigurationSet>();

            Mapper.CreateMap <NSM.SshSettingKeyPair, PVM.LinuxProvisioningConfigurationSet.SSHKeyPair>();
            Mapper.CreateMap <NSM.SshSettingPublicKey, PVM.LinuxProvisioningConfigurationSet.SSHPublicKey>();
            Mapper.CreateMap <NSM.SshSettings, PVM.LinuxProvisioningConfigurationSet.SSHSettings>();
            Mapper.CreateMap <NSM.ConfigurationSet, PVM.LinuxProvisioningConfigurationSet>()
            .ForMember(c => c.UserPassword, o => o.MapFrom(r => SecureStringHelper.GetSecureString(r.UserPassword)))
            .ForMember(c => c.SSH, o => o.MapFrom(r => r.SshSettings));
            Mapper.CreateMap <NSM.ConfigurationSet, PVM.WindowsProvisioningConfigurationSet>()
            .ForMember(c => c.AdminPassword, o => o.MapFrom(r => SecureStringHelper.GetSecureString(r.AdminPassword)));
            Mapper.CreateMap <NSM.InstanceEndpoint, PVM.InstanceEndpoint>()
            .ForMember(c => c.Vip, o => o.MapFrom(r => r.VirtualIPAddress != null ? r.VirtualIPAddress.ToString() : null))
            .ForMember(c => c.PublicPort, o => o.MapFrom(r => r.Port));

            Mapper.CreateMap <NSM.WindowsRemoteManagementSettings, PVM.WindowsProvisioningConfigurationSet.WinRmConfiguration>();
            Mapper.CreateMap <NSM.WindowsRemoteManagementListener, PVM.WindowsProvisioningConfigurationSet.WinRmListenerProperties>()
            .ForMember(c => c.Protocol, o => o.MapFrom(r => r.ListenerType.ToString()));
            Mapper.CreateMap <IList <NSM.WindowsRemoteManagementListener>, PVM.WindowsProvisioningConfigurationSet.WinRmListenerCollection>();

            // LoadBalancedEndpointList mapping
            Mapper.CreateMap <PVM.AccessControlListRule, NSM.AccessControlListRule>();
            Mapper.CreateMap <PVM.EndpointAccessControlList, NSM.EndpointAcl>();
            Mapper.CreateMap <PVM.InputEndpoint, VirtualMachineUpdateLoadBalancedSetParameters.InputEndpoint>()
            .ForMember(c => c.Rules, o => o.MapFrom(r => r.EndpointAccessControlList == null ? null : r.EndpointAccessControlList.Rules))
            .ForMember(c => c.VirtualIPAddress, o => o.MapFrom(r => r.Vip));

            Mapper.CreateMap <NSM.AccessControlListRule, PVM.AccessControlListRule>();
            Mapper.CreateMap <NSM.EndpointAcl, PVM.EndpointAccessControlList>();
            Mapper.CreateMap <NSM.VirtualMachineUpdateLoadBalancedSetParameters.InputEndpoint, PVM.InputEndpoint>()
            .ForMember(c => c.EndpointAccessControlList, o => o.MapFrom(r => r.Rules == null ? null : r.Rules))
            .ForMember(c => c.Vip, o => o.MapFrom(r => r.VirtualIPAddress));

            //Common mapping
            Mapper.CreateMap <OperationResponse, ManagementOperationContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.RequestId))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.StatusCode.ToString()));

            Mapper.CreateMap <OperationStatusResponse, ManagementOperationContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            //AffinityGroup mapping
            Mapper.CreateMap <AffinityGroupGetResponse, AffinityGroupContext>()
            .ForMember(c => c.VirtualMachineRoleSizes, o => o.MapFrom(r => r.ComputeCapabilities == null ? null : r.ComputeCapabilities.VirtualMachinesRoleSizes))
            .ForMember(c => c.WebWorkerRoleSizes, o => o.MapFrom(r => r.ComputeCapabilities == null ? null : r.ComputeCapabilities.WebWorkerRoleSizes));
            Mapper.CreateMap <AffinityGroupListResponse.AffinityGroup, AffinityGroupContext>()
            .ForMember(c => c.VirtualMachineRoleSizes, o => o.MapFrom(r => r.ComputeCapabilities == null ? null : r.ComputeCapabilities.VirtualMachinesRoleSizes))
            .ForMember(c => c.WebWorkerRoleSizes, o => o.MapFrom(r => r.ComputeCapabilities == null ? null : r.ComputeCapabilities.WebWorkerRoleSizes));
            Mapper.CreateMap <AffinityGroupGetResponse.HostedServiceReference, AffinityGroupContext.Service>()
            .ForMember(c => c.Url, o => o.MapFrom(r => r.Uri));
            Mapper.CreateMap <AffinityGroupGetResponse.StorageServiceReference, AffinityGroupContext.Service>()
            .ForMember(c => c.Url, o => o.MapFrom(r => r.Uri));
            Mapper.CreateMap <OperationStatusResponse, AffinityGroupContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            //Location mapping
            Mapper.CreateMap <LocationsListResponse.Location, LocationsContext>()
            .ForMember(c => c.VirtualMachineRoleSizes, o => o.MapFrom(r => r.ComputeCapabilities == null ? null : r.ComputeCapabilities.VirtualMachinesRoleSizes))
            .ForMember(c => c.WebWorkerRoleSizes, o => o.MapFrom(r => r.ComputeCapabilities == null ? null : r.ComputeCapabilities.WebWorkerRoleSizes));
            Mapper.CreateMap <OperationStatusResponse, LocationsContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            //Role sizes mapping
            Mapper.CreateMap <RoleSizeListResponse.RoleSize, RoleSizeContext>()
            .ForMember(c => c.InstanceSize, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.RoleSizeLabel, o => o.MapFrom(r => r.Label));
            Mapper.CreateMap <OperationStatusResponse, RoleSizeContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            //ServiceCertificate mapping
            Mapper.CreateMap <ServiceCertificateGetResponse, CertificateContext>()
            .ForMember(c => c.Data, o => o.MapFrom(r => r.Data != null ? Convert.ToBase64String(r.Data) : null));
            Mapper.CreateMap <ServiceCertificateListResponse.Certificate, CertificateContext>()
            .ForMember(c => c.Url, o => o.MapFrom(r => r.CertificateUri))
            .ForMember(c => c.Data, o => o.MapFrom(r => r.Data != null ? Convert.ToBase64String(r.Data) : null));
            Mapper.CreateMap <OperationStatusResponse, CertificateContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));
            Mapper.CreateMap <OperationStatusResponse, ManagementOperationContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            //OperatingSystems mapping
            Mapper.CreateMap <OperatingSystemListResponse.OperatingSystem, OSVersionsContext>();
            Mapper.CreateMap <OperationStatusResponse, OSVersionsContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            //Service mapping
            Mapper.CreateMap <HostedServiceProperties, HostedServiceDetailedContext>()
            .ForMember(c => c.Description, o => o.MapFrom(r => string.IsNullOrEmpty(r.Description) ? null : r.Description))
            .ForMember(c => c.DateModified, o => o.MapFrom(r => r.DateLastModified));
            Mapper.CreateMap <HostedServiceGetResponse, HostedServiceDetailedContext>()
            .ForMember(c => c.ExtendedProperties, o => o.MapFrom(r => r.Properties == null ? null : r.Properties.ExtendedProperties))
            .ForMember(c => c.VirtualMachineRoleSizes, o => o.MapFrom(r => r.ComputeCapabilities == null ? null : r.ComputeCapabilities.VirtualMachinesRoleSizes))
            .ForMember(c => c.WebWorkerRoleSizes, o => o.MapFrom(r => r.ComputeCapabilities == null ? null : r.ComputeCapabilities.WebWorkerRoleSizes))
            .ForMember(c => c.Url, o => o.MapFrom(r => r.Uri));
            Mapper.CreateMap <HostedServiceListResponse.HostedService, HostedServiceDetailedContext>()
            .ForMember(c => c.ExtendedProperties, o => o.MapFrom(r => r.Properties == null ? null : r.Properties.ExtendedProperties))
            .ForMember(c => c.VirtualMachineRoleSizes, o => o.MapFrom(r => r.ComputeCapabilities == null ? null : r.ComputeCapabilities.VirtualMachinesRoleSizes))
            .ForMember(c => c.WebWorkerRoleSizes, o => o.MapFrom(r => r.ComputeCapabilities == null ? null : r.ComputeCapabilities.WebWorkerRoleSizes))
            .ForMember(c => c.Url, o => o.MapFrom(r => r.Uri));
            Mapper.CreateMap <OperationStatusResponse, HostedServiceDetailedContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            //Disk mapping
            Mapper.CreateMap <VirtualMachineDiskListResponse.VirtualMachineDisk, DiskContext>()
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.DiskSizeInGB, o => o.MapFrom(r => r.LogicalSizeInGB))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystemType))
            .ForMember(c => c.DiskName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.AttachedTo, o => o.MapFrom(r => r.UsageDetails));
            Mapper.CreateMap <VirtualMachineDiskListResponse.VirtualMachineDiskUsageDetails, DiskContext.RoleReference>();

            Mapper.CreateMap <VirtualMachineDiskGetResponse, DiskContext>()
            .ForMember(c => c.AttachedTo, o => o.MapFrom(r => r.UsageDetails))
            .ForMember(c => c.DiskName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.DiskSizeInGB, o => o.MapFrom(r => r.LogicalSizeInGB))
            .ForMember(c => c.IsCorrupted, o => o.MapFrom(r => r.IsCorrupted))
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystemType));
            Mapper.CreateMap <VirtualMachineDiskGetResponse.VirtualMachineDiskUsageDetails, DiskContext.RoleReference>();

            Mapper.CreateMap <VirtualMachineDiskCreateResponse, DiskContext>()
            .ForMember(c => c.DiskName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.OS, o => o.MapFrom(r => r.OperatingSystem))
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.DiskSizeInGB, o => o.MapFrom(r => r.LogicalSizeInGB))
            .ForMember(c => c.AttachedTo, o => o.MapFrom(r => r.UsageDetails));
            Mapper.CreateMap <VirtualMachineDiskCreateResponse.VirtualMachineDiskUsageDetails, DiskContext.RoleReference>();

            Mapper.CreateMap <VirtualMachineDiskUpdateResponse, DiskContext>()
            .ForMember(c => c.DiskName, o => o.MapFrom(r => r.Name))
            .ForMember(c => c.MediaLink, o => o.MapFrom(r => r.MediaLinkUri))
            .ForMember(c => c.DiskSizeInGB, o => o.MapFrom(r => r.LogicalSizeInGB));

            Mapper.CreateMap <OperationStatusResponse, DiskContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            //Storage mapping
            Mapper.CreateMap <StorageAccountGetResponse, StorageServicePropertiesOperationContext>()
            .ForMember(c => c.StorageAccountDescription, o => o.MapFrom(r => r.StorageAccount.Properties == null ? null : r.StorageAccount.Properties.Description))
            .ForMember(c => c.StorageAccountName, o => o.MapFrom(r => r.StorageAccount.Name));
            Mapper.CreateMap <StorageAccountProperties, StorageServicePropertiesOperationContext>()
            .ForMember(c => c.StorageAccountDescription, o => o.MapFrom(r => r.Description))
            .ForMember(c => c.GeoPrimaryLocation, o => o.MapFrom(r => r.GeoPrimaryRegion))
            .ForMember(c => c.GeoSecondaryLocation, o => o.MapFrom(r => r.GeoSecondaryRegion))
            .ForMember(c => c.StorageAccountStatus, o => o.MapFrom(r => r.Status))
            .ForMember(c => c.StatusOfPrimary, o => o.MapFrom(r => r.StatusOfGeoPrimaryRegion))
            .ForMember(c => c.StatusOfSecondary, o => o.MapFrom(r => r.StatusOfGeoSecondaryRegion));
            Mapper.CreateMap <StorageAccount, StorageServicePropertiesOperationContext>()
            .ForMember(c => c.StorageAccountDescription, o => o.MapFrom(r => r.Properties == null ? null : r.Properties.Description))
            .ForMember(c => c.StorageAccountName, o => o.MapFrom(r => r.Name));
            Mapper.CreateMap <OperationStatusResponse, StorageServicePropertiesOperationContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            Mapper.CreateMap <StorageAccountGetKeysResponse, StorageServiceKeyOperationContext>()
            .ForMember(c => c.Primary, o => o.MapFrom(r => r.PrimaryKey))
            .ForMember(c => c.Secondary, o => o.MapFrom(r => r.SecondaryKey));
            Mapper.CreateMap <OperationStatusResponse, StorageServiceKeyOperationContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            Mapper.CreateMap <OperationStatusResponse, ManagementOperationContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            // DomainJoinSettings mapping for IaaS
            Mapper.CreateMap <NSM.DomainJoinCredentials, PVM.WindowsProvisioningConfigurationSet.DomainJoinCredentials>()
            .ForMember(c => c.Domain, o => o.MapFrom(r => r.Domain))
            .ForMember(c => c.Username, o => o.MapFrom(r => r.UserName))
            .ForMember(c => c.Password, o => o.MapFrom(r => SecureStringHelper.GetSecureString(r.Password)));
            Mapper.CreateMap <NSM.DomainJoinProvisioning, PVM.WindowsProvisioningConfigurationSet.DomainJoinProvisioning>()
            .ForMember(c => c.AccountData, o => o.MapFrom(r => r.AccountData));
            Mapper.CreateMap <NSM.DomainJoinSettings, PVM.WindowsProvisioningConfigurationSet.DomainJoinSettings>()
            .ForMember(c => c.Credentials, o => o.MapFrom(r => r.Credentials))
            .ForMember(c => c.JoinDomain, o => o.MapFrom(r => r.DomainToJoin))
            .ForMember(c => c.MachineObjectOU, o => o.MapFrom(r => r.LdapMachineObjectOU))
            .ForMember(c => c.Provisioning, o => o.MapFrom(r => r.Provisioning));

            Mapper.CreateMap <PVM.WindowsProvisioningConfigurationSet.DomainJoinCredentials, NSM.DomainJoinCredentials>()
            .ForMember(c => c.Domain, o => o.MapFrom(r => r.Domain))
            .ForMember(c => c.UserName, o => o.MapFrom(r => r.Username))
            .ForMember(c => c.Password, o => o.MapFrom(r => r.Password.ConvertToUnsecureString()));
            Mapper.CreateMap <PVM.WindowsProvisioningConfigurationSet.DomainJoinProvisioning, NSM.DomainJoinProvisioning>()
            .ForMember(c => c.AccountData, o => o.MapFrom(r => r.AccountData));
            Mapper.CreateMap <PVM.WindowsProvisioningConfigurationSet.DomainJoinSettings, NSM.DomainJoinSettings>()
            .ForMember(c => c.Credentials, o => o.MapFrom(r => r.Credentials))
            .ForMember(c => c.DomainToJoin, o => o.MapFrom(r => r.JoinDomain))
            .ForMember(c => c.LdapMachineObjectOU, o => o.MapFrom(r => r.MachineObjectOU))
            .ForMember(c => c.Provisioning, o => o.MapFrom(r => r.Provisioning));

            // Networks mapping
            Mapper.CreateMap <IList <string>, PVM.AddressPrefixList>()
            .ForItems <IList <string>, PVM.AddressPrefixList, string>();
            Mapper.CreateMap <NVM.NetworkListResponse.AddressSpace, PVM.AddressSpace>();
            Mapper.CreateMap <NVM.NetworkListResponse.Connection, PVM.Connection>();
            Mapper.CreateMap <NVM.NetworkListResponse.LocalNetworkSite, PVM.LocalNetworkSite>();
            Mapper.CreateMap <IList <NVM.NetworkListResponse.LocalNetworkSite>, PVM.LocalNetworkSiteList>()
            .ForItems <IList <NVM.NetworkListResponse.LocalNetworkSite>, PVM.LocalNetworkSiteList, PVM.LocalNetworkSite>();
            Mapper.CreateMap <NVM.NetworkListResponse.DnsServer, PVM.DnsServer>();
            Mapper.CreateMap <IList <NVM.NetworkListResponse.DnsServer>, PVM.DnsServerList>()
            .ForItems <IList <NVM.NetworkListResponse.DnsServer>, PVM.DnsServerList, PVM.DnsServer>();
            Mapper.CreateMap <NVM.NetworkListResponse.Subnet, PVM.Subnet>();
            Mapper.CreateMap <IList <NVM.NetworkListResponse.Subnet>, PVM.SubnetList>()
            .ForItems <IList <NVM.NetworkListResponse.Subnet>, PVM.SubnetList, PVM.Subnet>();
            Mapper.CreateMap <IList <NVM.NetworkListResponse.DnsServer>, PVM.DnsSettings>()
            .ForMember(c => c.DnsServers, o => o.MapFrom(r => r));
            Mapper.CreateMap <IList <NVM.NetworkListResponse.Gateway>, PVM.Gateway>();
            Mapper.CreateMap <NVM.NetworkListResponse.VirtualNetworkSite, PVM.VirtualNetworkSite>();
            Mapper.CreateMap <IList <NVM.NetworkListResponse.VirtualNetworkSite>, PVM.VirtualNetworkSiteList>()
            .ForItems <IList <NVM.NetworkListResponse.VirtualNetworkSite>, PVM.VirtualNetworkSiteList, PVM.VirtualNetworkSite>();
            Mapper.CreateMap <NVM.NetworkListResponse.VirtualNetworkSite, VirtualNetworkSiteContext>()
            .ForMember(c => c.AddressSpacePrefixes, o => o.MapFrom(r => r.AddressSpace == null ? null : r.AddressSpace.AddressPrefixes == null ? null :
                                                                   r.AddressSpace.AddressPrefixes.Select(p => p)))
            .ForMember(c => c.DnsServers, o => o.MapFrom(r => r.DnsServers.AsEnumerable()))
            .ForMember(c => c.GatewayProfile, o => o.MapFrom(r => r.Gateway.Profile))
            .ForMember(c => c.GatewaySites, o => o.MapFrom(r => r.Gateway.Sites));
            Mapper.CreateMap <OperationStatusResponse, VirtualNetworkSiteContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()))
            .ForMember(c => c.Id, o => o.Ignore());

            // Check Static IP Availability Response Mapping
            Mapper.CreateMap <NVM.NetworkStaticIPAvailabilityResponse, VirtualNetworkStaticIPAvailabilityContext>();
            Mapper.CreateMap <OperationStatusResponse, VirtualNetworkStaticIPAvailabilityContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()));

            // New SM to Model
            Mapper.CreateMap <NSM.StoredCertificateSettings, PVM.CertificateSetting>();
            Mapper.CreateMap <IList <NSM.StoredCertificateSettings>, PVM.CertificateSettingList>()
            .ForItems <IList <NSM.StoredCertificateSettings>, PVM.CertificateSettingList, PVM.CertificateSetting>();

            // Model to New SM
            Mapper.CreateMap <PVM.CertificateSetting, NSM.StoredCertificateSettings>();
            Mapper.CreateMap <PVM.CertificateSettingList, IList <NSM.StoredCertificateSettings> >()
            .ForItems <PVM.CertificateSettingList, IList <NSM.StoredCertificateSettings>, NSM.StoredCertificateSettings>();

            // Resource Extensions
            Mapper.CreateMap <NSM.ResourceExtensionParameterValue, PVM.ResourceExtensionParameterValue>()
            .ForMember(c => c.SecureValue, o => o.MapFrom(r => SecureStringHelper.GetSecureString(r)))
            .ForMember(c => c.Value, o => o.MapFrom(r => SecureStringHelper.GetPlainString(r)));
            Mapper.CreateMap <NSM.ResourceExtensionReference, PVM.ResourceExtensionReference>();

            Mapper.CreateMap <PVM.ResourceExtensionParameterValue, NSM.ResourceExtensionParameterValue>()
            .ForMember(c => c.Value, o => o.MapFrom(r => SecureStringHelper.GetPlainString(r)));
            Mapper.CreateMap <PVM.ResourceExtensionReference, NSM.ResourceExtensionReference>();

            // Reserved IP
            Mapper.CreateMap <OperationStatusResponse, ReservedIPContext>()
            .ForMember(c => c.OperationId, o => o.MapFrom(r => r.Id))
            .ForMember(c => c.OperationStatus, o => o.MapFrom(r => r.Status.ToString()))
            .ForMember(c => c.Id, o => o.Ignore());
            Mapper.CreateMap <NetworkReservedIPGetResponse, ReservedIPContext>()
            .ForMember(c => c.ReservedIPName, o => o.MapFrom(r => r.Name));
            Mapper.CreateMap <NetworkReservedIPListResponse.ReservedIP, ReservedIPContext>()
            .ForMember(c => c.ReservedIPName, o => o.MapFrom(r => r.Name));

            // Public IP
            Mapper.CreateMap <PVM.PublicIP, NSM.RoleInstance.PublicIP>();
            Mapper.CreateMap <PVM.AssignPublicIP, NSM.ConfigurationSet.PublicIP>();

            Mapper.CreateMap <NSM.RoleInstance.PublicIP, PVM.PublicIP>();
            Mapper.CreateMap <NSM.ConfigurationSet.PublicIP, PVM.AssignPublicIP>();
        }
        /// <summary>
        /// Get the SQL Extension's context
        /// </summary>
        /// <returns></returns>
        private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExtensionReference r)
        {
            string extensionName = VirtualMachineSqlServerExtensionCmdletBase.ExtensionPublishedNamespace + "."
                                   + VirtualMachineSqlServerExtensionCmdletBase.ExtensionPublishedName;

            VirtualMachineSqlServerExtensionContext context = new VirtualMachineSqlServerExtensionContext
            {
                ExtensionName        = r.Name,
                Publisher            = r.Publisher,
                ReferenceName        = r.ReferenceName,
                Version              = r.Version,
                State                = r.State,
                PublicConfiguration  = PublicConfiguration,
                PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration),
                RoleName             = VM.GetInstance().RoleName,
            };

            // gather extension status messages
            List <string> statusMessageList = new List <string>();

            List <NSM.ResourceExtensionStatus> extensionStatusList = this.GetResourceExtensionStatusList(context);

            // enumerate over extension status list and gather status for autopatching and autobackup
            // Note: valid reference to an extension status list is returned by GetResourceExtensionStatusList()
            foreach (NSM.ResourceExtensionStatus res in extensionStatusList)
            {
                // Expected ReferenceName = "Microsoft.SqlServer.Management.SqlIaaSAgent"
                if (!res.HandlerName.Equals(extensionName, System.StringComparison.InvariantCulture))
                {
                    // skip all non-sql extensions
                    continue;
                }

                WriteVerboseWithTimestamp("Found SQL Extension:" + r.ReferenceName);

                if (null != res.ExtensionSettingStatus)
                {
                    context.SubStatusList = res.ExtensionSettingStatus.SubStatusList;

                    foreach (NSM.ResourceExtensionSubStatus status in res.ExtensionSettingStatus.SubStatusList)
                    {
                        if (null != status.FormattedMessage)
                        {
                            string formattedMessage = status.FormattedMessage.Message;

                            // get current auto patching and auto backup config from extension status message
                            if (status.Name.Equals(AutoPatchingStatusMessageName, System.StringComparison.InvariantCulture))
                            {
                                context.AutoPatchingSettings = DeSerializeAutoPatchingSettings(status.Name, formattedMessage);
                            }
                            else if (status.Name.Equals(AutoBackupStatusMessageName, System.StringComparison.InvariantCulture))
                            {
                                context.AutoBackupSettings = DeSerializeAutoBackupSettings(status.Name, formattedMessage);
                            }
                            else if (status.Name.Equals(KeyVaultCredentialStatusMessageName, System.StringComparison.InvariantCulture))
                            {
                                context.KeyVaultCredentialSettings = DeSerializeKeyVaultCredentialSettings(status.Name, formattedMessage);
                            }

                            statusMessageList.Add(formattedMessage);
                        }
                    }
                }
            }

            context.StatusMessages = statusMessageList;
            return(context);
        }
示例#14
0
        private Management.Compute.Models.Role CreatePersistenVMRole(CloudStorageAccount currentStorage)
        {
            var vm = new Management.Compute.Models.Role
            {
                AvailabilitySetName = AvailabilitySetName,
                RoleName            = String.IsNullOrEmpty(Name) ? ServiceName : Name,         // default like the portal
                RoleSize            = InstanceSize,
                RoleType            = "PersistentVMRole",
                Label             = ServiceName,
                OSVirtualHardDisk = _isVMImage ? null : Mapper.Map <Management.Compute.Models.OSVirtualHardDisk>(
                    new OSVirtualHardDisk
                {
                    DiskName        = null,
                    SourceImageName = ImageName,
                    MediaLink       = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation),
                    HostCaching     = HostCaching
                }),
                VMImageName                 = _isVMImage ? this.ImageName : null,
                MediaLocation               = _isVMImage && !string.IsNullOrEmpty(this.MediaLocation) ? new Uri(this.MediaLocation) : null,
                ProvisionGuestAgent         = !this.DisableGuestAgent,
                ResourceExtensionReferences = this.DisableGuestAgent ? null : Mapper.Map <List <Management.Compute.Models.ResourceExtensionReference> >(
                    new VirtualMachineExtensionImageFactory(this.ComputeClient).MakeList(
                        VirtualMachineBGInfoExtensionCmdletBase.ExtensionDefaultPublisher,
                        VirtualMachineBGInfoExtensionCmdletBase.ExtensionDefaultName,
                        VirtualMachineBGInfoExtensionCmdletBase.ExtensionDefaultVersion))
            };

            if (!_isVMImage && vm.OSVirtualHardDisk.MediaLink == null && String.IsNullOrEmpty(vm.OSVirtualHardDisk.Name))
            {
                var mediaLinkFactory = new MediaLinkFactory(currentStorage, this.ServiceName, vm.RoleName);
                vm.OSVirtualHardDisk.MediaLink = mediaLinkFactory.Create();
            }

            string customDataBase64Str = null;

            if (!string.IsNullOrEmpty(this.CustomDataFile))
            {
                string fileName = this.TryResolvePath(this.CustomDataFile);
                customDataBase64Str = PersistentVMHelper.ConvertCustomDataFileToBase64(fileName);
            }

            var configurationSets = new Collection <ConfigurationSet>();
            var netConfig         = CreateNetworkConfigurationSet();

            if (ParameterSetName.Equals(WindowsParamSet, StringComparison.OrdinalIgnoreCase))
            {
                if (this.AdminUsername != null && this.Password != null)
                {
                    var windowsConfig = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.WindowsProvisioningConfigurationSet
                    {
                        AdminUsername             = this.AdminUsername,
                        AdminPassword             = SecureStringHelper.GetSecureString(Password),
                        ComputerName              = string.IsNullOrEmpty(Name) ? ServiceName : Name,
                        EnableAutomaticUpdates    = true,
                        ResetPasswordOnFirstLogon = false,
                        StoredCertificateSettings = CertUtilsNewSM.GetCertificateSettings(this.Certificates, this.X509Certificates),
                        WinRM      = GetWinRmConfiguration(),
                        CustomData = customDataBase64Str
                    };

                    if (windowsConfig.StoredCertificateSettings == null)
                    {
                        windowsConfig.StoredCertificateSettings = new Model.CertificateSettingList();
                    }

                    configurationSets.Add(windowsConfig);
                }

                netConfig.InputEndpoints.Add(new InputEndpoint {
                    LocalPort = 3389, Protocol = "tcp", Name = "RemoteDesktop"
                });
                if (!this.NoWinRMEndpoint.IsPresent && !this.DisableWinRMHttps.IsPresent)
                {
                    netConfig.InputEndpoints.Add(new InputEndpoint {
                        LocalPort = WinRMConstants.HttpsListenerPort, Protocol = "tcp", Name = WinRMConstants.EndpointName
                    });
                }

                configurationSets.Add(netConfig);
            }
            else if (ParameterSetName.Equals(LinuxParamSet, StringComparison.OrdinalIgnoreCase))
            {
                if (this.LinuxUser != null && this.Password != null)
                {
                    var linuxConfig = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.LinuxProvisioningConfigurationSet
                    {
                        HostName     = string.IsNullOrEmpty(this.Name) ? this.ServiceName : this.Name,
                        UserName     = this.LinuxUser,
                        UserPassword = SecureStringHelper.GetSecureString(this.Password),
                        DisableSshPasswordAuthentication = false,
                        CustomData = customDataBase64Str
                    };

                    if (this.SSHKeyPairs != null && this.SSHKeyPairs.Count > 0 ||
                        this.SSHPublicKeys != null && this.SSHPublicKeys.Count > 0)
                    {
                        linuxConfig.SSH = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.LinuxProvisioningConfigurationSet.SSHSettings
                        {
                            PublicKeys = this.SSHPublicKeys,
                            KeyPairs   = this.SSHKeyPairs
                        };
                    }

                    configurationSets.Add(linuxConfig);
                }

                var rdpEndpoint = new InputEndpoint {
                    LocalPort = 22, Protocol = "tcp", Name = "SSH"
                };
                netConfig.InputEndpoints.Add(rdpEndpoint);
                configurationSets.Add(netConfig);
            }

            PersistentVMHelper.MapConfigurationSets(configurationSets).ForEach(c => vm.ConfigurationSets.Add(c));

            return(vm);
        }
示例#15
0
        /// <summary>
        /// Get the SQL Extension's context
        /// </summary>
        /// <returns></returns>
        private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExtensionReference r)
        {
            VirtualMachineSqlServerExtensionContext context = new VirtualMachineSqlServerExtensionContext
            {
                ExtensionName        = r.Name,
                Publisher            = r.Publisher,
                ReferenceName        = r.ReferenceName,
                Version              = r.Version,
                State                = r.State,
                PublicConfiguration  = PublicConfiguration,
                PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration),
                RoleName             = VM.GetInstance().RoleName,
            };

            // gather extension status messages
            List <string> statusMessageList = new List <string>();

            List <NSM.ResourceExtensionStatus> extensionStatusList = this.GetResourceExtensionStatusList(context);

            // enumerate over extension status list and gather status for autopatching and autobackup
            // Note: valid reference to an extension status list is returned by GetResourceExtensionStatusList()
            foreach (NSM.ResourceExtensionStatus res in extensionStatusList)
            {
                // Extension handler name  in format publisher.ReferenceName
                string extensionHandlerName = string.Format(CultureInfo.InvariantCulture,
                                                            "{0}.{1}",
                                                            r.Publisher,
                                                            r.ReferenceName);

                // skip all non-sql extensions
                if (!res.HandlerName.Equals(extensionHandlerName, System.StringComparison.InvariantCulture))
                {
                    continue;
                }

                if (null != res.ExtensionSettingStatus)
                {
                    context.SubStatusList = res.ExtensionSettingStatus.SubStatusList;

                    foreach (NSM.ResourceExtensionSubStatus status in res.ExtensionSettingStatus.SubStatusList)
                    {
                        if (null != status.FormattedMessage)
                        {
                            string formattedMessage = status.FormattedMessage.Message;

                            // get current auto patching and auto backup config from extension status message
                            if (status.Name.Equals(AutoPatchingStatusMessageName, System.StringComparison.InvariantCulture))
                            {
                                context.AutoPatchingSettings = DeSerializeAutoPatchingSettings(status.Name, formattedMessage);
                            }

                            if (status.Name.Equals(AutoBackupStatusMessageName, System.StringComparison.InvariantCulture))
                            {
                                context.AutoBackupSettings = DeSerializeAutoBackupSettings(status.Name, formattedMessage);
                            }

                            statusMessageList.Add(formattedMessage);
                        }
                    }
                }
            }

            context.StatusMessages = statusMessageList;
            return(context);
        }
        /// <summary>
        /// Get the SQL Extension's context
        /// </summary>
        /// <returns></returns>
        private VirtualMachineSqlServerExtensionContext GetExtensionContext(ResourceExtensionReference r)
        {
            string extensionName = VirtualMachineSqlServerExtensionCmdletBase.ExtensionPublishedNamespace + "."
                                   + VirtualMachineSqlServerExtensionCmdletBase.ExtensionPublishedName;

            VirtualMachineSqlServerExtensionContext context = new VirtualMachineSqlServerExtensionContext
            {
                ExtensionName        = r.Name,
                Publisher            = r.Publisher,
                ReferenceName        = r.ReferenceName,
                Version              = r.Version,
                State                = r.State,
                PublicConfiguration  = PublicConfiguration,
                PrivateConfiguration = SecureStringHelper.GetSecureString(PrivateConfiguration),
                RoleName             = VM.GetInstance().RoleName,
            };

            // gather extension status messages
            List <string> statusMessageList = new List <string>();

            List <NSM.ResourceExtensionStatus> extensionStatusList = this.GetResourceExtensionStatusList(context);

            // enumerate over extension status list and gather status for autopatching and autobackup
            // Note: valid reference to an extension status list is returned by GetResourceExtensionStatusList()
            foreach (NSM.ResourceExtensionStatus res in extensionStatusList)
            {
                // Expected ReferenceName = "Microsoft.SqlServer.Management.SqlIaaSAgent"
                if (!res.HandlerName.Equals(extensionName, System.StringComparison.InvariantCulture))
                {
                    // skip all non-sql extensions
                    continue;
                }

                WriteVerboseWithTimestamp("Found SQL Extension:" + r.ReferenceName);

                if (null != res.ExtensionSettingStatus)
                {
                    context.SubStatusList   = res.ExtensionSettingStatus.SubStatusList;
                    context.ExtensionStatus = res.Status;

                    // Gather status messages because
                    // #$ISSUE- extension.Statuses is always null, follow up with Azure team
                    foreach (NSM.ResourceExtensionSubStatus status in res.ExtensionSettingStatus.SubStatusList)
                    {
                        if (null != status.FormattedMessage)
                        {
                            statusMessageList.Add(status.FormattedMessage.Message);
                        }
                    }
                    context.StatusMessages = statusMessageList;

                    // Extract sql configuration information from one of the sub statuses
                    if (context.SubStatusList == null ||
                        context.SubStatusList.FirstOrDefault(s =>
                                                             s.Name.Equals(SqlConfigurationStatusMessageName, StringComparison.InvariantCultureIgnoreCase)) == null)
                    {
                        WriteWarning(
                            String.Format(
                                CultureInfo.CurrentUICulture,
                                Properties.Resources.AzureVMSqlServerSqlConfigurationNotFound,
                                context.SubStatusList));

                        continue;
                    }

                    string sqlConfiguration = context.SubStatusList.First(s => s.Name.Equals(SqlConfigurationStatusMessageName, StringComparison.InvariantCultureIgnoreCase)).FormattedMessage.Message;

                    try
                    {
                        AzureVMSqlServerConfiguration settings = JsonConvert.DeserializeObject <AzureVMSqlServerConfiguration>(sqlConfiguration);

                        context.AutoBackupSettings = settings.AutoBackup == null ? null : new AutoBackupSettings()
                        {
                            Enable                = settings.AutoBackup.Enable,
                            EnableEncryption      = settings.AutoBackup.EnableEncryption,
                            RetentionPeriod       = settings.AutoBackup.RetentionPeriod,
                            StorageUrl            = settings.AutoBackup.StorageAccountUrl,
                            BackupSystemDbs       = settings.AutoBackup.BackupSystemDbs,
                            BackupScheduleType    = string.IsNullOrEmpty(settings.AutoBackup.BackupScheduleType) ? null : AutoBackupScheduleTypeMap[settings.AutoBackup.BackupScheduleType],
                            FullBackupFrequency   = settings.AutoBackup.FullBackupFrequency,
                            FullBackupStartTime   = settings.AutoBackup.FullBackupStartTime,
                            FullBackupWindowHours = settings.AutoBackup.FullBackupWindowHours,
                            LogBackupFrequency    = settings.AutoBackup.LogBackupFrequency
                        };

                        context.AutoPatchingSettings = settings.AutoPatching == null ? null : new AutoPatchingSettings()
                        {
                            Enable    = settings.AutoPatching.Enable,
                            DayOfWeek = settings.AutoPatching.DayOfWeek,
                            MaintenanceWindowDuration     = settings.AutoPatching.MaintenanceWindowDuration,
                            MaintenanceWindowStartingHour = settings.AutoPatching.MaintenanceWindowStartingHour,
                            PatchCategory = string.IsNullOrEmpty(settings.AutoPatching.PatchCategory) ? null : AutoPatchingCategoryMap[settings.AutoPatching.PatchCategory]
                        };

                        context.KeyVaultCredentialSettings = settings.AzureKeyVault == null ? null : new KeyVaultCredentialSettings()
                        {
                            Enable      = settings.AzureKeyVault.Enable,
                            Credentials = settings.AzureKeyVault.CredentialsList
                        };

                        context.AutoTelemetrySettings = settings.AutoTelemetryReport == null ? null : new AutoTelemetrySettings()
                        {
                            Region = settings.AutoTelemetryReport.Location,
                        };
                    }
                    catch (JsonException)
                    {
                        WriteWarning(
                            String.Format(
                                CultureInfo.CurrentUICulture,
                                Properties.Resources.AzureVMSqlServerWrongConfigFormat,
                                sqlConfiguration));
                    }
                }
            }

            return(context);
        }