*/
class VolumeManager extends APIModule {
+ /**
+ * Vol type groups
+ */
+ const VOLTYPE_GROUP_DISK = 'disk';
+ const VOLTYPE_GROUP_TAPE = 'tape';
+ const VOLTYPE_GROUP_CLOUD = 'cloud';
+
/**
* Volume types (voltype property)
*/
];
}
- public function getVolumes($criteria = array(), $limit_val = 0, $offset_val = 0) {
+ public function getVolumes($criteria = array(), $props = [], $limit_val = 0, $offset_val = 0) {
$order_pool_id = 'PoolId';
$order_volume = 'VolumeName';
$db_params = $this->getModule('api_config')->getConfig('db');
$order_volume = strtolower($order_volume);
}
$order = " ORDER BY $order_pool_id ASC, $order_volume ASC ";
+ if (key_exists('voltype', $props)) {
+ $voltypes = [];
+ switch ($props['voltype']) {
+ case self::VOLTYPE_GROUP_DISK: {
+ $voltypes = $this->getDiskVolTypes();
+ break;
+ }
+ case self::VOLTYPE_GROUP_TAPE: {
+ $voltypes = $this->getTapeVolTypes();
+ break;
+ }
+ case self::VOLTYPE_GROUP_CLOUD: {
+ $voltypes = $this->getCloudVolTypes();
+ break;
+ }
+ }
+ if (count($voltypes) > 0) {
+ if (!key_exists('Media.VolType', $criteria)) {
+ $criteria['Media.VolType'] = [];
+ }
+ $criteria['Media.VolType'][] = [
+ 'vals' => $voltypes,
+ 'operator' => 'IN'
+ ];
+ }
+ }
$limit = '';
if(is_int($limit_val) && $limit_val > 0) {
'vals' => [$poolid],
'operator' => 'AND'
]]
- ), 1);
+ ), [], 1);
if (is_array($volume) && count($volume) > 0) {
$volume = array_shift($volume);
}
'vals' => [$volume_name],
'operator' => 'AND'
]]
- ), 1);
+ ), [], 1);
if (is_array($volume) && count($volume) > 0) {
$volume = array_shift($volume);
}
$misc = $this->getModule('misc');
$limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int)$this->Request['limit'] : 0;
$offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
- $result = $this->getModule('volume')->getVolumes(array(), $limit, $offset);
+ $voltype = $this->Request->contains('voltype') && $misc->isValidVolType($this->Request['voltype']) ? $this->Request['voltype'] : null;
+
+ $props = [];
+ if (is_string($voltype)) {
+ $props['voltype'] = $voltype;
+ }
+
+ $result = $this->getModule('volume')->getVolumes(
+ [],
+ $props,
+ $limit,
+ $offset
+ );
$this->output = $result;
$this->error = VolumeError::ERROR_NO_ERRORS;
}
return (preg_match('/^(basic|full)$/', $view) === 1);
}
+ public function isValidVolType($voltype) {
+ $voltypes = ['disk', 'tape', 'cloud'];
+ return in_array($voltype, $voltypes);
+ }
public function escapeCharsToConsole($path) {
return preg_replace('/([$])/', '\\\${1}', $path);