protected override void OnCompleted() { if (Succeeded) { ConnectionsManager.ClearCacheAndRemoveConnection(Host.Connection); } ClearAllDelegates(); base.OnCompleted(); }
protected override void Run() { double p2 = 100.0 / _slaves.Count; int i2 = 0; this.Description = Messages.POOLCREATE_CREATING; Pool master_pool = Helpers.GetPoolOfOne(Connection); if (master_pool == null) { throw new XenAPI.Failure(XenAPI.Failure.INTERNAL_ERROR, Messages.CACHE_NOT_YET_POPULATED); } FixLicensing(master_pool, _hostsToRelicense, DoOnLicensingFailure); FixAd(master_pool, _hostsToAdConfigure, GetAdCredentials); FixCpus(master_pool, _hostsToCpuMask, AcceptNTolChanges); XenAPI.Pool.set_name_label(Session, master_pool.opaque_ref, _name); XenAPI.Pool.set_name_description(Session, master_pool.opaque_ref, _description); ClearNonSharedSrs(master_pool); Description = Messages.ACTION_POOL_WIZARD_CREATE_DESCRIPTION_ADDING_MEMBERS; foreach (Host slave in _slaves) { int lo = (int)(i2 * p2); int hi = (int)((i2 + 1) * p2); // RBAC: We have forced identical AD configs, but this will fail unless both slave-to-be and master sessions have the correct role. Session = NewSession(slave.Connection); RelatedTask = XenAPI.Pool.async_join(Session, master_pool.Connection.Hostname, master_pool.Connection.Username, master_pool.Connection.Password); PollToCompletion(lo, hi); // No need to log out the Session, because the slaves are all going to reset their databases anyway. i2++; } // Note that Session is now a useless slave Session, so we can't do any more actions on the master. // Save the original Session if you need it. Description = Messages.ACTION_POOL_WIZARD_CREATE_DESCRIPTION_DISCONNECTING; foreach (Host slave in _slaves) { slave.Connection.EndConnect(); // EndConnect will clear the cache itself, but on a background thread. To prevent a race between the event handlers // being removed with the connection, and the final cache clear events we explicitly call cache clear once more before // removing the connection. ConnectionsManager.ClearCacheAndRemoveConnection(slave.Connection); } Description = Messages.ACTION_POOL_WIZARD_CREATE_DESCRIPTION_DONE; }
private static void ShowConnectingDialogError(Form owner, IXenConnection connection, Exception error) { if (error is ExpressRestriction e) { Program.Invoke(Program.MainWindow, delegate() { new LicenseWarningDialog(e.HostName, e.ExistingHostName).ShowDialog(owner); }); return; } if (error is Failure f) { if (f.ErrorDescription[0] == Failure.HOST_IS_SLAVE) { string oldHost = connection.Name; string poolMasterName = f.ErrorDescription[1]; string pool_name = XenConnection.ConnectedElsewhere(poolMasterName); if (pool_name != null) { if (!Program.RunInAutomatedTestMode) { if (pool_name == oldHost) { using (var dlg = new InformationDialog(string.Format(Messages.OLD_CONNECTION_ALREADY_CONNECTED, pool_name)) { WindowTitle = Messages.ADD_NEW_CONNECT_TO }) { dlg.ShowDialog(owner); } } else { using (var dlg = new InformationDialog(string.Format(Messages.SLAVE_ALREADY_CONNECTED, oldHost, pool_name)) { WindowTitle = Messages.ADD_NEW_CONNECT_TO }) { dlg.ShowDialog(owner); } } } } else { DialogResult dialogResult; using (var dlg = new WarningDialog(string.Format(Messages.SLAVE_CONNECTION_ERROR, oldHost, poolMasterName), ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo) { WindowTitle = Messages.CONNECT_TO_SERVER }) { dialogResult = dlg.ShowDialog(owner); } if (DialogResult.Yes == dialogResult) { ((XenConnection)connection).Hostname = poolMasterName; BeginConnect(connection, true, owner, false); } } } else if (f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED) { AddError(owner, connection, Messages.ERROR_NO_PERMISSION, Messages.SOLUTION_NO_PERMISSION); } else if (f.ErrorDescription[0] == XenAPI.Failure.SESSION_AUTHENTICATION_FAILED) { AddError(owner, connection, Messages.ERROR_AUTHENTICATION, Messages.SOLUTION_AUTHENTICATION); } else if (f.ErrorDescription[0] == Failure.HOST_STILL_BOOTING) { AddError(owner, connection, Messages.ERROR_HOST_STILL_BOOTING, Messages.SOLUTION_HOST_STILL_BOOTING); } else { AddError(owner, connection, string.IsNullOrEmpty(f.Message) ? Messages.ERROR_UNKNOWN : f.Message, string.Empty); } } else if (error is WebException w) { if (((XenConnection)connection).SuppressErrors) { return; } var solutionCheckXenServer = Properties.Settings.Default.ProxySetting != (int)HTTPHelper.ProxyStyle.DirectConnection ? Messages.SOLUTION_CHECK_XENSERVER_WITH_PROXY : Messages.SOLUTION_CHECK_XENSERVER; switch (w.Status) { case WebExceptionStatus.ConnectionClosed: AddError(owner, connection, Messages.CONNECTION_CLOSED_BY_SERVER, string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname)); break; case WebExceptionStatus.ConnectFailure: AddError(owner, connection, Messages.CONNECTION_REFUSED, string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname)); break; case WebExceptionStatus.ProtocolError: if (w.Message != null && w.Message.Contains("(404)")) { AddError(owner, connection, string.Format(Messages.ERROR_NO_XENSERVER, ((XenConnection)connection).Hostname), string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname)); } else if (w.Message != null && w.Message.Contains("(407)")) { string proxyAddress = Properties.Settings.Default.ProxyAddress; AddError(owner, connection, string.Format(Messages.ERROR_PROXY_AUTHENTICATION, proxyAddress), string.Format(Messages.SOLUTION_CHECK_PROXY, proxyAddress)); } else { AddError(owner, connection, Messages.ERROR_UNKNOWN, Messages.SOLUTION_UNKNOWN); } break; case WebExceptionStatus.NameResolutionFailure: AddError(owner, connection, string.Format(Messages.ERROR_NOT_FOUND, ((XenConnection)connection).Hostname), Messages.SOLUTION_NOT_FOUND); break; case WebExceptionStatus.ReceiveFailure: case WebExceptionStatus.SendFailure: AddError(owner, connection, string.Format(Messages.ERROR_NO_XENSERVER, ((XenConnection)connection).Hostname), string.Format(solutionCheckXenServer, ((XenConnection)connection).Hostname)); break; case WebExceptionStatus.SecureChannelFailure: AddError(owner, connection, string.Format(Messages.ERROR_SECURE_CHANNEL_FAILURE, ((XenConnection)connection).Hostname), Messages.SOLUTION_UNKNOWN); break; default: AddError(owner, connection, Messages.ERROR_UNKNOWN, Messages.SOLUTION_UNKNOWN); break; } } else if (error is UriFormatException) { AddError(owner, connection, string.Format(Messages.ERROR_INVALID_URI, connection.Name), Messages.SOLUTION_NOT_FOUND); } else if (error is FileNotFoundException) { // If you're using the DbProxy AddError(owner, connection, string.Format(string.Format(Messages.ERROR_FILE_NOT_FOUND, ((XenConnection)connection).Hostname), connection.Name), Messages.SOLUTION_UNKNOWN); } else if (error is ConnectionExists c) { ConnectionsManager.ClearCacheAndRemoveConnection(connection); if (!Program.RunInAutomatedTestMode) { using (var dlg = new InformationDialog(c.GetDialogMessage(connection))) dlg.ShowDialog(owner); } } else if (error is ArgumentException) { // This happens if the server API is incompatible with our bindings. This should // never happen in production, but will happen during development if a field // changes type, for example. AddError(owner, connection, Messages.SERVER_API_INCOMPATIBLE, Messages.SOLUTION_UNKNOWN); } else if (error is ServerNotSupported) { // Server version is too old for this version of XenCenter AddError(owner, connection, string.Format(Messages.SERVER_TOO_OLD, BrandManager.ProductVersion70), Messages.SERVER_TOO_OLD_SOLUTION); } else { if (((XenConnection)connection).SuppressErrors) { return; } AddError(owner, connection, string.Format(Messages.ERROR_UNKNOWN, ((XenConnection)connection).Hostname), Messages.SOLUTION_UNKNOWN); } }
internal static void ShowConnectingDialogError_(Form owner, IXenConnection connection, Exception error) { if (error is ExpressRestriction) { ExpressRestriction e = (ExpressRestriction)error; Program.Invoke(Program.MainWindow, delegate() { new LicenseWarningDialog(e.HostName, e.ExistingHostName).ShowDialog(owner); }); return; } if (error is Failure) { Failure f = (Failure)error; if (f.ErrorDescription[0] == Failure.HOST_IS_SLAVE) { string oldHost = connection.Name; string poolMasterName = f.ErrorDescription[1]; string pool_name = XenConnection.ConnectedElsewhere(poolMasterName); if (pool_name != null) { if (!Program.RunInAutomatedTestMode) { if (pool_name == oldHost) { new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Information, string.Format(Messages.OLD_CONNECTION_ALREADY_CONNECTED, pool_name), Messages.ADD_NEW_CONNECT_TO)).ShowDialog(owner); } else { new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Information, string.Format(Messages.SLAVE_ALREADY_CONNECTED, oldHost, pool_name), Messages.ADD_NEW_CONNECT_TO)).ShowDialog(owner); } } } else { if (DialogResult.Yes == new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Warning, String.Format(Messages.SLAVE_CONNECTION_ERROR, oldHost, poolMasterName), Messages.CONNECT_TO_SERVER), ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo).ShowDialog(owner)) { ((XenConnection)connection).Hostname = poolMasterName; BeginConnect(connection, true, owner, false); } } } else if (f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED) { AddError(owner, connection, Messages.ERROR_NO_PERMISSION, Messages.SOLUTION_NO_PERMISSION); } else if (f.ErrorDescription[0] == XenAPI.Failure.SESSION_AUTHENTICATION_FAILED) { AddError(owner, connection, Messages.ERROR_AUTHENTICATION, Messages.SOLUTION_AUTHENTICATION); } else if (f.ErrorDescription[0] == Failure.HOST_STILL_BOOTING) { AddError(owner, connection, Messages.ERROR_HOST_STILL_BOOTING, Messages.SOLUTION_HOST_STILL_BOOTING); } else { AddError(owner, connection, string.IsNullOrEmpty(f.Message) ? Messages.ERROR_UNKNOWN : f.Message, string.Empty); } } else if (error is WebException) { if (((XenConnection)connection).SupressErrors) { return; } WebException w = (WebException)error; switch (w.Status) { case WebExceptionStatus.ConnectionClosed: AddError(owner, connection, Messages.CONNECTION_CLOSED_BY_SERVER, string.Format(Messages.SOLUTION_CHECK_XENSERVER, ((XenConnection)connection).Hostname)); break; case WebExceptionStatus.ConnectFailure: AddError(owner, connection, Messages.CONNECTION_REFUSED, string.Format(Messages.SOLUTION_CHECK_XENSERVER, ((XenConnection)connection).Hostname)); break; case WebExceptionStatus.ProtocolError: if (w.Message != null && w.Message.Contains("(404)")) { AddError(owner, connection, string.Format(Messages.ERROR_NO_XENSERVER, ((XenConnection)connection).Hostname), string.Format(Messages.SOLUTION_CHECK_XENSERVER, ((XenConnection)connection).Hostname)); } else { AddError(owner, connection, Messages.ERROR_UNKNOWN, Messages.SOLUTION_UNKNOWN); } break; case WebExceptionStatus.NameResolutionFailure: AddError(owner, connection, string.Format(Messages.ERROR_NOT_FOUND, ((XenConnection)connection).Hostname), Messages.SOLUTION_NOT_FOUND); break; case WebExceptionStatus.ReceiveFailure: case WebExceptionStatus.SendFailure: AddError(owner, connection, string.Format(Messages.ERROR_NO_XENSERVER, ((XenConnection)connection).Hostname), string.Format(Messages.SOLUTION_CHECK_XENSERVER, ((XenConnection)connection).Hostname)); break; default: AddError(owner, connection, Messages.ERROR_UNKNOWN, Messages.SOLUTION_UNKNOWN); break; } } else if (error is UriFormatException) { AddError(owner, connection, string.Format(Messages.ERROR_INVALID_URI, connection.Name), Messages.SOLUTION_NOT_FOUND); } else if (error is FileNotFoundException) { // If you're using the DbProxy AddError(owner, connection, string.Format(string.Format(Messages.ERROR_FILE_NOT_FOUND, ((XenConnection)connection).Hostname), connection.Name), Messages.SOLUTION_UNKNOWN); } else if (error is ConnectionExists) { ConnectionsManager.ClearCacheAndRemoveConnection(connection); if (!Program.RunInAutomatedTestMode) { ConnectionExists c = error as ConnectionExists; new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Information, c.GetDialogMessage(connection), Messages.XENCENTER)).ShowDialog(owner); } } else if (error is ArgumentException) { // This happens if the server API is incompatible with our bindings. This should // never happen in production, but will happen during development if a field // changes type, for example. AddError(owner, connection, Messages.SERVER_API_INCOMPATIBLE, Messages.SOLUTION_UNKNOWN); } else if (error is ServerNotSupported) { // Server version is too old for this version of XenCenter AddError(owner, connection, Messages.SERVER_TOO_OLD, Messages.SERVER_TOO_OLD_SOLUTION); } else { if (((XenConnection)connection).SupressErrors) { return; } AddError(owner, connection, string.Format(Messages.ERROR_UNKNOWN, ((XenConnection)connection).Hostname), Messages.SOLUTION_UNKNOWN); } }