コード例 #1
0
        public void Validate()
        {
            if (MachinesCount < 3)
            {
                throw new ArgumentOutOfRangeException(nameof(MachinesCount), $"There has to be at least 3 machines. You submitted {MachinesCount}");
            }

            foreach (var operation in Operations)
            {
                if (operation.Order < 0)
                {
                    throw new ArgumentException();
                }

                if (operation.MachineId < 0 || operation.MachineId >= MachinesCount)
                {
                    throw new ArgumentOutOfRangeException(nameof(operation.MachineId), $"Invalid machine id {operation.MachineId} of operation {operation.Id}");
                }

                var machineOperations = MachineOperations[operation.MachineId];

                if (!machineOperations.Any(x => x.Equals(operation)))
                {
                    throw new ArgumentException($"Operation {operation.Id} was not found on machine {operation.MachineId}");
                }
            }

            int[] notFilledEnoughMachines = MachineOperations.IndicesOf(x => x.Length < 3).ToArray();
            if (notFilledEnoughMachines.Length > 0)
            {
                throw new ArgumentException($"Every machine must have at least 2 operations. " +
                                            $"Machines not fulfilling this are: {string.Join(',', notFilledEnoughMachines)}");
            }
        }
コード例 #2
0
        /// <summary>
        /// Constructor.  Note that you should dispose the instance when you're finished with it.
        /// </summary>
        /// <param name="addressOrFQDN">The target XenServer IP address or FQDN.</param>
        /// <param name="username">The user name.</param>
        /// <param name="password">The password.</param>
        /// <param name="name">Optionally specifies the XenServer name.</param>
        /// <param name="logFolder">
        /// The folder where log files are to be written, otherwise or <c>null</c> or
        /// empty if logging is disabled.
        /// </param>
        public XenClient(string addressOrFQDN, string username, string password, string name = null, string logFolder = null)
        {
            Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(username));

            if (!IPAddress.TryParse(addressOrFQDN, out var address))
            {
                var hostEntry = Dns.GetHostEntry(addressOrFQDN);

                if (hostEntry.AddressList.Length == 0)
                {
                    throw new XenException($"[{addressOrFQDN}] is not a valid IP address or fully qualified domain name of a XenServer host.");
                }

                address = hostEntry.AddressList.First();
            }

            var logWriter = (TextWriter)null;

            if (!string.IsNullOrEmpty(logFolder))
            {
                Directory.CreateDirectory(logFolder);

                logWriter = new StreamWriter(Path.Combine(logFolder, $"XENSERVER-{addressOrFQDN}.log"));
            }

            Address           = addressOrFQDN;
            Name              = name;
            SshProxy          = new SshProxy <XenClient>(addressOrFQDN, null, address, SshCredentials.FromUserPassword(username, password), logWriter);
            SshProxy.Metadata = this;
            runOptions        = RunOptions.IgnoreRemotePath;

            // Initialize the operation classes.

            Repository = new RepositoryOperations(this);
            Template   = new TemplateOperations(this);
            Machine    = new MachineOperations(this);
        }