コード例 #1
0
        /// <summary>
        /// public static void prepare_peer()
        /// import Management if needed
        /// </summary>
        public static void prepare_peer()
        {
            Deploy.StageReporter("Setting up peer", "");
            logger.Info("Setting up peer");
            // waiting SSH session
            Deploy.StageReporter("", "Waiting for SSH ");
            logger.Info("Waiting for SSH 1");
            bool res_b = VMs.waiting_4ssh(_cloneName);

            if (!res_b)
            {
                logger.Error("SSH 1 false", "Can not open ssh, please check VM state manually");
                Program.ShowError("Can not open ssh, please check VM state manually and report error", "Waiting for SSH");
                Program.form1.Visible = false;
            }
            // DEPLOY PEER
            Inst.run_scripts(Program.inst_Dir, _cloneName);

            Deploy.StageReporter("", "Setting peer options");
            logger.Info("Setting peer options");

            //if (_arguments["peer"] == "trial")
            if (_arguments["peer"].Contains("MH"))
            {
                Deploy.StageReporter("Preparing management host", "");
                logger.Info("Preparing management host");
                logger.Info("trial - installing management host");
                if (_arguments["network-installation"].ToLower() != "true")
                {
                    // setting iptables rules
                    Deploy.StageReporter("", "Restricting SSH only");
                    Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", _privateKeys,
                                          "sudo iptables -P INPUT DROP; sudo iptables -P OUTPUT DROP; sudo iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT; sudo iptables -A OUTPUT -p tcp --sport 22 -m state --state ESTABLISHED, RELATED -j ACCEPT");
                }

                if (_arguments["network-installation"].ToLower() == "true")
                {
                    Inst.install_mh_nw();
                }
                else
                {
                    Inst.install_mh_lc(_privateKeys);
                }

                if (_arguments["network-installation"].ToLower() != "true")
                {
                    // setting iptables rules
                    Deploy.StageReporter("", "Allowing TCP trafic");
                    logger.Info("Allowing TCP trafic");
                    Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu",
                                          "sudo iptables - P INPUT ACCEPT; sudo iptables -P OUTPUT ACCEPT", 7);
                }
            }
            //if (_arguments["peer"] == "rh-only")
            if (!_arguments["peer"].Contains("MH") && !_arguments["peer"].Contains("DC"))
            {
                Program.form1.finished = 1;
            }
            Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu", "sudo sync;sync", 3);
        }
コード例 #2
0
        /// <summary>
        /// public static void prepare_rh()
        /// Preparing RH: clone VM, configure NAT for ssh needed for installation process
        /// setting CPUs, RAM, timezone
        /// setting up peer, import Management if needed
        /// </summary>
        public static void prepare_rh()
        {
            // PREPARE RH
            Deploy.StageReporter(" ", " ");
            Deploy.StageReporter("Preparing resource host", "");
            logger.Info("Preparing resource host");
            string res = "";

            Deploy.ShowMarquee();

            // clone VM
            Deploy.StageReporter("", "Cloning VM");
            VMs.clone_vm(_cloneName);

            //Preparing temporary network interfaces to upload and run installation scripts
            Deploy.StageReporter("", "Preparing NIC - NAT");
            logger.Info("Preparing NIC-NAT");
            res = Deploy.LaunchCommandLineApp("vboxmanage",
                                              $"modifyvm {_cloneName} --nic1 nat --cableconnected1 on --natpf1 'ssh-fwd,tcp,,4567,,22' --natpf1 'mgt-fwd,tcp,,9999,,8443'",
                                              60000);
            logger.Info("nic 1 --nat: {0}", res);

            if (res.ToLower().Contains("error"))
            {
                logger.Error("Can not run command, please check if VirtualBox installed properly", "Configuring nic1 nat");
            }
            res = Deploy.LaunchCommandLineApp("vboxmanage", $"modifyvm {_cloneName} --nic4 none", 60000);
            if (res.ToLower().Contains("error"))
            {
                logger.Error("Can not run command, please check if VirtualBox installed properly", "Configuring nic4 none");
            }
            // set RAM
            Deploy.StageReporter("", "Setting RAM");
            VMs.vm_set_RAM(_cloneName);

            //set number of cores
            Deploy.StageReporter("", "Setting number of processors");
            VMs.vm_set_CPUs(_cloneName);

            //set UTC timezone
            Deploy.StageReporter("", "Setting timezone");
            VMs.vm_set_timezone(_cloneName);

            //start VM, will try 2 times
            Deploy.StageReporter("", "Starting VM");
            if (!VMs.start_vm(_cloneName))
            {
                VMs.stop_vm(_cloneName);
                Thread.Sleep(10000);
                if (!VMs.start_vm(_cloneName))
                {
                    logger.Error("Can not start VM, please try to start manually", "Starting VM");
                    Program.ShowError("Can not start VM, please try to start manually", "Waiting for SSH");
                    Program.form1.Visible = false;
                }
            }
        }
