servermgrv2 init...

This commit is contained in:
최준흠 2023-07-25 11:53:08 +09:00
parent 0a2356080e
commit 40fc55ff5b
2 changed files with 44 additions and 51 deletions

View File

@ -47,11 +47,18 @@ class HPILOController extends \App\Controllers\Admin\AdminController
////추가 Action ////추가 Action
final public function console($uid) final public function console($uid)
{ {
try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]); $entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$ilo = new HPILO4($this->getAdapter($entity)); $ilo = new HPILO4($this->getAdapter($entity));
$this->_viewDatas['SessionKey'] = $ilo->console(); $this->_viewDatas['SessionKey'] = $ilo->console();
$this->_viewDatas['entity'] = $entity; $this->_viewDatas['entity'] = $entity;
return view($this->_viewPath . '/console_iframe', $this->_viewDatas); return view($this->_viewPath . '/console_iframe', $this->_viewDatas);
} catch (\Exception $e) {
$message = "{$entity->getTitle()} " . __FUNCTION__ . " 실패하였습니다.";
log_message("warning", $message . "<br>\n{$e->getMessage()}");
log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message, 'back');
}
} }
final public function reset($uid, string $type) final public function reset($uid, string $type)
@ -75,9 +82,12 @@ class HPILOController extends \App\Controllers\Admin\AdminController
} }
} }
private function refresh(HPILO4 $ilo, HPILOEntity $entity) final public function reload($uid)
{ {
$entity = $ilo->refresh($entity); try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$ilo = new HPILO4($this->getAdapter($entity));
$entity = $ilo->reload($entity);
if ($entity->hasChanged()) { if ($entity->hasChanged()) {
if (!$this->_model->save($entity)) { if (!$this->_model->save($entity)) {
log_message("error", __FUNCTION__ . "에서 호출:" . $this->_model->getLastQuery()); log_message("error", __FUNCTION__ . "에서 호출:" . $this->_model->getLastQuery());
@ -85,15 +95,6 @@ class HPILOController extends \App\Controllers\Admin\AdminController
throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->_model->errors())); throw new \Exception(__FUNCTION__ . " 오류 발생.\n" . var_export($this->_model->errors()));
} }
} }
return $entity;
}
final public function reload($uid)
{
try {
$entity = $this->_model->getEntity([$this->_model->getPrimaryKey() => $uid]);
$ilo = new HPILO4($this->getAdapter($entity));
// throw new \Exception(var_export($ilo, true));
$entity = $this->refresh($ilo, $entity);
$message = "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다."; $message = "{$entity->getTitle()} " . __FUNCTION__ . " 완료하였습니다.";
log_message("info", "{$this->_viewDatas['title']} {$message}"); log_message("info", "{$this->_viewDatas['title']} {$message}");
return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL'])); return alert_CommonHelper($message, $this->_session->get(SESSION_NAMES['RETURN_URL']));

View File

@ -8,22 +8,12 @@ use App\Libraries\Adapter\API\Adapter;
class HPILO4 class HPILO4
{ {
private $_adapter = null; private $_adapter = null;
private $_system = array(); private $_health = "OK";
protected $_base_url = "/redfish/v1"; protected $_base_url = "/redfish/v1";
public function __construct(Adapter $adapter) public function __construct(Adapter $adapter)
{ {
$this->_adapter = $adapter; $this->_adapter = $adapter;
} }
private function getSystemInfo()
{
$results = $this->_adapter->get($this->_base_url . "/Systems/1/");
$this->_system['model'] = sprintf("%s %s", $results->Model, $results->BiosVersion);
$this->_system['processor'] = trim($results->Processors->ProcessorFamily) . " * " . $results->Processors->Count;
$this->_system['memory'] = $results->Memory->TotalSystemMemoryGB;
$this->_system['health'] = 'OK';
$this->_system['power'] = $results->Power;
$this->_system['detail'] = '';
}
private function getMemoryInfo($url) private function getMemoryInfo($url)
{ {
@ -31,7 +21,7 @@ class HPILO4
$results = $this->_adapter->get($url); $results = $this->_adapter->get($url);
//오류체크 //오류체크
if ($results->DIMMStatus != "GoodInUse") { if ($results->DIMMStatus != "GoodInUse") {
$this->_system['health'] = "ERROR"; $this->_health = "ERROR";
} }
return sprintf( return sprintf(
"%s: %s %sMhz %sMB => %s", "%s: %s %sMhz %sMB => %s",
@ -58,7 +48,7 @@ class HPILO4
$info = $this->_adapter->get($url); $info = $this->_adapter->get($url);
//오류체크 //오류체크
if ($info->Status->Health != "OK") { if ($info->Status->Health != "OK") {
$this->_system['health'] = "ERROR"; $this->_health = "ERROR";
} }
return sprintf( return sprintf(
"%s %s %sGB => %s", "%s %s %sGB => %s",
@ -68,7 +58,7 @@ class HPILO4
$info->Status->Health $info->Status->Health
); );
} }
private function getPhysicalDiskInfos(): array private function getPhysicalDiskInfos(): string
{ {
$results = $this->_adapter->get($this->_base_url . "/Systems/1/SmartStorage/ArrayControllers/0/DiskDrives/"); $results = $this->_adapter->get($this->_base_url . "/Systems/1/SmartStorage/ArrayControllers/0/DiskDrives/");
$disks = array("\n------Physical Disk------"); $disks = array("\n------Physical Disk------");
@ -77,16 +67,15 @@ class HPILO4
array_push($disks, $this->getPhysicalDiskInfo($link->href)); array_push($disks, $this->getPhysicalDiskInfo($link->href));
} }
} }
return $disks; return implode("\n", $disks);
} }
private function getLogicalDiskInfo($url): string
private function getLogicalDiskInfo($url)
{ {
//url에서 맨앞의 /를 없애야함(substr사용) //url에서 맨앞의 /를 없애야함(substr사용)
$info = $this->_adapter->get($url); $info = $this->_adapter->get($url);
//오류체크 //오류체크
if ($info->Status->Health != "OK") { if ($info->Status->Health != "OK") {
$this->_system['health'] = "ERROR"; $this->_health = "ERROR";
} }
return sprintf( return sprintf(
"%s Raid:%s %s_%s %sMB => %s", "%s Raid:%s %s_%s %sMB => %s",
@ -98,7 +87,7 @@ class HPILO4
$info->Status->Health $info->Status->Health
); );
} }
private function getLogicalDiskInfos(): array private function getLogicalDiskInfos(): string
{ {
$results = $this->_adapter->get($this->_base_url . "/Systems/1/SmartStorage/ArrayControllers/0/LogicalDrives/"); $results = $this->_adapter->get($this->_base_url . "/Systems/1/SmartStorage/ArrayControllers/0/LogicalDrives/");
$disks = array("\n------Logical Disk------"); $disks = array("\n------Logical Disk------");
@ -107,21 +96,21 @@ class HPILO4
array_push($disks, $this->getLogicalDiskInfo($link->href)); array_push($disks, $this->getLogicalDiskInfo($link->href));
} }
} }
return $disks; return implode("\n", $disks);
} }
private function getFanInfos(): array private function getFanInfos(): string
{ {
$results = $this->_adapter->get($this->_base_url . "/Chassis/1/Thermal/"); $results = $this->_adapter->get($this->_base_url . "/Chassis/1/Thermal/");
$fans = array("\n------Fan------"); $fans = array("\n------Fan------");
foreach ($results->Fans as $fan) { foreach ($results->Fans as $fan) {
//오류체크 //오류체크
if ($fan->Status->Health != "OK") { if ($fan->Status->Health != "OK") {
$this->_system['health'] = "ERROR"; $this->_health = "ERROR";
} }
array_push($fans, sprintf("%s => %s", $fan->FanName, $fan->Status->Health)); array_push($fans, sprintf("%s => %s", $fan->FanName, $fan->Status->Health));
} }
return $fans; return implode("\n", $fans);
} }
public function console() public function console()
@ -152,16 +141,19 @@ class HPILO4
return $this->_adapter->post($this->_base_url . "/Systems/1", array("Action" => 'Reset', "ResetType" => $resetType)); return $this->_adapter->post($this->_base_url . "/Systems/1", array("Action" => 'Reset', "ResetType" => $resetType));
} }
public function refresh(HPILOEntity $entity): HPILOEntity public function reload(HPILOEntity $entity): HPILOEntity
{ {
$this->getSystemInfo(); //시스템 정보 가져오기
$this->_system['detail'] .= implode("\n", $this->getMemoryInfos()); $results = $this->_adapter->get($this->_base_url . "/Systems/1/");
$this->_system['detail'] .= implode("\n", $this->getPhysicalDiskInfos()); $entity->model = sprintf("%s %s", $results->Model, $results->BiosVersion);
$this->_system['detail'] .= implode("\n", $this->getLogicalDiskInfos()); $entity->processor = trim($results->Processors->ProcessorFamily) . " * " . $results->Processors->Count;
$this->_system['detail'] .= implode("\n", $this->getFanInfos()); $entity->memory = $results->Memory->TotalSystemMemoryGB;
foreach ($this->_system as $field => $value) { $entity->power = $results->Power;
$entity->$field = $value; //각 부품별 정보 가져오기
} $entity->detail = $this->getMemoryInfos();
$entity->detail .= $this->getPhysicalDiskInfos();
$entity->detail .= $this->getLogicalDiskInfos();
$entity->detail .= $this->getFanInfos();
return $entity; return $entity;
} }
} }