def delete_attribute_in_type(type_id=None): with argument_required("attr_id"): attr_ids = request.values.get("attr_id", "") attr_id_list = attr_ids.strip().split(",") manager = CITypeAttributeManager() manager.delete(type_id, attr_id_list) return jsonify(attributes=attr_id_list)
def get_attributes_by_type(type_id=None): manager = CITypeAttributeManager() from models.cmdb import CITypeCache, CIAttributeCache t = CITypeCache.get(type_id) if not t: return abort(400, "CIType {0} is not existed".format(type_id)) uniq_id = t.uniq_id unique = CIAttributeCache.get(uniq_id).attr_name return jsonify(attributes=manager.get_attributes_by_type_id(type_id), type_id=type_id, uniq_id=uniq_id, unique=unique)
def create_attributes_to_citype(type_id=None): with argument_required("attr_id"): attr_ids = request.values.get("attr_id", "") is_required = request.values.get("is_required", False) attr_id_list = attr_ids.strip().split(",") if "" in attr_id_list: attr_id_list.remove("") attr_id_list = map(int, attr_id_list) try: is_required = int(is_required) except ValueError: abort(500, "argument format is error") manager = CITypeAttributeManager() manager.add(type_id, attr_id_list, is_required=is_required) return jsonify(attributes=attr_id_list)