def _find_rack_locator(self): """ Depending on the server, the type of the `HP ProLiant System/Rack Locator` can change. So we need to find it every time """ # FIXME: make a dmidecode function get_by_dminame() ? if self.is_blade(): locator = dmidecode.get_by_type(self.dmi, 204) if self.product.startswith("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(), } # HP ProLiant m750, m710x, m510 Server Cartridge if self.product.startswith("ProLiant m") and self.product.endswith( "Server Cartridge"): locator = dmidecode.get_by_type(self.dmi, 2) chassis = dmidecode.get_by_type(self.dmi, 3) return { "Enclosure Model": "Moonshot 1500 Chassis", "Enclosure Name": "Unknown", "Server Bay": locator[0]["Location In Chassis"].strip(), "Enclosure Serial": chassis[0]["Serial Number"].strip(), } return locator[0]
def is_vm(dmi): bios = dmidecode.get_by_type(dmi, 'BIOS') system = dmidecode.get_by_type(dmi, 'System') if 'Hyper-V' in bios[0]['Version'] or \ 'Xen' in bios[0]['Version'] or \ 'Google Compute Engine' in system[0]['Product Name'] or \ 'VirtualBox' in bios[0]['Version'] or \ 'VMware' in system[0]['Manufacturer']: return True return False
def __init__(self, dmi=None): if dmi: self.dmi = dmi else: self.dmi = dmidecode.parse() self.baseboard = dmidecode.get_by_type(self.dmi, 'Baseboard') self.bios = dmidecode.get_by_type(self.dmi, 'BIOS') self.chassis = dmidecode.get_by_type(self.dmi, 'Chassis') self.system = dmidecode.get_by_type(self.dmi, 'System') self.network = None
def get_power_supply(self): power_supply = [] for psu in dmidecode.get_by_type(self.server.dmi, PSU_DMI_TYPE): if 'Present' not in psu['Status'] or psu['Status'] == 'Not Present': continue try: max_power = int(psu.get('Max Power Capacity').split()[0]) except ValueError: max_power = None desc = '{} - {}'.format( psu.get('Manufacturer', 'No Manufacturer').strip(), psu.get('Name', 'No name').strip(), ) sn = psu.get('Serial Number', '').strip() # Let's assume that if no serial and no power reported we skip it if sn == '' and max_power is None: continue if sn == '': sn = 'N/A' power_supply.append({ 'name': sn, 'description': desc, 'allocated_draw': None, 'maximum_draw': max_power, 'device': self.device_id, }) return power_supply
def run(config): manufacturer = dmidecode.get_by_type('Chassis')[0].get('Manufacturer') server = MANUFACTURERS[manufacturer](dmi=dmidecode) if config.debug: server.print_debug() if config.register: server.netbox_create(config) if config.update_all or config.update_network or config.update_location or \ config.update_inventory or config.update_psu: server.netbox_update(config) return True
def run(config): dmi = dmidecode.parse() manufacturer = dmidecode.get_by_type(dmi, 'Chassis')[0].get('Manufacturer') try: server = MANUFACTURERS[manufacturer](dmi=dmi) except KeyError: server = GenericHost(dmi=dmi) if config.debug: server.print_debug() if config.register: server.netbox_create(config) if config.update_all or config.update_network or config.update_location or \ config.update_inventory or config.update_psu: server.netbox_update(config) return True
def _find_rack_locator(self): """ Depending on the server, the type of the `HP ProLiant System/Rack Locator` can change. So we need to find it every time """ # FIXME: make a dmidecode function get_by_dminame() ? if self.is_blade(): locator = dmidecode.get_by_type(self.dmi, 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(), } return locator[0]
def run(config): dmi = dmidecode.parse() if config.virtual.enabled or is_vm(dmi): if not config.virtual.cluster_name: raise Exception( 'virtual.cluster_name parameter is mandatory because it\'s a VM' ) server = VirtualMachine(dmi=dmi) else: manufacturer = dmidecode.get_by_type(dmi, 'Chassis')[0].get('Manufacturer') try: server = MANUFACTURERS[manufacturer](dmi=dmi) except KeyError: server = GenericHost(dmi=dmi) if config.debug: server.print_debug() if config.register or config.update_all or config.update_network or config.update_location or \ config.update_inventory or config.update_psu: server.netbox_create_or_update(config) return True
def __init__(self, *args, **kwargs): super(GenericHost, self).__init__(*args, **kwargs) self.manufacturer = dmidecode.get_by_type( self.dmi, 'Baseboard')[0].get('Manufacturer')