예제 #1
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);
                }
            }
        }
 void tryDecompress(String userDataFile, String unzippedDir)
 {
     EucaFileUtil.Unzip(unzippedDir, userDataFile);
 }
예제 #3
0
        protected override void OnAfterInstall(IDictionary savedState)
        {
            base.OnAfterInstall(savedState);
            try
            {
                RegistryKey regKey =
                    Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Eucalyptus Systems").
                    OpenSubKey("Eucalyptus", true);
                if (regKey == null)
                {
                    regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE").OpenSubKey("Eucalyptus Systems").
                             OpenSubKey("Eucalyptus", true);
                }
                object objLocation = regKey.GetValue("InstallLocation");
                regKey.Close();

                if (objLocation == null)
                {
                    string msg = "Can't retrieve Eucalyptus' location from registry";
                    Log(msg);
                    throw new Exception(msg); /// will halt the installation
                }
                _installLocation = (string)objLocation;
                string exe = _installLocation + "\\" + "PostInstallation.exe";

                if (!System.IO.File.Exists(exe))
                {
                    string msg = string.Format("Can't find the 'PostInstallation.exe' in {0}", _installLocation);
                    Log(msg);
                    throw new Exception(msg); // will halt the installation
                }

                string xenPVFile  = _installLocation + "\\xenpv.zip";
                string virtioFile = _installLocation + "\\virtio.zip";
                string vmwareFile = _installLocation + "\\vmware";
                string hypervFile = _installLocation + "\\hyperv";

                if (!(File.Exists(xenPVFile) || File.Exists(virtioFile) || File.Exists(vmwareFile) || File.Exists(hypervFile)))
                {
                    throw new InstallException("No hypervisor is chosen!");
                }
                int retCode = 0;
                try
                {
                    retCode = LaunchEucaPostInstaller(exe, "--registry");
                    if (retCode != 0)
                    {
                        Log(string.Format("[FAILURE]'PostInstaller.exe --registry' returned error code ({0})", retCode));
                    }
                }
                catch (Exception e)
                {
                    Log(string.Format("[FAILURE] 'PostInstllation.exe --registry generated exception ({0})", e.Message));
                }

                try
                {
                    retCode = LaunchEucaPostInstaller(exe, "--envconf");
                    if (retCode != 0)
                    {
                        Log(string.Format("[FAILURE]'PostInstaller.exe --envconf' returned error code ({0})", retCode));
                    }
                }
                catch (Exception e)
                {
                    Log(string.Format("[FAILURE] 'PostInstllation.exe --envconf generated exception ({0})", e.Message));
                }

                try
                {
                    retCode = LaunchEucaPostInstaller(exe, "--norecovery");
                    if (retCode != 0)
                    {
                        Log(string.Format("[FAILURE] 'PostInstaller.exe --norecovery' returned error code ({0})", retCode));
                    }
                }
                catch (Exception e)
                {
                    Log(string.Format("[FAILURE] 'PostInstllation.exe --norecovery generated exception ({0})", e.Message));
                }

                string xenPVDir = _installLocation + "\\xenpv";
                try
                {
                    if (File.Exists(xenPVFile))
                    {
                        if (EucaFileUtil.Unzip(_installLocation, xenPVFile))
                        {
                            ;
                        }
                        else
                        {
                            Log(string.Format("[FAILURE] Couldn't install xenpv; unzip failed for file: {0}", xenPVFile));
                        }
                    }
                    else // meaning that xenpv is not checked during the installation
                    {
                        ;
                    }
                }
                catch (Exception e)
                {
                    Log(e.Message);
                    Log(e.StackTrace);
                    throw e;    /// this will termnate installation abnormally
                }
                finally
                {
                    try
                    {
                        if (File.Exists(xenPVFile))
                        {
                            File.Delete(xenPVFile);
                        }
                    }
                    catch (Exception) { }
                }

                string virtioDir = _installLocation + "\\virtio";
                try
                {
                    if (File.Exists(virtioFile))
                    {
                        if (EucaFileUtil.Unzip(_installLocation, virtioFile))
                        {
                            string[] paths = Directory.GetDirectories(virtioDir);
                            if (paths != null && paths.Length > 0)
                            {
                                if (paths.Length > 1)
                                {
                                    Log(string.Format("[WARNING] Multiple virtio drivers are found; we're using {0}", paths[0]));
                                }
                                retCode = LaunchEucaPostInstaller(exe, string.Format("--virtio \"{0}\"", paths[0]));
                                if (retCode != 0)
                                {
                                    Log(string.Format("[FAILURE] 'PostInstallation.exe --virtio returned error code ({0})", retCode));
                                    throw new Exception("Could not complete KVM VirtIO installation; Please see Eucalyptus documentation");
                                }
                            }
                            else
                            {
                                Log(string.Format("[FAILURE] Virtio drivers are not found in {0}", virtioDir));
                            }
                        }
                        else
                        {
                            Log(string.Format("[FAILURE] Virtio installation failed; could not unzip file: {0}", virtioFile));
                        }
                    }
                    else
                    {
                        ; // means that virtio option is not checked during the installation
                    }
                }
                catch (Exception e)
                {
                    throw e;  /// this will termnate installation abnormally
                }
                finally
                {
                    try
                    {
                        if (File.Exists(virtioFile))
                        {
                            File.Delete(virtioFile);
                        }
                    }
                    catch (Exception) { }
                }
            }
            catch (Exception e)
            {
                Log("Eucalyptus installation has failed.");
                Log(e.Message);
                Log(e.StackTrace);
                throw e;
            }
        }