aboutsummaryrefslogtreecommitdiffstats
path: root/moon_manager/moon_manager/pip_driver.py
blob: 1a451577b4fd9365d6c0e1abf63ee72e27945551 (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
# Software Name: MOON

# Version: 5.4

# SPDX-FileCopyrightText: Copyright (c) 2018-2020 Orange and its contributors
# SPDX-License-Identifier: Apache-2.0

# This software is distributed under the 'Apache License 2.0',
# the text of which is available at 'http://www.apache.org/licenses/LICENSE-2.0.txt'
# or see the "LICENSE" file for more details.

"""
Drivers fot the Policy Information Point
"""

import logging
from moon_manager.api import configuration
from moon_manager.api.information import information, global_attrs

LOGGER = logging.getLogger("moon.manager.pip_driver")


InformationManager = None
AttrsManager = None


class Driver:
    """
    Generic driver
    """

    def __init__(self, driver_name, engine_name, conf={}):
        self.name = driver_name
        self.plug = configuration.get_information_driver(driver_name)
        if self.plug:
            self.driver = self.plug.Connector(driver_name, engine_name, conf)
        else:
            self.driver = VoidConnector(driver_name, engine_name)


class InformationDriver(Driver):
    """
    Driver for information retrieval for external components like OpenStack
    """

    def __init__(self, driver_name, engine_name, conf):
        super(InformationDriver, self).__init__(driver_name, engine_name, conf)
        self.engine = engine_name

    def set_auth(self, **kwargs):
        """Set authorizations if necessary

        :param kwargs: arguments which are necessary to login to the server
        :return: headers to use
        """
        raise NotImplementedError()  # pragma: no cover

    def unset_auth(self, **kwargs):
        """Unset the authorization is necessary

        :param kwargs: arguments which are necessary to logout to the server
        :return: headers to use
        """
        raise NotImplementedError()  # pragma: no cover

    def get_items(self, item_id=None, **kwargs):
        """List items in the server

        :param item_id: the item name or item ID
        :param kwargs: all arguments necessary to list items
        :return: a list of items
        """
        raise NotImplementedError()  # pragma: no cover

    def add_item(self, item_id=None, **kwargs):
        """Add a item in the server

        :param item_id: the item name or item ID
        :param kwargs: all arguments necessary to add a item
        :return: the item added
        """
        raise NotImplementedError()  # pragma: no cover

    def update_item(self, item_id, **kwargs):
        """Update a item in the server

        :param item_id: the item name or item ID
        :param kwargs: all arguments necessary to update the item
        :return: the item updated
        """
        raise NotImplementedError()  # pragma: no cover

    def delete_item(self, item_id, **kwargs):
        """Delete a item in the server

        :param item_id: the item name or item ID
        :param kwargs: all arguments necessary to delete the item
        :return: True if the item has been deleted
        """
        raise NotImplementedError()  # pragma: no coverl


class GlobalAttrsDriver:
    """
    Driver for global attributes in Moon
    """

    def __init__(self, driver_name, engine_name):
        self.name = driver_name
        self.plug = configuration.get_global_attrs_driver()
        if self.plug:
            self.driver = self.plug.Connector(driver_name, engine_name)
        else:
            self.driver = VoidConnector(driver_name, engine_name)
        self.engine = engine_name

    def set_auth(self, **kwargs):
        """Set authorizations if necessary

        :param kwargs: arguments which are necessary to login to the server
        :return: headers to use
        """
        raise NotImplementedError()  # pragma: no cover

    def unset_auth(self, **kwargs):
        """Unset the authorization is necessary

        :param kwargs: arguments which are necessary to logout to the server
        :return: headers to use
        """
        raise NotImplementedError()  # pragma: no cover

    def get_users(self, user_id=None, **kwargs):
        """List users in the server

        :param user_id: the user name or user ID
        :param kwargs: all arguments necessary to list users
        :return: a list of users
        """
        raise NotImplementedError()  # pragma: no cover

    def add_user(self, user_id=None, **kwargs):
        """Add a user in the server

        :param user_id: the user name or user ID
        :param kwargs: all arguments necessary to add a user
        :return: the user added
        """
        raise NotImplementedError()  # pragma: no cover

    def update_user(self, user_id, **kwargs):
        """Update a user in the server

        :param user_id: the user name or user ID
        :param kwargs: all arguments necessary to update the user
        :return: the user updated
        """
        raise NotImplementedError()  # pragma: no cover

    def delete_user(self, user_id, **kwargs):
        """Delete a user in the server

        :param user_id: the user name or user ID
        :param kwargs: all arguments necessary to delete the user
        :return: True if the user has been deleted
        """
        raise NotImplementedError()  # pragma: no cover

    def get_objects(self, object_id=None, object_type=None, **kwargs):
        """List objects in the server

        :param object_id: the object name or user ID
        :param object_type: the object type (project, vms, ...)
        :param kwargs: all arguments necessary to list the object
        :return: a list of objects
        """
        raise NotImplementedError()  # pragma: no cover

    def get_object(self, object_type=None, **kwargs):
        """List a specific object in the server

        :param object_type: the object type (project, vms, ...)
        :param kwargs: all arguments necessary to list the object
        :return: a list of objects
        """
        raise NotImplementedError()  # pragma: no cover

    def add_object(self, object_id=None, object_type=None, **kwargs):
        """Add an object in the server

        :param object_id: the object name or user ID
        :param object_type: the object type (project, vms, ...)
        :param kwargs: all arguments necessary to add the object
        :return: the object added
        """
        raise NotImplementedError()  # pragma: no cover

    def update_object(self, object_id, object_type=None, **kwargs):
        """Update an object in the server

        :param object_id: the object name or user ID
        :param object_type: the object type (project, vms, ...)
        :param kwargs: all arguments necessary to update the object
        :return: the object updated
        """
        raise NotImplementedError()  # pragma: no cover

    def delete_object(self, object_id, object_type=None, **kwargs):
        """Delete an object in the server

        :param object_id: the object name or user ID
        :param object_type: the object type (project, vms, ...)
        :param kwargs: all arguments necessary to delete the object
        :return: True if the object has been deleted
        """
        raise NotImplementedError()  # pragma: no cover


class VoidConnector(InformationDriver):
    """
    Driver for information retrieval for external components like OpenStack
    """

    def __init__(self, driver_name, engine_name):
        self.engine = engine_name

    def set_auth(self, **kwargs):
        """Set authorizations if necessary

        :param kwargs: arguments which are necessary to login to the server
        :return: headers to use
        """
        return

    def unset_auth(self, **kwargs):
        """Unset the authorization is necessary

        :param kwargs: arguments which are necessary to logout to the server
        :return: headers to use
        """
        return

    def get_users(self, user_id=None, **kwargs):
        """List users in the server

        :param user_id: the user name or user ID
        :param kwargs: all arguments necessary to list users
        :return: a list of users
        """
        return {}

    def add_user(self, user_id=None, **kwargs):
        """Add a user in the server

        :param user_id: the user name or user ID
        :param kwargs: all arguments necessary to add a user
        :return: the user added
        """
        return {}

    def update_user(self, user_id, **kwargs):
        """Update a user in the server

        :param user_id: the user name or user ID
        :param kwargs: all arguments necessary to update the user
        :return: the user updated
        """
        return {}

    def delete_user(self, user_id, **kwargs):
        """Delete a user in the server

        :param user_id: the user name or user ID
        :param kwargs: all arguments necessary to delete the user
        :return: True if the user has been deleted
        """
        return {}

    def get_objects(self, object_id=None, object_type=None, **kwargs):
        """List objects in the server

        :param object_id: the object name or user ID
        :param object_type: the object type (project, vms, ...)
        :param kwargs: all arguments necessary to list the object
        :return: a list of objects
        """
        return {}

    def add_object(self, object_id=None, object_type=None, **kwargs):
        """Add an object in the server

        :param object_id: the object name or user ID
        :param object_type: the object type (project, vms, ...)
        :param kwargs: all arguments necessary to add the object
        :return: the object added
        """
        return {}

    def update_object(self, object_id, object_type=None, **kwargs):
        """Update an object in the server

        :param object_id: the object name or user ID
        :param object_type: the object type (project, vms, ...)
        :param kwargs: all arguments necessary to update the object
        :return: the object updated
        """
        return {}

    def delete_object(self, object_id, object_type=None, **kwargs):
        """Delete an object in the server

        :param object_id: the object name or user ID
        :param object_type: the object type (project, vms, ...)
        :param kwargs: all arguments necessary to delete the object
        :return: True if the object has been deleted
        """
        return {}


def init():
    """Initialize the managers

    :return: nothing
    """
    global InformationManager, AttrsManager

    InformationManager = {"subjects": [], "objects": [], "actions": []}

    LOGGER.info("Initializing driver")
    conf = configuration.get_configuration("information")

    for category in InformationManager:
        if category not in conf:
            continue
        drivers = conf.get(category).get("drivers")
        for driver in drivers:
            InformationManager[category].append(
                information.InformationManager(
                    InformationDriver(driver, drivers[driver].get("url"), conf[category]["drivers"].get(driver, {}))
                )
            )

    conf = configuration.get_configuration("information").get("global_attrs")

    AttrsManager = global_attrs.GlobalAttrsManager(
        GlobalAttrsDriver(conf['driver'], "")
    )


init()