Skip to content

Commit b088f2a

Browse files
committed
feat(Datacenter): PUE support
1 parent 26d68f2 commit b088f2a

4 files changed

Lines changed: 136 additions & 0 deletions

File tree

install/mysql/plugin_carbon_empty.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_carbon_computerusageprofiles` (
181181
PRIMARY KEY (`id`)
182182
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
183183

184+
CREATE TABLE IF NOT EXISTS `glpi_plugin_carbon_datacenters` (
185+
`id` int unsigned NOT NULL AUTO_INCREMENT,
186+
`datacenters_id` int unsigned NOT NULL DEFAULT '0',
187+
`pue` float DEFAULT NULL,
188+
PRIMARY KEY (`id`),
189+
UNIQUE KEY `unicity` (`datacenters_id`)
190+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
191+
184192
CREATE TABLE IF NOT EXISTS `glpi_plugin_carbon_embodiedimpacts` (
185193
`id` int unsigned NOT NULL AUTO_INCREMENT,
186194
`itemtype` varchar(255) DEFAULT NULL,

setup.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232

3333
use Config as GlpiConfig;
3434
use CronTask as GlpiCronTask;
35+
use Datacenter as GlpiDatacenter;
3536
use Glpi\Plugin\Hooks;
3637
use GlpiPlugin\Carbon\Config;
3738
use GlpiPlugin\Carbon\CronTask;
39+
use GlpiPlugin\Carbon\Datacenter;
3840
use GlpiPlugin\Carbon\Dashboard\Grid;
3941
use GlpiPlugin\Carbon\Dashboard\Widget;
4042
use GlpiPlugin\Carbon\DataSource\CarbonIntensity\ClientFactory as CarbonIntensityClientFactory;
@@ -152,6 +154,7 @@ function plugin_carbon_registerClasses()
152154
Plugin::registerClass(Profile::class, ['addtabon' => GlpiProfile::class]);
153155
Plugin::registerClass(Location::class, ['addtabon' => GlpiLocation::class]);
154156
Plugin::registerClass(CronTask::class, ['addtabon' => GlpiCronTask::class]);
157+
Plugin::registerClass(Datacenter::class, ['addtabon' => GlpiDatacenter::class]);
155158

156159
foreach (PLUGIN_CARBON_TYPES as $itemtype) {
157160
$core_type_class = $itemtype . 'Type';

src/Datacenter.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/**
4+
* -------------------------------------------------------------------------
5+
* Carbon plugin for GLPI
6+
*
7+
* @copyright Copyright (C) 2024-2025 Teclib' and contributors.
8+
* @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
9+
* @link https://github.com/pluginsGLPI/carbon
10+
*
11+
* -------------------------------------------------------------------------
12+
*
13+
* LICENSE
14+
*
15+
* This file is part of Carbon plugin for GLPI.
16+
*
17+
* This program is free software: you can redistribute it and/or modify
18+
* it under the terms of the GNU General Public License as published by
19+
* the Free Software Foundation, either version 3 of the License, or
20+
* (at your option) any later version.
21+
*
22+
* This program is distributed in the hope that it will be useful,
23+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+
* GNU General Public License for more details.
26+
*
27+
* You should have received a copy of the GNU General Public License
28+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
29+
*
30+
* -------------------------------------------------------------------------
31+
*/
32+
33+
namespace GlpiPlugin\Carbon;
34+
35+
use CommonDBChild;
36+
use CommonGLPI;
37+
use Datacenter as GlpiDatacenter;
38+
use Glpi\Application\View\TemplateRenderer;
39+
use Override;
40+
41+
class Datacenter extends CommonDBChild
42+
{
43+
// From CommonDBRelation
44+
public static $itemtype = GlpiDatacenter::class;
45+
public static $items_id = 'datacenters_id';
46+
47+
#[Override]
48+
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
49+
{
50+
if ($item instanceof GlpiDatacenter) {
51+
return self::createTabEntry(__('Environmental impact', 'carbon'), 0);
52+
}
53+
return '';
54+
}
55+
56+
#[Override]
57+
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
58+
{
59+
if ($item instanceof GlpiDatacenter) {
60+
/** @var GlpiDatacenter $item */
61+
$location = new self();
62+
$location->showForDatacenter($item);
63+
}
64+
return true;
65+
}
66+
67+
public function showForDatacenter(GlpiDatacenter $item, array $options = [])
68+
{
69+
$this->getFromDBByCrit(['datacenters_id' => $item->getID()]);
70+
if ($this->isNewItem()) {
71+
$this->add(['datacenters_id' => $item->getID()]);
72+
}
73+
74+
TemplateRenderer::getInstance()->display('@carbon/datacenter.html.twig', [
75+
'item' => $this,
76+
'params' => [
77+
'candel' => false,
78+
],
79+
]);
80+
81+
return true;
82+
}
83+
}

templates/datacenter.html.twig

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{#
2+
# -------------------------------------------------------------------------
3+
# Carbon plugin for GLPI
4+
#
5+
# @copyright Copyright (C) 2024-2025 Teclib' and contributors.
6+
# @license https://www.gnu.org/licenses/gpl-3.0.txt GPLv3+
7+
# @license MIT https://opensource.org/licenses/mit-license.php
8+
# @link https://github.com/pluginsGLPI/carbon
9+
#
10+
# -------------------------------------------------------------------------
11+
#
12+
# LICENSE
13+
#
14+
# This file is part of Carbon plugin for GLPI.
15+
#
16+
# This program is free software: you can redistribute it and/or modify
17+
# it under the terms of the GNU General Public License as published by
18+
# the Free Software Foundation, either version 3 of the License, or
19+
# (at your option) any later version.
20+
#
21+
# This program is distributed in the hope that it will be useful,
22+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
# GNU General Public License for more details.
25+
#
26+
# You should have received a copy of the GNU General Public License
27+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
28+
#
29+
# -------------------------------------------------------------------------
30+
#}
31+
32+
{% extends "generic_show_form.html.twig" %}
33+
{% import "components/form/fields_macros.html.twig" as fields %}
34+
35+
{% block form_fields %}
36+
{{ fields.numberField('pue',
37+
item.fields['pue'] ?? '',
38+
__('Power Usage Effectiveness (PUE)', 'carbon'),
39+
{
40+
41+
}) }}
42+
{% endblock %}

0 commit comments

Comments
 (0)