protected VmInstanceConnectionSettings ApplyDefaults(ZoneConnectionSettings zoneSettings) { var prototype = new VmInstanceConnectionSettings(this.ProjectId, this.InstanceName); ApplyOverlay(prototype, zoneSettings, this); return(prototype); }
public VmInstanceConnectionSettings OverlayBy(VmInstanceConnectionSettings instanceSettings) { var result = VmInstanceConnectionSettings.CreateNew( instanceSettings.ProjectId, instanceSettings.InstanceName); ApplyOverlay(result, this, instanceSettings); return(result); }
public void SetVmInstanceSettings(VmInstanceConnectionSettings settings) { using (var key = this.projectRepository.OpenRegistryKey( settings.ProjectId, VmPrefix + settings.InstanceName, true)) { settings.Save(key); } }
//------------------------------------------------------------------------- // Create. //------------------------------------------------------------------------- public static VmInstanceConnectionSettings FromKey( string projectId, string instanceName, RegistryKey registryKey) { var settings = new VmInstanceConnectionSettings(projectId, instanceName); settings.InitializeFromKey(registryKey); return(settings); }
//--------------------------------------------------------------------- // Virtual Machines. //--------------------------------------------------------------------- public VmInstanceConnectionSettings GetVmInstanceSettings(string projectId, string instanceName) { using (var key = this.projectRepository.OpenRegistryKey( projectId, VmPrefix + instanceName, true)) { return(VmInstanceConnectionSettings.FromKey( projectId, instanceName, key)); } }
private async Task ConnectInstanceAsync( InstanceLocator instanceRef, VmInstanceConnectionSettings settings) { var tunnel = await this.jobService.RunInBackground( new JobDescription( $"Opening Cloud IAP tunnel to {instanceRef.Name}...", JobUserFeedbackType.BackgroundFeedback), async token => { try { var destination = new TunnelDestination( instanceRef, (ushort)settings.RdpPort.IntValue); // Give IAP the same timeout for probing as RDP itself. // Note that the timeouts are not additive. var timeout = TimeSpan.FromSeconds(settings.ConnectionTimeout.IntValue); return(await this.tunnelBrokerService.ConnectAsync( destination, new SameProcessRelayPolicy(), timeout) .ConfigureAwait(false)); } catch (NetworkStreamClosedException e) { throw new IapRdpConnectionFailedException( "Connecting to the instance failed. Make sure that you have " + "configured your firewall rules to permit Cloud IAP access " + $"to {instanceRef.Name}", HelpTopics.CreateIapFirewallRule, e); } catch (UnauthorizedException) { throw new IapRdpConnectionFailedException( "You are not authorized to connect to this VM instance.\n\n" + $"Verify that the Cloud IAP API is enabled in the project {instanceRef.ProjectId} " + "and that your user has the 'IAP-secured Tunnel User' role.", HelpTopics.IapAccess); } }).ConfigureAwait(true); this.remoteDesktopService.Connect( instanceRef, "localhost", (ushort)tunnel.LocalPort, settings); }
public async Task ActivateOrConnectInstanceAsync(IapRdpUrl url) { if (this.remoteDesktopService.TryActivate(url.Instance)) { // RDP session was active, nothing left to do. return; } VmInstanceConnectionSettings settings; if (this.projectExplorer.TryFindNode(url.Instance) is IProjectExplorerVmInstanceNode vmNode) { // We have a full set of settings for this VM, so use that as basis settings = (VmInstanceConnectionSettings) this.settingsService.GetConnectionSettings(vmNode); // Apply parameters from URL on top. settings.ApplyUrlQuery(url.Parameters); } else { settings = VmInstanceConnectionSettings.FromUrl(url); } await this.credentialPrompt.ShowCredentialsPromptAsync( this.window, url.Instance, settings, false) .ConfigureAwait(true); await ConnectInstanceAsync( url.Instance, settings) .ConfigureAwait(true); }