Ejemplo n.º 1
0
    def handle(self, **kwargs):
        groups = ServerGroup.objects().order_by('name')

        i = 1
        for g in groups:
            print '%i) %s' % (i, g.name)
            i += 1
        
        print 'q) Quit'

        num = self._get_string('Enter number to edit')
        
        g = groups[int(num)-1]

        print
        print "Editing %s now..." % g
        print 
        
        servers = []

        i = 1
        for s in Server.objects().order_by('name'):
            if s.id in g.servers:
                print '%i) %s' % (i, s.host)
                i += 1l;s
                servers.append(s)
            
        num = self._get_string('Enter number to to delete from the group')
        
        g.servers.remove(servers[int(num)-1].id)
        g.save()
Ejemplo n.º 2
0
    def handle(self, **kwargs):
        if kwargs['server']:
            objs = Server.objects()
        if kwargs['group']:
            
            i = 1
            for s in Server.objects():
                print '%i) %s' % (i, s.host)
                i += 1
    
            num = self._get_string('Enter number to add to')
            
            obj = servers[int(num)-1]
        
        if kwargs['group']:
            groups = ServerGroup.objects()
    
            i = 1
            for g in groups:
                print '%i) %s' % (i, g.name)
                i += 1
    
            num = self._get_string('Enter number to add to')
        
            obj = groups[int(num)-1]


        while True:
            #
            # list the logs for the server/group now
            #
            if len(obj.logs) == 0:
                break
            
            i = 1
            for l in obj.logs:
                print '%i) %s' % (i, l)
                i += 1
                
            num = int(self._get_string('Enter number to delete'))
            if num > 0:
                obj.logs.pop(num-1)
                obj.save()
Ejemplo n.º 3
0
def do_verify(request):
    #
    # getting if the uuid is assigned to a server.. if not create it
    #
    s = Server.objects(uuid=request.POST['server']).first()
    if s is None:
        s = Server(host=request.POST['host'], uuid=request.POST['server'])
        s.save()
        
    return s
Ejemplo n.º 4
0
def edit_deploy_form(request, deploy_name):
    job = Job.objects(builders__name=deploy_name + '-deploy')[0]
    
    if request.user.is_superuser:
        server_list = Server.objects.all()
    else:
        server_list = Server.objects(users=str(request.user))
    
    context = {
        'job': job,
        'server_list': server_list,
    }
    
    return render(request, 'job/deploy/edit.html', context)
Ejemplo n.º 5
0
def show_index(request, group=False): 
    if group:
        #
        # getting the groups
        #
        groups = ServerGroup.objects()
        
        return render_to_response('server/index_group.html', {'groups': groups}, context_instance=RequestContext(request))
    else:
        #
        # getting all the servers
        #
        servers = Server.objects()

        return render_to_response('server/index.html', {'servers': servers}, context_instance=RequestContext(request))
Ejemplo n.º 6
0
def edit_build_form(request, build_name):
    job = Job.objects(builders__name=build_name  + '-build')[0]
    
    if request.user.is_superuser:
        server_list = Server.objects.all()
    else:
        server_list = Server.objects(users=str(request.user))
    
    context = {
        'builders': job.builders,
        'job': job,
        'schedulers': job.schedulers[0],
        'server_list': server_list,
    }
    
    return render(request, 'job/build/edit.html', context)
Ejemplo n.º 7
0
def index(request):
    if request.user.is_superuser:
        job_list = Job.objects.all()
        server_list = Server.objects.all()
    else:
        job_list = Job.objects(users=str(request.user))
        server_list = Server.objects(users=str(request.user))
    
    user_list = User.objects.all()
    
    context = {
        'job_list': job_list,
        'server_list': server_list,
        'user_list': user_list
    }
    
    return render(request, 'permission/index.html', context)
Ejemplo n.º 8
0
    def handle(self, **kwargs):
        if kwargs['group']:
            groups = ServerGroup.objects()
    
            i = 1
            for g in groups:
                print '%i) %s' % (i, g.name)
                i += 1
    
            num = self._get_string('Enter number to add to')
        
            obj = groups[int(num)-1]
        elif kwargs['server']:
            servers = Server.objects()
            
            i = 1
            for s in servers:
                print '%i) %s' % (i, s.host)
                i += 1
    
            print 'q) Quit'
    
            num = self._get_string('Enter number to add to')
            
            obj = servers[int(num)-1]


        while True:
            log = self._get_string('Enter full path to log (hit enter to exit)', required=False)

            if log == "":
                break
            else:
                #
                # append the log to it
                #
                if obj.logs is None:
                    obj.logs = [log]
                else:
                    obj.logs.append(log)
                
                obj.save()
Ejemplo n.º 9
0
def do_add(request):
    #
    # find the server
    #
    s = Server.objects(uuid=request.POST['server']).first()
    
    #
    # add the log
    #
    j = simplejson.loads(request.POST['log'])
    
    #
    # formatting the log
    #
    log = ""
    for l in j['line']:
        log += l.strip() + "\n"

    l = Log(server=s, log=j['log'], line=log)
    l.save()
    
Ejemplo n.º 10
0
def show_server(request, server=None):
    
    s = Server.objects(host=server).first()

    if request.GET.has_key('log'):
        if request.method == "POST":
            #
            # grabbing the last 50 logs from our search string
            #
            logs = Log.objects(server=s, log=request.GET['log'], line__icontains=request.POST['search']).limit(50)
        else:
            #
            # grabbing the last 50 logs
            #
            logs = Log.objects(server=s, log=request.GET['log']).limit(50)
        
        log = ""
        for l in logs:
            log += l.line
            
        return render_to_response('server/log.html', {'server': s, 'log': log}, context_instance=RequestContext(request))

    
    return render_to_response('server/server.html', {'server': s}, context_instance=RequestContext(request))
