コード例 #1
0
        public CreateVMAction(IXenConnection connection, VM template, Host copyBiosStringsFrom, string name, string description, InstallMethod installMethod,
                              string pvArgs, VDI cd, string url, Host homeServer, long vcpus, long memoryDynamicMin, long memoryDynamicMax, long memoryStaticMax,
                              List <DiskDescription> disks, SR fullCopySR, List <VIF> vifs, bool startAfter, Action <VM, bool> warningDialogHAInvalidConfig, Action <VMStartAbstractAction, Failure> startDiagnosisForm)
            : base(connection, string.Format(Messages.CREATE_VM, name), string.Format(Messages.CREATE_VM_FROM_TEMPLATE, name, Helpers.GetName(template)))
        {
            Template            = template;
            CopyBiosStringsFrom = copyBiosStringsFrom;
            FullCopySR          = fullCopySR;
            NameLabel           = name;
            NameDescription     = description;
            InsMethod           = installMethod;
            PvArgs           = pvArgs;
            Cd               = cd;
            Url              = url;
            HomeServer       = homeServer;
            Vcpus            = vcpus;
            MemoryDynamicMin = memoryDynamicMin;
            MemoryDynamicMax = memoryDynamicMax;
            MemoryStaticMax  = memoryStaticMax;
            Disks            = disks;
            Vifs             = vifs;
            StartAfter       = startAfter;
            _warningDialogHAInvalidConfig = warningDialogHAInvalidConfig;
            _startDiagnosisForm           = startDiagnosisForm;

            Pool pool_of_one = Helpers.GetPoolOfOne(Connection);

            if (HomeServer != null || pool_of_one != null) // otherwise we have no where to put the action
            {
                AppliesTo.Add(HomeServer != null ? HomeServer.opaque_ref : pool_of_one.opaque_ref);
            }

            #region RBAC Dependencies

            if (StartAfter)
            {
                ApiMethodsToRoleCheck.Add("vm.start");
            }
            if (HomeServerChanged())
            {
                ApiMethodsToRoleCheck.Add("vm.set_affinity");
            }
            if (Template.memory_dynamic_min != MemoryDynamicMin || Template.memory_dynamic_max != MemoryDynamicMax || Template.memory_static_max != MemoryStaticMax)
            {
                ApiMethodsToRoleCheck.Add("vm.set_memory_limits");
            }

            ApiMethodsToRoleCheck.AddRange(StaticRBACDependencies);

            ApiMethodsToRoleCheck.AddRange(Role.CommonTaskApiList);
            ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList);
            #endregion
        }
コード例 #2
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                log.Remove(0, log.Length);
                InstallMethod im          = new InstallMethod(installer.Create);
                AsyncCallback cb          = new AsyncCallback(InstallCallback);
                IAsyncResult  asyncResult = im.BeginInvoke(schema, cb, im);

                WaitHandle[] bg   = new WaitHandle[] { asyncResult.AsyncWaitHandle };
                Progress     prog = new Progress(StatusMessage.Running);
                while (prog.Status != StatusMessage.Exit)
                {
                    prog = installer.GetProgress(!WaitHandle.WaitAll(bg, 100, true));
                    backgroundWorker1.ReportProgress(prog.Percent, prog);
                }
            }
            catch (Exception ex)
            {
                Progress prog = new Progress(StatusMessage.Exit, 100, ex.Message);
                backgroundWorker1.ReportProgress(prog.Percent, prog);
            }
        }
