コード例 #1
0
ファイル: hypervisor.cs プロジェクト: XeroDayLabs/hypervisors
        public void patchFreeNASInstallation()
        {
            // This will install the XDL modifications to the FreeNAS web UI.
            // It should only be done once, after installation of FreeNAS.

            // TODO: autodetect freenas version?
//            Byte[] patchFile = Properties.Resources.freenas_support_freenas11;
            Byte[] patchFile = Properties.Resources.freenas_support_freenas9;
            // Sometimes Git will change newlines, so be sure we give unix-style newlines when executing
            patchFile = patchFile.Where(x => x != '\r').ToArray();
            copyToGuestFromBuffer("/root/freenas-xdl.patch", patchFile);
            executionResult res = startExecutable("/bin/sh", "-c \"exec /usr/bin/patch --batch --quiet --directory=/usr/local/www < /root/freenas-xdl.patch\"");

            if (res.resultCode != 0)
            {
                throw new executionFailedException(res);
            }

            // Then restart nginx and django, which should both restart OK.
            executionResult nginxRestartRes = startExecutable("service", "nginx restart");

            if (nginxRestartRes.resultCode != 0)
            {
                throw new executionFailedException(nginxRestartRes);
            }
            executionResult djangoRestartRes = startExecutable("service", "django restart");

            if (djangoRestartRes.resultCode != 0)
            {
                throw new executionFailedException(djangoRestartRes);
            }
        }
コード例 #2
0
        public override IAsyncExecutionResult startExecutableAsyncInteractively(string toExecute, string args, string workingDir = null)
        {
            if (workingDir != null)
            {
                throw new NotSupportedException();
            }

            string tempDir = string.Format("C:\\users\\{0}\\", _username);

            execFileSet fileSet = base.prepareForExecution(toExecute, args, tempDir);

            // Use a scheduled task to run interactively with the remote users desktop.
            // Shell out to create it.
            string scheduledTaskName = Guid.NewGuid().ToString();

            using (hypervisor_localhost local = new hypervisor_localhost())
            {
                executionResult taskCreation = local.startExecutable("schtasks.exe", string.Format(
                                                                         "/f /create /s {0} /tr \"'{1}'\" /it /sc onstart /tn {4} /u {2} /p {3} ",
                                                                         _guestIP, fileSet.launcherPath, _username, _password, scheduledTaskName));
                if (taskCreation.resultCode != 0)
                {
                    throw new hypervisorExecutionException("Couldn't create scheduled task, stdout " + taskCreation.stdout + " / stderr " + taskCreation.stderr);
                }
                executionResult taskStart = local.startExecutable("schtasks.exe", string.Format(
                                                                      "/run /s {0} /tn {3} /u {1} /p {2}",
                                                                      _guestIP, _username, _password, scheduledTaskName));
                if (taskStart.resultCode != 0)
                {
                    throw new hypervisorExecutionException("Couldn't start scheduled task, stdout " + taskStart.stdout + " / stderr " + taskStart.stderr);
                }
            }
            return(new asyncExecutionResultViaFile(this, fileSet));
        }
コード例 #3
0
        public override void testConnectivity()
        {
            executionResult res = startExecutable("echo", "teststring");

            if (!res.stdout.Contains("teststring"))
            {
                throw new hypervisorExecutionException_retryable();
            }
        }
コード例 #4
0
        public override void testConnectivity()
        {
            executionResult res = startExecutable("C:\\windows\\system32\\cmd.exe", "/c echo teststring");

            if (!res.stdout.Contains("teststring"))
            {
                throw new hypervisorExecutionException_retryable();
            }
        }
コード例 #5
0
        public override executionResult startExecutable(string toExecute, string args, string workingdir = null, cancellableDateTime deadline = null)
        {
            if (_executor == null)
            {
                throw new NotSupportedException();
            }
            executionResult toRet = _executor.startExecutable(toExecute, args, workingdir, deadline);

            //Debug.WriteLine("Command '{0}' with args '{1}' returned {2} stdout '{3}' stderr '{4}'", toExecute, args, toRet.resultCode, toRet.stdout, toRet.stderr);

            return(toRet);
        }
コード例 #6
0
        public virtual executionResult startExecutable(string toExecute, string args, string workingDir = null, cancellableDateTime deadline = null)
        {
            if (deadline == null)
            {
                deadline = new cancellableDateTime(TimeSpan.FromMinutes(3));
            }

            IAsyncExecutionResult resultInProgress = null;

            try
            {
                while (resultInProgress == null)
                {
                    resultInProgress = startExecutableAsync(toExecute, args, workingDir);
//	FIXME!!!
//     This is causing an awful assembly load failure when it throws :/
//     Disabling the timeout for now because I am waaay behind schedule already
//                if (DateTime.Now > deadline)
//                    throw new hypervisorExecutionException();
                    deadline.doCancellableSleep(TimeSpan.FromSeconds(3));
                }

                while (true)
                {
                    deadline.doCancellableSleep(TimeSpan.FromSeconds(3));

                    executionResult res = resultInProgress.getResultIfComplete();

                    if (res != null)
                    {
                        return(res);
                    }
                }
            }
            finally
            {
                if (resultInProgress != null)
                {
                    resultInProgress.Dispose();
                }
            }
        }
コード例 #7
0
ファイル: hypervisor.cs プロジェクト: XeroDayLabs/hypervisors
 public executionFailedException(executionResult res)
 {
     _msg = String.Format(
         "Execution on remote systemn resulted in error: Return code was {0}, stdout was '{1}', and stderr was '{2}",
         res.resultCode, res.stdout, res.stderr);
 }