#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2014             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.

# {
#     'tcp_port': 443,
#     'secret': 'wef',
#     'infos': ['hostsystem', 'virtualmachine'],
#     'user': 'wefwef'
# }

def agent_vsphere_arguments(params, hostname, ipaddress):
    args = ''
    if "tcp_port" in params:
        args += " -p %d" % params["tcp_port"]

    args += " -u " + quote_shell_string(params["user"])
    args += " -s " + quote_shell_string(params["secret"])
    args += " -i " + ",".join(params["infos"])

    direct = params.get("direct", False)

    if direct == "agent":
        args += ' --agent'
    elif direct:
        args += ' --direct --hostname ' + quote_shell_string(hostname)

    if params.get("skip_placeholder_vms", True):
        args += " -P"

    if "spaces" in params:
        args += ' --spaces %s' % params["spaces"]

    if "timeout" in params:
        args += ' --timeout %d' % params["timeout"]

    if params.get("use_pysphere"):
        args += ' --pysphere'

    if params.get("vm_pwr_display"):
        args += ' --vm_pwr_display %s' % params.get("vm_pwr_display")

    if params.get("host_pwr_display"):
        args += ' --host_pwr_display %s' % params.get("host_pwr_display")

    if "ssl" in params:
        if params["ssl"] == False:
            args += ' --no-cert-check ' + quote_shell_string(ipaddress)
        elif params["ssl"] == True:
            args += " " + quote_shell_string(hostname)
        else:
            args += " " + quote_shell_string(params["ssl"])
    else: # legacy mode
        args += " " + quote_shell_string(ipaddress)

    return args

special_agent_info['vsphere'] = agent_vsphere_arguments