コード例 #3
0
ファイル: CreateVMAction.cs プロジェクト: ywwseu/xenadmin
        public CreateVMAction(IXenConnection connection, VM template, Host copyBiosStringsFrom,
                              string name, string description, InstallMethod installMethod,
                              string pvArgs, VDI cd, string url, Host homeServer, long vcpusMax, long vcpusAtStartup,
                              long memoryDynamicMin, long memoryDynamicMax, long memoryStaticMax,
                              List <DiskDescription> disks, SR fullCopySR, List <VIF> vifs, bool startAfter,
                              Action <VM, bool> warningDialogHAInvalidConfig,
                              Action <VMStartAbstractAction, Failure> startDiagnosisForm,
                              GPU_group gpuGroup, VGPU_type vgpuType, bool modifyVgpuSettings, long coresPerSocket, string cloudConfigDriveTemplateText)
            : base(connection, string.Format(Messages.CREATE_VM, name),
                   string.Format(Messages.CREATE_VM_FROM_TEMPLATE, name, Helpers.GetName(template)))
        {
            Template            = template;
            CopyBiosStringsFrom = copyBiosStringsFrom;
            FullCopySR          = fullCopySR;
            NameLabel           = name;
            NameDescription     = description;
            InsMethod           = installMethod;
            PvArgs           = pvArgs;
            Cd               = cd;
            Url              = url;
            HomeServer       = homeServer;
            VcpusMax         = vcpusMax;
            VcpusAtStartup   = vcpusAtStartup;
            MemoryDynamicMin = memoryDynamicMin;
            MemoryDynamicMax = memoryDynamicMax;
            MemoryStaticMax  = memoryStaticMax;
            Disks            = disks;
            Vifs             = vifs;
            StartAfter       = startAfter;
            _warningDialogHAInvalidConfig = warningDialogHAInvalidConfig;
            _startDiagnosisForm           = startDiagnosisForm;
            GpuGroup       = gpuGroup;
            VgpuType       = vgpuType;
            CoresPerSocket = coresPerSocket;
            this.cloudConfigDriveTemplateText = cloudConfigDriveTemplateText;

            Pool pool_of_one = Helpers.GetPoolOfOne(Connection);

            if (HomeServer != null || pool_of_one != null) // otherwise we have no where to put the action
            {
                AppliesTo.Add(HomeServer != null ? HomeServer.opaque_ref : pool_of_one.opaque_ref);
            }

            assignOrRemoveVgpu = GpuGroup != null && VgpuType != null || modifyVgpuSettings && Helpers.GpuCapability(Connection);

            #region RBAC Dependencies

            if (StartAfter)
            {
                ApiMethodsToRoleCheck.Add("vm.start");
            }
            if (HomeServerChanged())
            {
                ApiMethodsToRoleCheck.Add("vm.set_affinity");
            }
            if (Template.memory_dynamic_min != MemoryDynamicMin || Template.memory_dynamic_max != MemoryDynamicMax || Template.memory_static_max != MemoryStaticMax)
            {
                ApiMethodsToRoleCheck.Add("vm.set_memory_limits");
            }

            if (assignOrRemoveVgpu)
            {
                ApiMethodsToRoleCheck.Add("VGPU.destroy");
                ApiMethodsToRoleCheck.Add("VGPU.create");
            }

            ApiMethodsToRoleCheck.AddRange(StaticRBACDependencies);

            ApiMethodsToRoleCheck.AddRange(Role.CommonTaskApiList);
            ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList);

            #endregion
        }
