public void Validate(ClusterDefinition clusterDefinition) { Covenant.Requires <ArgumentNullException>(clusterDefinition != null, nameof(clusterDefinition)); switch (Environment) { case HostingEnvironments.Aws: if (Aws == null) { throw new ClusterDefinitionException($"[{nameof(HostingOptions)}.{nameof(Aws)}] must be initialized when cloud provider is [{Environment}]."); } Aws.Validate(clusterDefinition); break; case HostingEnvironments.Azure: if (Azure == null) { throw new ClusterDefinitionException($"[{nameof(HostingOptions)}.{nameof(Azure)}] must be initialized when cloud provider is [{Environment}]."); } Azure.Validate(clusterDefinition); break; case HostingEnvironments.Google: if (Google == null) { throw new ClusterDefinitionException($"[{nameof(HostingOptions)}.{nameof(Google)}] must be initialized when cloud provider is [{Environment}]."); } Google.Validate(clusterDefinition); break; case HostingEnvironments.HyperV: HyperV = HyperV ?? new HyperVOptions(); HyperV.Validate(clusterDefinition); break; case HostingEnvironments.HyperVLocal: HyperVDev = HyperVDev ?? new LocalHyperVOptions(); HyperVDev.Validate(clusterDefinition); break; case HostingEnvironments.Machine: Machine = Machine ?? new MachineOptions(); Machine.Validate(clusterDefinition); break; case HostingEnvironments.XenServer: XenServer = XenServer ?? new XenServerOptions(); XenServer.Validate(clusterDefinition); break; default: throw new NotImplementedException(); } if (!string.IsNullOrWhiteSpace(VmNamePrefix)) { if (!ClusterDefinition.IsValidName(VmNamePrefix)) { throw new ClusterDefinitionException($"[{nameof(HostingOptions)}.{nameof(VmNamePrefix)}={VmNamePrefix}] must include only letters, digits, underscores, or periods."); } } }
/// <summary> /// Validates the options and also ensures that all <c>null</c> properties are /// initialized to their default values. /// </summary> /// <param name="clusterDefinition">The cluster definition.</param> /// <exception cref="ClusterDefinitionException">Thrown if the definition is not valid.</exception> public void Validate(ClusterDefinition clusterDefinition) { Covenant.Requires <ArgumentNullException>(clusterDefinition != null, nameof(clusterDefinition)); switch (Environment) { case HostingEnvironment.Aws: if (Aws == null) { throw new ClusterDefinitionException($"[{nameof(ClusterDefinition.Hosting)}.{nameof(Aws)}] must be initialized when cloud provider is [{Environment}]."); } Aws.Validate(clusterDefinition); Cloud = Cloud ?? new CloudOptions(); Cloud.Validate(clusterDefinition); break; case HostingEnvironment.Azure: if (Azure == null) { throw new ClusterDefinitionException($"[{nameof(ClusterDefinition.Hosting)}.{nameof(Azure)}] must be initialized when cloud provider is [{Environment}]."); } Azure.Validate(clusterDefinition); Cloud = Cloud ?? new CloudOptions(); Cloud.Validate(clusterDefinition); break; case HostingEnvironment.BareMetal: Machine = Machine ?? new MachineHostingOptions(); Machine.Validate(clusterDefinition); break; case HostingEnvironment.Google: if (Google == null) { throw new ClusterDefinitionException($"[{nameof(ClusterDefinition.Hosting)}.{nameof(Google)}] must be initialized when cloud provider is [{Environment}]."); } Google.Validate(clusterDefinition); Cloud = Cloud ?? new CloudOptions(); Cloud.Validate(clusterDefinition); break; case HostingEnvironment.HyperV: HyperV = HyperV ?? new HyperVHostingOptions(); HyperV.Validate(clusterDefinition); Vm = Vm ?? new VmHostingOptions(); Vm.Validate(clusterDefinition); break; case HostingEnvironment.XenServer: XenServer = XenServer ?? new XenServerHostingOptions(); XenServer.Validate(clusterDefinition); Cloud = Cloud ?? new CloudOptions(); Cloud.Validate(clusterDefinition); Vm = Vm ?? new VmHostingOptions(); Vm.Validate(clusterDefinition); break; default: throw new NotImplementedException(); } }
public void Validate(HiveDefinition hiveDefinition) { Covenant.Requires <ArgumentNullException>(hiveDefinition != null); switch (Environment) { case HostingEnvironments.Aws: if (Aws == null) { throw new HiveDefinitionException($"[{nameof(HostingOptions)}.{nameof(Aws)}] must be initialized when cloud provider is [{Environment}]."); } Aws.Validate(hiveDefinition); break; case HostingEnvironments.Azure: if (Azure == null) { throw new HiveDefinitionException($"[{nameof(HostingOptions)}.{nameof(Azure)}] must be initialized when cloud provider is [{Environment}]."); } Azure.Validate(hiveDefinition); break; case HostingEnvironments.Google: if (Google == null) { throw new HiveDefinitionException($"[{nameof(HostingOptions)}.{nameof(Google)}] must be initialized when cloud provider is [{Environment}]."); } Google.Validate(hiveDefinition); break; case HostingEnvironments.HyperV: HyperV = HyperV ?? new HyperVOptions(); HyperV.Validate(hiveDefinition); break; case HostingEnvironments.HyperVDev: LocalHyperV = LocalHyperV ?? new LocalHyperVOptions(); LocalHyperV.Validate(hiveDefinition); break; case HostingEnvironments.Machine: Machine = Machine ?? new MachineOptions(); Machine.Validate(hiveDefinition); break; case HostingEnvironments.XenServer: XenServer = XenServer ?? new XenServerOptions(); XenServer.Validate(hiveDefinition); break; default: throw new NotImplementedException(); } if (IsCloudProvider && !hiveDefinition.Vpn.Enabled) { // VPN is implicitly enabled when hosting on a cloud. hiveDefinition.Vpn.Enabled = true; } if (!string.IsNullOrWhiteSpace(VmNamePrefix)) { if (!HiveDefinition.IsValidName(VmNamePrefix)) { throw new HiveDefinitionException($"[{nameof(HostingOptions)}.{nameof(VmNamePrefix)}={VmNamePrefix}] must include only letters, digits, underscores, or periods."); } } }