581 lines
21 KiB
C#
581 lines
21 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Intel.Management.Wsman;
|
|
using System.Collections.ObjectModel;
|
|
using System.Management.Automation;
|
|
|
|
namespace Intel.Management.Module
|
|
{
|
|
public class StorageAdminItem : DriveContainer
|
|
{
|
|
|
|
private class EnterpriseAcl : DriveItem
|
|
{
|
|
StorageAdminItem _storageItem;
|
|
string _entName;
|
|
|
|
public EnterpriseAcl(string name, StorageAdminItem item)
|
|
: base(name, "StorageACL")
|
|
{
|
|
_storageItem = item;
|
|
IManagedInstance outObj = _storageItem.GetEaclEntry(_name);
|
|
_entName = outObj.GetProperty("EnterpriseName").ToString();
|
|
}
|
|
|
|
public override string Name
|
|
{
|
|
get
|
|
{
|
|
return _entName;
|
|
}
|
|
}
|
|
|
|
public override void RemoveItem( bool force)
|
|
{
|
|
_storageItem.RemoveEaclEntry(_name);
|
|
_storageItem.RemoveEnterpriseItem(this);
|
|
}
|
|
}
|
|
|
|
|
|
public class EnterpriseContainer : DriveContainer
|
|
{
|
|
StorageAdminItem _storageItem;
|
|
|
|
public EnterpriseContainer(StorageAdminItem item) : base("Enterprises")
|
|
{
|
|
_storageItem = item;
|
|
_items = null;
|
|
}
|
|
|
|
public override DriveItem[] GetChildItems(bool force)
|
|
{
|
|
|
|
if (_items == null || force )
|
|
{
|
|
IManagedInstance outObj = _storageItem.GetEaclList();
|
|
|
|
List<DriveItem> list = new List<DriveItem>();
|
|
|
|
IWsmanItem handles = outObj.GetProperty("Handles");
|
|
if (handles!= null)
|
|
{
|
|
foreach (IWsmanItem handle in handles)
|
|
{
|
|
list.Add(new EnterpriseAcl(handle.ToString(), _storageItem));
|
|
}
|
|
}
|
|
list.Sort(_defaultComparer);
|
|
_items = list.ToArray();
|
|
}
|
|
return _items;
|
|
}
|
|
|
|
public override DriveItem NewItem( string name, string type, object newItem, object newParamaters, bool force)
|
|
{
|
|
string handle= _storageItem.AddEaclEntry(name);
|
|
EnterpriseAcl result = new EnterpriseAcl(handle, _storageItem);
|
|
_storageItem.AddEnterpriseItem(result);
|
|
return result;
|
|
}
|
|
}
|
|
|
|
public class PartnerAcl : DriveItem
|
|
{
|
|
StorageAdminItem _storageItem;
|
|
Dictionary<string, object> _props;
|
|
|
|
|
|
public PartnerAcl(Dictionary<string, object> props, StorageAdminItem item)
|
|
: base(props["ApplicationName"].ToString(), "ParnterAcl")
|
|
{
|
|
_props = props;
|
|
_storageItem = item;
|
|
}
|
|
|
|
public override string[] Properties
|
|
{
|
|
get { return _props.Keys.ToArray(); }
|
|
}
|
|
|
|
public override object GetProperty(Collection<string> propList,bool force)
|
|
{
|
|
return GetProperties(_props, propList);
|
|
}
|
|
|
|
public override void SetProperty(PSObject propertyValue, bool force)
|
|
{
|
|
_storageItem.UpdateFpaclEntry(_props["Handle"].ToString(),
|
|
propertyValue.Properties["TotalAllocationSize"].Value.ToString());
|
|
|
|
_props["TotalAllocationSize"] = propertyValue.Properties["TotalAllocationSize"].Value.ToString();
|
|
}
|
|
|
|
public override void RemoveItem( bool force)
|
|
{
|
|
_storageItem.RemoveFpaclEntry(_props["Handle"].ToString());
|
|
_storageItem.RemovePartnerItem(this);
|
|
}
|
|
}
|
|
|
|
|
|
public class PartnerDynamicParameters
|
|
{
|
|
public PartnerDynamicParameters()
|
|
{
|
|
_maxSize=48*1024; //default to 48K storage
|
|
}
|
|
|
|
[Parameter(Mandatory = true,Position = 0, HelpMessage = "An application name that can be used in subsequent storage operations")]
|
|
public string NewApplication
|
|
{
|
|
get { return _app; }
|
|
set { _app = value; }
|
|
}
|
|
|
|
[Parameter(Mandatory = true, Position = 1, HelpMessage = "The name of the vendor supplying the Application")]
|
|
public string VendorName
|
|
{
|
|
get { return _vendor; }
|
|
set { _vendor = value; }
|
|
}
|
|
|
|
[Parameter(Mandatory = false, Position = 2, HelpMessage = "Maximum size in bytes the application can allocate. Must be a multiple of 4KB")]
|
|
public uint TotalAllocationSize
|
|
{
|
|
get
|
|
{
|
|
return _maxSize;
|
|
}
|
|
set
|
|
{
|
|
uint blocksize = (value / (4 * 1024));
|
|
blocksize = blocksize * (4 * 1024);
|
|
if (value > blocksize)
|
|
blocksize = blocksize + (4 * 1024);
|
|
_maxSize = blocksize;
|
|
}
|
|
|
|
}
|
|
|
|
private string _vendor;
|
|
private string _app;
|
|
private uint _maxSize;
|
|
}
|
|
|
|
|
|
|
|
public class VendorContainer : DriveContainer
|
|
{
|
|
StorageAdminItem _storageItem;
|
|
|
|
public VendorContainer(string name, StorageAdminItem item)
|
|
: base(name)
|
|
{
|
|
_storageItem = item;
|
|
|
|
}
|
|
|
|
public VendorContainer(string handle, Dictionary<string,object> props, StorageAdminItem item)
|
|
: base(props["VendorName"].ToString())
|
|
{
|
|
_storageItem = item;
|
|
|
|
List<DriveItem> list = new List<DriveItem>();
|
|
if (_items != null) list.AddRange(_items);
|
|
|
|
list.Add( new PartnerAcl(props,_storageItem) );
|
|
|
|
_items = list.ToArray();
|
|
}
|
|
|
|
public void RemovePartnerItem(PartnerAcl item)
|
|
{
|
|
List<DriveItem> list = new List<DriveItem>();
|
|
if (_items != null) list.AddRange(_items);
|
|
if (list.Remove(item)) _items = list.ToArray();
|
|
}
|
|
}
|
|
|
|
public class PartnerContainer : DriveContainer
|
|
{
|
|
StorageAdminItem _storageItem;
|
|
//PartnerDynamicParameters _commandParameters = null;
|
|
|
|
public PartnerContainer(StorageAdminItem item)
|
|
: base("Partners")
|
|
{
|
|
_storageItem = item;
|
|
_items = null;
|
|
}
|
|
|
|
public override DriveItem[] GetChildItems(bool force)
|
|
{
|
|
if (_items == null || force)
|
|
{
|
|
IManagedInstance outObj = _storageItem.GetFpaclList();
|
|
List<DriveContainer> list = new List<DriveContainer>();
|
|
|
|
IWsmanItem handles = outObj.GetProperty("Handles");
|
|
if (handles != null)
|
|
{
|
|
foreach (IWsmanItem handle in handles)
|
|
{
|
|
IManagedInstance entryObj = _storageItem.GetFpaclEntry(handle.ToString());
|
|
|
|
|
|
string vendorName= entryObj.GetProperty("VendorName").ToString();
|
|
|
|
Dictionary<string, object> props = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
props.Add("ApplicationName",entryObj.GetProperty("ApplicationName").ToString());
|
|
props.Add("TotalAllocationSize",uint.Parse(entryObj.GetProperty("TotalAllocationSize").ToString()));
|
|
props.Add("VendorName", vendorName);
|
|
props.Add("IsPartner", bool.Parse(entryObj.GetProperty("IsPartner").ToString()));
|
|
props.Add("AttrType", uint.Parse(entryObj.GetProperty("AttrType").ToString()));
|
|
props.Add("Handle", uint.Parse(handle.ToString()));
|
|
|
|
|
|
DriveContainer vendorItem = list.Find(delegate(DriveContainer item) { return string.Compare(item.Name, vendorName, true) == 0; });
|
|
|
|
if (vendorItem == null)
|
|
{
|
|
vendorItem = new VendorContainer(vendorName, _storageItem);
|
|
list.Add(vendorItem);
|
|
|
|
}
|
|
|
|
vendorItem.AddChildItem(new PartnerAcl( props, _storageItem));
|
|
|
|
|
|
}
|
|
}
|
|
|
|
_items = list.ToArray();
|
|
}
|
|
return _items;
|
|
}
|
|
|
|
public void RemovePartnerItem(PartnerAcl item)
|
|
{
|
|
foreach (VendorContainer vendor in _items)
|
|
{
|
|
vendor.RemovePartnerItem(item);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public class RegisteredAppItem : DriveItem
|
|
{
|
|
StorageAdminItem _storageItem;
|
|
Dictionary<string, object> _props;
|
|
|
|
public RegisteredAppItem(string name, StorageAdminItem item)
|
|
: base(name, "RegistredApplication")
|
|
{
|
|
_props = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
|
|
_props.Add("AttrType", null);
|
|
_props.Add("UUID", null);
|
|
_props.Add("VendorName", null);
|
|
_props.Add("ApplicationName", null);
|
|
_props.Add("EnterpriseName", null);
|
|
_props.Add("CurrentAllocationSize", null);
|
|
_props.Add("ActiveSession", null);
|
|
_props.Add("Partner", null);
|
|
|
|
_storageItem = item;
|
|
}
|
|
|
|
|
|
public override string[] Properties
|
|
{
|
|
get { return _props.Keys.ToArray(); }
|
|
}
|
|
|
|
|
|
public override object GetProperty(Collection<string> propList, bool force)
|
|
{
|
|
//public uint32 AdminGetApplicationAttributes([IN]uint32 Handle, [OUT]uint32 AttrType, [OUT]uint8 UUID[16], [OUT]string VendorName, [OUT]string ApplicationName, [OUT]string EnterpriseName, [OUT]uint32 CurrentAllocationSize, [OUT]boolean ActiveSession, [OUT]boolean Partner)
|
|
if (_props["ApplicationName"] == null)
|
|
{
|
|
IManagedInstance outObj = _storageItem.GetApplicationAttributes(_name);
|
|
_props["VendorName"] = outObj.GetProperty("VendorName").ToString();
|
|
//convert UUID to string
|
|
Guid uuid = new Guid(Convert.FromBase64String(outObj.GetProperty("UUID").ToString()));
|
|
_props["UUID"] = uuid.ToString();
|
|
|
|
_props["ApplicationName"] = outObj.GetProperty("ApplicationName").ToString();
|
|
_props["EnterpriseName"] = outObj.GetProperty("EnterpriseName").ToString();
|
|
_props["CurrentAllocationSize"] = uint.Parse(outObj.GetProperty("CurrentAllocationSize").ToString());
|
|
_props["ActiveSession"] = bool.Parse(outObj.GetProperty("ActiveSession").ToString());
|
|
_props["Partner"] = bool.Parse(outObj.GetProperty("Partner").ToString());
|
|
_props["AttrType"] = uint.Parse(outObj.GetProperty("AttrType").ToString());
|
|
}
|
|
|
|
return GetProperties(_props, propList);
|
|
}
|
|
|
|
public override void SetProperty(PSObject propertyValue, bool force)
|
|
{
|
|
_storageItem.UpdateFpaclEntry(_name,
|
|
propertyValue.Properties["TotalAllocationSize"].Value.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
public class RegisteredAppsContainer : DriveContainer
|
|
{
|
|
StorageAdminItem _storageItem;
|
|
|
|
|
|
public RegisteredAppsContainer(StorageAdminItem item)
|
|
: base("RegisteredApps")
|
|
{
|
|
_storageItem = item;
|
|
_items = null;
|
|
}
|
|
|
|
public override DriveItem[] GetChildItems(bool force)
|
|
{
|
|
if (_items == null || force)
|
|
{
|
|
IManagedInstance outObj = _storageItem.GetRegisteredApps();
|
|
|
|
List<DriveItem> list = new List<DriveItem>();
|
|
|
|
IWsmanItem handles = outObj.GetProperty("ApplicationHandles");
|
|
if (handles != null)
|
|
{
|
|
foreach (IWsmanItem handle in handles)
|
|
{
|
|
list.Add(new RegisteredAppItem(handle.ToString(), _storageItem));
|
|
}
|
|
}
|
|
|
|
_items = list.ToArray();
|
|
}
|
|
return _items;
|
|
}
|
|
}
|
|
|
|
public Dictionary<string,object> _props;
|
|
IManagedReference _storageAdminRef;
|
|
EnterpriseContainer _enterprises;
|
|
PartnerContainer _partners;
|
|
|
|
public StorageAdminItem(AmtDriveInfo info) : base("Storage")
|
|
{
|
|
// define Storeage admin properties
|
|
_props = new Dictionary<string,object>(StringComparer.OrdinalIgnoreCase);
|
|
_props.Add("TotalStorage",null);
|
|
_props.Add("TotalAllocatedStorage",null);
|
|
_props.Add("MaxPartnerStorage",null);
|
|
_props.Add("TotalPartnerAllocatedStorage",null);
|
|
_props.Add("MaxNonPartnerStorage",null);
|
|
_props.Add("MaxFpaclEntries",null);
|
|
_props.Add("MaxAslEntries",null);
|
|
_props.Add("MaxEaclEntries",null);
|
|
_props.Add("MaxGroupsPerBlock",null);
|
|
_props.Add("MaxMembersPerGroup",null);
|
|
_props.Add("MaxNonPartnerTotalAllocationSize",null);
|
|
|
|
_enterprises = new EnterpriseContainer(this);
|
|
_partners = new PartnerContainer(this);
|
|
|
|
//define Admin storage
|
|
DriveItem[] storageItems = { _enterprises,
|
|
_partners,
|
|
new RegisteredAppsContainer(this),
|
|
};
|
|
|
|
_items = storageItems;
|
|
|
|
_storageAdminRef = info.WsmanConnection.NewReference("AMT_ThirdPartyDataStorageAdministrationService");
|
|
|
|
}
|
|
|
|
|
|
private void RemoveEnterpriseItem(DriveItem item)
|
|
{
|
|
_enterprises.RemoveChildItem(item);
|
|
}
|
|
|
|
private void AddEnterpriseItem(DriveItem item)
|
|
{
|
|
_enterprises.AddChildItem(item);
|
|
}
|
|
|
|
private void RemovePartnerItem(PartnerAcl partner)
|
|
{
|
|
|
|
_partners.RemovePartnerItem(partner);
|
|
}
|
|
|
|
public override string[] Properties
|
|
{
|
|
get { return _props.Keys.ToArray(); }
|
|
}
|
|
|
|
|
|
private IManagedInstance GetGlobalStorageAttributes()
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("GetGlobalStorageAttributes");
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
return outObj;
|
|
}
|
|
|
|
|
|
private IManagedInstance SetGlobalStorageAttributes(string name, string value)
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("SetGlobalStorageAttributes");
|
|
inputObj.SetProperty(name, value);
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
return outObj;
|
|
}
|
|
|
|
|
|
private IManagedInstance GetEaclEntry(string handle)
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("GetStorageEaclEntry");
|
|
inputObj.SetProperty("Handle", handle);
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
return outObj;
|
|
}
|
|
|
|
private IManagedInstance GetFpaclEntry(string handle)
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("GetStorageAllocEntry");
|
|
inputObj.SetProperty("Handle", handle);
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
return outObj;
|
|
}
|
|
|
|
|
|
private IManagedInstance GetEaclList()
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("EnumerateStorageEaclEntries");
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
return outObj;
|
|
}
|
|
|
|
private IManagedInstance GetFpaclList()
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("EnumerateStorageAllocEntries");
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
|
|
return outObj;
|
|
}
|
|
|
|
private IManagedInstance GetRegisteredApps()
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("AdminGetRegisteredApplications");
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
return outObj;
|
|
}
|
|
|
|
private string AddEaclEntry(string name)
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("AddStorageEaclEntry");
|
|
inputObj.SetProperty("EnterpriseName",name);
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
return outObj.GetProperty("Handle").ToString();
|
|
}
|
|
|
|
private string AddFpaclEntry(string appName, string vendor, string size)
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("AddStorageFpaclEntry");
|
|
inputObj = _storageAdminRef.CreateMethodInput("AddStorageFpaclEntry");
|
|
inputObj.SetProperty("AttrType","1");
|
|
inputObj.SetProperty("ApplicationName",appName);
|
|
inputObj.SetProperty("VendorName",vendor);
|
|
inputObj.SetProperty("IsPartner", "true");
|
|
inputObj.SetProperty("TotalAllocationSize",size);
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
return outObj.GetProperty("Handle").ToString();
|
|
}
|
|
|
|
private void RemoveEaclEntry(string handle)
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("RemoveStorageEaclEntry");
|
|
inputObj.SetProperty("Handle", handle);
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
}
|
|
|
|
private void RemoveFpaclEntry(string handle)
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("RemoveStorageFpaclEntry");
|
|
inputObj.SetProperty("Handle", handle);
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
}
|
|
|
|
private void UpdateFpaclEntry(string handle, string newSize)
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("UpdateStorageFpaclEntry");
|
|
inputObj.SetProperty("Handle", handle);
|
|
inputObj.SetProperty("NewAllocationSize", newSize);
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
}
|
|
|
|
private IManagedInstance GetApplicationAttributes(string handle)
|
|
{
|
|
IManagedInstance inputObj = _storageAdminRef.CreateMethodInput("AdminGetApplicationAttributes");
|
|
inputObj.SetProperty("Handle", handle);
|
|
IManagedInstance outObj = _storageAdminRef.InvokeMethod(inputObj);
|
|
StorageItem.StorageOperationException.CheckResult(outObj);
|
|
return outObj;
|
|
}
|
|
|
|
|
|
public override object GetProperty(Collection<string> propList, bool force)
|
|
{
|
|
|
|
IManagedInstance outObj = this.GetGlobalStorageAttributes();
|
|
|
|
foreach (string propName in _props.Keys.ToArray())
|
|
{
|
|
_props[propName] = uint.Parse(outObj.GetProperty(propName).ToString());
|
|
}
|
|
return GetProperties(_props, propList);
|
|
}
|
|
|
|
public override void SetProperty(PSObject propertyValue, bool force)
|
|
{
|
|
string name=null;
|
|
string value=null;
|
|
foreach (PSPropertyInfo propInfo in propertyValue.Properties)
|
|
{
|
|
name=propInfo.Name;
|
|
value = propInfo.Value.ToString();
|
|
|
|
}
|
|
|
|
if (name == null ||
|
|
(string.Compare("MaxPartnerStorage", name, true) != 0 &&
|
|
string.Compare("MaxNonPartnerTotalAllocationSize", name, true) != 0))
|
|
new ArgumentException();
|
|
|
|
SetGlobalStorageAttributes(name, value);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|