コード例 #4
0
ファイル: Manager.cs プロジェクト: kouweizhong/sqlinstaller
        /// <summary>
        /// Console application entry point.
        /// </summary>
        /// <param name="args">An array of arguments.</param>
        /// <returns>Zero (0) for success and non-zero for failure.</returns>
        public static async Task <int> Run(string[] args)
        {
            await Task.Delay(1);

            int       exitCode   = 0;
            double    spinCycle  = Constants.MinSpinTimeout;
            bool      forceWrite = false;
            Installer installer;
            Spinner   spin = new Spinner();

            try
            {
                string configPath = string.Empty;

                // Retain backwards compatability with using just config file as a single parameter.
                if (args.Length > 0 && !args[0].StartsWith("/", StringComparison.OrdinalIgnoreCase))
                {
                    configPath = args[0];
                    if (!File.Exists(configPath))
                    {
                        forceWrite = true;
                    }
                }
                else
                {
                    configPath = Path.Combine(Directory.GetCurrentDirectory(), Constants.SQLInstallerXml);
                }

                // Allow parameter overrides and/or specifying all parameters from command line.
                Arguments <Parameters> parms = null;
                if (File.Exists(configPath))
                {
                    parms = new Arguments <Parameters>(args, Parameters.Load(configPath));
                }
                else
                {
                    parms = new Arguments <Parameters>(args, new Parameters(configPath));
                }

                if (!parms.IsValid)
                {
                    throw new ApplicationException(parms.ValidationErrors);
                }

                if (parms.Instance.WriteConfig || forceWrite)
                {
                    if (!parms.Instance.IsProtected)
                    {
                        parms.Instance.ProtectConnectionString();
                    }
                    else
                    {
                        parms.Instance.Write();
                    }
                }

                spin.Start(spinCycle);
                Console.WriteLine(Resources.StatusConnecting);

                installer = new Installer(parms.Instance);
                installer.Prepare();
                spin.Stop();

                if (installer.Exists && !parms.Instance.Options.Has(Options.Drop))
                {
                    if (installer.IsCurrent && !parms.Instance.Options.Has(Options.Retry))
                    {
                        Console.WriteLine(parms.Instance.Database + Resources.StatusAlreadyUpgraded + installer.Version + Resources.StatusBy + installer.UpgradeBy);
                        return(0);
                    }
                    else
                    {
                        if (!parms.Instance.NoPrompt && !installer.CleanInstall)
                        {
                            ConsoleKey key = ConsoleKey.NoName;
                            while (key != ConsoleKey.N && key != ConsoleKey.Y)
                            {
                                Console.WriteLine();
                                Console.Write(Resources.AskUpgrade + parms.Instance.Database + Resources.AskToVersion + installer.Upgrade + Resources.AskYesNo);
                                key = Console.ReadKey(true).Key;
                            }

                            Console.WriteLine(key);
                            if (key == ConsoleKey.N)
                            {
                                return(0);
                            }
                        }
                    }
                }

                InstallMethod im = new InstallMethod(installer.Create);
                AsyncCallback cb = new AsyncCallback(InstallCallback);

                IAsyncResult asyncResult = im.BeginInvoke(cb, im);

                WaitHandle[] bg   = new WaitHandle[] { asyncResult.AsyncWaitHandle };
                Progress     prog = new Progress(StatusMessage.Running);
                while (prog.Status != StatusMessage.Exit)
                {
                    prog = installer.GetProgress(!WaitHandle.WaitAll(bg, 100, true));
                    switch (prog.Status)
                    {
                    case StatusMessage.Start:
                        Console.WriteLine(prog.Message + Constants.Wait);
                        spin.Start(spinCycle);
                        break;

                    case StatusMessage.Detail:
                        spin.Stop();
                        Console.WriteLine(prog.Message);
                        spin.Start(spinCycle);
                        break;

                    case StatusMessage.Exit:
                        spin.Stop();
                        Console.WriteLine(Resources.StatusCompletedWith + prog.Percent + Resources.StatusErrorCount);
                        break;

                    case StatusMessage.Complete:
                    case StatusMessage.Running:
                    case StatusMessage.Progress:
                    default:
                        break;
                    }
                }

                if (parms.Instance.Options.HasFlag(Options.ExitCode) && installer.Errors > 0)
                {
                    exitCode = -1;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format(Resources.ErrorGeneric, ex.Message));
                exitCode = -1;
            }
            finally
            {
                if (spin != null)
                {
                    spin.Stop();
                }
            }

            return(exitCode);
        }
コード例 #5
0
ファイル: Manager.cs プロジェクト: kouweizhong/sqlinstaller
        /// <summary>
        /// The callback method for the main installer thread.
        /// </summary>
        /// <param name="iar">The result from the called thread.</param>
        public static void InstallCallback(IAsyncResult iar)
        {
            InstallMethod im = (InstallMethod)iar.AsyncState;

            im.EndInvoke(iar);
        }
コード例 #6
0
        public CreateVMAction(IXenConnection connection, VM template, Host copyBiosStringsFrom,
            string name, string description, InstallMethod installMethod,
            string pvArgs, VDI cd, string url, Host homeServer, long vcpus,
            long memoryDynamicMin, long memoryDynamicMax, long memoryStaticMax,
            List<DiskDescription> disks, SR fullCopySR, List<VIF> vifs, bool startAfter,
            Action<VM, bool> warningDialogHAInvalidConfig,
            Action<VMStartAbstractAction, Failure> startDiagnosisForm,
            GPU_group gpuGroup, VGPU_type vgpuType, long coresPerSocket, string cloudConfigDriveTemplateText)
            : base(connection, string.Format(Messages.CREATE_VM, name),
            string.Format(Messages.CREATE_VM_FROM_TEMPLATE, name, Helpers.GetName(template)))
        {
            Template = template;
            CopyBiosStringsFrom = copyBiosStringsFrom;
            FullCopySR = fullCopySR;
            NameLabel = name;
            NameDescription = description;
            InsMethod = installMethod;
            PvArgs = pvArgs;
            Cd = cd;
            Url = url;
            HomeServer = homeServer;
            Vcpus = vcpus;
            MemoryDynamicMin = memoryDynamicMin;
            MemoryDynamicMax = memoryDynamicMax;
            MemoryStaticMax = memoryStaticMax;
            Disks = disks;
            Vifs = vifs;
            StartAfter = startAfter;
            _warningDialogHAInvalidConfig = warningDialogHAInvalidConfig;
            _startDiagnosisForm = startDiagnosisForm;
            GpuGroup = gpuGroup;
            VgpuType = vgpuType;
            CoresPerSocket = coresPerSocket;
            this.cloudConfigDriveTemplateText = cloudConfigDriveTemplateText;

            Pool pool_of_one = Helpers.GetPoolOfOne(Connection);
            if (HomeServer != null || pool_of_one != null) // otherwise we have no where to put the action
                AppliesTo.Add(HomeServer != null ? HomeServer.opaque_ref : pool_of_one.opaque_ref);

            assignOrRemoveVgpu = (GpuGroup != null && VgpuType != null)
                             || Helpers.GpuCapability(Connection);

            #region RBAC Dependencies

            if (StartAfter)
                ApiMethodsToRoleCheck.Add("vm.start");
            if (HomeServerChanged())
                ApiMethodsToRoleCheck.Add("vm.set_affinity");
            if (Template.memory_dynamic_min != MemoryDynamicMin || Template.memory_dynamic_max != MemoryDynamicMax || Template.memory_static_max != MemoryStaticMax)
                ApiMethodsToRoleCheck.Add("vm.set_memory_limits");

            if (assignOrRemoveVgpu)
            {
                ApiMethodsToRoleCheck.Add("VGPU.destroy");
                ApiMethodsToRoleCheck.Add("VGPU.create");
            }

            ApiMethodsToRoleCheck.AddRange(StaticRBACDependencies);

            ApiMethodsToRoleCheck.AddRange(Role.CommonTaskApiList);
            ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList);

            #endregion
        }
