"""

Mock implementation of what a CMDBClient should return, This is typically a simple HTTP client which
interacts with whatever Configuration Management system you have. It could also just interact with JSON
files if that is what you want.

All object names should be finalized by this plugin, so utilize Naming.name to to set final names.

"""

import logging

import libsolace
from libsolace.Naming import name
from libsolace.plugin import Plugin
from libsolace.util import get_key_from_kwargs

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())


@libsolace.plugin_registry.register
class CMDBClient(Plugin):
    # the name used to call the plugin
    plugin_name = "CMDBClient"

    def __init__(self, settings=None, **kwargs):
        """
        Example:
        >>> cmdbapi =
        :param settings:
        :param kwargs:
        :return:
        """
        logger.debug("Configuring with settings: %s" % settings)
        self.settings = settings
        self.url = settings["CMDB_URL"]

    def get_vpns_by_owner(self, *args, **kwargs):
        """
        return a LIST of vpns groups by some "owner", each VPN contains final config,
        so all environment overrides and that should be taken care of here!
        :param environment: the name of the environment
        """

        owner_name = args[0]  # type: str
        environment = get_key_from_kwargs("environment", kwargs)  # type: str

        vpns = []

        vpn1 = {}
        vpn1['owner'] = owner_name
        vpn1['vpn_config'] = {}
        vpn1['vpn_config']['spool_size'] = '1024'
        vpn1['password'] = '<PASSWORD>'
        vpn1['id'] = '%s_testvpn'
        vpn1['name'] = name(vpn1['id'], environment)

        vpns.append(vpn1)
        return vpns

    def get_users_of_vpn(self, *args, **kwargs):
        """
        Just return a list of users for a VPN
        """

        vpn_name = args[0]  # type: str
        environment = get_key_from_kwargs("environment", kwargs)  # type: str

        users = []

        user1 = {}
        user1['username'] = name('%s_testproductA', environment)
        user1['password'] = '<PASSWORD>'

        users.append(user1)
        return users

    def get_queues_of_vpn(self, *args, **kwargs):
        """
        As with VPN, all configs should be finalized before returned.
        """

        vpn_name = args[0]  # type: str
        environment = get_key_from_kwargs("environment", kwargs)  # type: str

        queues = []

        queue1 = {}
        queue1['queue_config'] = {}
        queue1['queue_config']["exclusive"] = "true"
        queue1['queue_config']["queue_size"] = "4096"
        queue1['queue_config']["retries"] = 0
        queue1['queue_config']['max_bind_count'] = 1000
        queue1['queue_config']['owner'] = name("%s_testproductA", environment)
        queue1['queue_config']["consume"] = "all"
        queue1["name"] = "testqueue1"

        queues.append(queue1)
        return queues

"""

Mock implementation of what a CMDBClient should return, This is typically a simple HTTP client which
interacts with whatever Configuration Management system you have. It could also just interact with JSON
files if that is what you want.

All object names should be finalized by this plugin, so utilize Naming.name to to set final names.

"""

import logging

import libsolace
from libsolace.Naming import name
from libsolace.plugin import Plugin
from libsolace.util import get_key_from_kwargs

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())


@libsolace.plugin_registry.register
class CMDBClient(Plugin):
    # the name used to call the plugin
    plugin_name = "CMDBClient"

    def __init__(self, settings=None, **kwargs):
        """
        Example:
        >>> cmdbapi =
        :param settings:
        :param kwargs:
        :return:
        """
        logger.debug("Configuring with settings: %s" % settings)
        self.settings = settings
        self.url = settings["CMDB_URL"]

    def get_vpns_by_owner(self, *args, **kwargs):
        """
        return a LIST of vpns groups by some "owner", each VPN contains final config,
        so all environment overrides and that should be taken care of here!
        :param environment: the name of the environment
        """

        owner_name = args[0]  # type: str
        environment = get_key_from_kwargs("environment", kwargs)  # type: str

        vpns = []

        vpn1 = {}
        vpn1['owner'] = owner_name
        vpn1['vpn_config'] = {}
        vpn1['vpn_config']['spool_size'] = '1024'
        vpn1['password'] = '<PASSWORD>'
        vpn1['id'] = '%s_testvpn'
        vpn1['name'] = name(vpn1['id'], environment)

        vpns.append(vpn1)
        return vpns

    def get_users_of_vpn(self, *args, **kwargs):
        """
        Just return a list of users for a VPN
        """

        vpn_name = args[0]  # type: str
        environment = get_key_from_kwargs("environment", kwargs)  # type: str

        users = []

        user1 = {}
        user1['username'] = name('%s_testproductA', environment)
        user1['password'] = '<PASSWORD>'

        users.append(user1)
        return users

    def get_queues_of_vpn(self, *args, **kwargs):
        """
        As with VPN, all configs should be finalized before returned.
        """

        vpn_name = args[0]  # type: str
        environment = get_key_from_kwargs("environment", kwargs)  # type: str

        queues = []

        queue1 = {}
        queue1['queue_config'] = {}
        queue1['queue_config']["exclusive"] = "true"
        queue1['queue_config']["queue_size"] = "4096"
        queue1['queue_config']["retries"] = 0
        queue1['queue_config']['max_bind_count'] = 1000
        queue1['queue_config']['owner'] = name("%s_testproductA", environment)
        queue1['queue_config']["consume"] = "all"
        queue1["name"] = "testqueue1"

        queues.append(queue1)
        return queues

Mock implementation of what a CMDBClient should return, This is typically a simple HTTP client which interacts with whatever Configuration Management system you have. It could also just interact with JSON files if that is what you want.  All object names should be finalized by this plugin, so utilize Naming.name to to set final names. # the name used to call the plugin Example:         >>> cmdbapi =         :param settings:         :param kwargs:         :return: return a LIST of vpns groups by some "owner", each VPN contains final config,         so all environment overrides and that should be taken care of here!         :param environment: the name of the environment # type: str # type: str Just return a list of users for a VPN # type: str # type: str As with VPN, all configs should be finalized before returned. # type: str # type: str