Moved multiple copies of method setting other_config keys to the parent class.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2017-09-03 00:16:54 +01:00
parent da3cd070ee
commit 89c14d7176
7 changed files with 45 additions and 172 deletions

View File

@ -151,18 +151,7 @@ namespace XenAPI
public string iscsi_iqn
{
get { return Get(other_config, "iscsi_iqn") ?? ""; }
set
{
if (iscsi_iqn != value)
{
Dictionary<string, string> new_other_config =
other_config == null ?
new Dictionary<string, string>() :
new Dictionary<string, string>(other_config);
new_other_config["iscsi_iqn"] = value;
other_config = new_other_config;
}
}
set { other_config = SetDictionaryKey(other_config, "iscsi_iqn", value); }
}
public override string ToString()
@ -760,27 +749,7 @@ namespace XenAPI
public string SysLogDestination
{
get { return logging != null && logging.ContainsKey("syslog_destination") ? logging["syslog_destination"] : null; }
set
{
if (SysLogDestination != value)
{
Dictionary<string, string> new_logging =
logging == null ?
new Dictionary<string, string>() :
new Dictionary<string, string>(logging);
if (value == null)
{
new_logging.Remove("syslog_destination");
}
else
{
new_logging["syslog_destination"] = value;
}
logging = new_logging;
}
}
set { logging = SetDictionaryKey(logging, "syslog_destination", value); }
}
public static bool IsFullyPatched(Host host,IEnumerable<IXenConnection> connections)

View File

@ -135,22 +135,7 @@ namespace XenAPI
// absence of the key gives AutoPlug=true, not false.
return Get(other_config, "automatic") != "false";
}
set
{
Changed |= AutoPlug != value;
set_other_config("automatic", value ? "true" : "false");
}
}
void set_other_config(string key, string value)
{
Dictionary<string, string> new_other_config =
other_config == null ?
new Dictionary<string, string>() :
new Dictionary<string, string>(other_config);
new_other_config[key] = value;
other_config = new_other_config;
set { other_config = SetDictionaryKey(other_config, "automatic", value ? "true" : "false"); }
}
public override bool Show(bool showHiddenVMs)

View File

@ -83,15 +83,8 @@ namespace XenAPI
// This is the name of the secondary management interface
public string ManagementPurpose
{
get
{
return Get(other_config, "management_purpose");
}
set
{
Changed |= ManagementPurpose != value;
set_other_config("management_purpose", value);
}
get { return Get(other_config, "management_purpose"); }
set { other_config = SetDictionaryKey(other_config, "management_purpose", value); }
}
internal string NICIdentifier(out bool is_bond)
@ -320,19 +313,6 @@ namespace XenAPI
}
}
void set_other_config(string key, string value)
{
Dictionary<string, string> new_other_config =
other_config == null ?
new Dictionary<string, string>() :
new Dictionary<string, string>(other_config);
if (value == null)
new_other_config.Remove(key);
else
new_other_config[key] = value;
other_config = new_other_config;
}
/// <summary>
/// Returns either the IP address of the PIF, DHCP or Unknown as appropriate
/// </summary>

View File

@ -78,21 +78,7 @@ namespace XenAPI
public bool IsOwner
{
get { return other_config != null && other_config.ContainsKey("owner"); }
set
{
if (value != IsOwner)
{
Dictionary<string, string> new_other_config =
other_config == null ?
new Dictionary<string, string>() :
new Dictionary<string, string>(other_config);
if (value)
new_other_config["owner"] = "true";
else
new_other_config.Remove("owner");
other_config = new_other_config;
}
}
set { _other_config = SetDictionaryKey(other_config, "owner", value ? "true" : null); }
}
public int IONice
@ -106,22 +92,15 @@ namespace XenAPI
}
set
{
if (value != IONice)
{
Dictionary<string, string> new_qos_algorithm_params =
qos_algorithm_params == null ?
new Dictionary<string, string>() :
new Dictionary<string, string>(qos_algorithm_params);
new_qos_algorithm_params["class"] = value.ToString();
// set the IO scheduling algorithm to use
qos_algorithm_type = "ionice";
// set the IO scheduling algorithm to use
qos_algorithm_type = "ionice";
// which scheduling class ionice should use
// best-effort for now (other options are 'rt' and 'idle')
new_qos_algorithm_params["sched"] = "be";
// which scheduling class ionice should use
// best-effort for now (other options are 'rt' and 'idle')
qos_algorithm_params = new_qos_algorithm_params;
}
qos_algorithm_params = SetDictionaryKeys(qos_algorithm_params,
new KeyValuePair<string, string>("class", value.ToString()),
new KeyValuePair<string, string>("sched", "be"));
}
}

