Add bulk power management via CLI
This commit is contained in:
parent
c6137db529
commit
021710aa1c
5 changed files with 182 additions and 0 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue