1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Server module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-server |
6
|
|
|
* @package hipanel-module-server |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\server\models; |
12
|
|
|
|
13
|
|
|
use hipanel\modules\server\validators\MacValidator; |
14
|
|
|
use hiqdev\hiart\ActiveQuery; |
15
|
|
|
use Yii; |
16
|
|
|
|
17
|
|
|
class Hub extends \hipanel\base\Model |
18
|
|
|
{ |
19
|
|
|
use \hipanel\base\ModelTrait; |
20
|
|
|
|
21
|
|
|
const SCENARIO_CREATE = 'create'; |
22
|
|
|
const SCENARIO_UPDATE = 'update'; |
23
|
|
|
const SCENARIO_OPTIONS = 'options'; |
24
|
|
|
|
25
|
|
|
public function rules() |
26
|
|
|
{ |
27
|
|
|
return array_merge(parent::rules(), [ |
28
|
|
|
[['id', 'access_id', 'type_id', 'state_id', 'buyer_id', 'units'], 'integer'], |
29
|
|
|
[[ |
30
|
|
|
'name', 'dc', 'mac', 'remoteid', 'note', 'ip', 'type_label', 'buyer', 'note', 'inn', 'model', |
31
|
|
|
'community', 'login', 'traf_server_id', 'order_no', 'password', 'ports_num', 'traf_server_id', |
32
|
|
|
'vlan_server_id', 'community', 'snmp_version_id', 'digit_capacity_id', 'nic_media', 'base_port_no', |
33
|
|
|
'oob_key', 'traf_server_id_label', 'vlan_server_id_label', 'type', |
34
|
|
|
], 'string'], |
35
|
|
|
[['virtual'], 'boolean'], |
36
|
|
|
|
37
|
|
|
// Create and update |
38
|
|
|
[['type_id', 'name'], 'required', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]], |
39
|
|
|
[['id'], 'integer', 'on' => self::SCENARIO_UPDATE], |
40
|
|
|
[['inn', 'mac', 'ip', 'model', 'order_no', 'note'], 'string', 'on' => [self::SCENARIO_CREATE, self::SCENARIO_UPDATE]], |
41
|
|
|
|
42
|
|
|
// set Options |
43
|
|
|
[[ |
44
|
|
|
'id', 'inn', 'model', 'login', 'password', 'ports_num', 'community', |
45
|
|
|
'snmp_version_id', 'digit_capacity_id', 'nic_media', 'base_port_no', 'base_port_no', |
46
|
|
|
], 'safe', 'on' => 'options'], |
47
|
|
|
[['traf_server_id', 'vlan_server_id'], 'integer', 'on' => self::SCENARIO_OPTIONS], |
48
|
|
|
|
49
|
|
|
[['ip'], 'ip', 'on' => ['create', 'update', 'options']], |
50
|
|
|
[['mac'], MacValidator::class], |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function attributeLabels() |
55
|
|
|
{ |
56
|
|
|
return array_merge(parent::attributeLabels(), [ |
57
|
|
|
'type_id' => Yii::t('hipanel', 'Type'), |
58
|
|
|
'buyer_id' => Yii::t('hipanel:server:hub', 'Buyer'), |
59
|
|
|
'inn' => Yii::t('hipanel:server:hub', 'INN'), |
60
|
|
|
'model' => Yii::t('hipanel:server:hub', 'Model'), |
61
|
|
|
'order_no' => Yii::t('hipanel:server:hub', 'Order No.'), |
62
|
|
|
'login' => Yii::t('hipanel:server:hub', 'Login'), |
63
|
|
|
'password' => Yii::t('hipanel:server:hub', 'Password'), |
64
|
|
|
'ports_num' => Yii::t('hipanel:server:hub', 'Number of ports'), |
65
|
|
|
'traf_server_id' => Yii::t('hipanel:server:hub', 'Server where traf is counted'), |
66
|
|
|
'vlan_server_id' => Yii::t('hipanel:server:hub', 'Server in same VLAN'), |
67
|
|
|
'community' => Yii::t('hipanel:server:hub', 'Community'), |
68
|
|
|
'snmp_version_id' => Yii::t('hipanel:server:hub', 'SNMP version'), |
69
|
|
|
'digit_capacity_id' => Yii::t('hipanel:server:hub', 'Digit capacity'), |
70
|
|
|
'nic_media' => Yii::t('hipanel:server:hub', 'NIC media'), |
71
|
|
|
'base_port_no' => Yii::t('hipanel:server:hub', 'Base port no'), |
72
|
|
|
'oob_key' => Yii::t('hipanel:server:hub', 'OOB license key'), |
73
|
|
|
'mac' => Yii::t('hipanel:server:hub', 'MAC address'), |
74
|
|
|
'name' => Yii::t('hipanel:server:hub', 'Name'), |
75
|
|
|
'note' => Yii::t('hipanel:server:hub', 'Note'), |
76
|
|
|
'net' => Yii::t('hipanel:server', 'Switch'), |
77
|
|
|
'kvm' => Yii::t('hipanel:server', 'KVM'), |
78
|
|
|
'pdu' => Yii::t('hipanel:server', 'APC'), |
79
|
|
|
'rack' => Yii::t('hipanel:server', 'Rack'), |
80
|
|
|
'ipmi' => Yii::t('hipanel:server', 'IPMI'), |
81
|
|
|
'name_ilike' => Yii::t('hipanel:server:hub', 'Switch'), |
82
|
|
|
]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getBindings() |
86
|
|
|
{ |
87
|
|
|
return $this->hasMany(Binding::class, ['device_id' => 'id'])->indexBy('type'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getBinding($type) |
91
|
|
|
{ |
92
|
|
|
if (!isset($this->bindings[$type])) { |
|
|
|
|
93
|
|
|
return null; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $this->bindings[$type]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getHardwareSettings(): ActiveQuery |
100
|
|
|
{ |
101
|
|
|
return $this->hasOne(HardwareSettings::class, ['id' => 'id']); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|