Exemplo n.º 1
0
        /// <summary>
        /// Creates VM base on config settings
        /// </summary>
        /// <param name="configAction">settings object to configure what to have virtualbox create</param>
        /// <param name="callback"></param>
        public void CreateVm(Action <CreateVmSettings> configAction = null, Action <IProcess> callback = null)
        {
            var settings = new CreateVmSettings();

            configAction?.Invoke(settings);

            this.RunCreateVm(settings, callback);
        }
Exemplo n.º 2
0
        private void RunCreateVm(CreateVmSettings vmSetting, Action <IProcess> callback = null, int retryTimes = 0)
        {
            if (vmSetting == null)
            {
                return;
            }

            var args = new ProcessArgumentBuilder();

            args.Append("createvm");
            args.Append("--name");
            args.Append(vmSetting.VmName);
            args.Append("--ostype");
            args.Append(vmSetting.OsType);
            args.Append("--register");

            this.Log.Information("createvm name: {0}", vmSetting.VmName);

            this.Run(this.Settings, args, this.GetProcessSettings(callback != null), proc =>
            {
                if (proc.GetExitCode() != 0)
                {
                    var errStrings = proc.GetStandardError().ToArray();
                    var stderr     = string.Join("\n", errStrings);
                    this.Log.Error("Failed to create vm for: {0}. Bailing. Error: {1}", vmSetting.VmName, stderr);
                }
                else
                {
                    foreach (var contollerSetting in vmSetting.ControllerSettings)
                    {
                        this.RunCreateStorageCtl(vmSetting.VmName, contollerSetting, controllerProc =>
                        {
                            if (controllerProc.GetExitCode() != 0)
                            {
                                this.Log.Error("Failed to create controller: {0} for vm: {1}", contollerSetting.Name, vmSetting.VmName);
                            }
                        });
                    }
                }

                callback?.Invoke(proc);
            });
        }