protected override void Run() { log.Debug("Running SR.Create()"); log.DebugFormat("host='{0}'", Host.Name); log.DebugFormat("name='{0}'", _srName); log.DebugFormat("description='{0}'", _srDescription); log.DebugFormat("type='{0}'", _srType); log.DebugFormat("content type='{0}'", _srContentType); log.DebugFormat("is shared='{0}'", _srIsShared); string secretuuid = null; if (Helpers.MidnightRideOrGreater(Connection)) { string value; if (_dconf.TryGetValue("cifspassword", out value)) { secretuuid = CreateSecret("cifspassword", value); } else if (_dconf.TryGetValue("password", out value)) { secretuuid = CreateSecret("password", value); } else if (_dconf.TryGetValue("chappassword", out value)) { secretuuid = CreateSecret("chappassword", value); } } if (Helpers.MidnightRideOrGreater(Connection)) { string tempvalue; System.Diagnostics.Debug.Assert(!_dconf.TryGetValue("password", out tempvalue), "The device config contains 'password', but it should have already been removed!"); System.Diagnostics.Debug.Assert(!_dconf.TryGetValue("cifspassword", out tempvalue), "The device config contains 'cifspassword', but it should have already been removed!"); System.Diagnostics.Debug.Assert(!_dconf.TryGetValue("chappassword", out tempvalue), "The device config contains 'chappassword', but it should have already been removed!"); } if (_srType == SR.SRTypes.cslg && !Helpers.BostonOrGreater(Connection)) { // make sure this connection is added to the storagelink service. StorageLinkConnection slCon = _SLConnection; if (slCon != null) { slCon.AddXenConnection(Connection); } } Description = Messages.ACTION_SR_CREATING; XenRef <SR> sr; try { sr = XenAPI.SR.create(Session, Host.opaque_ref, _dconf, 0, _srName, _srDescription, _srType.ToString().ToLowerInvariant(), _srContentType, _srIsShared, new Dictionary <string, string>()); Result = sr; } catch { if (!string.IsNullOrEmpty(secretuuid)) { string opaqref = Secret.get_by_uuid(Session, secretuuid); Secret.destroy(Session, opaqref); } throw; } finally { // Destroy secret after the SR creation is complete. This is safe // since all PBDs will have duplicated the secret (CA-113396). // // We do this on a best-effort basis because some types of errors // mean the secret was never actually created, so the operation will // fail, masking any earlier error (CA-145254), or causing a successful // SR.create to be reported as an error. The worst that can happen is // that an unused secret will be left lying around without warning. try { if (!string.IsNullOrEmpty(secretuuid) && Helpers.CreedenceOrGreater(Connection)) { string opaqref = Secret.get_by_uuid(Session, secretuuid); Secret.destroy(Session, opaqref); } } catch { } } log.Debug("Checking that SR.create() actually succeeded"); foreach (XenRef <PBD> pbdRef in XenAPI.SR.get_PBDs(Session, sr.opaque_ref)) { if (!XenAPI.PBD.get_currently_attached(Session, pbdRef)) { // The automatic plug done by the SR.create has failed to plug this PDB: // try the plug manually, and report the failure. Roll back the operation // by forgetting the SR. try { XenAPI.PBD.plug(this.Session, pbdRef); } catch (Exception exn) { if (exn is Failure) { Failure f = (Failure)exn; if (f.ErrorDescription[0] == Failure.HOST_OFFLINE || f.ErrorDescription[0] == Failure.HOST_STILL_BOOTING) { log.Warn("Unable to check storage settings, due to host being down", f); } } else { log.Debug("Plug failed on a PBD: performing SR.forget"); ForgetFailedSR(sr); throw; } } } } Dictionary <string, string> other_config = new Dictionary <string, string>(); other_config.Add("auto-scan", _srContentType == XenAPI.SR.Content_Type_ISO ? "true" : "false"); XenAPI.SR.set_other_config(Session, Result, other_config); if (isFirstSharedNonISOSR()) { SR new_sr = Connection.WaitForCache(new XenRef <SR>(Result), GetCancelling); if (Cancelling) { throw new CancelledException(); } if (new_sr == null) { throw new Failure(Failure.HANDLE_INVALID, "SR", Result); } // Set this SR to be the default new SrAction(SrActionKind.SetAsDefault, new_sr).RunExternal(Session); } Description = Messages.ACTION_SR_CREATE_SUCCESSFUL; }
protected override void Run() { log.Debug("Running SR.Create()"); log.DebugFormat("host='{0}'", Host.Name); log.DebugFormat("name='{0}'", _srName); log.DebugFormat("description='{0}'", _srDescription); log.DebugFormat("type='{0}'", _srType); log.DebugFormat("content type='{0}'", _srContentType); log.DebugFormat("is shared='{0}'", _srIsShared); string secretuuid = null; if (Helpers.MidnightRideOrGreater(Connection)) { string value; if (_dconf.TryGetValue("cifspassword", out value)) { secretuuid = CreateSecret("cifspassword", value); } else if (_dconf.TryGetValue("password", out value)) { secretuuid = CreateSecret("password", value); } else if (_dconf.TryGetValue("chappassword", out value)) { secretuuid = CreateSecret("chappassword", value); } } if (_srType == SR.SRTypes.cslg && !Helpers.BostonOrGreater(Connection)) { // make sure this connection is added to the storagelink service. StorageLinkConnection slCon = _SLConnection; if (slCon != null) { slCon.AddXenConnection(Connection); } } Description = Messages.ACTION_SR_CREATING; XenRef <SR> sr; try { sr = XenAPI.SR.create(Session, Host.opaque_ref, _dconf, 0, _srName, _srDescription, _srType.ToString().ToLowerInvariant(), _srContentType, _srIsShared, new Dictionary <string, string>()); Result = sr; } catch { if (!string.IsNullOrEmpty(secretuuid)) { string opaqref = Secret.get_by_uuid(Session, secretuuid); Secret.destroy(Session, opaqref); } throw; } log.Debug("Checking that SR.create() actually succeeded"); foreach (XenRef <PBD> pbdRef in XenAPI.SR.get_PBDs(Session, sr.opaque_ref)) { if (!XenAPI.PBD.get_currently_attached(Session, pbdRef)) { // The automatic plug done by the SR.create has failed to plug this PDB: // try the plug manually, and report the failure. Roll back the operation // by forgetting the SR. try { XenAPI.PBD.plug(this.Session, pbdRef); } catch (Exception exn) { if (exn is Failure) { Failure f = (Failure)exn; if (f.ErrorDescription[0] == Failure.HOST_OFFLINE || f.ErrorDescription[0] == Failure.HOST_STILL_BOOTING) { log.Warn("Unable to check storage settings, due to host being down", f); } } else { log.Debug("Plug failed on a PBD: performing SR.forget"); ForgetFailedSR(sr); throw; } } } } Dictionary <string, string> other_config = new Dictionary <string, string>(); other_config.Add("auto-scan", _srContentType == XenAPI.SR.Content_Type_ISO ? "true" : "false"); XenAPI.SR.set_other_config(Session, Result, other_config); if (isFirstSharedNonISOSR()) { SR new_sr = Connection.WaitForCache(new XenRef <SR>(Result), GetCancelling); if (Cancelling) { throw new CancelledException(); } if (new_sr == null) { throw new Failure(Failure.HANDLE_INVALID, "SR", Result); } // Set this SR to be the default new SrAction(SrActionKind.SetAsDefault, new_sr).RunExternal(Session); } Description = Messages.ACTION_SR_CREATE_SUCCESSFUL; }
/// <summary> /// Runs this instance. /// </summary> protected override void Run() { Dictionary <String, String> dconf = GetAuthenticationDeviceConfig(); Log.DebugFormat("Attempting to find SRs on CSLG {0}.", dconf["target"]); if (Connection != null && Helpers.MidnightRideOrGreater(Connection) && !Helpers.CowleyOrGreater(Connection)) { RunProbe(dconf); _cslgSystemStorages = new ReadOnlyCollection <CslgSystemStorage>(ParseStorageSystemsXml(Util.GetContentsOfValueNode(Result))); } else if (Connection != null && Helpers.BostonOrGreater(Connection)) { dconf["adapterid"] = _adapterid; RunProbe(dconf); if (!string.IsNullOrEmpty(Result)) { _cslgSystemStorages = new ReadOnlyCollection <CslgSystemStorage>(ParseStorageSystemsXml(Util.GetContentsOfValueNode(Result))); } } else { bool created = false; if (Connection != null) { // There will be no connection if a storagelink-object is selected in the tree. string secretRef = Secret.get_by_uuid(Connection.Session, dconf["password_secret"]); string password = Secret.get_value(Connection.Session, secretRef); StorageLinkConnection = _SLConnections.Find(c => c.Host == dconf["target"] && c.Username == dconf["username"] && c.Password == password); if (StorageLinkConnection == null) { // the user has clicked the "test connection" button in the properties dialog then // the storagelink connection won't exist in the Program.StorageLinkConnections collection. StorageLinkConnection = new StorageLinkConnection(_invoker, dconf["target"], dconf["username"], password); StorageLinkConnection.BeginConnect(); created = true; } } else { StorageLinkConnection = _SLConnections.Find(c => c.Host == dconf["target"] && c.Username == dconf["username"]); } try { var list = new List <CslgSystemStorage>(); // wait for storagelink connection to finish populating for (int i = 0; i < 600 && StorageLinkConnection.ConnectionState == StorageLinkConnectionState.Connecting; i++) { Thread.Sleep(100); } if (!string.IsNullOrEmpty(StorageLinkConnection.Error)) { throw new InvalidOperationException(StorageLinkConnection.Error); } if (StorageLinkConnection.ConnectionState != StorageLinkConnectionState.Connected) { throw new InvalidOperationException(string.Format(Messages.STORAGELINK_UNABLE_TO_CONNECT, dconf["target"])); } foreach (StorageLinkSystem s in StorageLinkConnection.Cache.StorageSystems) { var provisioningOptions = new List <CslgParameter> { new CslgParameter(null, Messages.NEWSR_CSLG_NONE) }; if ((s.Capabilities & StorageLinkEnums.StorageSystemCapabilities.POOL_LEVEL_DEDUPLICATION) != 0) { provisioningOptions.Add(new CslgParameter("DEDUP", Messages.NEWSR_CSLG_DEDUPLICATION)); } var protocols = new List <CslgParameter> { new CslgParameter(null, Messages.NEWSR_CSLG_AUTO) }; if ((s.Capabilities & StorageLinkEnums.StorageSystemCapabilities.ISCSI) != 0) { protocols.Add(new CslgParameter("ISCSI", Messages.NEWSR_CSLG_ISCSI)); } if ((s.Capabilities & StorageLinkEnums.StorageSystemCapabilities.FIBRE_CHANNEL) != 0) { protocols.Add(new CslgParameter("FC", Messages.NEWSR_CSLG_FC)); } list.Add(new CslgSystemStorage(s.ToString(), s.StorageSystemId, protocols, provisioningOptions, false, s)); } _cslgSystemStorages = new ReadOnlyCollection <CslgSystemStorage>(list); } finally { if (created) { StorageLinkConnection.EndConnect(); } } } }
public void SetUp() { _ws = new MockStorageLinkWebService("Mock", "bla", "bla"); _con = new StorageLinkConnection(null, _ws); }
public StorageLinkServer(StorageLinkConnection storageLinkConnection, string opaque_ref, string friendlyName) : base(storageLinkConnection, opaque_ref, friendlyName) { base.opaque_ref = opaque_ref; }