View File

@ -151,18 +151,7 @@ namespace XenAPI
else
return "";
}
set
{
if (value != VMHint)
{
Dictionary<string, string> new_sm_config =
sm_config == null ?
new Dictionary<string, string>() :
new Dictionary<string, string>(sm_config);
new_sm_config["vmhint"] = value;
sm_config = new_sm_config;
}
}
set { sm_config = SetDictionaryKey(sm_config, "vmhint", value); }
}
public override string ToString()

View File

@ -332,20 +332,7 @@ namespace XenAPI
return "CD";
}
set
{
if (value == BootOrder)
return;
Dictionary<string, string> new_HVM_boot_params =
HVM_boot_params == null ?
new Dictionary<string, string>() :
new Dictionary<string, string>(HVM_boot_params);
new_HVM_boot_params["order"] = value.ToLower();
HVM_boot_params = new_HVM_boot_params;
}
set { HVM_boot_params = SetDictionaryKey(HVM_boot_params, "order", value.ToLower()); }
}
public long Memory
@ -373,18 +360,7 @@ namespace XenAPI
else
return 256;
}
set
{
if (value != VCPUWeight)
{
Dictionary<string, string> new_VCPUs_params =
VCPUs_params == null ?
new Dictionary<string, string>() :
new Dictionary<string, string>(VCPUs_params);
new_VCPUs_params["weight"] = value.ToString();
VCPUs_params = new_VCPUs_params;
}
}
set { VCPUs_params = SetDictionaryKey(VCPUs_params, "weight", value.ToString()); }
}
public bool DefaultTemplate
@ -400,7 +376,7 @@ namespace XenAPI
public string InstallRepository
{
get { return Get(other_config, "install-repository"); }
set { if (InstallRepository != value) { set_other_config("install-repository", value); } }
set { other_config = SetDictionaryKey(other_config, "install-repository", value); }
}
public string InstallDistro
@ -561,16 +537,6 @@ namespace XenAPI
}
}
void set_other_config(string key, string value)
{
Dictionary<string, string> new_other_config =
other_config == null ?
new Dictionary<string, string>() :
new Dictionary<string, string>(other_config);
new_other_config[key] = value;
other_config = new_other_config;
}
// AutoPowerOn is supposed to be unsupported. However, we advise customers how to
// enable it (http://support.citrix.com/article/CTX133910), so XenCenter has to be
// able to recognise it, and turn it off during Rolling Pool Upgrade.
@ -580,11 +546,7 @@ namespace XenAPI
{
return BoolKey(other_config, "auto_poweron");
}
set
{
if (value != AutoPowerOn)
set_other_config("auto_poweron", value.ToString().ToLower());
}
set { other_config = SetDictionaryKey(other_config, "auto_poweron", value.ToString().ToLower()); }
}
public bool IgnoreExcessiveVcpus
@ -593,11 +555,7 @@ namespace XenAPI
{
return BoolKey(other_config, "ignore_excessive_vcpus");
}
set
{
if (value != IgnoreExcessiveVcpus)
set_other_config("ignore_excessive_vcpus", value.ToString().ToLower());
}
set { other_config = SetDictionaryKey(other_config, "ignore_excessive_vcpus", value.ToString().ToLower()); }
}
public string IsOnSharedStorage()
@ -1744,19 +1702,7 @@ namespace XenAPI
}
return DEFAULT_CORES_PER_SOCKET;
}
set
{
if (value != CoresPerSocket)
{
Dictionary<string, string> newPlatform =
platform == null ?
new Dictionary<string, string>() :
new Dictionary<string, string>(platform);
newPlatform["cores-per-socket"] = value.ToString();
platform = newPlatform;
}
}
set { platform = SetDictionaryKey(platform, "cores-per-socket", value.ToString()); }
}
public long MaxCoresPerSocket

View File

@ -230,6 +230,31 @@ namespace XenAPI
}
}
public static Dictionary<string, string> SetDictionaryKey(Dictionary<string, string> dict, string key, string value)
{
return SetDictionaryKeys(dict, new KeyValuePair<string, string>(key, value));
}
public static Dictionary<string, string> SetDictionaryKeys(Dictionary<string, string> dict, params KeyValuePair<string, string>[] kvps)
{
var newDict = dict == null
? new Dictionary<string, string>()
: new Dictionary<string, string>(dict);
foreach (var kvp in kvps)
{
string key = kvp.Key;
string value = kvp.Value;
if (value == null)
newDict.Remove(key);
else
newDict[key] = value;
}
return newDict;
}
/// <summary>
/// If d[k] == "true", then return true. Anything else is false.
/// Handles all the cases with d being null or not containing k.