コード例 #3
0
ファイル: Inst.cs プロジェクト: nibircse/installers
        /// <summary>
        /// Creates tmpfs folder, uploads snap file and prepare-server.sh. Runs installation scripts.
        /// </summary>
        /// <param name="appDir">The application instalation directory.</param>
        /// <param name="vmName">Name of the VM.</param>
        public static void run_scripts(string appDir, string vmName)
        {
            bool b_res = false;

            // creating tmpfs folder
            b_res = create_tmpfs();
            if (!b_res)
            {
                Program.ShowError("Can not open ssh to create tmpfs, please check network and VM state and reinstall later", "No tmpfs");
                Program.form1.Visible = false;
            }

            // copying snap
            b_res = upload_files(appDir);
            logger.Info("Copying Subutai files: {0}, prepare-server.sh", TC.snapFile);
            if (!b_res)
            {
                Program.ShowError("Cannot upload Subutai files to RH, canceling", "Setting up RH");
                Program.form1.Visible = false;
            }

            // adopting prepare-server.sh
            if (!adopt_scripts())
            {
                Program.ShowError("Can not open ssh to adapt scripts, please check network and VM state and reinstall later", "No tmpfs");
                Program.form1.Visible = false;
            }

            // running prepare-server.sh script
            b_res = prepare_server_task(appDir);
            if (!b_res)
            {
                Program.ShowError("Can not run scripts, please check network and VM state and reinstall later", "No prepare-server");
                Program.form1.Visible = false;
            }

            // configuring nic
            bool res_b = VMs.vm_reconfigure_nic(vmName);

            if (!res_b)
            {
                logger.Error("VM not started", "Can not start VM, please check VM state manually and report error");
                Program.ShowError("Can not start VM after NIC reconfiguration, please check network and VM state and report error", "VM not started");
                Program.form1.Visible = false;
            }

            //stop and start machine
            Deploy.StageReporter("", "Waiting for SSH");
            logger.Info("Waiting for SSH - 2");
            res_b = VMs.waiting_4ssh(vmName);
            if (!res_b)
            {
                logger.Info("SSH 2 false", "Can not open ssh, please check VM state manually and report error");
                Program.ShowError("Can not open ssh after NIC reconfiguration, please check network and VM state and reinstall later", "No SSH");
                Program.form1.Visible = false;
            }
        }
コード例 #4
0
        /// <summary>
        /// private void showing()
        /// Showing system and installation parameters form
        /// Installation is not possible if one of system parameters is red
        /// For Windows 7 can not define if VT/x is enabled in BIOS
        /// </summary>
        private void showing()
        {
            tbxAppDir.Text     = Inst.subutai_path(); //Show Installation path, defined in installer
            tbxAppDir.Enabled  = false;               //Change of installation type not allowed
            tbxAppDir.ReadOnly = true;
            //Defining system parameters
            hostOSversion      = Environment.OSVersion.Version.ToString();                                                  //OS version (6.1, 6.2, 10)
            hostOSversion_user = SysCheck.OS_name().Replace("Windows", "Win");                                              //OS name in human readable format
            shortVersion       = hostOSversion.Substring(0, 3);
            hostCores          = Environment.ProcessorCount;                                                                //number of logical processors
            host64             = Environment.Is64BitOperatingSystem;                                                        //Processor architecture - x86 or x64
            vboxVersion        = SysCheck.vbox_version();                                                                   //Oracle VirtualBox version
            hostRam            = (ulong)new Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory / 1024 / 1024; //RAM in MB
            hostVT             = SysCheck.check_vt();                                                                       //Checking if VT-x is enabled

            //Filling textboxes
            l_Proc.Text = hostCores.ToString();//SysCheck.hostCores.ToString();
            l_RAM.Text  = hostRam.ToString();
            l_S64.Text  = host64.ToString();
            l_OS.Text   = hostOSversion_user;
            l_VT.Text   = hostVT;
            l_VB.Text   = vboxVersion;

            tb_Info.Text = "Subutai can be installed on Windows versions 7, 8, 8.1, 10.";
            // "* This value may need to be checked in BIOS. If installation fails, check if
            //hardware support for virtualization(VT-x/AMD-V) is allowed in BIOS.";
            tb_Info.Text += Environment.NewLine;
            tb_Info.Text += Environment.NewLine;

            tb_Proc_VM.Text = VMs.vm_CPUs().ToString();
            tb_RAM_VM.Text  = VMs.vm_RAM().ToString();

            //Log system info:
            logger.Info("OS: {0}, {1}", hostOSversion, hostOSversion_user);
            logger.Info("CPUs: {0}", hostCores);
            logger.Info("Is 64x: {0}", host64);
            logger.Info("RAM: {0}MB", hostRam);
            logger.Info("VT/x enabled: {0}", hostVT);
            logger.Info("Oracle VBox version: {0}", vboxVersion);
            //Check if can install
            //checking(peerType(getCheckedRadio(gbxTypeInst)));
            string pType = peerType(clbPeerType);

            if (pType != "")
            {
                checking(peerType(clbPeerType));
            }
        }
