2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using XenAdmin.Core;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Actions
|
|
|
|
|
{
|
2022-12-22 00:02:07 +01:00
|
|
|
|
public class SrReattachAction : AsyncAction
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
|
|
|
|
|
|
private readonly SR sr;
|
2022-12-22 00:02:07 +01:00
|
|
|
|
private readonly string name;
|
|
|
|
|
private readonly string description;
|
|
|
|
|
private readonly Dictionary<string, string> dconf;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// RBAC dependencies needed to reattach SR.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static RbacMethodList StaticRBACDependencies = new RbacMethodList("sr.set_name_label",
|
|
|
|
|
"sr.set_name_description",
|
|
|
|
|
"pbd.async_create",
|
|
|
|
|
"pbd.async_plug");
|
|
|
|
|
|
2022-12-22 00:02:07 +01:00
|
|
|
|
public SrReattachAction(SR sr, string name, string description, Dictionary<string, string> dconf)
|
|
|
|
|
: base(sr.Connection, string.Format(Messages.ACTION_SR_ATTACHING_TITLE, name, Helpers.GetName(sr.Connection)))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
this.sr = sr;
|
|
|
|
|
this.name = name;
|
|
|
|
|
this.description = description;
|
|
|
|
|
this.dconf = dconf;
|
2022-12-22 00:02:07 +01:00
|
|
|
|
ApiMethodsToRoleCheck.AddRange(StaticRBACDependencies);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Run()
|
|
|
|
|
{
|
|
|
|
|
log.Debug("Running SR Reconfigure Action");
|
|
|
|
|
log.DebugFormat("SR uuid = '{0}'", sr.uuid);
|
|
|
|
|
log.DebugFormat("name = '{0}'", name);
|
|
|
|
|
log.DebugFormat("description = '{0}'", description);
|
|
|
|
|
|
|
|
|
|
Description = Messages.ACTION_SR_ATTACHING;
|
2016-03-30 16:39:00 +02:00
|
|
|
|
|
|
|
|
|
// Repair the SR with new PBDs for each host in the pool
|
2013-06-24 13:41:48 +02:00
|
|
|
|
PBD pbdTemplate = new PBD();
|
|
|
|
|
pbdTemplate.currently_attached = false;
|
|
|
|
|
pbdTemplate.device_config = dconf;
|
|
|
|
|
pbdTemplate.SR = new XenRef<SR>(sr.opaque_ref);
|
|
|
|
|
|
|
|
|
|
int delta = 100 / (Connection.Cache.HostCount * 2);
|
|
|
|
|
foreach (Host host in Connection.Cache.Hosts)
|
|
|
|
|
{
|
|
|
|
|
// Create the PBD
|
2017-09-03 04:33:29 +02:00
|
|
|
|
log.DebugFormat("Creating PBD for host {0}", host.Name());
|
2022-12-22 00:02:07 +01:00
|
|
|
|
Description = string.Format(Messages.ACTION_SR_REPAIR_CREATE_PBD, Helpers.GetName(host));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
pbdTemplate.host = new XenRef<Host>(host.opaque_ref);
|
2022-12-22 00:02:07 +01:00
|
|
|
|
RelatedTask = PBD.async_create(Session, pbdTemplate);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
PollToCompletion(PercentComplete, PercentComplete + delta);
|
2022-12-22 00:02:07 +01:00
|
|
|
|
XenRef<PBD> pbdRef = new XenRef<PBD>(Result);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
// Now plug the PBD
|
2017-09-03 04:33:29 +02:00
|
|
|
|
log.DebugFormat("Plugging PBD for host {0}", host.Name());
|
2022-12-22 00:02:07 +01:00
|
|
|
|
Description = string.Format(Messages.ACTION_SR_REPAIR_PLUGGING_PBD, Helpers.GetName(host));
|
|
|
|
|
RelatedTask = PBD.async_plug(Session, pbdRef);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
PollToCompletion(PercentComplete, PercentComplete + delta);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 16:39:00 +02:00
|
|
|
|
// Update the name and description of the SR
|
2022-12-22 00:02:07 +01:00
|
|
|
|
SR.set_name_label(Session, sr.opaque_ref, name);
|
|
|
|
|
SR.set_name_description(Session, sr.opaque_ref, description);
|
2016-03-30 16:39:00 +02:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Description = Messages.ACTION_SR_ATTACH_SUCCESSFUL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|