Пример #1
0
    def add_item(self, item, params, id_=None, context=None):
        """Add item to model.

         Args:
             item: The item to add to the model
             id_: The ID of the item, or None if an ID should be generated
             context: Key-values providing frame of reference of request

         Returns:
              Tuple of (ID, newly_created_item)

         Raises:
             KeyError: ID already exists.
         """
        obj = None
        try:
            if self.dist_arch:
                obj = self.bus.add_datasource(item=item)
                utils.create_datasource_policy(self.bus, obj["name"], self.engine)
            else:
                obj = self.datasource_mgr.add_datasource(item=item)
        except (
            exception.BadConfig,
            exception.DatasourceNameInUse,
            exception.DriverNotFound,
            exception.DatasourceCreationError,
        ) as e:
            LOG.exception(_("Datasource creation failed."))
            if obj:
                # Do cleanup
                self.delete_datasource(obj)
            raise webservice.DataModelException(e.code, e.message, http_status_code=e.code)

        return (obj["id"], obj)
Пример #2
0
def create2(node, policy_engine=True, datasources=True, api=True):
    """Get Congress up.

    Creates a DseNode if one is not provided and adds policy_engine,
    datasources, api to that node.

    :param node is a DseNode
    :param policy_engine controls whether policy_engine is included
    :param datasources controls whether datasources are included
    :param api controls whether API is included
    :returns DseNode
    """
    # create services as required
    services = {}
    if api:
        LOG.info("Registering congress API service on node %s", node.node_id)
        services['api'], services['api_service'] = create_api()
        node.register_service(services['api_service'])

    if policy_engine:
        LOG.info("Registering congress PolicyEngine service on node %s",
                 node.node_id)
        services[ENGINE_SERVICE_NAME] = create_policy_engine()
        node.register_service(services[ENGINE_SERVICE_NAME])
        initialize_policy_engine(services[ENGINE_SERVICE_NAME])

    if datasources:
        LOG.info("Registering congress datasource services on node %s",
                 node.node_id)
        services['datasources'] = create_datasources(node)
        for ds in services['datasources']:
            try:
                utils.create_datasource_policy(ds, ds.name,
                                               ENGINE_SERVICE_NAME)
            except (exception.BadConfig,
                    exception.DatasourceNameInUse,
                    exception.DriverNotFound,
                    exception.DatasourceCreationError) as e:
                LOG.exception("Datasource %s creation failed. %s" % (ds, e))
                node.unregister_service(ds)

    # TODO(dse2): Figure out what to do about the synchronizer
    # # Start datasource synchronizer after explicitly starting the
    # # datasources, because the explicit call to create a datasource
    # # will crash if the synchronizer creates the datasource first.
    # synchronizer_path = os.path.join(src_path, "synchronizer.py")
    # LOG.info("main::start() synchronizer: %s", synchronizer_path)
    # cage.loadModule("Synchronizer", synchronizer_path)
    # cage.createservice(
    #     name="synchronizer",
    #     moduleName="Synchronizer",
    #     description="DB synchronizer instance",
    #     args={'poll_time': cfg.CONF.datasource_sync_period})
    # synchronizer = cage.service_object('synchronizer')
    # engine.set_synchronizer(synchronizer)

    return services