Exemplo n.º 1
0
def helm_list(request):
    ins = Tiller(K8S_HOST, K8S_PORT)
    if request.method == 'GET':
        # print 'GET'
        # chart_path = RepoUtils.from_repo(CHART_REPO,'jenkins')
        # print chart_path


        action = request.GET.get('action', False)
        name = request.GET.get('name', None)
        if action == 'detail':
            release_status = ins.get_release_status(name)
            release_content = ins.get_release_content(name)
            release_history = ins.get_history(name)
            # print release_history.releases[0]
            resource = [
                {
                    "type": yaml.load(x)['kind'],
                    "content": x
                }
                for x in release_content.release.manifest.split('---') if yaml.load(x)
            ]
            # print resource
            # resource = [ x for x in release_content.release.manifest.split('---')]
            # release_history.releases[0]
            return render(
                request,'helm_detail.html',
                {
                    "status": release_status,
                    "content": release_content,
                    "history": release_history.releases,
                    "resource": resource,
                    "request": request
                }

            )
        list = ins.list_releases()
        return render(
            request,'helm_publish.html',
            {
                "list_name": list,
                "request": request
            })
    action = request.POST.get('action', None)
    name = request.POST.get('name',None)
    if action == 'rollback':
        version = request.POST.get('version',None)
        # print type(version)
        try:
            rollback_result = ins.rollback_release(name=name,version=int(version))
        except Exception,e:
            print e
        print rollback_result
        return JsonResponse({'result': rollback_result})
Exemplo n.º 2
0
tiller_port = '44134'
#chart_path = RepoUtils.from_repo('https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts', 'mariadb')
chart_path = from_repo(
    'https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts', 'mariadb')
chart = ChartBuilder({
    'name': 'mariadb',
    'source': {
        'type': 'directory',
        'location': chart_path
    }
})
# 构建chart元数据
#chart = ChartBuilder({'name': 'mongodb', 'source': {'type': 'directory', 'location': '/tmp/pyhelm-kibwtj8d/mongodb'}})
#chart = ChartBuilder({'name': 'stable/mongodb', 'version':'0.4.27', 'source': {'type': 'repo', 'version': '0.4.27', 'location': 'https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts'}})
# 生成tiller连接实例
tiller_ins = Tiller(tiller_host, tiller_port)
import pdb
pdb.set_trace()
# 安装 release
tiller_ins.install_release(chart.get_helm_chart(),
                           dry_run=False,
                           namespace='default')
# 列出 release
tiller_ins.list_releases(limit=0, status_codes=[], namespace=None)
# 删除 release
tiller_ins.uninstall_release(release_name)
# 获得 release 版本历史
tiller_ins.get_history(name, max=MAX_HISTORY)
# 回滚 release
tiller_ins.rollback_release(name, version, timeout=REQUEST_TIMEOUT)
Exemplo n.º 3
0
# -*- coding:utf-8 -*-
#from pyhelm.repo import RepoUtils
from pyhelm.repo import from_repo
import pdb;pdb.set_trace()
from pyhelm.chartbuilder import ChartBuilder
from pyhelm.tiller import Tiller
import pdb;pdb.set_trace()
tiller_host='127.0.0.1'
tiller_port='44134'
#chart_path = RepoUtils.from_repo('https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts', 'mariadb')
chart_path = from_repo('https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts', 'mariadb')
chart = ChartBuilder({'name': 'mariadb', 'source': {'type': 'directory', 'location': chart_path}})
# 构建chart元数据  
#chart = ChartBuilder({'name': 'mongodb', 'source': {'type': 'directory', 'location': '/tmp/pyhelm-kibwtj8d/mongodb'}})  
#chart = ChartBuilder({'name': 'stable/mongodb', 'version':'0.4.27', 'source': {'type': 'repo', 'version': '0.4.27', 'location': 'https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts'}})
# 生成tiller连接实例  
tiller_ins = Tiller(tiller_host, tiller_port)  
import pdb;pdb.set_trace()
# 安装 release  
tiller_ins.install_release(chart.get_helm_chart(), dry_run=False, namespace='default')  
# 列出 release  
tiller_ins.list_releases(limit=0, status_codes=[], namespace=None)  
# 删除 release  
tiller_ins.uninstall_release(release_name)  
# 获得 release 版本历史  
tiller_ins.get_history(name, max=MAX_HISTORY) 
# 回滚 release  
tiller_ins.rollback_release(name, version, timeout=REQUEST_TIMEOUT)