-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMDBClient.py
97 lines (75 loc) · 2.93 KB
/
CMDBClient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
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.plugin import Plugin
from libsolace.Naming import name
from libsolace.util import get_key_from_settings
from libsolace.util import get_key_from_kwargs
@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:
"""
logging.debug("Configuring with settings: %s" % settings)
self.settings = settings.__dict__ # type: dict
self.url = get_key_from_settings("CMDB_URL", self.settings)
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'] = 'd0nt_u5e_th1s'
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'] = 'somepassword'
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