#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

# Example output:
# <<<netapp_api_info:sep(9)>>>
# ### 7Mode
# system-name netapp-host
# system-id   4082367488
# system-model    SIMBOX
# system-machine-type SIMBOX
# vendor-id   NetApp
# system-serial-number    4082367488
# board-speed 2933
# board-type  NetApp VSim
# cpu-serial-number   999999
# number-of-processors    2
# memory-size 1599
# cpu-processor-id    0x206c2
# cpu-microcode-version   21
# maximum-aggregate-size  2199023255552
# maximum-flexible-volume-size    17592186044416

# ### Clustermode
# node clu1-02  cpu-microcode-version 21    prod-type FAS   system-model SIMBOX memory-size 8192    board-speed 2933


def inv_netapp_api_info(info):
    info_dict = dict((x[0], x[1]) for x in info if x[0] != "node")

    sw_os = inv_tree("software.os.")
    hw_chassis = inv_tree("hardware.chassis.")
    hw_system = inv_tree("hardware.system.")
    hw_cpu = inv_tree("hardware.cpu.")

    # General data
    for what, name, where_to in [
        ("backplane-serial-number", "serial", hw_chassis),
        ("system-model", "model", hw_system),
        ("system-machine-type", "product", hw_system),
        ("system-serial-number", "serial", hw_system),
        ("system-id", "id", hw_system),
        # TODO: find good location for the configurable system name
        #                                 ("system-name",                "system_name",     sw_os),
        ("vendor-id", "vendor", sw_os),
        ("number-of-processors", "cores", hw_cpu),
        ("cpu-processor-type", "model", hw_cpu),
    ]:
        if what in info_dict:
            where_to[name] = info_dict[what]


# TODO: Clustermode inventory data. Clarify the correct subtrees
#    # Node specific data
#    node_dict = {}
#    for line in info:
#        if line[0].startswith("node"):
#            node = line[0].split(" ", 1)[1]
#            node_dict.setdefault(node, {})
#            for entry in line[1:]:
#                tokens = entry.split(" ", 1)
#                node_dict[node][tokens[0]] = tokens[1]
#

inv_info["netapp_api_info"] = {
    "inv_function": inv_netapp_api_info,
}
