Some more code simplifications.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2018-03-29 19:16:44 +01:00
parent 4b0aa132d2
commit 6adcd2b83f
3 changed files with 16 additions and 38 deletions

View File

@ -248,6 +248,7 @@ namespace XenAdmin.Wizards.DRWizards
private const String LUNSERIAL = "LUNSerial";
private const String SCSIID = "SCSIid";
private const String METADATA = "metadata";
private void ScanForSRs(SR.SRTypes type)
{
@ -262,7 +263,8 @@ namespace XenAdmin.Wizards.DRWizards
foreach (FibreChannelDevice device in devices)
{
string deviceId = string.IsNullOrEmpty(device.SCSIid) ? device.Path : device.SCSIid;
var metadataSrs = ScanDeviceForSRs(SR.SRTypes.lvmohba, deviceId, GetFCDeviceConfig(device));
var metadataSrs = ScanDeviceForSRs(SR.SRTypes.lvmohba, deviceId,
new Dictionary<string, string> {{SCSIID, device.SCSIid}});
if (metadataSrs != null && metadataSrs.Count > 0)
srs.AddRange(metadataSrs);
}
@ -310,30 +312,15 @@ namespace XenAdmin.Wizards.DRWizards
return action.Succeeded ? action.FibreChannelDevices : null;
}
private Dictionary<String, String> GetFCDeviceConfig(FibreChannelDevice device)
{
if (device == null)
return null;
var dconf = new Dictionary<string, string>();
dconf[SrProbeAction.SCSIid] = device.SCSIid;
return dconf;
}
private const String METADATA = "metadata";
private List<SR.SRInfo> ScanDeviceForSRs(SR.SRTypes type, string deviceId, Dictionary<string, string> dconf)
{
Host master = Helpers.GetMaster(Connection);
if (master == null || dconf == null)
return null;
Dictionary<string, string> smconf = new Dictionary<string, string>();
smconf[METADATA] = "true";
// Start probe
SrProbeAction srProbeAction = new SrProbeAction(Connection, master, type, dconf, smconf);
SrProbeAction srProbeAction = new SrProbeAction(Connection, master, type, dconf,
new Dictionary<string, string> {{METADATA, "true"}});
using (var dlg = new ActionProgressDialog(srProbeAction, ProgressBarStyle.Marquee))
dlg.ShowDialog(this);

View File

@ -31,9 +31,7 @@
using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;
using XenAdmin.Actions;
using XenAdmin.Core;
using XenAdmin.Network;
using XenAPI;
@ -59,7 +57,7 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages
public LvmOhbaSrDescriptor(FibreChannelDevice device, IXenConnection connection)
{
Device = device;
DeviceConfig[SrProbeAction.SCSIid] = device.SCSIid;
DeviceConfig["SCSIid"] = device.SCSIid;
Description = string.Format(Messages.NEWSR_LVMOHBA_DESCRIPTION, device.Vendor, device.Serial);
}
@ -78,8 +76,8 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages
{
public FcoeSrDescriptor(FibreChannelDevice device) : base(device)
{
DeviceConfig[SrProbeAction.SCSIid] = device.SCSIid;
DeviceConfig[SrProbeAction.PATH] = device.Path;
DeviceConfig["SCSIid"] = device.SCSIid;
DeviceConfig["path"] = device.Path;
Description = string.Format(Messages.NEWSR_LVMOFCOE_DESCRIPTION, device.Vendor, device.Serial);
}

View File

@ -43,9 +43,6 @@ namespace XenAdmin.Actions
private readonly Host host;
public readonly SR.SRTypes SrType;
private readonly Dictionary<String, String> dconf;
public const String DEVICE = "device";
public const String SCSIid = "SCSIid";
public const String PATH = "path";
public List<Probe_result> ProbeExtResult;
@ -62,33 +59,29 @@ namespace XenAdmin.Actions
this.SrType = srType;
this.dconf = dconf;
string target;
switch (srType)
{
case SR.SRTypes.nfs:
Description = string.Format(Messages.ACTION_SR_SCANNING,
SR.getFriendlyTypeName(srType), dconf["server"]);
target = dconf["server"];
break;
case SR.SRTypes.lvmoiscsi:
Description = string.Format(Messages.ACTION_SR_SCANNING,
SR.getFriendlyTypeName(srType), dconf["target"]);
target = dconf["target"];
break;
case SR.SRTypes.lvmohba:
case SR.SRTypes.lvmofcoe:
String device = dconf.ContainsKey(DEVICE) ?
dconf[DEVICE] : dconf[SCSIid];
Description = string.Format(Messages.ACTION_SR_SCANNING,
SR.getFriendlyTypeName(srType), device);
target = dconf.ContainsKey("device") ? dconf["device"] : dconf["SCSIid"];
break;
case SR.SRTypes.gfs2:
Description = string.Format(Messages.ACTION_SR_SCANNING,
SR.getFriendlyTypeName(srType), dconf.ContainsKey("ips") ? dconf["ips"] : dconf["ScsiId"]);
target = dconf.ContainsKey("ips") ? dconf["ips"] : dconf["ScsiId"];
break;
default:
Description = string.Format(Messages.ACTION_SR_SCANNING,
SR.getFriendlyTypeName(srType), Messages.REPAIRSR_SERVER); // this is a bit minging: CA-22111
target = Messages.REPAIRSR_SERVER;
break;
}
Description = string.Format(Messages.ACTION_SR_SCANNING, SR.getFriendlyTypeName(srType), target);
this.smconf = smconf;
}