using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Intel.Management.Wsman;
namespace Intel.Management.PSModule.Amt
{
class AmtRootService : DriveContainer
{
public AmtRootService(string name, WsmanConnection conn)
: base(name + ":", null)
{
_conn = conn;
_items = null;
}
public override void GetChildItems(ChildWriter writer)
{
writer.Add(new ConfigDrive( this));
writer.Add(new InventoryService( this));
writer.Add(new StorageManager( this));
writer.Add(new EventLogService( this));
}
public override string[] Properties
{
get
{
return _properties;
}
}
public override object GetReturnObject()
{
return new NameValuePairItem(Name, Value);
}
public string PowerState
{
get
{
string result = "Unknown";
IManagedReference refToSystem = Connection.NewReference("CIM_ComputerSystem");
refToSystem.AddSelector("Name", "ManagedSystem");
IManagedReference refToState = Connection.NewReference("CIM_AssociatedPowerManagementService");
refToState.AddSelector("UserOfService", refToSystem);
IManagedInstance powerState = refToState.Get();
switch (powerState.GetProperty("PowerState").ToString())
{
case "2":
result = "On";
break;
case "3":
case "4":
result = "Sleeping";
break;
case "8":
result = "Off";
break;
default:
break;
}
return result;
}
set
{
IManagedReference refToSystem = Connection.NewReference("CIM_ComputerSystem");
refToSystem.AddSelector("Name", "ManagedSystem");
IManagedReference refToService = Connection.NewReference("CIM_PowerManagementService");
refToService.AddSelector("Name", "Intel(r) AMT Power Management Service");
IManagedInstance inputObj = refToService.CreateMethodInput("RequestPowerStateChange");
inputObj.SetProperty("ManagedElement", refToSystem);
if (string.Compare(value,"On",true)==0)
inputObj.SetProperty("PowerState", "2");
else if (string.Compare(value, "Off", true) == 0)
inputObj.SetProperty("PowerState", "8");
else if (string.Compare(value, "Restart", true) == 0)
inputObj.SetProperty("PowerState", "10");
inputObj.SetProperty("ManagedElement", refToSystem);
IManagedInstance outObj = refToService.InvokeMethod(inputObj);
switch (outObj.GetProperty("ReturnValue").ToString())
{
case "0":
break;
case "1":
throw new WsmanInvokeException("Not Supported");
case "2":
throw new WsmanInvokeException("Unknown or Unspecified Error");
case "3":
throw new WsmanInvokeException("Cannot complete within Timeout Period");
case "4":
throw new WsmanInvokeException("Failed");
case "5":
throw new WsmanInvokeException("Invalid Parameter");
case "6":
throw new WsmanInvokeException("In Use");
case "4097":
throw new WsmanInvokeException("Invalid State Transition");
case "4099":
throw new WsmanInvokeException("Busy");
default:
throw new WsmanInvokeException("AMT error " + outObj.GetProperty("ReturnValue").ToString());
}
}
}
public IWsmanConnection Connection
{
get
{
return _conn;
}
}
public IManagedReference AmtGeneralSettingsRef
{
get
{
return _conn.NewReference("SELECT * FROM AMT_GeneralSettings");
}
}
class ConfigDrive : DriveContainer
{
string[] _properties = { "State", };
ValueMap _state;
public ConfigDrive(DriveItem parent)
: base("Config", parent)
{
_items = null;
}
public override string[] Properties
{
get
{
return _properties;
}
}
protected override void LoadProperties(DriveProvider provider)
{
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
IManagedReference refToService = conn.NewReference("AMT_SetupAndConfigurationService");
IManagedInstance service = refToService.Get();
_state = ValueMap.Create(
service.GetProperty("ProvisioningState").ToString(),
ValueList.ConfigurationState);
}
public ValueMap State
{
get { return _state; }
}
///
/// Items for AMT:/Configuration/
///
///
public override void GetChildItems(ChildWriter writer)
{
writer.Add(new AuditorService(this));
writer.Add(new RBAService(this));
writer.Add(new EtcService(this));
writer.Add(new KVMService(this));
writer.Add(new RedirectionService(this));
writer.Add(new AlarmService(this));
writer.Add(new StorageAdmin(this));
}
public override void Invoke(Intel.Management.PSModule.DriveProvider provider)
{
IWsmanConnection conn = ((AmtRootService)GetRoot()).Connection;
IManagedReference refToService = conn.NewReference("AMT_SetupAndConfigurationService");
IManagedInstance inputObj = refToService.CreateMethodInput("CommitChanges");
IManagedInstance outObj = refToService.InvokeMethod(inputObj);
switch (outObj.GetProperty("ReturnValue").ToString())
{
case "0":
break;
case "1":
AmtException.ThrowInvokeError(outObj, "Internal Error");
break;
case "38":
AmtException.ThrowInvokeError(outObj, "Flash write limit exceeded");
break;
case "2057":
AmtException.ThrowInvokeError(outObj, "Data missing");
break;
default:
AmtException.ThrowInvokeError(outObj);
break;
}
}
} //end configDrive class
WsmanConnection _conn;
string[] _properties = { "Connection","PowerState" };
}//Amt Root Drive
}