コード例 #7
0
        static int Main(string[] args)
        {
            int          returnCode = 0;
            CommandLine  cl         = new CommandLine();
            Runtime      installer;
            ProviderType provType = ProviderType.SqlServer;
            Spinner      spin     = new Spinner();

            try
            {
                cl.Required.Add("database", "Database name (required).");
                cl.Optional.Add("server", "Database server name (default last used).");
                cl.Optional.Add("create", "Create database if it does not exist.");
                cl.Optional.Add("drop", "Drop database if it exists.");
                cl.Optional.Add("verbose", "Show everything.");
                cl.Optional.Add("path", "Path to the scripts directory (default last used).");
                cl.Optional.Add("type", "Database type [SqlServer|Oracle|PostGres].");
                cl.Optional.Add("user", "Database user (if not using integrated security).");
                cl.Optional.Add("password", "Database user Password.");
                cl.Optional.Add("noprompt", "Do not prompt for upgrade.");
                cl.Optional.Add("retry", "Retry last upgrade (for development only).");
                cl.Optional.Add("?", "Help.");
                cl.Parse(args);

                if (cl.Parameters.ContainsKey("?"))
                {
                    System.Console.WriteLine(cl.ShowUsage());
                    System.Console.WriteLine("E.g. SqlInstaller.exe /database=MyDatabase /server=MyServer /path=\"C:\\SQL Scripts\\MyDatabase\" /verbose");
                }
                else
                {
                    string database = string.Empty;
                    string server   = string.Empty;
                    string path     = string.Empty;
                    try
                    {
                        using (RegistryKey installerKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\JHOB Technologies\SQLInstaller"))
                        {
                            if (cl.Parameters.ContainsKey("type"))
                            {
                                if (string.Compare(cl.Parameters["type"], "PostGres", true) == 0)
                                {
                                    provType = ProviderType.PostGres;
                                }
                                else if (string.Compare(cl.Parameters["type"], "Oracle", true) == 0)
                                {
                                    provType = ProviderType.Oracle;
                                }
                            }
                            if (cl.Parameters.ContainsKey("path"))
                            {
                                path = cl.Parameters["path"];
                                if (path.Length == 0 || string.Compare(path, "true", true) == 0)
                                {
                                    path = ".";
                                }
                            }
                            else
                            {
                                path = installerKey.GetValue("Scripts", ".") as string;
                            }
                            if (cl.Parameters.ContainsKey("server"))
                            {
                                server = cl.Parameters["server"];
                            }
                            if (server.Length == 0 || string.Compare(server, "true", true) == 0)
                            {
                                server = installerKey.GetValue("Server", "localhost") as string;
                            }
                            if (cl.Parameters.ContainsKey("database"))
                            {
                                database = cl.Parameters["database"];
                            }
                            installerKey.Close();
                        }
                    }
                    catch (Exception) { }

                    if (database.Length == 0 || string.Compare(database, "true", true) == 0)
                    {
                        throw new ArgumentException("Missing required parameter: /database");
                    }

                    RuntimeFlag flags = RuntimeFlag.None;

                    string user     = string.Empty;
                    string password = string.Empty;

                    if (cl.Parameters.ContainsKey("user"))
                    {
                        user = cl.Parameters["user"];
                    }
                    if (cl.Parameters.ContainsKey("password"))
                    {
                        password = cl.Parameters["password"];
                    }

                    if (!cl.Parameters.ContainsKey("create") || string.Compare(cl.Parameters["create"], "true", true) == 0)
                    {
                        flags |= RuntimeFlag.Create;
                    }
                    if (cl.Parameters.ContainsKey("drop") && string.Compare(cl.Parameters["drop"], "true", true) == 0)
                    {
                        flags |= RuntimeFlag.Drop;
                    }
                    if (cl.Parameters.ContainsKey("retry") && string.Compare(cl.Parameters["retry"], "true", true) == 0)
                    {
                        flags |= RuntimeFlag.Retry;
                    }
                    if (cl.Parameters.ContainsKey("verbose") && string.Compare(cl.Parameters["verbose"], "true", true) == 0)
                    {
                        flags |= RuntimeFlag.Verbose;
                    }

                    spin.Start(250);
                    System.Console.Write("Connecting to " + server + "...");

                    installer = new Runtime(path, flags);
                    Schema schema = installer.Prepare(provType, server, database, user, password);
                    spin.Stop();
                    System.Console.WriteLine("Done.");

                    try
                    {
                        using (RegistryKey installerKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\JHOB Technologies\SQLInstaller", true))
                        {
                            DirectoryInfo di = new DirectoryInfo(path);
                            installerKey.SetValue("Scripts", path, RegistryValueKind.String);
                            installerKey.SetValue("Server", server, RegistryValueKind.String);
                            installerKey.SetValue("Database", database, RegistryValueKind.String);
                            installerKey.Close();
                        }
                    }
                    catch (Exception) { }

                    if (schema.Exists && (flags & RuntimeFlag.Drop) != RuntimeFlag.Drop)
                    {
                        if (schema.IsCurrent)
                        {
                            System.Console.WriteLine(schema.Provider.Database + " has already been upgraded to " + schema.Version + " by " + schema.UpgradeBy);
                            return(0);
                        }
                        else
                        {
                            if (!cl.Parameters.ContainsKey("noprompt") || cl.Parameters["noprompt"].ToLower().StartsWith("f"))
                            {
                                ConsoleKey key = ConsoleKey.NoName;
                                while (key != ConsoleKey.N && key != ConsoleKey.Y)
                                {
                                    System.Console.Write("\rUpgrade " + schema.Provider.Database + " to Version " + schema.Upgrade + " (Y/N)? ");
                                    key = System.Console.ReadKey(true).Key;
                                }
                                System.Console.WriteLine(key);
                                if (key == ConsoleKey.N)
                                {
                                    return(0);
                                }
                            }
                        }
                    }

                    spin.Start(250);
                    InstallMethod im = new InstallMethod(installer.Create);
                    AsyncCallback cb = new AsyncCallback(InstallCallback);

                    IAsyncResult asyncResult = im.BeginInvoke(schema, cb, im);

                    WaitHandle[] bg   = new WaitHandle[] { asyncResult.AsyncWaitHandle };
                    Progress     prog = new Progress(StatusMessage.Running);
                    while (prog.Status != StatusMessage.Exit)
                    {
                        prog = installer.GetProgress(!WaitHandle.WaitAll(bg, 100, true));
                        switch (prog.Status)
                        {
                        case StatusMessage.Start:
                            System.Console.Write("\r" + prog.Message + "...");
                            break;

                        case StatusMessage.Complete:
                        case StatusMessage.Detail:
                            System.Console.WriteLine(prog.Message);
                            break;

                        case StatusMessage.Exit:
                            System.Console.WriteLine("Completed with " + prog.Percent + " errors.");
                            returnCode = prog.Percent;
                            break;

                        case StatusMessage.Running:
                        case StatusMessage.Progress:
                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                returnCode = -1;
                System.Console.WriteLine();
                System.Console.WriteLine(cl.ShowUsage());
                System.Console.WriteLine(ex.Message);
            }
            finally
            {
                if (spin != null)
                {
                    spin.Stop();
                }
            }

            return(returnCode);
        }
コード例 #8
0
 public InstallAttribute(Type type, InstallMethod method = InstallMethod.Single, string id = "")
 {
     this.type   = type;
     this.method = method;
     this.id     = id;
 }