Beispiel #1
0
def system_install_managed(request,id=None):
    """
    Management host to be installed
    """
    user = request.user
    if id:
        system_install = get_object_or_404(SystemInstall, pk=id)
        page_name = '编辑主机'
    else:
        system_install = SystemInstall()
        page_name = '添加主机'
    if request.method == 'POST': 
        operate = request.POST.get('operate')
        form = SystemInstallForm(request.POST,instance=system_install)
        if form.is_valid():
            if operate:
                if operate == 'update':
                    form.save()
                    db = db_operate() 
                    sql = 'select ip from installed_systeminstall where id = %s' % (id)
                    ret = db.mysql_command(settings.cobblerdb,sql)
                    Message.objects.create(type='idc', action='install', action_ip=ret, content='主机信息已更新(macadd、system_version),准备装机')
                    return HttpResponseRedirect(reverse('install_list'))
                else:
                    pass
    else:
        form = SystemInstallForm(instance=system_install)

    return render_to_response('install_manage.html',
           {"form": form,
            "page_name": page_name,
           },context_instance=RequestContext(request))   
Beispiel #2
0
def host_list_manage(request, id=None):
    """
    Manage Host List
    """
    user = request.user
    if id:
        host_list = get_object_or_404(HostList, pk=id)
        action = 'edit'
        page_name = '编辑主机'
        db = db_operate()
        sql = 'select ip from omc_hostlist where id = %s' % (id)
        ret = db.mysql_command(settings.cobblerdb, sql)
    else:
        host_list = HostList()
        action = 'add'
        page_name = '新增主机'

    if request.method == 'GET':
        delete = request.GET.get('delete')
        id = request.GET.get('id')
        if delete:
            Message.objects.create(type='host',
                                   action='manage',
                                   action_ip=ret,
                                   content='主机下架')
            host_list = get_object_or_404(HostList, pk=id)
            host_list.delete()
            return HttpResponseRedirect(reverse('host_list'))

    if request.method == 'POST':
        form = HostsListForm(request.POST, instance=host_list)
        operate = request.POST.get('operate')
        if form.is_valid():
            if action == 'add':
                form.save()
                return HttpResponseRedirect(reverse('host_list'))
            if operate:
                if operate == 'update':
                    form.save()
                    Message.objects.create(type='host',
                                           action='manage',
                                           action_ip=ret,
                                           content='主机信息更新')
                    return HttpResponseRedirect(reverse('host_list'))
                else:
                    pass
    else:
        form = HostsListForm(instance=host_list)

    return render_to_response('asset_host_manage.html', {
        "form": form,
        "page_name": page_name,
        "action": action,
    },
                              context_instance=RequestContext(request))
Beispiel #3
0
def host_list_manage(request,id=None):
    """
    Manage Host List
    """
    user = request.user
    if id:
        host_list = get_object_or_404(HostList, pk=id)
        action = 'edit'
        page_name = '编辑主机'
        db = db_operate() 
        sql = 'select ip from oms_hostlist where id = %s' % (id)
        ret = db.mysql_command(settings.cobblerdb,sql)
    else:
        host_list = HostList()
        action = 'add'   
        page_name = '新增主机'

    if request.method == 'GET':
        delete = request.GET.get('delete')
        id = request.GET.get('id')
        if delete:
           Message.objects.create(type='host', action='manage', action_ip=ret, content='主机下架')
           host_list = get_object_or_404(HostList, pk=id)
           host_list.delete()
           return HttpResponseRedirect(reverse('host_list'))

    if request.method == 'POST': 
        form = HostsListForm(request.POST,instance=host_list)
        operate = request.POST.get('operate')
        if form.is_valid():
            if action == 'add':
                form.save()
                return HttpResponseRedirect(reverse('host_list'))
            if operate:
                if operate == 'update':
                    form.save()
                    Message.objects.create(type='host', action='manage', action_ip=ret, content='主机信息更新')
                    return HttpResponseRedirect(reverse('host_list'))
                else:
                    pass
    else:
        form = HostsListForm(instance=host_list)

    return render_to_response('asset_host_manage.html',
           {"form": form,
            "page_name": page_name,
            "action": action,
           },context_instance=RequestContext(request))
