예제 #1
0
        /// <summary>
        /// Validates the options.
        /// </summary>
        /// <param name="clusterDefinition">The cluster definition.</param>
        /// <exception cref="ClusterDefinitionException">Thrown if the definition is not valid.</exception>
        internal void Validate(ClusterDefinition clusterDefinition)
        {
            var hypervisorHostPrefix = $"{nameof(ClusterDefinition.Hosting)}.{nameof(ClusterDefinition.Hosting.Vm)}";

            if (string.IsNullOrEmpty(Name))
            {
                throw new ClusterDefinitionException($"[{hypervisorHostPrefix}.{nameof(Name)}] is required when specifying a hypervisor host.");
            }

            if (string.IsNullOrEmpty(Address))
            {
                throw new ClusterDefinitionException($"[{hypervisorHostPrefix}.{nameof(Address)}] is required when specifying a hypervisor host.");
            }

            if (!IPAddress.TryParse(Address, out var ipAddress) && !NetHelper.IsValidHost(Address))
            {
                throw new ClusterDefinitionException($"[{hypervisorHostPrefix}.{nameof(Address)}={Address}] is not a valid IP address or hostname.");
            }

            if (string.IsNullOrEmpty(Username) && string.IsNullOrEmpty(clusterDefinition.Hosting.Vm.HostUsername))
            {
                throw new ClusterDefinitionException($"[{hypervisorHostPrefix}.{nameof(Username)}] is required when specifying a hypervisor host and no default username is specified by [{nameof(HostingOptions)}.{nameof(HostingOptions.Vm.HostUsername)}].");
            }

            if (string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(clusterDefinition.Hosting.Vm.HostPassword))
            {
                throw new ClusterDefinitionException($"[{hypervisorHostPrefix}.{nameof(Password)}] is required when specifying a hypervisor host and no default password is specified by [{nameof(HostingOptions)}.{nameof(HostingOptions.Vm.HostPassword)}].");
            }
        }
예제 #2
0
        /// <summary>
        /// Returns the prefix to be used when provisioning virtual machines in hypervisor environments.
        /// </summary>
        /// <param name="clusterDefinition">The cluster definition.</param>
        /// <returns>The prefix.</returns>
        public string GetVmNamePrefix(ClusterDefinition clusterDefinition)
        {
            // We don't add a prefix for the special neon-desktop cluster.

            if (clusterDefinition.IsDesktopBuiltIn)
            {
                return(String.Empty);
            }

            var prefix = string.Empty;

            if (NamePrefix == null)
            {
                prefix = $"{clusterDefinition.Name}-".ToLowerInvariant();
            }
            else if (string.IsNullOrWhiteSpace(NamePrefix))
            {
                prefix = string.Empty;
            }
            else
            {
                prefix = $"{NamePrefix}-".ToLowerInvariant();
            }

            if (KubeHelper.ClusterspaceMode != KubeClusterspaceMode.Disabled && !string.IsNullOrEmpty(clusterDefinition.Deployment.Prefix))
            {
                prefix = $"{clusterDefinition.Deployment.Prefix}-{prefix}";
            }

            return(prefix);
        }
예제 #3
0
        /// <summary>
        /// Returns the size of the data disk as a string with optional <see cref="ByteUnits"/> unit suffix.
        /// </summary>
        /// <param name="clusterDefinition">The cluster definition.</param>
        /// <returns>The disk size or <c>null</c> when the node has no data disk.</returns>
        public string GetDataDiskSize(ClusterDefinition clusterDefinition)
        {
            Covenant.Requires <ArgumentNullException>(clusterDefinition != null, nameof(clusterDefinition));

            switch (clusterDefinition.Hosting.Environment)
            {
            case HostingEnvironment.Aws:

                return(Aws.OpenEBSVolumeSize ?? clusterDefinition.Hosting.Aws.DefaultOpenEBSVolumeSize);

            case HostingEnvironment.Azure:

                return(Azure.OpenEBSDiskSize ?? clusterDefinition.Hosting.Azure.DefaultOpenEBSDiskSize);

            case HostingEnvironment.BareMetal:

                throw new NotImplementedException();

            case HostingEnvironment.Google:

                throw new NotImplementedException();

            case HostingEnvironment.HyperV:
            case HostingEnvironment.XenServer:

                return(Vm.GetOsDisk(clusterDefinition).ToString());

            default:

                throw new NotImplementedException();
            }
        }
예제 #4
0
 /// <summary>
 /// Validates the options.
 /// </summary>
 /// <param name="clusterDefinition">The cluster definition.</param>
 /// <exception cref="ClusterDefinitionException">Thrown if the definition is not valid.</exception>
 internal void Validate(ClusterDefinition clusterDefinition)
 {
     if (!string.IsNullOrEmpty(Prefix) && !ClusterDefinition.PrefixRegex.IsMatch(Prefix))
     {
         throw new ClusterDefinitionException($"[{nameof(ClusterDefinition.Deployment)}.{nameof(Prefix)}={Prefix}] is not a valid prefix.");
     }
 }
예제 #5
0
 /// <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)
 {
     if (StepStaggerSeconds < 0)
     {
         throw new ClusterDefinitionException($"[{nameof(SetupOptions)}.{nameof(StepStaggerSeconds)}={StepStaggerSeconds}] cannot be negative.");
     }
 }
예제 #6
0
 public void Validate(ClusterDefinition clusterDefinition)
 {
     if (PasswordLength < 8)
     {
         throw new ClusterDefinitionException($"[{nameof(NodeOptions)}.{nameof(PasswordLength)}={PasswordLength}] cannot be less than 8 characters.");
     }
 }
예제 #7
0
        /// <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));

            var issuerSpecPrefix = $"{nameof(IssuerSpec)}";

            Acme = Acme ?? new AcmeIssuer();
            Acme.Validate(clusterDefinition);
        }
예제 #8
0
 /// <summary>
 /// Validates the address rule.
 /// </summary>
 /// <param name="clusterDefinition">The cluster definition.</param>
 /// <param name="context">Indicates where the address rule is specified, like: <b>ingress-rule-address</b> or <b>egress-address</b></param>
 /// <exception cref="ClusterDefinitionException">Thrown for an invalid rule.</exception>
 public void Validate(ClusterDefinition clusterDefinition, string context)
 {
     if (!IsAny)
     {
         if (!NetHelper.TryParseIPv4Address(AddressOrSubnet, out var v1) && !NetworkCidr.TryParse(AddressOrSubnet, out var v2))
         {
             throw new ClusterDefinitionException($"Invalid address or subnet [{AddressOrSubnet}] specified for a [{context}].");
         }
     }
 }
예제 #9
0
        /// <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));

            KeySecretRef = KeySecretRef ?? new AcmeSecretKeySelector()
            {
                Key  = "secret",
                Name = "neon-acme-secret"
            };
        }
예제 #10
0
 /// <summary>
 /// Returns the maximum number processors to allocate for this node when
 /// hosted on a hypervisor.
 /// </summary>
 /// <param name="clusterDefinition">The cluster definition.</param>
 /// <returns>The number of cores.</returns>
 public int GetVmProcessors(ClusterDefinition clusterDefinition)
 {
     if (VmProcessors != 0)
     {
         return(VmProcessors);
     }
     else
     {
         return(clusterDefinition.Hosting.VmProcessors);
     }
 }