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 = string.IsNullOrEmpty(InstanceSize) ? null :
                           (VirtualMachineRoleSize?)Enum.Parse(typeof(VirtualMachineRoleSize), InstanceSize, true),
                RoleType = "PersistentVMRole",
                Label = ServiceName,
                OSVirtualHardDisk = Mapper.Map(new OSVirtualHardDisk
                {
                    DiskName = null,
                    SourceImageName = ImageName,
                    MediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation),
                    HostCaching = HostCaching
                }, new Management.Compute.Models.OSVirtualHardDisk())
            };

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

            var netConfig = CreateNetworkConfigurationSet();

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

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

                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});
                }
                var configurationSets = new Collection<ConfigurationSet>{windowsConfig, netConfig};
                PersistentVMHelper.MapConfigurationSets(configurationSets).ForEach(c => vm.ConfigurationSets.Add(c));
            }
            else
            {
                var linuxConfig = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.LinuxProvisioningConfigurationSet
                {
                    HostName = string.IsNullOrEmpty(this.Name) ? this.ServiceName : this.Name,
                    UserName = this.LinuxUser,
                    UserPassword = this.Password,
                    DisableSshPasswordAuthentication = false
                };

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

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

                var configurationSets = new Collection<ConfigurationSet> { linuxConfig, netConfig };
                PersistentVMHelper.MapConfigurationSets(configurationSets).ForEach(c => vm.ConfigurationSets.Add(c));
            }

            return vm;
        }
Exemplo n.º 2
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 <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();
            }

            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.PersistentVMModel.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()
                    };

                    if (windowsConfig.StoredCertificateSettings == null)
                    {
                        windowsConfig.StoredCertificateSettings = new Model.PersistentVMModel.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.PersistentVMModel.LinuxProvisioningConfigurationSet
                    {
                        HostName     = string.IsNullOrEmpty(this.Name) ? this.ServiceName : this.Name,
                        UserName     = this.LinuxUser,
                        UserPassword = SecureStringHelper.GetSecureString(this.Password),
                        DisableSshPasswordAuthentication = false
                    };

                    if (this.SSHKeyPairs != null && this.SSHKeyPairs.Count > 0 ||
                        this.SSHPublicKeys != null && this.SSHPublicKeys.Count > 0)
                    {
                        linuxConfig.SSH = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.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);
        }
Exemplo n.º 3
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<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();
            }

            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.PersistentVMModel.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()
                    };

                    if (windowsConfig.StoredCertificateSettings == null)
                    {
                        windowsConfig.StoredCertificateSettings = new Model.PersistentVMModel.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.PersistentVMModel.LinuxProvisioningConfigurationSet
                    {
                        HostName = string.IsNullOrEmpty(this.Name) ? this.ServiceName : this.Name,
                        UserName = this.LinuxUser,
                        UserPassword = SecureStringHelper.GetSecureString(this.Password),
                        DisableSshPasswordAuthentication = false
                    };

                    if (this.SSHKeyPairs != null && this.SSHKeyPairs.Count > 0 ||
                        this.SSHPublicKeys != null && this.SSHPublicKeys.Count > 0)
                    {
                        linuxConfig.SSH = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.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;
        }
Exemplo n.º 4
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 = string.IsNullOrEmpty(InstanceSize) ? null :
                           (VirtualMachineRoleSize?)Enum.Parse(typeof(VirtualMachineRoleSize), InstanceSize, true),
                RoleType = "PersistentVMRole",
                Label = ServiceName,
                OSVirtualHardDisk = Mapper.Map(new OSVirtualHardDisk
                {
                    DiskName = null,
                    SourceImageName = ImageName,
                    MediaLink = string.IsNullOrEmpty(MediaLocation) ? null : new Uri(MediaLocation),
                    HostCaching = HostCaching
                }, new Management.Compute.Models.OSVirtualHardDisk())
            };

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

            var netConfig = CreateNetworkConfigurationSet();

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

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

                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});
                }
                var configurationSets = new Collection<ConfigurationSet>{windowsConfig, netConfig};
                PersistentVMHelper.MapConfigurationSets(configurationSets).ForEach(c => vm.ConfigurationSets.Add(c));
            }
            else
            {
                var linuxConfig = new Microsoft.WindowsAzure.Commands.ServiceManagement.Model.PersistentVMModel.LinuxProvisioningConfigurationSet
                {
                    HostName = string.IsNullOrEmpty(this.Name) ? this.ServiceName : this.Name,
                    UserName = this.LinuxUser,
                    UserPassword = this.Password,
                    DisableSshPasswordAuthentication = false
                };

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

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

                var configurationSets = new Collection<ConfigurationSet> { linuxConfig, netConfig };
                PersistentVMHelper.MapConfigurationSets(configurationSets).ForEach(c => vm.ConfigurationSets.Add(c));
            }

            return vm;
        }