Merge pull request #323 from MihaelaStoica/CP-10927

CP-10927: Add container restart operation and add all lifetime operations to the toolbar
This commit is contained in:
Gabor Apati-Nagy 2015-02-11 17:11:47 +00:00
commit e92ae33cc7
13 changed files with 359 additions and 6 deletions

View File

@ -1303,6 +1303,7 @@ namespace XenAdmin.Commands
items.AddIfEnabled(new StopDockerContainerCommand(mainWindow, selection));
items.AddIfEnabled(new PauseDockerContainerCommand(mainWindow, selection));
items.AddIfEnabled(new ResumeDockerContainerCommand(mainWindow, selection));
items.AddIfEnabled(new RestartDockerContainerCommand(mainWindow, selection));
}
public override bool IsValid(SelectedItemCollection selection)
@ -1329,6 +1330,7 @@ namespace XenAdmin.Commands
items.AddIfEnabled(new StopDockerContainerCommand(mainWindow, selection));
items.AddIfEnabled(new PauseDockerContainerCommand(mainWindow, selection));
items.AddIfEnabled(new ResumeDockerContainerCommand(mainWindow, selection));
items.AddIfEnabled(new RestartDockerContainerCommand(mainWindow, selection));
}
public override bool IsValid(SelectedItemCollection selection)

View File

