Add bulk power management via CLI

This commit is contained in:
Dane Everitt 2018-03-02 20:58:58 -06:00
parent c6137db529
commit 021710aa1c
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 182 additions and 0 deletions

View file

@ -264,6 +264,45 @@ class ServerRepository extends EloquentRepository implements ServerRepositoryInt
}
}
/**
* Return all of the servers that should have a power action performed aganist them.
*
* @param int[] $servers
* @param int[] $nodes
* @param bool $returnCount
* @return int|\Generator
*/
public function getServersForPowerAction(array $servers = [], array $nodes = [], bool $returnCount = false)
{
$instance = $this->getBuilder();
if (! empty($nodes) && ! empty($servers)) {
$instance->whereIn('id', $servers)->orWhereIn('node_id', $nodes);
} elseif (empty($nodes) && ! empty($servers)) {
$instance->whereIn('id', $servers);
} elseif (! empty($nodes) && empty($servers)) {
$instance->whereIn('node_id', $nodes);
}
if ($returnCount) {
return $instance->count();
}
return $instance->with('node')->cursor();
}
/**
* Return the total number of servers that will be affected by the query.
*
* @param int[] $servers
* @param int[] $nodes
* @return int
*/
public function getServersForPowerActionCount(array $servers = [], array $nodes = []): int
{
return $this->getServersForPowerAction($servers, $nodes, true);
}
/**
* Return an array of server IDs that a given user can access based
* on owner and subuser permissions.