Ejemplo n.º 11
0
def add_build(request):
    if request.method == 'POST':
        build_name = request.POST.get('build-name', '') + '-build'
        
        scheduler = Scheduler(
            scheduler_type='SingleBranchScheduler',
            name=build_name,
            builder_names=[build_name],
            change_filter=SchedulerChangeFilter(category=build_name)
        )
        
        build_steps = []
        for typ, arg in zip(request.POST.getlist('build-step-type'), request.POST.getlist('build-step-arg')):
            if typ == 'Git':
                build_step = BuildStep(
                    type='Git',
                    repourl=request.POST.get('repourl', ''),
                    mode='incremental',
                    workdir=request.POST.get('repourl', '').split('/')[-1].split('.')[0],
                    branch=request.POST.get('branch', '')
                )
                if build_step.repourl.startswith('http://'):
                    build_step.repourl = ''.join([
                        'http://',
                        quote(request.POST.get('repo-username', '')),
                        ':',
                        quote(request.POST.get('repo-password', '')),
                        '@',
                        build_step.repourl[7:]
                    ])
            elif typ == 'ShellCommand':
                build_step = BuildStep(
                    type='ShellCommand',
                    workdir='.',
                    command=arg
                )
            build_steps.append(copy.deepcopy(build_step))
        
        # Get Buildmaster's IP Addr
        skt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        skt.connect(("ctripcorp.com", 80))
        
        builder = Builder(
            name=build_name,
            server_names=[skt.getsockname()[0]],
            factory=build_steps,
            builddir=build_name
        )
        
        job = Job(
            schedulers=[scheduler],
            builders=builder,
            users=[request.POST.get('operator', '')]
        )
        job.save()
        
        return HttpResponse()
    else:
        if request.user.is_superuser:
            server_list = Server.objects.all()
        else:
            server_list = Server.objects(users=str(request.user))
            
        context = {'server_list': server_list}
        
        return render(request, 'job/build/add.html', context)
Ejemplo n.º 12
0
def add_deploy(request):
    if request.method == 'POST':
        deploy_name = request.POST.get('deploy-name', '') + '-deploy'
        
        scheduler = Scheduler(
            scheduler_type='SingleBranchScheduler',
            name=deploy_name,
            builder_names=[deploy_name],
            change_filter=SchedulerChangeFilter(category=deploy_name)
        )
        
        '''
        ID | Deploy Type
        1  | Deploy a Existed Build
        2  | Deploy From Git Repository
        '''
        
        if request.POST.get('deploy-type', '') == '1':
            deploy_type = 1
        elif request.POST.get('deploy-type', '') == '2':
            deploy_type = 2
        
        build_steps = []
        for typ, arg in zip(request.POST.getlist('build-step-type'), request.POST.getlist('build-step-arg')):
            if typ == 'Git':
                build_step = BuildStep(
                    type='Git',
                    repourl=request.POST.get('repourl', ''),
                    mode='incremental',
                    workdir=request.POST.get('repourl', '').split('/')[-1].split('.')[0],
                    branch=request.POST.get('branch', '')
                )
                if build_step.repourl.startswith('http://'):
                    build_step.repourl = ''.join([
                        'http://',
                        quote(request.POST.get('repo-username', '')),
                        ':',
                        quote(request.POST.get('repo-password', '')),
                        '@',
                        build_step.repourl[7:]
                    ])
            elif typ == 'ShellCommand':
                build_step = BuildStep(
                    type='ShellCommand',
                    workdir='.',
                    command=arg
                )
            elif typ == 'FileDownload':
                build_step = BuildStep(
                    type='FileDownload',
                    mastersrc='/home/op1/buildbot-slave/' + request.POST.get('build-select', '') + '-build/' + arg,
                    slavedest=arg.split('/')[-1],
                    workdir='.',
                    build=request.POST.get('build-select', ''),
                    path=arg
                )
            build_steps.append(copy.deepcopy(build_step))
        
        builder = Builder(
            name=deploy_name,
            server_names=[request.POST.get('server', '')],
            factory=build_steps,
            builddir=deploy_name,
            deploy_type=deploy_type
        )
        
        job = Job(
            schedulers=[scheduler],
            builders=builder,
            users=[request.POST.get('operator', '')]
        )
        job.save()
        
        return HttpResponse()
    else:
        if request.user.is_superuser:
            server_list = Server.objects.all()
        else:
            server_list = Server.objects(users=str(request.user))
            
        try:
            build_list = sorted(set([str(job.builders.name[:-6]) for job in Job.objects(builders__name__endswith='-build')]))
        except:
            build_list = []
            
        context = {
            'build_list': build_list,
            'server_list': server_list
        }
        
        return render(request, 'job/deploy/add.html', context)
Ejemplo n.º 13
0
def edit_server_user(request):
    if request.method == 'POST':
        Server.objects(server_name=request.POST.get('server_name', '')).\
            update_one(set__users=list(request.POST.getlist('server_users[]')))
    
    return HttpResponse()
Ejemplo n.º 14
0
def get_server_user(request):
    try:
        server = Server.objects(server_name=request.POST.get(server_name, '')).first()
        return HttpResponse(', '.join([str(user) for user in server.users]))
    except:
        return HttpResponse('')