@ -52,6 +52,8 @@ namespace XenAdmin.Commands
public override Image MenuImage { get { return Resources._000_paused_h32bit_16; } }
public override Image ToolBarImage { get { return Resources._000_Paused_h32bit_24; } }
protected override bool CanExecuteCore(SelectedItemCollection selection)
{
if (selection.AllItemsAre<DockerContainer>())

View File

@ -0,0 +1,85 @@
/* Copyright (c) Citrix Systems Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using XenAdmin.Actions;
using XenAdmin.Model;
using XenAdmin.Properties;
using XenAPI;
namespace XenAdmin.Commands
{
internal class RestartDockerContainerCommand : Command
{
public RestartDockerContainerCommand()
{ }
public RestartDockerContainerCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection)
: base(mainWindow, selection)
{ }
public override string MenuText { get { return Messages.MAINWINDOW_RESTART; } }
public override Image MenuImage { get { return Resources._001_Reboot_h32bit_16; } }
public override Image ToolBarImage { get { return Resources._001_Reboot_h32bit_24; } }
protected override bool CanExecuteCore(SelectedItemCollection selection)
{
if (selection.AllItemsAre<DockerContainer>())
return selection.AtLeastOneXenObjectCan<DockerContainer>(CanExecute);
return false;
}
private static bool CanExecute(DockerContainer dockerContainer)
{
return dockerContainer.power_state == vm_power_state.Running;
}
protected override void ExecuteCore(SelectedItemCollection selection)
{
var dockerContainers = new List<DockerContainer>();
if (selection.AllItemsAre<DockerContainer>())
{
dockerContainers = (from IXenObject obj in selection.AsXenObjects()
let container = (DockerContainer)obj
where CanExecute(container)
select container).ToList();
}
foreach (var container in dockerContainers)
(new RestartDockerContainerAction(container)).RunAsync();
}
}
}

View File

@ -52,6 +52,8 @@ namespace XenAdmin.Commands
public override Image MenuImage { get { return Resources._000_Resumed_h32bit_16; } }
public override Image ToolBarImage { get { return Resources._000_Resumed_h32bit_24; } }
protected override bool CanExecuteCore(SelectedItemCollection selection)
{
if (selection.AllItemsAre<DockerContainer>())

View File

@ -49,9 +49,11 @@ namespace XenAdmin.Commands
{ }
public override string MenuText { get { return Messages.MAINWINDOW_START; } }
public override Image MenuImage { get { return Resources._001_PowerOn_h32bit_16; } }
public override Image ToolBarImage { get { return Resources._001_PowerOn_h32bit_24; } }
protected override bool CanExecuteCore(SelectedItemCollection selection)
{
if (selection.AllItemsAre<DockerContainer>())

View File

@ -49,9 +49,11 @@ namespace XenAdmin.Commands
{ }
public override string MenuText { get { return Messages.MAINWINDOW_STOP; } }
public override Image MenuImage { get { return Resources._001_ShutDown_h32bit_16; } }
public override Image ToolBarImage { get { return Resources._001_ShutDown_h32bit_24; } }
protected override bool CanExecuteCore(SelectedItemCollection selection)
{
if (selection.AllItemsAre<DockerContainer>())

View File

@ -114,6 +114,11 @@ namespace XenAdmin
this.SuspendToolbarButton = new XenAdmin.Commands.CommandToolStripButton();
this.ForceShutdownToolbarButton = new XenAdmin.Commands.CommandToolStripButton();
this.ForceRebootToolbarButton = new XenAdmin.Commands.CommandToolStripButton();
this.stopContainerToolStripButton = new XenAdmin.Commands.CommandToolStripButton();
this.startContainerToolStripButton = new XenAdmin.Commands.CommandToolStripButton();
this.restartContainerToolStripButton = new XenAdmin.Commands.CommandToolStripButton();
this.resumeContainerToolStripButton = new XenAdmin.Commands.CommandToolStripButton();
this.pauseContainerToolStripButton = new XenAdmin.Commands.CommandToolStripButton();
this.statusToolTip = new System.Windows.Forms.ToolTip(this.components);
this.ToolBarContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.ShowToolbarMenuItem = new System.Windows.Forms.ToolStripMenuItem();
@ -559,7 +564,12 @@ namespace XenAdmin
this.resumeToolStripButton,
this.SuspendToolbarButton,
this.ForceShutdownToolbarButton,
this.ForceRebootToolbarButton});
this.ForceRebootToolbarButton,
this.stopContainerToolStripButton,
this.startContainerToolStripButton,
this.restartContainerToolStripButton,
this.resumeContainerToolStripButton,
this.pauseContainerToolStripButton});
this.ToolStrip.Name = "ToolStrip";
this.ToolStrip.Stretch = true;
this.ToolStrip.TabStop = true;
@ -688,6 +698,41 @@ namespace XenAdmin
this.ForceRebootToolbarButton.Image = global::XenAdmin.Properties.Resources._001_ForceReboot_h32bit_24;
this.ForceRebootToolbarButton.Name = "ForceRebootToolbarButton";
//
// stopContainerToolStripButton
//
this.stopContainerToolStripButton.Command = new XenAdmin.Commands.StopDockerContainerCommand();
resources.ApplyResources(this.stopContainerToolStripButton, "stopContainerToolStripButton");
this.stopContainerToolStripButton.Image = global::XenAdmin.Properties.Resources._001_ShutDown_h32bit_24;
this.stopContainerToolStripButton.Name = "stopContainerToolStripButton";
//
// startContainerToolStripButton
//
this.startContainerToolStripButton.Command = new XenAdmin.Commands.StartDockerContainerCommand();
resources.ApplyResources(this.startContainerToolStripButton, "startContainerToolStripButton");
this.startContainerToolStripButton.Image = global::XenAdmin.Properties.Resources._001_PowerOn_h32bit_24;
this.startContainerToolStripButton.Name = "startContainerToolStripButton";
//
// restartContainerToolStripButton
//
this.restartContainerToolStripButton.Command = new XenAdmin.Commands.RestartDockerContainerCommand();
resources.ApplyResources(this.restartContainerToolStripButton, "restartContainerToolStripButton");
this.restartContainerToolStripButton.Image = global::XenAdmin.Properties.Resources._001_Reboot_h32bit_24;
this.restartContainerToolStripButton.Name = "restartContainerToolStripButton";
//
// resumeContainerToolStripButton
//
this.resumeContainerToolStripButton.Command = new XenAdmin.Commands.ResumeDockerContainerCommand();
resources.ApplyResources(this.resumeContainerToolStripButton, "resumeContainerToolStripButton");
this.resumeContainerToolStripButton.Image = global::XenAdmin.Properties.Resources._000_Resumed_h32bit_24;
this.resumeContainerToolStripButton.Name = "resumeContainerToolStripButton";
//
// pauseContainerToolStripButton
//
this.pauseContainerToolStripButton.Command = new XenAdmin.Commands.PauseDockerContainerCommand();
resources.ApplyResources(this.pauseContainerToolStripButton, "pauseContainerToolStripButton");
this.pauseContainerToolStripButton.Image = global::XenAdmin.Properties.Resources._000_Paused_h32bit_24;
this.pauseContainerToolStripButton.Name = "pauseContainerToolStripButton";
//
// ToolBarContextMenu
//
this.ToolBarContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -2040,6 +2085,11 @@ namespace XenAdmin
private ToolStripStatusLabel statusLabel;
private ToolStripProgressBar statusProgressBar;
private CommandToolStripMenuItem reclaimFreedSpacetripMenuItem;
private CommandToolStripButton startContainerToolStripButton;
private CommandToolStripButton stopContainerToolStripButton;
private CommandToolStripButton pauseContainerToolStripButton;
private CommandToolStripButton resumeContainerToolStripButton;
private CommandToolStripButton restartContainerToolStripButton;
}
}

View File

@ -1243,12 +1243,22 @@ namespace XenAdmin
ToolStrip.Enabled = ToolbarsEnabled;
ShowToolbarMenuItem.Checked = toolbarToolStripMenuItem.Checked = ToolbarsEnabled;
bool containerButtonsAvailable = startContainerToolStripButton.Enabled || stopContainerToolStripButton.Enabled ||
resumeContainerToolStripButton.Enabled || pauseContainerToolStripButton.Enabled || restartContainerToolStripButton.Enabled;
startContainerToolStripButton.Available = containerButtonsAvailable && startContainerToolStripButton.Enabled;
stopContainerToolStripButton.Available = containerButtonsAvailable && (stopContainerToolStripButton.Enabled || !startContainerToolStripButton.Available);
resumeContainerToolStripButton.Available = containerButtonsAvailable && resumeContainerToolStripButton.Enabled;
pauseContainerToolStripButton.Available = containerButtonsAvailable && (pauseContainerToolStripButton.Enabled || !resumeContainerToolStripButton.Available);
restartContainerToolStripButton.Available = containerButtonsAvailable;
powerOnHostToolStripButton.Available = powerOnHostToolStripButton.Enabled;
startVMToolStripButton.Available = startVMToolStripButton.Enabled;
shutDownToolStripButton.Available = shutDownToolStripButton.Enabled || (!startVMToolStripButton.Available && !powerOnHostToolStripButton.Available);
shutDownToolStripButton.Available = shutDownToolStripButton.Enabled || (!startVMToolStripButton.Available && !powerOnHostToolStripButton.Available && !containerButtonsAvailable);
RebootToolbarButton.Available = RebootToolbarButton.Enabled || !containerButtonsAvailable;
resumeToolStripButton.Available = resumeToolStripButton.Enabled;
SuspendToolbarButton.Available = SuspendToolbarButton.Enabled || !resumeToolStripButton.Available;
SuspendToolbarButton.Available = SuspendToolbarButton.Enabled || (!resumeToolStripButton.Available && !containerButtonsAvailable);
ForceRebootToolbarButton.Available = ((ForceVMRebootCommand)ForceRebootToolbarButton.Command).ShowOnMainToolBar;
ForceShutdownToolbarButton.Available = ((ForceVMShutDownCommand)ForceShutdownToolbarButton.Command).ShowOnMainToolBar;

View File

@ -1503,6 +1503,111 @@
<data name="ForceRebootToolbarButton.Visible" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="stopContainerToolStripButton.Font" type="System.Drawing.Font, System.Drawing">
<value>Tahoma, 8.25pt</value>
</data>
<data name="stopContainerToolStripButton.ImageAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="stopContainerToolStripButton.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
<value>Magenta</value>
</data>
<data name="stopContainerToolStripButton.Size" type="System.Drawing.Size, System.Drawing">
<value>33, 17</value>
</data>
<data name="stopContainerToolStripButton.Text" xml:space="preserve">
<value>Stop</value>
</data>
<data name="stopContainerToolStripButton.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="stopContainerToolStripButton.ToolTipText" xml:space="preserve">
<value>Stop Docker Container</value>
</data>
<data name="startContainerToolStripButton.Font" type="System.Drawing.Font, System.Drawing">
<value>Tahoma, 8.25pt</value>
</data>
<data name="startContainerToolStripButton.ImageAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="startContainerToolStripButton.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
<value>Magenta</value>
</data>
<data name="startContainerToolStripButton.Size" type="System.Drawing.Size, System.Drawing">
<value>59, 28</value>
</data>
<data name="startContainerToolStripButton.Text" xml:space="preserve">
<value>Start</value>
</data>
<data name="startContainerToolStripButton.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="startContainerToolStripButton.ToolTipText" xml:space="preserve">
<value>Start Docker Container</value>
</data>
<data name="restartContainerToolStripButton.Font" type="System.Drawing.Font, System.Drawing">
<value>Tahoma, 8.25pt</value>
</data>
<data name="restartContainerToolStripButton.ImageAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="restartContainerToolStripButton.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
<value>Magenta</value>
</data>
<data name="restartContainerToolStripButton.Size" type="System.Drawing.Size, System.Drawing">
<value>71, 28</value>
</data>
<data name="restartContainerToolStripButton.Text" xml:space="preserve">
<value>Restart</value>
</data>
<data name="restartContainerToolStripButton.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="restartContainerToolStripButton.ToolTipText" xml:space="preserve">
<value>Restart Docker Container</value>
</data>
<data name="resumeContainerToolStripButton.Font" type="System.Drawing.Font, System.Drawing">
<value>Tahoma, 8.25pt</value>
</data>
<data name="resumeContainerToolStripButton.ImageAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="resumeContainerToolStripButton.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
<value>Magenta</value>
</data>
<data name="resumeContainerToolStripButton.Size" type="System.Drawing.Size, System.Drawing">
<value>73, 28</value>
</data>
<data name="resumeContainerToolStripButton.Text" xml:space="preserve">
<value>Resume</value>
</data>
<data name="resumeContainerToolStripButton.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="resumeContainerToolStripButton.ToolTipText" xml:space="preserve">
<value>Resume Docker Container</value>
</data>
<data name="pauseContainerToolStripButton.Font" type="System.Drawing.Font, System.Drawing">
<value>Tahoma, 8.25pt</value>
</data>
<data name="pauseContainerToolStripButton.ImageAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="pauseContainerToolStripButton.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
<value>Magenta</value>
</data>
<data name="pauseContainerToolStripButton.Size" type="System.Drawing.Size, System.Drawing">
<value>64, 28</value>
</data>
<data name="pauseContainerToolStripButton.Text" xml:space="preserve">
<value>Pause</value>
</data>
<data name="pauseContainerToolStripButton.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="pauseContainerToolStripButton.ToolTipText" xml:space="preserve">
<value>Pause Docker Container</value>
</data>
<data name="ToolStrip.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 24</value>
</data>
@ -2654,6 +2759,36 @@
<data name="&gt;&gt;ForceRebootToolbarButton.Type" xml:space="preserve">
<value>XenAdmin.Commands.CommandToolStripButton, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;stopContainerToolStripButton.Name" xml:space="preserve">
<value>stopContainerToolStripButton</value>
</data>
<data name="&gt;&gt;stopContainerToolStripButton.Type" xml:space="preserve">
<value>XenAdmin.Commands.CommandToolStripButton, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;startContainerToolStripButton.Name" xml:space="preserve">
<value>startContainerToolStripButton</value>
</data>
<data name="&gt;&gt;startContainerToolStripButton.Type" xml:space="preserve">
<value>XenAdmin.Commands.CommandToolStripButton, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;restartContainerToolStripButton.Name" xml:space="preserve">
<value>restartContainerToolStripButton</value>
</data>
<data name="&gt;&gt;restartContainerToolStripButton.Type" xml:space="preserve">
<value>XenAdmin.Commands.CommandToolStripButton, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;resumeContainerToolStripButton.Name" xml:space="preserve">
<value>resumeContainerToolStripButton</value>
</data>
<data name="&gt;&gt;resumeContainerToolStripButton.Type" xml:space="preserve">
<value>XenAdmin.Commands.CommandToolStripButton, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;pauseContainerToolStripButton.Name" xml:space="preserve">
<value>pauseContainerToolStripButton</value>
</data>
<data name="&gt;&gt;pauseContainerToolStripButton.Type" xml:space="preserve">
<value>XenAdmin.Commands.CommandToolStripButton, XenCenterMain, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;statusToolTip.Name" xml:space="preserve">
<value>statusToolTip</value>
</data>

View File

@ -108,6 +108,7 @@
<Compile Include="Alerts\Types\MessageAlert.cs" />
<Compile Include="Alerts\Types\XenServerPatchAlert.cs" />
<Compile Include="Alerts\Types\XenServerVersionAlert.cs" />
<Compile Include="Commands\RestartDockerContainerCommand.cs" />
<Compile Include="Commands\ResumeDockerContainerCommand.cs" />
<Compile Include="Commands\PauseDockerContainerCommand.cs" />
<Compile Include="Commands\StopDockerContainerCommand.cs" />

View File

@ -106,4 +106,18 @@ namespace XenAdmin.Actions
"unpause")
{ }
}
/// <summary>
/// Restart the Docker container
/// </summary>
public class RestartDockerContainerAction : DockerContainerLifetimeAction
{
public RestartDockerContainerAction(DockerContainer dockerContainer)
: base(dockerContainer,
string.Format(Messages.ACTION_RESTART_CONTAINER_TITLE, dockerContainer.Name),
Messages.ACTION_RESTART_CONTAINER_DESCRIPTION,
Messages.ACTION_RESTART_CONTAINER_END_DESCRIPTION,
"restart")
{ }
}
}

View File

@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.34209
// Runtime Version:4.0.30319.18444
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@ -1437,6 +1437,33 @@ namespace XenAdmin {
}
}
/// <summary>
/// Looks up a localized string similar to Restarting.
/// </summary>
public static string ACTION_RESTART_CONTAINER_DESCRIPTION {
get {
return ResourceManager.GetString("ACTION_RESTART_CONTAINER_DESCRIPTION", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Restarted.
/// </summary>
public static string ACTION_RESTART_CONTAINER_END_DESCRIPTION {
get {
return ResourceManager.GetString("ACTION_RESTART_CONTAINER_END_DESCRIPTION", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Restarting Docker Container &apos;{0}&apos;.
/// </summary>
public static string ACTION_RESTART_CONTAINER_TITLE {
get {
return ResourceManager.GetString("ACTION_RESTART_CONTAINER_TITLE", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Resuming.
/// </summary>
@ -19394,6 +19421,15 @@ namespace XenAdmin {
}
}
/// <summary>
/// Looks up a localized string similar to Re&amp;start.
/// </summary>
public static string MAINWINDOW_RESTART {
get {
return ResourceManager.GetString("MAINWINDOW_RESTART", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Restart Toolstac&amp;k.
/// </summary>

View File

@ -12482,4 +12482,16 @@ You will need to navigate to the Console on each of the selected VMs to complete
<data name="YOU_ARE_HERE" xml:space="preserve">
<value>You are here</value>
</data>
<data name="ACTION_RESTART_CONTAINER_DESCRIPTION" xml:space="preserve">
<value>Restarting</value>
</data>
<data name="ACTION_RESTART_CONTAINER_END_DESCRIPTION" xml:space="preserve">
<value>Restarted</value>
</data>
<data name="ACTION_RESTART_CONTAINER_TITLE" xml:space="preserve">
<value>Restarting Docker Container '{0}'</value>
</data>
<data name="MAINWINDOW_RESTART" xml:space="preserve">
<value>Re&amp;start</value>
</data>
</root>