def get_create_req_msg_from_kh(kh_inst): key = str(type(kh_inst)) + str(kh_inst.SerializeToString()) if mbt_obj_store.config_objects_kh(key, 'create') is not None: mbt_handle = mbt_obj_store.config_objects_kh(key, 'create') if mbt_obj_store.config_objects(mbt_handle) is not None: (service_name, key_or_handle, ext_refs, immutable_objs, create_req_msg) = mbt_obj_store.config_objects(mbt_handle) return create_req_msg return None
def get_ext_ref_obj_from_kh(kh_inst): assert False cfg_spec_obj = mbt_obj_store.cfg_spec_obj_store_kh(type(kh_obj).__name__) for mbt_handle in cfg_spec_obj.ext_ref_obj_list(): if mbt_obj_store.config_objects(mbt_handle) is not None: (service_name, key_or_handle, ext_refs, immutable_objs, create_req_msg) = mbt_obj_store.config_objects(mbt_handle) if key_or_handle == kh_obj: return create_req_msg return None
def create_config_from_kh(kh_str, constraints, ext_refs): expected_api_status = 'API_STATUS_OK' cfg_spec_obj = mbt_obj_store.cfg_spec_obj_store_kh(kh_str) immutable_objs = {} max_reached = False # TODO which key_or_handle to return if multiple constaints? if constraints is not None: for constraint in constraints: (mbt_status, api_status, mbt_handle, rsp_msg) = cfg_spec_obj.create_with_constraints( ext_refs, constraint, immutable_objs, mbt_obj_store.default_max_retires()) if mbt_status == mbt_obj_store.MbtRetStatus.MBT_RET_MAX_REACHED: api_status = 'API_STATUS_OK' max_reached = True mbt_handle = cfg_spec_obj.get_config_object(0) if expected_api_status != api_status: msg.err_print("Expected: " + expected_api_status + ", Got: " + api_status) assert False else: (mbt_status, api_status, mbt_handle, rsp_msg) = cfg_spec_obj.create_with_constraints( ext_refs, constraints, immutable_objs, mbt_obj_store.default_max_retires()) if mbt_status == mbt_obj_store.MbtRetStatus.MBT_RET_MAX_REACHED: api_status = 'API_STATUS_OK' max_reached = True mbt_handle = cfg_spec_obj.get_config_object(0) if expected_api_status != api_status: msg.err_print("Expected: " + expected_api_status + ", Got: " + api_status) assert False if mbt_obj_store.config_objects(mbt_handle) is not None: (_service_name, _key_or_handle, _ext_refs, _immutable_objs, _create_req_msg) = mbt_obj_store.config_objects(mbt_handle) # If max objects is reached, ext_refs does not get updated since the generator is not invoked. # Update the ext_refs with ext_refs for the message corresponding to mbt_handle if max_reached == True: ext_refs.update(_ext_refs) return _key_or_handle return None
def internal_op(self, mbt_handle, config_method_type, config_method_name): api_status = 'API_STATUS_ERR' rsp_msg = None config_method = self._config_methods[config_method_type] if config_method.ignore() == True: debug_print ("Ignoring " + config_method_name) api_status = 'API_STATUS_OK' return (api_status, rsp_msg) if mbt_obj_store.config_objects(mbt_handle) is None: print (config_method_name + ": config object could not be found for handle: " + str(mbt_handle)) return (api_status, rsp_msg) grpc_req_rsp_msg = GrpcReqRspMsg(config_method.request()()) # get object details from global store (service_name, key_or_handle, ext_refs, immutable_objs, create_req_msg) = mbt_obj_store.config_objects(mbt_handle) ext_constraints = None req_msg = grpc_req_rsp_msg.generate_message(key_or_handle, ext_refs, ext_constraints, immutable_objs) data = ConfigData() if config_method.pre_cb(): config_method.pre_cb().call(data, req_msg, None) debug_print (req_msg) rsp_msg = config_method.api()(req_msg) if config_method.post_cb(): config_method.post_cb().call(data, req_msg, rsp_msg) if config_method_type == ConfigMethodType.CREATE: self._num_create_ops += 1 elif config_method_type == ConfigMethodType.GET: self._num_get_ops += 1 elif config_method_type == ConfigMethodType.UPDATE: self._num_update_ops += 1 elif config_method_type == ConfigMethodType.DELETE: self._num_delete_ops += 1 if rsp_msg is not None: api_status = GrpcReqRspMsg.GetApiStatusObject(rsp_msg) return (api_status, rsp_msg)
def get_ext_ref_kh_from_global_store(key_or_handle_str, constraints): for (ref_obj_spec, mbt_handle) in mbt_obj_store.get_ref_obj_list(): if (ref_obj_spec.key_handle == key_or_handle_str): if constraints: ref_obj_spec_constraints = msg.GrpcReqRspMsg.extract_constraints( ref_obj_spec.constraints)[0] msg.debug_print("Expected constraits: " + str(constraints) + ", found: " + str(ref_obj_spec_constraints)) if constraints != ref_obj_spec_constraints: continue if mbt_obj_store.config_objects(mbt_handle) is not None: (_service_name, _key_or_handle, _ext_refs, _immutable_objs, _create_req_msg) = mbt_obj_store.config_objects(mbt_handle) return _key_or_handle return None