Beispiel #4
0
def get_server_asset(request):
    """
    Get information service assets
    """
    
    if request.method == 'GET':
        action = request.get_full_path().split('=')[1]
        if action == 'flush':
            hostlist_sql = 'select hostname from asset_hostlist'
            server_sql = 'select hostname from asset_serverasset'
            db = db_operate() 
            host_ret = db.mysql_command(settings.cobblerdb,hostlist_sql)
            server_ret = db.mysql_command(settings.cobblerdb,server_sql)
            obj = [i for i in host_ret if i not in server_ret]       #主机列表数据与服务器资产数据IP做差集,数据更新时只更新差集,避免一次性更新全部
            ret = multitle_collect(obj)
            for i in ret:
                ServerAsset.objects.create(manufacturer=i[0], productname=i[1], service_tag=i[2], cpu_model=i[3], cpu_nums=i[4], cpu_groups=i[5],mem=i[6], disk=i[7], raid=i[8], hostname=i[9], ip=i[10], macaddress=i[11], os=i[12], virtual=i[13], idc_name=i[14])
        Message.objects.create(type='server', action='manage', action_ip='扫描', content='录入%s服务器软件、硬件信息' % (obj))
          
        return HttpResponseRedirect(reverse('server_asset_list'))
Beispiel #5
0
def get_server_asset(request):
    """
    Get information service assets
    """

    if request.method == 'GET':
        action = request.get_full_path().split('=')[1]
        if action == 'flush':
            hostlist_sql = 'select hostname from asset_hostlist'
            server_sql = 'select hostname from asset_serverasset'
            db = db_operate()
            host_ret = db.mysql_command(settings.cobblerdb, hostlist_sql)
            server_ret = db.mysql_command(settings.cobblerdb, server_sql)
            obj = [i for i in host_ret if i not in server_ret
                   ]  #主机列表数据与服务器资产数据IP做差集,数据更新时只更新差集,避免一次性更新全部
            ret = multitle_collect(obj)
            for i in ret:
                ServerAsset.objects.create(manufacturer=i[0],
                                           productname=i[1],
                                           service_tag=i[2],
                                           cpu_model=i[3],
                                           cpu_nums=i[4],
                                           cpu_groups=i[5],
                                           mem=i[6],
                                           disk=i[7],
                                           raid=i[8],
                                           hostname=i[9],
                                           ip=i[10],
                                           macaddress=i[11],
                                           os=i[12],
                                           virtual=i[13],
                                           idc_name=i[14])
        Message.objects.create(type='server',
                               action='manage',
                               action_ip='扫描',
                               content='录入%s服务器软件、硬件信息' % (obj))

        return HttpResponseRedirect(reverse('server_asset_list'))
Beispiel #6
0
def system_install_managed(request, id=None):
    """
    Management host to be installed
    """
    user = request.user
    if id:
        system_install = get_object_or_404(SystemInstall, pk=id)
        page_name = '编辑主机'
    else:
        system_install = SystemInstall()
        page_name = '添加主机'
    if request.method == 'POST':
        operate = request.POST.get('operate')
        form = SystemInstallForm(request.POST, instance=system_install)
        if form.is_valid():
            if operate:
                if operate == 'update':
                    form.save()
                    db = db_operate()
                    sql = 'select ip from installed_systeminstall where id = %s' % (
                        id)
                    ret = db.mysql_command(settings.cobblerdb, sql)
                    Message.objects.create(
                        type='idc',
                        action='install',
                        action_ip=ret,
                        content='主机信息已更新(macadd、system_version),准备装机')
                    return HttpResponseRedirect(reverse('install_list'))
                else:
                    pass
    else:
        form = SystemInstallForm(instance=system_install)

    return render_to_response('install_manage.html', {
        "form": form,
        "page_name": page_name,
    },
                              context_instance=RequestContext(request))