2016-01-29 16:33:45 +01:00
|
|
|
/* Copyright (c) Citrix Systems Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
* 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;
|
2016-08-17 23:35:01 +02:00
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Actions
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// This action installs the PV tools on a selected windows VM.
|
|
|
|
/// </summary>
|
|
|
|
public class InstallPVToolsAction : AsyncAction
|
|
|
|
{
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
private readonly bool _searchHiddenIsOs;
|
|
|
|
|
2016-08-17 23:35:01 +02:00
|
|
|
public InstallPVToolsAction(VM vm, bool searchHiddenISOs)
|
2013-06-24 13:41:48 +02:00
|
|
|
: base(vm.Connection, string.Format(Messages.INSTALLTOOLS_TITLE, vm.Name))
|
|
|
|
{
|
|
|
|
VM = vm;
|
|
|
|
_searchHiddenIsOs = searchHiddenISOs;
|
2016-08-17 23:35:01 +02:00
|
|
|
|
|
|
|
#region RBAC Dependencies
|
2013-06-24 13:41:48 +02:00
|
|
|
foreach (SR sr in VM.Connection.Cache.SRs)
|
|
|
|
{
|
|
|
|
if (sr.IsToolsSR && sr.IsBroken())
|
|
|
|
{
|
|
|
|
ApiMethodsToRoleCheck.Add("pbd.plug");
|
|
|
|
ApiMethodsToRoleCheck.Add("pbd.create");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ApiMethodsToRoleCheck.Add("vbd.eject");
|
|
|
|
ApiMethodsToRoleCheck.Add("vbd.insert");
|
|
|
|
ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList);
|
2016-08-17 23:35:01 +02:00
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Run()
|
|
|
|
{
|
|
|
|
// check the xstools sr is present, if not try and repair it
|
|
|
|
foreach(SR sr in VM.Connection.Cache.SRs)
|
|
|
|
{
|
|
|
|
if (sr.IsToolsSR && sr.IsBroken())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2016-08-17 23:35:01 +02:00
|
|
|
SrRepairAction action = new SrRepairAction(sr.Connection, sr, false);
|
2013-06-24 13:41:48 +02:00
|
|
|
action.RunExternal(Session);
|
|
|
|
}
|
2016-08-17 23:35:01 +02:00
|
|
|
catch (Failure f)
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
2016-08-17 23:35:01 +02:00
|
|
|
throw new Failure(Messages.XS_TOOLS_SR_NOT_FOUND, f);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the version (if any) of the PV tools already on this host...
|
|
|
|
VM_guest_metrics guestMetrics = Connection.Resolve(VM.guest_metrics);
|
2016-01-20 13:13:35 +01:00
|
|
|
if (guestMetrics != null && !VM.HasNewVirtualisationStates && guestMetrics.PV_drivers_up_to_date)
|
2013-06-24 13:41:48 +02:00
|
|
|
{
|
|
|
|
this.Description = Messages.INSTALLTOOLS_EXIST;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the VM has a cd-rom...
|
|
|
|
XenAPI.VBD cdrom = VM.FindVMCDROM();
|
|
|
|
if (cdrom == null)
|
|
|
|
{
|
2016-08-17 23:35:01 +02:00
|
|
|
throw new Failure(Messages.INSTALLTOOLS_COULDNOTFIND_CD);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find the tools ISO...
|
|
|
|
XenAPI.VDI winIso = findWinISO(_searchHiddenIsOs);
|
|
|
|
if (winIso == null)
|
|
|
|
{
|
2016-08-17 23:35:01 +02:00
|
|
|
throw new Failure(Messages.INSTALLTOOLS_COULDNOTFIND_WIN);
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Description = Messages.INSTALLTOOLS_STARTING;
|
|
|
|
|
|
|
|
// Eject anything that's currently in the cd-rom...
|
|
|
|
if (!cdrom.empty)
|
|
|
|
{
|
|
|
|
XenAPI.VBD.eject(Session, cdrom.opaque_ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert the tools ISO...
|
|
|
|
XenAPI.VBD.insert(Session, cdrom.opaque_ref, winIso.opaque_ref);
|
|
|
|
|
2016-08-17 23:35:01 +02:00
|
|
|
// done here; installation continues on the VM
|
2013-06-24 13:41:48 +02:00
|
|
|
Description = Messages.INSTALLTOOLS_DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the windows ISO disc by scanning the SRs - will return
|
|
|
|
// null if the disc could not be found...
|
|
|
|
private XenAPI.VDI findWinISO(bool searchHiddenISOs)
|
|
|
|
{
|
|
|
|
foreach (SR sr in Connection.Cache.SRs)
|
|
|
|
{
|
|
|
|
if (XenAPI.SR.SRTypes.iso.ToString() == sr.content_type)
|
|
|
|
{
|
2016-08-17 23:35:01 +02:00
|
|
|
var vdis = Connection.ResolveAllShownXenModelObjects(sr.VDIs, searchHiddenISOs);
|
|
|
|
var vdi = vdis.FirstOrDefault(v => v.IsToolsIso);
|
|
|
|
if (vdi != null)
|
|
|
|
return vdi;
|
2013-06-24 13:41:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|