1.heat-engine启动一个rpc server端,EngineService在初始化时加载heat.clients插件和初始化env,
env中包括各种资源关键字对应的映射类和constraints对应的类
2.在加载heat.engine.resources中资源时,每个资源都定义有资源处理的方法handle_* 和资源映射的resource_mapping或available_resource_mapping, 如下:
def resource_mapping(): return { 'OS::Glance::Image': GlanceImage }
PluginManager加载heat.engine.resources中所有资源模块,resource_mapping.load_all(manager)调用所有模块中resource_mapping,返回资源关键字和映射类,添加到env中
3.以创建stack为例
stack = self._parse_template_and_validate_stack( cnxt, stack_name, template, params, files, environment_files, args, owner_id, nested_depth, user_creds_id, stack_user_project_id, convergence, parent_resource_name, template_id) #解析模板返回stack stack_id = stack.store() # stack存入数据库 if cfg.CONF.reauthentication_auth_method == 'trusts': stack = parser.Stack.load( cnxt, stack_id=stack_id, use_stored_context=True) _create_stack_user(stack) if convergence: action = stack.CREATE if stack.adopt_stack_data: action = stack.ADOPT stack.thread_group_mgr = self.thread_group_mgr stack.converge_stack(template=stack.t, action=action) else: msg_queue = eventlet.queue.LightQueue() # _stack_create 创建stack th = self.thread_group_mgr.start_with_lock(cnxt, stack, self.engine_id, _stack_create, stack, msg_queue=msg_queue) th.link(self.thread_group_mgr.remove_msg_queue, stack.id, msg_queue) self.thread_group_mgr.add_msg_queue(stack.id, msg_queue)
在stack中创建资源,self.stack_task中,加载资源依赖,以tree递归加载,直到tree的叶子节点上
resource_action 中调用资源中handle_*进行资源的更删改查等操作