#!/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.

# {
#     '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", params["user"]]
    args += [passwordstore_get_cmdline("-s=%s", params["secret"])]
    args += ["-i", ",".join(params["infos"])]

    #  True: Queried host is a host system
    #  False: Queried host is the vCenter
    if params["direct"]:
        args += ['--direct', '--hostname', hostname]

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

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

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

    if params.get("vm_pwr_display"):
        args += ['--vm_pwr_display', params.get("vm_pwr_display")]

    if params.get("vm_piggyname"):
        args += ['--vm_piggyname', params.get("vm_piggyname")]

    if params.get("host_pwr_display"):
        args += ['--host_pwr_display', params.get("host_pwr_display")]

    if params.get("snapshots_on_host", False):
        args += ['--snapshots-on-host']

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

    return args


special_agent_info['vsphere'] = agent_vsphere_arguments
