コード例 #1
0
 public static void Log(string msg)
 {
     if (strLogPath == null)
     {
         object obj = GetRegistryValue("InstallLocation");
         strLogPath             = (obj != null) ? ((string)obj) + "\\eucalog_install.txt" : "C:\\eucalog_install.txt";
         EucaLogger.LogLocation = strLogPath;
     }
     EucaLogger.Debug(msg);
 }
コード例 #2
0
        /****
        * Contents in the unzipped directory
        * script: script file to be handled by ScriptHandler
        * powershell: powershell file to be handled by ScriptHandler
        * eucalyptus: eucalyptus file to be handled by EucalyptusParameterHandler
        * include: include file to be handled by IncludeHandler
        * and any other resource files to be used by script/powershell handlers (exe, dll, etc)
        ****/
        override protected void Handle()
        {
            if (!Directory.Exists(UnzippedDir))
            {
                EucaLogger.Error(String.Format("Can't find the unzipped directory {0}", UnzippedDir));
                return;
            }
            else if (File.Exists(UserDataFile))
            {
                try
                {
                    EucaFileUtil.Unzip(UnzippedDir, UserDataFile);
                }
                catch (Exception ex)
                {
                    EucaLogger.Exception(String.Format("Failed to unzip {0} into {1}", UserDataFile, UnzippedDir), ex);
                    return;
                }
            }

            foreach (String filePath in Directory.GetFiles(UnzippedDir))
            {
                String          fileName = Path.GetFileName(filePath).ToLower();
                UserDataHandler handler  = null;
                if (fileName.Equals("script") || fileName.Equals("powershell"))
                {
                    handler = new ScriptHandler();
                }
                else if (fileName.Equals("eucalyptus"))
                {
                    handler = new EucalyptusParameterHandler();
                }
                else if (fileName.Equals("include"))
                {
                    handler = new IncludeHandler();
                }
                else
                {
                    EucaLogger.Debug(String.Format("unknown file: {0}", fileName));
                    continue;
                }

                try
                {
                    handler.HandleUserData(filePath);
                    EucaLogger.Debug(String.Format("Successfully handled the contents in {0}", fileName));
                }
                catch (Exception ex)
                {
                    EucaLogger.Exception(String.Format("failed to handle the file {0}", fileName), ex);
                }
            }
        }
コード例 #3
0
        public void Init()
        {
            string userDataFile = null;

            try
            {
                userDataFile = CloudInit.CloudInitDirectory + "\\user-data";
                EucaUtil.GetUserData(userDataFile);
                if (!File.Exists(userDataFile))
                {
                    throw new EucaException("User data file not found");
                }
                if ((new FileInfo(userDataFile)).Length <= 0)
                {
                    throw new EucaException("Invalid user data file");
                }
            }
            catch (Exception ex)
            {
                EucaLogger.Debug("Unable to download the user-data");
                throw ex;
            }

            // detect the contents
            UserDataHandler handler = null;

            try
            {
                handler = UserDataHandlerFactory.Instance.GetHandler(userDataFile);
            }
            catch (Exception ex)
            {
                EucaLogger.Exception("Unable to find the handler for matching user-data contents", ex);
                return;
            }
            // invoke handler
            try
            {
                handler.HandleUserData(userDataFile);
            }
            catch (Exception e)
            {
                EucaLogger.Exception("User data handler threw exception", e);
            }
            // return
        }
コード例 #4
0
        private void ExecutePowershell(String powershellFile)
        {
            String exec = "powershell.exe";
            String args = String.Format("-NonInteractive -File {0}", powershellFile);

            EucaLogger.Debug(String.Format("Executing {0} {1}", exec, args));
            try
            {
                Win32_CommandResult result = SystemsUtil.SpawnProcessAndWait(exec, args);
                EucaLogger.Debug(String.Format("Execution finished with exit code={0}", result.ExitCode));
                EucaLogger.Debug(String.Format("Stdout: {0}", result.Stdout));
                EucaLogger.Debug(String.Format("Stderr: {0}", result.Stderr));
            }
            catch (Exception ex)
            {
                EucaLogger.Exception("Execution failed", ex);
            }
        }