コード例 #5
0
ファイル: Inst.cs プロジェクト: nibircse/installers
        /// <summary>
        /// Running prepares-server script.
        /// </summary>
        /// <returns></returns>
        public static bool prepare_server(string appDir)
        {
            // running prepare-server.sh script
            string ssh_res   = "";
            string ssh_res_1 = "";
            bool   b_res     = false;

            Deploy.StageReporter("", "Running installation scripts");
            ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu", "sudo bash /home/ubuntu/tmpfs/prepare-server.sh", 7);
            logger.Info("Running installation scripts: {0}", ssh_res);
            if (ssh_res.Contains("Connection Error"))
            {
                if (!VMs.restart_vm(TC._cloneName))
                {
                    Program.ShowError("Can not communicate with VM, please check network and VM state and reinstall later", "No SSH");
                    Program.form1.Visible = false;
                }
                ssh_res   = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu", "ls /home/ubuntu/tmpfs/prepare-server.sh", 7);
                ssh_res_1 = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu", $"sudo ls bash /home/ubuntu/tmpfs/{TC.snapFile}", 3);
                if (ssh_res.ToLower().Contains("no such file") || ssh_res_1.ToLower().Contains("no such file"))
                {
                    b_res = upload_files(appDir);
                    if (!b_res)
                    {
                        Program.ShowError("Cannot upload Subutai files to RH, canceling", "Setting up RH");
                        Program.form1.Visible = false;
                    }
                }

                logger.Info("Running installation scripts second time: {0}", ssh_res);
                if (ssh_res.Contains("Connection Error"))
                {
                    return(false);
                }
            }
            // deploying peer options
            Thread.Sleep(5000);
            ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu", "sudo sync;sync", 3);
            Thread.Sleep(5000);
            return(true);
        }
コード例 #6
0
ファイル: Inst.cs プロジェクト: nibircse/installers
        /// <summary>
        /// Creates TMPFS.
        /// </summary>
        /// <returns></returns>
        public static bool create_tmpfs()
        {
            string ssh_res = "";

            // creating tmpfs folder
            Deploy.StageReporter("", "Creating tmps folder");
            ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu", "mkdir tmpfs; sudo mount -t tmpfs -o size=1G tmpfs /home/ubuntu/tmpfs", 20);
            logger.Info("Creating tmpfs folder: {0}", ssh_res);
            if (ssh_res.Contains("Connection Error"))
            {
                if (!VMs.restart_vm(TC._cloneName))
                {
                    Program.ShowError("Can not communicate with VM, please check network and VM state and reinstall later", "No SSH");
                }
                ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu", "mkdir tmpfs; sudo mount -t tmpfs -o size=1G tmpfs /home/ubuntu/tmpfs", 20);
                logger.Info("Creating tmpfs folder second time: {0}", ssh_res);
                if (ssh_res.Contains("Connection Error"))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #7
0
ファイル: Inst.cs プロジェクト: nibircse/installers
        /// <summary>
        /// public static void install_mh_nw()
        /// Installing management host, ssh using name-password
        /// </summary>
        public static void install_mh_nw()
        {
            //installing master template

            bool b_res = import_templ_task("master");

            // installing management template
            b_res = import_templ_task("management");
            string ssh_res = "";

            if (!b_res)
            {
                logger.Info("trying import management again");
                //need to remove previouis import
                string killcmd = "sudo kill `ps -ef | grep import | grep -v grep | awk '{print $2}'`";
                ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu",
                                                killcmd, 7);
                logger.Info("Importing stuck first time, killing processes: {0}", ssh_res);

                if (ssh_res.Contains("Connection Error"))
                {
                    string kh_path = Path.Combine($"{ Program.inst_Dir}home", Environment.UserName, ".ssh", "known_hosts");
                    FD.edit_known_hosts(kh_path);

                    //restarting VM
                    if (!VMs.restart_vm(TC._cloneName))
                    {
                        //can not restart VM
                        Program.ShowError("Can not restart VM, please check VM state and try to install later", "Can not start VM");
                        Program.form1.Visible = false;
                    }
                    ;
                }
                //remove previously installed master
                ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu",
                                                "sudo subutai destroy master", 7);
                logger.Info("Destroying master to import second time: {0}", ssh_res);

                ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu",
                                                "sudo subutai destroy management", 7);
                logger.Info("Destroying management to import second time: {0}", ssh_res);

                b_res = import_templ_task("master");

                b_res = import_templ_task("management");
                if (!b_res)
                {
                    logger.Info("import management failed second time");
                    Program.form1.Invoke((MethodInvoker) delegate
                    {
                        Program.ShowError("Management template was not installed, installation failed, please try to install later", "Management template was not imported");
                        Program.form1.Visible = false;
                    });
                }
            }

            ssh_res = Deploy.SendSshCommand("127.0.0.1", 4567, "ubuntu", "ubuntu",
                                            "sudo bash subutai info ipaddr", 7);
            //todo: delete old
            logger.Info("Import management address returned by subutai info: {0}", ssh_res);

            string rhIP = Deploy.com_out(ssh_res, 1);

            if (!is_ip_address(rhIP))
            {
                logger.Error("import management failed ", "Management template was not installed");
                Program.ShowError("Management template was not installed, installation failed, removing", "Management template was not imported");
                Program.form1.Visible = false;
            }
        }