~salvatore-orlando/neutron/quantum-api

« back to all changes in this revision

Viewing changes to quantum/manager.py

  • Committer: Salvatore Orlando
  • Date: 2011-06-24 13:52:17 UTC
  • mfrom: (6.1.14 quantum-trunk)
  • Revision ID: salvatore.orlando@eu.citrix.com-20110624135217-h6uz1zu3fxxpf3wt
Merge trunk
Resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
 
20
20
"""
21
 
Quantum's Manager class is responsible for parsing a config file
22
 
and instantiating the correct plugin that concretely implement
23
 
quantum_plugin_base class
24
 
 
 
21
Quantum's Manager class is responsible for parsing a config file and
 
22
instantiating the correct plugin that concretely implement quantum_plugin_base
 
23
class.
25
24
The caller should make sure that QuantumManager is a singleton.
26
25
"""
27
26
import gettext
 
27
import os
28
28
gettext.install('quantum', unicode=1)
29
29
 
 
30
import os
 
31
 
30
32
from common import utils
31
33
from quantum_plugin_base import QuantumPluginBase
32
34
 
33
 
CONFIG_FILE = "quantum/plugins.ini"
 
35
CONFIG_FILE = "plugins.ini"
 
36
 
 
37
 
 
38
def find_config(basepath):
 
39
    for root, dirs, files in os.walk(basepath):
 
40
        if CONFIG_FILE in files:
 
41
            return os.path.join(root, CONFIG_FILE)
 
42
    return None
34
43
 
35
44
 
36
45
class QuantumManager(object):
37
46
 
38
 
    def __init__(self, config=CONFIG_FILE):
39
 
        self.configuration_file = CONFIG_FILE
40
 
        plugin_location = utils.getPluginFromConfig(CONFIG_FILE)
41
 
        print "PLUGIN LOCATION:%s" % plugin_location
 
47
    def __init__(self, config=None):
 
48
        if config == None:
 
49
            self.configuration_file = find_config(
 
50
                os.path.abspath(os.path.dirname(__file__)))
 
51
        else:
 
52
            self.configuration_file = config
 
53
        plugin_location = utils.getPluginFromConfig(self.configuration_file)
42
54
        plugin_klass = utils.import_class(plugin_location)
43
55
        if not issubclass(plugin_klass, QuantumPluginBase):
44
56
            raise Exception("Configured Quantum plug-in " \
50
62
 
51
63
    def get_manager(self):
52
64
        return self.plugin
53
 
 
54
 
 
55
 
# TODO(somik): rmove the main class
56
 
# Added for temporary testing purposes
57
 
def main():
58
 
    manager = QuantumManager()
59
 
    myManager = manager.get_manager()
60
 
    myManager.get_all_networks("tesst")
61
 
    #print("is a plugin")
62
 
 
63
 
# Standard boilerplate to call the main() function.
64
 
if __name__ == '__main__':
65
 
    main()