Exemplo n.º 1
0
        /// <summary>
        /// Configure <see cref=" LinuxServiceType"/> file
        /// </summary>
        /// <param name="address">Linux server IP Address</param>
        /// <param name="type"><see cref=" LinuxServiceType"/></param>
        /// <param name="winFilePath">Configuration File Path</param>
        /// <param name="keyValue">Current value in file</param>
        /// <param name="configureValue">New value to be configured</param>
        public static void ConfigureFile(IPAddress address, LinuxServiceType type, string winFilePath, Collection <string> keyValue, Collection <string> configureValue)
        {
            string linuxFilePath = string.Empty;

            if (LinuxServiceType.DHCP == type)
            {
                linuxFilePath = LINUX_DHCP_PATH;
            }
            else if (LinuxServiceType.BOOTP == type)
            {
                linuxFilePath = LINUX_BOOTP_PATH;
            }
            else if (LinuxServiceType.TFTP == type)
            {
                linuxFilePath = LINUX_TFTP_PATH;
            }
            else if (LinuxServiceType.DHCPV6 == type)
            {
                linuxFilePath = LINUX_DHCPV6_PATH;
            }
            else
            {
                TraceFactory.Logger.Info("Invalid type: {0} for configuring file.".FormatWith(type));
                return;
            }

            ConfigureFile(address, winFilePath, linuxFilePath, keyValue, configureValue);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Stop service on Linux server
        /// </summary>
        /// <param name="address">Linux Server IP Address</param>
        /// <param name="type"><see cref=" LinuxServiceType"/></param>
        public static void StopService(IPAddress address, LinuxServiceType type)
        {
            string command = string.Empty;

            if (LinuxServiceType.DHCP == type)
            {
                command = "/etc/init.d/isc-dhcp-server stop";
            }
            else if (LinuxServiceType.BOOTP == type)
            {
                command = "/etc/init.d/bootp stop";
            }
            else if (LinuxServiceType.TFTP == type)
            {
                command = "/etc/init.d/xinetd stop";
            }
            else if (LinuxServiceType.RARP == type)
            {
                command = "service rarpd stop";
            }
            else if (LinuxServiceType.DHCPV6 == type)
            {
                command = "/etc/init.d/isc-dhcp-server6 stop";
            }

            TraceFactory.Logger.Info("Stopping {0} service.".FormatWith(type));
            ExecuteCommand(address, command);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reserve IP Address on requested service
        /// </summary>
        /// <param name="linuxServerAddress">Linux server IP Address</param>
        /// <param name="addressToReserve">Address to reserve</param>
        /// <param name="macAddress">Mac Address of device</param>
        /// <param name="type"><see cref=" LinuxServiceType"/></param>
        /// <param name="gateway">Gateway for Scope</param>
        /// <param name="subnetMask">Subnet mask of scope</param>
        private static void ReserveIP(IPAddress linuxServerAddress, IPAddress addressToReserve, string macAddress, LinuxServiceType type, IPAddress gateway = null, IPAddress subnetMask = null)
        {
            string linuxFilePath   = string.Empty;
            string linuxBackupPath = string.Empty;
            string winFilePath     = Path.GetTempPath();

            Collection <string> keyValue       = new Collection <string>();
            Collection <string> configureValue = new Collection <string>();

            // SubnetMask is mandatory: BootP
            if (null == subnetMask)
            {
                subnetMask = IPAddress.Parse("255.255.255.0");
            }

            if (null == gateway)
            {
                int length    = linuxServerAddress.ToString().Length;
                int lastIndex = linuxServerAddress.ToString().LastIndexOf('.') + 1;

                // Configure gateway
                gateway = IPAddress.Parse(string.Format(CultureInfo.CurrentCulture, "{0}{1}", linuxServerAddress.ToString().Remove(lastIndex, length - lastIndex), "1"));
            }

            if (macAddress.Contains("-"))
            {
                macAddress = macAddress.Replace('-', ':');
            }
            else if (!macAddress.Contains(":"))
            {
                // Insert ':' char at every 3rd position of mac address
                macAddress = Regex.Replace(macAddress, ".{2}", "$0:");
                macAddress = macAddress.Remove(macAddress.Length - 1, 1);
            }

            keyValue.Add(KEY_IPADDRESS);
            keyValue.Add(KEY_SUBNET_MASK);
            keyValue.Add(KEY_GATEWAY);
            keyValue.Add(KEY_MAC_ADDRESS);

            configureValue.Add(addressToReserve.ToString());
            configureValue.Add(subnetMask.ToString());
            configureValue.Add(gateway.ToString());
            configureValue.Add(macAddress);

            if (LinuxServiceType.DHCP == type)
            {
                // Format

                /*
                 *                      host Aeneas1 {
                 *                      hardware ethernet 00:9c:02:84:55:46;
                 *                      fixed-address 192.168.2.65;
                 *                      }
                 * */

                linuxBackupPath = linuxFilePath = LINUX_DHCP_PATH;
                winFilePath     = Path.Combine(winFilePath, DHCP_FILE);
            }
            else if (LinuxServiceType.BOOTP == type)
            {
                // Format

                /*
                 *              client:\
                 *              ha="00:9c:02:84:c1:6e":\
                 *              ip=192.168.192.160:\
                 *              gw=192.168.192.1:\
                 *              sm=255.255.255.0:\
                 *              :T144="/tftpboot/tftp.cfg":
                 * */

                // Bootp File doesn't have any data initially, hence directly picking default file
                linuxBackupPath = string.Concat(BACKUP_FOLDER_PATH, BOOTP_FILE);
                winFilePath     = Path.Combine(winFilePath, BOOTP_FILE);
                linuxFilePath   = LINUX_BOOTP_PATH;
            }
            else if (LinuxServiceType.DHCPV6 == type)
            {
                // Format

                /*
                 *               host Aeneas2 {
                 *               host-identifier option dhcp6.client-id 00:02:00:00:00:0b:2c:59:e5:7a:92:f4;
                 *               fixed -address6 2000:192:192:192:192:192:192:125;
                 *               }
                 * */

                // Uuid is specific to only Dhcpv6
                keyValue.Add(KEY_UUID);
                configureValue.Add(macAddress);

                linuxBackupPath = linuxFilePath = LINUX_DHCPV6_PATH;
                winFilePath     = Path.Combine(winFilePath, DHCPV6_FILE);
            }
            else
            {
                // Need to implement for other services also
                throw new NotImplementedException();
            }

            // Copy configuration file from Linux to local temporary folder
            CopyFileFromLinux(linuxServerAddress, linuxBackupPath, winFilePath);

            // Replace values and copy back to Linux
            ConfigureFile(linuxServerAddress, winFilePath, linuxFilePath, keyValue, configureValue, isReservation: true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Reserve IP Address
 /// </summary>
 /// <param name="linuxServerIPAddress">Linux server IP Address</param>
 /// <param name="addressToReserve">Address to reserve</param>
 /// <param name="macAddress">Mac address of device</param>
 /// <param name="reservationIndex">Reservation Index</param>
 /// <param name="gateway">Gateway</param>
 /// <param name="subnetMask">Subnet Mask</param>
 /// <param name="type"><see cref=" LinuxServiceType"/></param>
 public static void ReserveIPAddress(IPAddress linuxServerIPAddress, IPAddress addressToReserve, string macAddress, LinuxServiceType type, int reservationIndex = 0, IPAddress gateway = null, IPAddress subnetMask = null)
 {
     TraceFactory.Logger.Info("Reserving {0} IP Address in {1}".FormatWith(addressToReserve, type));
     ReserveIP(linuxServerIPAddress, addressToReserve, macAddress, type, gateway, subnetMask);
 }