-
Notifications
You must be signed in to change notification settings - Fork 3
Implementing a new Server Control (IPMI) Type
Zane H edited this page Jan 21, 2022
·
3 revisions
Packages can implement new Server Control Types to add support for IPMI/other power control devices that do not come with SynergyCP by default. Implementing a new Server Control type is simple.
The Handler is the class that runs certain PHP code when a user clicks a power control button on your Server Control Type. All Handlers must implement the interface App\Server\Control\Type\ControlHandler
. It is recommended that you start by copying our ControlDoNothing
class:
<?php
namespace App\Server\Control;
class ControlDoNothing extends ControlBase {
/**
* Set server power to off.
*
* @return \App\Server\Control\Type\ControlHandler
*/
public function powerOff() {
return $this;
}
/**
* @param string $type
*
* @return \App\Server\Control\Type\ControlHandler
*/
public function power($type) {
return $this;
}
/**
* Reset server power.
*
* @return \App\Server\Control\Type\ControlHandler
*/
public function powerReset() {
return $this;
}
/**
* @return \App\Server\Control\Type\ControlHandler
*/
public function resetBmc() {
return $this;
}
/**
* Set a temporary boot device, which will only apply to next boot.
*
* @param string $dev
*
* @return \App\Server\Control\Type\ControlHandler
*/
public function setTemporaryBootDevice($dev) {
return $this;
}
/**
* Set a temporary boot flag, which will only apply to next boot.
*
* @param string $dev
*
* @return \App\Server\Control\Type\ControlHandler
*/
public function setTemporaryBootFlag($dev) {
return $this;
}
/**
* @return \App\Server\Control\Type\ControlHandler
*/
public function pxeBoot() {
return $this;
}
/**
* @return bool
*/
public function isPowerOn() {
return true;
}
/**
* Set a permanent boot device, which will last across all future boots (until changed via IPMI or BIOS).
*
* @param string $dev
*
* @return \App\Server\Control\Type\ControlHandler
*/
public function setPermanentBootDevice($dev) {
return $this;
}
/**
* @return \App\Server\Control\Type\ControlHandler
*/
public function addUser() {
$details = $this->getClientDetails();
$details->setPassword($this->getClientPasswordOrGenerate());
$details->setUsername($this->getClientUserNameOrDefault());
$this->getServer()->setIpmiClientDetails($details);
return $this;
}
/**
* @return int
*/
public function getUserId() {
return 1;
}
/**
* @param string $password
*
* @return \App\Server\Control\Type\ControlHandler
*/
public function resetUserPass(&$password = null) {
$password = $password ?: $this->generateClientPassword();
return $this;
}
/**
* @return \App\Server\Control\Type\ControlHandler
*/
public function resetUserPerms() {
return $this;
}
/**
* @return \App\Server\Control\Type\ControlHandler
*/
public function deleteUser() {
$this->deleteClientPassword();
return $this;
}
public function getSystemID(): string {
return 'Do Nothing';
}
public function freshSystemInfo(): string {
return 'Do Nothing';
}
}
You can name your version of the class whatever you like, just make sure it's in your package's namespace.
To add the Handler to the list of available options, you will need to do a Database Migration to include it. An example of this:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use App\Server\Control\Type\Type;
class MigrateServerControlTypes extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up() {
Type::create([
'name' => 'Do Nothing',
'handler' => \App\Server\Control\ControlDoNothing::class,
]);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down() {
//
}
}