diff --git a/application/controllers/VmsController.php b/application/controllers/VmsController.php index c22845a4..516863fa 100644 --- a/application/controllers/VmsController.php +++ b/application/controllers/VmsController.php @@ -93,6 +93,8 @@ public function snapshotAction() { $this->handleTabs(); $urlParams = $this->getParentParamsToPreserve(); + $filterVdi = $this->params->get('filter_vdi', '0'); + $this->actions()->add([ Link::create( $this->translate('Disk Usage'), @@ -106,8 +108,16 @@ public function snapshotAction() $urlParams, ['class' => 'icon-left-small'] ), + Link::create( + $filterVdi === '1' ? $this->translate('Show All VMs') : $this->translate('Hide VDI, Templates & Off'), + 'vspheredb/vms/snapshot', + array_merge($urlParams, ['filter_vdi' => $filterVdi === '1' ? '0' : '1']), + ['class' => 'icon-filter'] + ) ]); + $table = new VmsSnapshotsTable($this->db(), $this->url()); + (new AdditionalTableActions($table, Auth::getInstance(), $this->url())) ->appendTo($this->actions()); $this->showTable($table, 'vspheredb/vms', $this->translate('Virtual Machines with Snapshots')); diff --git a/library/Vspheredb/Web/Table/Objects/VmsSnapshotsTable.php b/library/Vspheredb/Web/Table/Objects/VmsSnapshotsTable.php index 13bce23b..8ef2698e 100644 --- a/library/Vspheredb/Web/Table/Objects/VmsSnapshotsTable.php +++ b/library/Vspheredb/Web/Table/Objects/VmsSnapshotsTable.php @@ -9,12 +9,20 @@ class VmsSnapshotsTable extends ObjectsTable { protected $baseUrl = 'vspheredb/vm'; + + protected $vmsRequestUrl; protected $searchColumns = [ 'object_name', 'guest_host_name', ]; + public function __construct($db, $url = null) + { + $this->vmsRequestUrl = $url; + parent::__construct($db, $url); + } + public function filterHost($uuid) { $this->getQuery()->where('vc.runtime_host_uuid = ?', $uuid); @@ -70,6 +78,21 @@ public function prepareQuery() [] )->group('vm.uuid'); + $urlFilter = '0'; + if ($this->vmsRequestUrl !== null) { + $urlFilter = $this->vmsRequestUrl->getParam('filter_vdi', '0'); + } + + if ($urlFilter === '1') { + $query->where("vm.template = 'n' OR vm.template = 0"); + $query->where("vm.runtime_power_state != 'poweredOff'"); + $query->where("LOWER(o.object_name) NOT LIKE 'cp-template-%'"); + $query->where("LOWER(o.object_name) NOT LIKE 'cp-replica-%'"); + $query->where("LOWER(o.object_name) NOT LIKE '%-vdi-%'"); + $query->where("LOWER(o.object_name) NOT LIKE '%-gis-%'"); + $query->where("LOWER(o.object_name) NOT LIKE '%horizon%'"); + } + return $query; }