CLOUDSTACK-5605: Fixing GetStorage stats command for hyper-v. The agent

wasn't looking up the share path correctly for reading the stats of a smb
share.
This commit is contained in:
Devdeep Singh 2014-01-01 14:29:43 +05:30
parent dc0420c633
commit faa503d6fc

View File

@ -909,18 +909,23 @@ namespace HypervResource
var tInfo = new Dictionary<string, string>(); var tInfo = new Dictionary<string, string>();
long capacityBytes = 0; long capacityBytes = 0;
long availableBytes = 0; long availableBytes = 0;
string hostPath = null;
if (poolType == StoragePoolType.Filesystem) if (poolType == StoragePoolType.Filesystem)
{ {
GetCapacityForLocalPath(localPath, out capacityBytes, out availableBytes); GetCapacityForLocalPath(localPath, out capacityBytes, out availableBytes);
hostPath = localPath;
} }
else if (poolType == StoragePoolType.NetworkFilesystem) else if (poolType == StoragePoolType.NetworkFilesystem)
{ {
NFSTO share = new NFSTO(); NFSTO share = new NFSTO();
String uriStr = "cifs://" + (string)cmd.pool.host + (string)cmd.pool.path; String uriStr = "cifs://" + (string)cmd.pool.host + (string)cmd.pool.path;
share.uri = new Uri(uriStr); share.uri = new Uri(uriStr);
hostPath = Utils.NormalizePath(share.UncPath);
// Check access to share. // Check access to share.
Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password); Utils.ConnectToRemote(share.UncPath, share.Domain, share.User, share.Password);
Utils.GetShareDetails(share.UncPath, out capacityBytes, out availableBytes); Utils.GetShareDetails(share.UncPath, out capacityBytes, out availableBytes);
config.setPrimaryStorage((string)cmd.pool.uuid, hostPath);
} }
else else
{ {
@ -932,8 +937,8 @@ namespace HypervResource
{ {
uuid = uuid, uuid = uuid,
host = cmd.pool.host, host = cmd.pool.host,
localPath = cmd.pool.host, hostPath = cmd.pool.path,
hostPath = cmd.localPath, localPath = hostPath,
poolType = cmd.pool.type, poolType = cmd.pool.type,
capacityBytes = capacityBytes, capacityBytes = capacityBytes,
availableBytes = availableBytes availableBytes = availableBytes
@ -943,6 +948,7 @@ namespace HypervResource
{ {
result = result, result = result,
details = details, details = details,
localPath = hostPath,
templateInfo = tInfo, templateInfo = tInfo,
poolInfo = poolInfo, poolInfo = poolInfo,
contextMap = contextMap contextMap = contextMap
@ -1645,11 +1651,42 @@ namespace HypervResource
long used = 0; long used = 0;
try try
{ {
string localPath = (string)cmd.localPath; StoragePoolType poolType;
GetCapacityForLocalPath(localPath, out capacity, out available); string poolId = (string)cmd.id;
used = capacity - available; string hostPath = null;
result = true; if (!Enum.TryParse<StoragePoolType>((string)cmd.pooltype, out poolType))
logger.Debug(CloudStackTypes.GetStorageStatsCommand + " set used bytes to " + used); {
details = "Request to get unsupported pool type: " + ((string)cmd.pooltype == null ? "NULL" : (string)cmd.pooltype) + "in cmd " +
JsonConvert.SerializeObject(cmd);
logger.Error(details);
}
else if (poolType == StoragePoolType.Filesystem)
{
hostPath = (string)cmd.localPath;;
GetCapacityForLocalPath(hostPath, out capacity, out available);
used = capacity - available;
result = true;
}
else if (poolType == StoragePoolType.NetworkFilesystem)
{
string sharePath = config.getPrimaryStorage((string)cmd.id);
if (sharePath != null)
{
hostPath = sharePath;
Utils.GetShareDetails(sharePath, out capacity, out available);
used = capacity - available;
result = true;
}
}
else
{
result = false;
}
if (result)
{
logger.Debug(CloudStackTypes.GetStorageStatsCommand + " set used bytes for " + hostPath + " to " + used);
}
} }
catch (Exception ex) catch (Exception ex)
{ {