private void testConnectionButton_Click(object sender, EventArgs e) { string password = textBoxPassword.Text.Trim(); string address = textBoxHostAddress.Text.Trim(); string username = textBoxUsername.Text.Trim(); string title = string.Format(Messages.STORAGELINK_TEST_CONNECTION, address); DelegatedAsyncAction action = null; action = new DelegatedAsyncAction(_xenObjectCopy.Connection, title, "", "", s => { string secretUuid = Secret.CreateSecret(_xenObjectCopy.Connection.Session, password); var scanAction = new SrCslgStorageSystemScanAction(Program.MainWindow, _xenObjectCopy.Connection, Program.StorageLinkConnections.GetCopy(), address, username, secretUuid); scanAction.RunExternal(action.Session); string secretRef = Secret.get_by_uuid(_xenObjectCopy.Connection.Session, secretUuid); Secret.destroy(_xenObjectCopy.Connection.Session, secretRef); }, true); action.AppliesTo.Add(_xenObjectCopy.opaque_ref); new ActionProgressDialog(action, ProgressBarStyle.Marquee).ShowDialog(this); passFailLabel.Visible = true; passFailLabel.Text = action.Succeeded ? Messages.CSLG_EDIT_CONNECTION_PASSED : Messages.CSLG_EDIT_CONNECTION_FAILED; passFailPictureBox.Image = action.Succeeded ? Resources._000_Tick_h32bit_16 : Resources._000_Abort_h32bit_16; }
protected void RunProbe(Dictionary <string, string> dconf) { // CA-40132 create a new secret based on the secret that was passed in to the constructor. This is required so that the // server doesn't associate the secret with a particular SR and then delete it when the SR is detached. string newPasswordSecret = ""; if (!Helpers.BostonOrGreater(Connection)) { string secretRef = Secret.get_by_uuid(Session, _passwordSecret); string password = Secret.get_value(Session, secretRef); newPasswordSecret = Secret.CreateSecret(Session, password); } else { newPasswordSecret = Secret.CreateSecret(Session, _passwordSecret); } dconf["password_secret"] = newPasswordSecret; try { RelatedTask = XenAPI.SR.async_probe(Session, Helpers.GetMaster(Connection).opaque_ref, dconf, XenAPI.SR.SRTypes.cslg.ToString(), new Dictionary <String, String>()); PollToCompletion(); } finally { // now destroy the secret. if (!string.IsNullOrEmpty(newPasswordSecret)) { string newSecretRef = Secret.get_by_uuid(Session, newPasswordSecret); Secret.destroy(Session, newSecretRef); } } }
private string CreateSecret(string key, string value) { _dconf.Remove(key); string uuid = Secret.CreateSecret(Session, value); _dconf[string.Format("{0}_secret", key)] = uuid; return(uuid); }
public static void SetSecretInfo(IXenConnection connection, Dictionary <string, string> config, string infoKey, string infoValue) { if (string.IsNullOrEmpty(infoKey)) { return; } if (infoValue == null) { if (config.ContainsKey(infoKey)) { TryToDestroySecret(connection, config[infoKey]); config.Remove(infoKey); } } else if (config.ContainsKey(infoKey)) { try { string secretRef = Secret.get_by_uuid(connection.Session, config[infoKey]); Secret.set_value(connection.Session, secretRef, infoValue); } catch (Failure) { config[infoKey] = Secret.CreateSecret(connection.Session, infoValue); } catch (WebException) { config[infoKey] = Secret.CreateSecret(connection.Session, infoValue); } } else { config[infoKey] = Secret.CreateSecret(connection.Session, infoValue); } }
private string CreateSecret(Session session, string username, string password) { string val = string.Format("{0}{1}{2}", username, CREDENTIALS_SEPARATOR, password); return(Secret.CreateSecret(session, val)); }
private void SaveConfig(Host host, Host.PowerOnMode mode) { var newMode = mode.ToString(); var config = mode.Config; string secretuuid = ""; if (newMode == "iLO" && Helpers.StockholmOrGreater(Connection)) { //the UI should have already prevented us from getting here, but be defensive newMode = ""; config = new Dictionary <string, string>(); } try { if (newMode == "DRAC" || newMode == "iLO" || newMode != "wake-on-lan" && newMode != "") { if (config.ContainsKey("power_on_password_secret")) { secretuuid = Secret.CreateSecret(Session, config["power_on_password_secret"]); config["power_on_password_secret"] = secretuuid; } } else if (string.IsNullOrEmpty(newMode)) { //if WLB is on, we need to exclude the host from WLB power management, //since we cannot turn it back on if it is powered down automatically try { Pool pool = Helpers.GetPool(Connection); if (pool != null && WlbServerState.GetState(pool) == WlbServerState.ServerState.Enabled) { var hostConfig = new WlbHostConfiguration(host.uuid) { ParticipatesInPowerManagement = false }; var wlbAction = new SendWlbConfigurationAction(pool, hostConfig.ToDictionary(), SendWlbConfigurationKind.SetHostConfiguration); wlbAction.RunExternal(Session); } } catch { //Do nothing on failure. } } Host.set_power_on_mode(Session, host.opaque_ref, newMode, config); } catch { if (!string.IsNullOrEmpty(secretuuid)) { string secretRef = Secret.get_by_uuid(Session, secretuuid); Secret.destroy(Session, secretRef); } throw; } }
protected void SaveConfig(Host host) { string secretuuid = ""; try { Dictionary <string, string> powerONConfig = new Dictionary <string, string>(); if (newMode == "DRAC" || newMode == "iLO") { powerONConfig.Add("power_on_ip", ip); powerONConfig.Add("power_on_user", user); secretuuid = Secret.CreateSecret(Session, password); powerONConfig.Add("power_on_password_secret", secretuuid); } else if (newMode != "wake-on-lan" && newMode != "") { foreach (KeyValuePair <string, string> pair in customConfig) { if (pair.Key == "power_on_password_secret") { secretuuid = Secret.CreateSecret(Session, pair.Value); powerONConfig.Add(pair.Key, secretuuid); } else { powerONConfig.Add(pair.Key, pair.Value); } } } else if (string.IsNullOrEmpty(newMode)) { // We don't want this bit to alter the function of the main action so... try { Pool pool = Core.Helpers.GetPool(this.Connection); if (null != pool) { if (WlbServerState.GetState(pool) == XenAdmin.Wlb.WlbServerState.ServerState.Enabled) { //Tell WLB to not allow this host to be powered down automatically, since we cannot turn it back on WlbHostConfiguration hostConfig = new WlbHostConfiguration(host.uuid); hostConfig.ParticipatesInPowerManagement = false; //Use the existing SendWlbConfig action, as it wraps the config functionality // as well as the RBAC checks. SendWlbConfigurationAction wlbAction = new SendWlbConfigurationAction(pool, hostConfig.ToDictionary(), SendWlbConfigurationKind.SetHostConfiguration); wlbAction.RunExternal(Session); } } } catch (Exception) { //Do nothing on failure. } } Host.set_power_on_mode(Session, host.opaque_ref, newMode, powerONConfig); } catch (Exception e) { if (!string.IsNullOrEmpty(secretuuid)) { string secretRef = Secret.get_by_uuid(Session, secretuuid); Secret.destroy(Session, secretRef); } throw e; } }