コード例 #5
0
        private void ExecuteCommandLine(String scriptFile)
        {
            String exec = "cmd.exe";
            String args = String.Format("/c {0}", scriptFile);

            EucaLogger.Debug(String.Format("Executing {0} {1}", exec, args));
            try
            {
                Win32_CommandResult result = SystemsUtil.SpawnProcessAndWait(exec, args);
                EucaLogger.Debug(String.Format("Execution finished with exit code={0}", result.ExitCode));
                EucaLogger.Debug(String.Format("Stdout: {0}", result.Stdout));
                EucaLogger.Debug(String.Format("Stderr: {0}", result.Stderr));
            }
            catch (Exception ex)
            {
                EucaLogger.Exception("Execution failed", ex);
            }
        }
コード例 #6
0
        /*
         * <eucalyptus>
         * key1:value1
         * key2:value2
         * </eucalytpus>
         *
         * <eucalyptus> key1:value1, key2:value2 </eucalyptus>
         */
        override protected void Handle()
        {
            var keyValues = this.AsMultiLinesWithoutTag
                            .Where(line => line.Split(':').Length == 2)
                            .Select(line => new KeyValuePair <String, String>(line.Split(':')[0], line.Split(':')[1]));

            foreach (var kv in keyValues)
            {
                try
                {
                    SetEucaRegistryValue(kv.Key, kv.Value);
                    EucaLogger.Debug(String.Format("Eucalyptus registry updated: {0}-{1}", kv.Key, kv.Value));
                }
                catch (Exception e)
                {
                    EucaLogger.Exception("Could not set registry value", e);
                }
            }
        }
コード例 #7
0
        override protected void Handle()
        {
            EucaLogger.Debug("Script/Powershell Handler invoked");

            List <String> scripts = MakeScriptFragments();

            foreach (String file in scripts)
            {
                if (file.EndsWith(".cmd"))
                {
                    ExecuteCommandLine(file);
                }
                else if (file.EndsWith(".ps1"))
                {
                    ExecutePowershell(file);
                }
                else
                {
                    EucaLogger.Error("Unknown file format found");
                }
            }
        }
コード例 #8
0
        private void buttonSysprep_Click(object sender, EventArgs e)
        {
            //   IMPLEMENT_SYS_PREP;
            try
            {
                DialogResult answer = MessageBox.Show("Sysprep should be performed only when you are finished with VM setup. Do you want to run the sysprep now?",
                                                      "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (answer == DialogResult.No)
                {
                    return;
                }

                string answerPath = this.SysprepAnswerFile;
                if (answerPath == null)
                {
                    MessageBox.Show("Sysprep is not supported on this Windows version. Please check with the administration manual to find the supported OS",
                                    "WARNING");
                    return;
                }

                if (!File.Exists(answerPath))
                {
                    MessageBox.Show(string.Format("Sysprep answer file is not found ({0})", answerPath));
                    return;
                }

                string sysprepDest = string.Format("C:\\{0}", (new FileInfo(answerPath)).Name);
                if (File.Exists(sysprepDest))
                {
                    File.Delete(sysprepDest);
                }

                File.Copy(answerPath, sysprepDest);
                string sysprepExec = string.Format("{0}\\sysprep\\sysprep.exe",
                                                   Environment.GetFolderPath(Environment.SpecialFolder.System));

                string arg = string.Format("/generalize /oobe /quit /unattend:\"{0}\"", sysprepDest);
                EucaLogger.Debug("sysprep argument: " + arg);

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.UseShellExecute = true;

                Win32_CommandResult result = EucaUtil.SpawnProcessAndWait(sysprepExec, arg);
                if (result.ExitCode != 0)
                {
                    MessageBox.Show(string.Format("Sysprep returned exit code: {0}", result.ExitCode));
                    EucaLogger.Debug(string.Format("Sysprep exit code: {0}, stdout: {1}, stderr: {2}", result.ExitCode, result.Stdout, result.Stderr));
                    return;
                }
                else
                {
                    MessageBox.Show("Sysprep finished successfully. You can shutdown the VM and register it with Eucalyptus front-end.");
                    System.Environment.Exit(0);
                }
            }
            catch (Exception ie)
            {
                MessageBox.Show(string.Format("Unexpected exception thrown: {0}", ie.Message), "WARNING");
                EucaLogger.Exception("Unexpected exception thrown while running sysprep", ie);
                return;
            }
        }
コード例 #9
0
 override protected void Handle()
 {
     EucaLogger.Debug("Bogus handler");
 }