def __init__(self, options=None, config_file=None):
        # If no options have been provided, create an empty dict
        if not options:
            options = {}

        if config_file:
            config_file = [config_file]

        self.configuration_file = find_config_file(options, config_file,
                                                   CONFIG_FILE)
        if not 'plugin_provider' in options:
            options['plugin_provider'] = \
                utils.get_plugin_from_config(self.configuration_file)
        LOG.debug("Plugin location:%s", options['plugin_provider'])

        # If the plugin can't be found let them know gracefully
        try:
            plugin_klass = utils.import_class(options['plugin_provider'])
        except ClassNotFound:
            raise Exception("Plugin not found.  You can install a " \
                            "plugin with: pip install <plugin-name>\n" \
                            "Example: pip install quantum-sample-plugin")

        if not issubclass(plugin_klass, QuantumPluginBase):
            raise Exception("Configured Quantum plug-in " \
                            "didn't pass compatibility test")
        else:
            LOG.debug("Successfully imported Quantum plug-in." \
                      "All compatibility tests passed")
        self.plugin = plugin_klass()
Ejemplo n.º 2
0
    def __init__(self, options=None, config_file=None):
        # If no options have been provided, create an empty dict
        if not options:
            options = {}

        if config_file:
            config_file = [config_file]

        self.configuration_file = find_config_file(options, config_file,
                                                   CONFIG_FILE)
        if not 'plugin_provider' in options:
            options['plugin_provider'] = \
                utils.get_plugin_from_config(self.configuration_file)
        LOG.debug("Plugin location:%s", options['plugin_provider'])

        # If the plugin can't be found let them know gracefully
        try:
            plugin_klass = utils.import_class(options['plugin_provider'])
        except ClassNotFound:
            raise Exception("Plugin not found.  You can install a " \
                            "plugin with: pip install <plugin-name>\n" \
                            "Example: pip install quantum-sample-plugin")

        if not issubclass(plugin_klass, QuantumPluginBase):
            raise Exception("Configured Quantum plug-in " \
                            "didn't pass compatibility test")
        else:
            LOG.debug("Successfully imported Quantum plug-in." \
                      "All compatibility tests passed")
        self.plugin = plugin_klass()
Ejemplo n.º 3
0
 def __init__(self, options=None, config_file=None):
     if config_file == None:
         fix_path = lambda p: os.path.abspath(os.path.expanduser(p))
         config_file_dirs = [fix_path(os.getcwd()),
                     fix_path(os.path.join(os.getcwd(), 'server', 'etc')),
                     fix_path(os.path.join('~', '.quantum')),
                     fix_path('~'),
                     '/etc/quantum/',
                     '/etc']
         for cfg_dir in config_file_dirs:
             cfg_file = os.path.join(cfg_dir, CONFIG_FILE)
             if os.path.exists(cfg_file):
                 self.configuration_file = cfg_file
     else:
         self.configuration_file = config_file
     # If no options have been provided, create an empty dict
     if not options:
         options = {}
     if not 'plugin_provider' in options:
         options['plugin_provider'] = \
             utils.get_plugin_from_config(self.configuration_file)
     LOG.debug("Plugin location:%s", options['plugin_provider'])
     plugin_klass = utils.import_class(options['plugin_provider'])
     if not issubclass(plugin_klass, QuantumPluginBase):
         raise Exception("Configured Quantum plug-in " \
                         "didn't pass compatibility test")
     else:
         LOG.debug("Successfully imported Quantum plug-in." \
                   "All compatibility tests passed")
     self.plugin = plugin_klass()
Ejemplo n.º 4
0
    def setUp(self, api_router_klass, xml_metadata_dict):
        options = {}
        options["plugin_provider"] = test_config["plugin_name"]
        api_router_cls = utils.import_class(api_router_klass)
        self.api = api_router_cls(options)
        self.tenant_id = "test_tenant"
        self.network_name = "test_network"

        # Prepare XML & JSON deserializers
        net_xml_deserializer = XMLDeserializer(xml_metadata_dict[NETS])
        port_xml_deserializer = XMLDeserializer(xml_metadata_dict[PORTS])
        att_xml_deserializer = XMLDeserializer(xml_metadata_dict[ATTS])

        json_deserializer = JSONDeserializer()

        self._net_deserializers = {"application/xml": net_xml_deserializer, "application/json": json_deserializer}
        self._port_deserializers = {"application/xml": port_xml_deserializer, "application/json": json_deserializer}
        self._att_deserializers = {"application/xml": att_xml_deserializer, "application/json": json_deserializer}