2019-08-02 18:39:05 +02:00
|
|
|
from netbox_agent.server import ServerBase
|
|
|
|
|
2019-08-04 00:00:22 +02:00
|
|
|
|
2019-08-03 15:46:21 +02:00
|
|
|
class HPHost(ServerBase):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(HPHost, self).__init__(*args, **kwargs)
|
|
|
|
if self.is_blade():
|
|
|
|
self.hp_rack_locator = self._find_rack_locator()
|
2019-08-26 16:54:48 +02:00
|
|
|
self.manufacturer = 'HP'
|
2019-08-03 15:46:21 +02:00
|
|
|
|
|
|
|
def is_blade(self):
|
|
|
|
return self.get_product_name().startswith('ProLiant BL')
|
|
|
|
|
|
|
|
def _find_rack_locator(self):
|
2019-08-04 00:00:22 +02:00
|
|
|
"""
|
2019-08-03 15:46:21 +02:00
|
|
|
Depending on the server, the type of the `HP ProLiant System/Rack Locator`
|
|
|
|
can change.
|
|
|
|
So we need to find it every time
|
2019-08-04 00:00:22 +02:00
|
|
|
"""
|
2019-08-03 15:46:21 +02:00
|
|
|
# FIXME: make a dmidecode function get_by_dminame() ?
|
|
|
|
if self.is_blade():
|
2019-08-21 16:17:01 +02:00
|
|
|
locator = self.dmi.get_by_type(204)
|
|
|
|
if self.get_product_name() == 'ProLiant BL460c Gen10':
|
|
|
|
locator = locator[0]['Strings']
|
|
|
|
return {
|
|
|
|
'Enclosure Model': locator[2].strip(),
|
|
|
|
'Enclosure Name': locator[0].strip(),
|
|
|
|
'Server Bay': locator[3].strip(),
|
|
|
|
'Enclosure Serial': locator[4].strip(),
|
2020-02-02 20:08:56 +01:00
|
|
|
}
|
2019-08-21 16:17:01 +02:00
|
|
|
return locator[0]
|
2019-08-03 15:46:21 +02:00
|
|
|
|
|
|
|
def get_blade_slot(self):
|
|
|
|
if self.is_blade():
|
2019-08-08 14:37:02 +02:00
|
|
|
return 'Bay {}'.format(
|
|
|
|
int(self.hp_rack_locator['Server Bay'].strip())
|
2020-02-02 20:08:56 +01:00
|
|
|
)
|
2019-08-03 15:46:21 +02:00
|
|
|
return None
|
|
|
|
|
|
|
|
def get_chassis(self):
|
|
|
|
if self.is_blade():
|
|
|
|
return self.hp_rack_locator['Enclosure Model'].strip()
|
|
|
|
return self.get_product_name()
|
|
|
|
|
2019-08-08 14:37:02 +02:00
|
|
|
def get_chassis_name(self):
|
|
|
|
if not self.is_blade():
|
|
|
|
return None
|
|
|
|
return self.hp_rack_locator['Enclosure Name'].strip()
|
|
|
|
|
2019-08-03 15:46:21 +02:00
|
|
|
def get_chassis_service_tag(self):
|
|
|
|
if self.is_blade():
|
|
|
|
return self.hp_rack_locator['Enclosure Serial'].strip()
|
|
|
|
return self.get_service_tag()
|