예제 #1
0
 def save_batch_variables(self, request, project_id, var_id):
     """批量保存
     针对一个变量,保存所有命名空间上的值
     """
     self.slz = serializers.ClusterVariableSLZ(data=request.data)
     self.slz.is_valid(raise_exception=True)
     qs = self.get_var_obj(project_id, var_id)
     ClusterVariable.batch_save_by_var_id(qs, self.slz.data['cluster_vars'])
     return Response({"code": 0, "message": 'ok', "data": []})
예제 #2
0
 def get_variables(self, request, project_id, cluster_id):
     """获取集群下所有的变量信息"""
     variables = ClusterVariable.get_cluster_vars(cluster_id, project_id)
     return Response({
         "code": 0,
         "message": "OK",
         "count": len(variables),
         "data": variables
     })
예제 #3
0
 def batch_save(self, request, project_id, cluster_id):
     """批量保存集群变量
     针对一个命名空间,保存所有的变量
     """
     self.slz = serializers.ClusterVariableSLZ(data=request.data)
     self.slz.is_valid(raise_exception=True)
     res, not_exist_vars = ClusterVariable.batch_save(
         cluster_id, self.slz.data['cluster_vars'])
     msg = 'OK'
     if not_exist_vars:
         not_exist_show_msg = [
             '%s[id:%s]' % (i['key'], i['id']) for i in not_exist_vars
         ]
         msg = _('以下变量不存在:{}').format(';'.join(not_exist_show_msg))
     return Response({"code": 0, "message": msg, "data": not_exist_vars})
예제 #4
0
    def get_batch_variables(self, request, project_id, var_id):
        """查询变量在所有集群下的值"""
        qs = self.get_var_obj(project_id, var_id)
        default_value = qs.default_value

        cluser_vars = ClusterVariable.get_project_cluster_vars_by_var(
            project_id, var_id)
        cluster_list = self.get_cluser_list_by_user_perm(request, project_id)
        for _n in cluster_list:
            if _n['cluster_id'] in cluser_vars:
                _n['variable_value'] = cluser_vars.get(_n['cluster_id'])
            else:
                _n['variable_value'] = default_value

        return Response({"code": 0, "message": "OK", "data": cluster_list})
예제 #5
0
def get_cluster_variables(project_id, cluster_id):
    """查询集群下的变量"""
    cluster_vars = ClusterVariable.get_cluster_vars(cluster_id, project_id)
    return {info["key"]: info["value"] for info in cluster_vars}