Пример #1
0
def virtual_edit(request,uuid):
    server = get_object_or_404(Server, uuid=uuid)
    asset = server.asset
    cpu = asset.cpu
    cf = CPUForm(instance=cpu)
    af = AssetForm(instance=asset)
    sf = ServerForm(instance=server)

    nic = NIC.objects.filter(asset=asset)

    project_all = Project.objects.all()
    project_host = server.project.all()
    projects = [p for p in project_all if p not in project_host]

    service_all = Service.objects.all()
    service_host = server.service.all()
    services = [s for s in service_all if s not in service_host]

    if request.method == 'POST':
        af = AssetForm(request.POST, instance=asset)
        sf = ServerForm(request.POST, instance=server)
        cf = CPUForm(request.POST, instance=cpu)

        if all((af.is_valid(),sf.is_valid(),cf.is_valid())):
            asset_data = af.save()
            cpu_data = cf.save(commit=False)
            cpu_data.asset = asset_data
            cpu_data.save()
            server_data = sf.save(commit=False)
            server_data.asset = asset_data
            server_data.save()
            sf.save_m2m()
            return HttpResponseRedirect('/allow/welcome/')
    return render(request,'assets/virtual_edit.html', locals())
Пример #2
0
def server_add(request):
	"Add a new server to the cluster"
	form = ServerForm(request.POST or None)
	if form.is_valid():
		form.save()
		return redirect('limeade_cluster_server_list')
	return render_to_response("limeade_cluster/server_add.html",
		{"form": form}, context_instance = RequestContext(request))
Пример #3
0
def server_edit(request, slug):
	"Edit a server"
	server = Server.objects.get(pk=slug)
	form = ServerForm(request.POST or None, instance=server)
	if form.is_valid():
		form.save()
		return redirect('limeade_cluster_server_list')
	return render_to_response("limeade_cluster/server_edit.html",
		{"form": form}, context_instance = RequestContext(request))
Пример #4
0
def addserver(request):
    if request.POST:
        form = ServerForm(request.POST)
        if form.is_valid():
            form.save()
            messages.success(request, 'Server added!')
            return HttpResponseRedirect('/servers/add/')
    else:
        form = ServerForm()

    return render(request, 'addserver.html', locals())
Пример #5
0
def virtual_add(request):
    sf = ServerForm()
    af = AssetForm()
    cf = CPUForm()
    projects = Project.objects.all()
    services = Service.objects.all()
    ff_error = []
    if request.method == 'POST':
        af = AssetForm(request.POST)
        sf = ServerForm(request.POST)
        cf = CPUForm(request.POST)
        ip = request.POST.get('ssh_host', '')
        if Server.objects.filter(ssh_host=ip):
            ff_error.append(u'添加失败, 该IP %s 已存在!' % ip)
            return render(request,'assets/virtual_add.html', locals())
        if all((af.is_valid(),sf.is_valid(),cf.is_valid())):
            asset_data = af.save(commit=False)
            asset_data.asset_type = "virtual"
            asset_data.save()
            cpu_data = cf.save(commit=False)
            cpu_data.asset = asset_data
            cpu_data.save()
            cf.save_m2m()
            server_data = sf.save(commit=False)
            server_data.asset = asset_data
            server_data.save()
            sf.save_m2m()
## 网卡信息
            nic_name0 = request.POST.get('nic_name0', '')
            if nic_name0:
                for i in range(6):
                    nic_name = "nic_name" + str(i)
                    nic_name = request.POST.get(nic_name)

                    nic_memo = "nic_memo" + str(i)
                    nic_memo = request.POST.get(nic_memo)

                    nic_macaddress = "nic_macaddress" + str(i)
                    nic_macaddress = request.POST.get(nic_macaddress)

                    nic_ipaddress = "nic_ipaddress" + str(i)
                    nic_ipaddress = request.POST.get(nic_ipaddress)

                    nic_netmask = "nic_netmask" + str(i)
                    nic_netmask = request.POST.get(nic_netmask)

                    if nic_name and nic_macaddress:
                        NIC.objects.create(asset = asset_data,name=nic_name,macaddress=nic_macaddress,
                        ipaddress=nic_ipaddress,netmask=nic_netmask,memo=nic_memo)
            obj = get_object_or_404(Server, ssh_host=server_data.ssh_host)
            return render(request,'assets/asset_success.html', locals())
        else:
            ff_error.append("关键信息遗漏或格式错误")
    return render(request,'assets/virtual_add.html', locals())
Пример #6
0
def server_add(request):
    """Add a new server to the cluster.
    
    :param request: the request object
    
    :returns: an edit form template
    """
    form = ServerForm(request.POST or None)
    if form.is_valid():
        form.save()
        return redirect('limeade_cluster_server_list')
    return render_to_response("limeade_cluster/server_add.html",
                              {"form": form},
                              context_instance=RequestContext(request))
Пример #7
0
def server_add(request):
    """Add a new server to the cluster.
    
    :param request: the request object
    
    :returns: an edit form template
    """
    form = ServerForm(request.POST or None)
    if form.is_valid():
        form.save()
        return redirect("limeade_cluster_server_list")
    return render_to_response(
        "limeade_cluster/server_add.html", {"form": form}, context_instance=RequestContext(request)
    )
Пример #8
0
def server_edit(request, slug):
    """Edit a server.
    
    :param request: the request object
    :param slug: the id of the server
    
    :returns: an edit form template
    """
    server = Server.objects.get(pk=slug)
    form = ServerForm(request.POST or None, instance=server)
    if form.is_valid():
        form.save()
        return redirect("limeade_cluster_server_list")
    return render_to_response(
        "limeade_cluster/server_edit.html", {"form": form}, context_instance=RequestContext(request)
    )
Пример #9
0
def server_edit(request, slug):
    """Edit a server.
    
    :param request: the request object
    :param slug: the id of the server
    
    :returns: an edit form template
    """
    server = Server.objects.get(pk=slug)
    form = ServerForm(request.POST or None, instance=server)
    if form.is_valid():
        form.save()
        return redirect('limeade_cluster_server_list')
    return render_to_response("limeade_cluster/server_edit.html",
                              {"form": form},
                              context_instance=RequestContext(request))
Пример #10
0
def addserver(request):
    if request.method == 'POST':
        form = ServerForm(request.POST)  #将提交的请求数据,绑定为表单
        if form.is_valid():  #用表单的方法校验数据是否合法
            Servers.objects.create(  #生成数据对象,自动保存到数据库中
                hostname=form.cleaned_data['hostname'],
                ip=form.cleaned_data['ip'],
                port=form.cleaned_data['port'],
                os=form.cleaned_data['os'],
                user=form.cleaned_data['user'],
                passwd=form.cleaned_data['passwd'],
                idc=form.cleaned_data['idc'],
            )
            return HttpResponseRedirect('/sm/server_manage')
    else:
        form = ServerForm()
    return render_to_response('sm/addserver.html', {'form': form})  #模板目录
Пример #11
0
def editserver(request, server_id):
    servers = get_object_or_404(Server, pk=server_id)
    t = "Edit"

    if request.POST:
        form = ServerForm(request.POST, instance=servers)
        if form.is_valid():
            form.save()

            return HttpResponseRedirect('/servers/')

    else:
        form = ServerForm(instance=servers)

    return render_to_response("editserver.html", {
        'form': form,
        't': t,
    }, context_instance=RequestContext(request))
Пример #12
0
def addserver(request):
	if request.method=='POST':
		form=ServerForm(request.POST)      #将提交的请求数据,绑定为表单
		print form
		if form.is_valid():             #用表单的方法校验数据是否合法
			Servers.objects.create(		#生成数据对象,自动保存到数据库中
			hostname=form.cleaned_data['hostname'],
			ip=form.cleaned_data['ip'],
			port=form.cleaned_data['port'],
			os=form.cleaned_data['os'],
			user=form.cleaned_data['user'],
			passwd=form.cleaned_data['passwd'],
			idc=form.cleaned_data['idc'],
			)
			return HttpResponseRedirect('/sm/server_manage')
	else:
		form=ServerForm()
	return render_to_response('sm/addserver.html',{'form':form})   #模板目录
Пример #13
0
def edit_server(request):
	id=request.GET.get('id')
	host_form=Servers.objects.filter(id=id)       #查询出id对应的主机
	if	request.method=='POST':
		form=ServerForm(request.POST)      #绑定表单
		if form.is_valid():             #如果提交的数据合法
			Servers.objects.filter(id=id).update(		#filter返回一个对象列表,用update更新数据库中的条目
			hostname=form.cleaned_data['hostname'],
			ip=form.cleaned_data['ip'],
			port=form.cleaned_data['port'],
			os=form.cleaned_data['os'],
			user=form.cleaned_data['user'],
			passwd=form.cleaned_data['passwd'],
			idc=form.cleaned_data['idc'],
			)
			return HttpResponseRedirect('/sm/server_manage')
	else:
		form=ServerForm()
	return render_to_response('sm/edit_server.html',{'form':host_form})
Пример #14
0
def edit_server(request):
    id = request.GET.get('id')
    host_form = Servers.objects.filter(id=id)  #查询出id对应的主机
    if request.method == 'POST':
        form = ServerForm(request.POST)  #绑定表单
        if form.is_valid():  #如果提交的数据合法
            Servers.objects.filter(
                id=id).update(  #filter返回一个对象列表,用update更新数据库中的条目
                    hostname=form.cleaned_data['hostname'],
                    ip=form.cleaned_data['ip'],
                    port=form.cleaned_data['port'],
                    os=form.cleaned_data['os'],
                    user=form.cleaned_data['user'],
                    passwd=form.cleaned_data['passwd'],
                    idc=form.cleaned_data['idc'],
                )
            return HttpResponseRedirect('/sm/server_manage')
    else:
        form = ServerForm()
    return render_to_response('sm/edit_server.html', {'form': host_form})
Пример #15
0
def server_add(request):
    sf = ServerForm()
    af = AssetForm()
    projects = Project.objects.all()
    services = Service.objects.all()
    ff_error = []
    if request.method == 'POST':
        af = AssetForm(request.POST)
        sf = ServerForm(request.POST)
        ip = request.POST.get('ssh_host', '')
        if Server.objects.filter(ssh_host=ip):
            ff_error.append(u'添加失败, 该IP %s 已存在!' % ip)
            return render(request, 'assets/server_add.html', locals())
        if all((af.is_valid(), sf.is_valid())):
            asset_data = af.save(commit=False)
            asset_data.asset_type = "serverhost"
            asset_data.save()
            server_data = sf.save(commit=False)
            server_data.asset = asset_data
            server_data.save()
            sf.save_m2m()
            ##网卡
            nic_name0 = request.POST.get('nic_name0', '')
            if nic_name0:
                for i in range(6):
                    nic_name = "nic_name" + str(i)
                    nic_name = request.POST.get(nic_name)
                    nic_ipaddress = "nic_ipaddress" + str(i)
                    nic_ipaddress = request.POST.get(nic_ipaddress)
                    if nic_name and nic_ipaddress:
                        NIC.objects.create(asset=asset_data,
                                           name=nic_name,
                                           ipaddress=nic_ipaddress)
            obj = server_data
            return render(request, 'assets/asset_success.html', locals())
        else:
            ff_error.append("关键信息遗漏或格式错误")
    return render(request, 'assets/server_add.html', locals())
Пример #16
0
def servers(request):

    all_servers = Server.objects.all().order_by('name')

    if request.method == 'POST':
        form = ServerForm(request.POST)
        if form.is_valid():
            s = Server()
            s.set_from_dict(form.cleaned_data)

            all_pollers = Poller.objects.all().order_by('name')
            for p in all_pollers:
                try:
                    create_poller_dir(p.path, s.ipaddr)
                except Exception, e:
                    print str(e)
                    messages.error(request, 'There was an error creating the %s path on the server. Server not saved.' % p.path)
                    return render(request, 'dispatch_web/servers.html', {'form': form, 'servers': all_servers})

            s.save()
            return HttpResponseRedirect(reverse('dispatch:servers'))
        else:
            messages.error(request, 'There was an error submitting your information.')
Пример #17
0
def server_add(request):
    sf = ServerForm()
    af = AssetForm()
    cf = CPUForm()
    projects = Project.objects.all()
    services = Service.objects.all()
    ff_error = []
    if request.method == 'POST':
        af = AssetForm(request.POST)
        sf = ServerForm(request.POST)
        cf = CPUForm(request.POST)
        ip = request.POST.get('ssh_host', '')
        if Server.objects.filter(ssh_host=ip):
            ff_error.append(u'添加失败, 该IP %s 已存在!' % ip)
            return render(request,'assets/server_add.html', locals())
        if all((af.is_valid(),sf.is_valid(),cf.is_valid())):
            asset_data = af.save()
            cpu_data = cf.save(commit=False)
            cpu_data.asset = asset_data
            cpu_data.save()
            cf.save_m2m()
            server_data = sf.save(commit=False)
            server_data.asset = asset_data
            server_data.save()
            sf.save_m2m()
##网卡
            nic_name0 = request.POST.get('nic_name0', '')
            if nic_name0:
                for i in range(6):
                    nic_name = "nic_name" + str(i)
                    nic_name = request.POST.get(nic_name)

                    nic_memo = "nic_memo" + str(i)
                    nic_memo = request.POST.get(nic_memo)

                    nic_macaddress = "nic_macaddress" + str(i)
                    nic_macaddress = request.POST.get(nic_macaddress)

                    nic_ipaddress = "nic_ipaddress" + str(i)
                    nic_ipaddress = request.POST.get(nic_ipaddress)

                    nic_netmask = "nic_netmask" + str(i)
                    nic_netmask = request.POST.get(nic_netmask)

                    nic_model = "nic_model" + str(i)
                    nic_model = request.POST.get(nic_model)

                    if nic_name and nic_macaddress:
                        NIC.objects.create(asset = asset_data,name=nic_name,model=nic_model,macaddress=nic_macaddress,
                        ipaddress=nic_ipaddress,netmask=nic_netmask,memo=nic_memo)
            return HttpResponseRedirect('/allow/welcome/')
## 内存
            ram_model0 = request.POST.get('ram_model0', '')
            if ram_model0:
                for i in range(16):
                    ram_model = "ram_model" + str(i)
                    ram_model = request.POST.get(ram_model)

                    ram_slot = "ram_slot" + str(i)
                    ram_slot = request.POST.get(ram_slot)

                    ram_capacity = "ram_capacity" + str(i)
                    ram_capacity = request.POST.get(ram_capacity)

                    ram_sn = "ram_sn" + str(i)
                    ram_sn = request.POST.get(ram_sn)

                    ram_memo = "ram_memo" + str(i)
                    ram_memo = request.POST.get(ram_memo)

                    if ram_model and ram_capacity:
                        RAM.objects.create(asset = asset_data,model=ram_model,slot=ram_slot,
                        capacity=ram_capacity,sn=ram_sn,memo=ram_memo)
##硬盘
            disk_model0 = request.POST.get('disk_model0', '')
            if disk_model0:
                for i in range(12):
                    disk_model = "disk_model" + str(i)
                    disk_model = request.POST.get(disk_model)

                    disk_manufactory = "disk_manufactory" + str(i)
                    disk_manufactory = request.POST.get(disk_manufactory)

                    disk_capacity = "disk_capacity" + str(i)
                    disk_capacity = request.POST.get(disk_capacity)

                    disk_iface_type = "disk_iface_type" + str(i)
                    disk_iface_type = request.POST.get(disk_iface_type)

                    disk_slot = "disk_slot" + str(i)
                    disk_slot = request.POST.get(disk_slot)

                    disk_sn = "disk_sn" + str(i)
                    disk_sn = request.POST.get(disk_sn)

                    disk_memo = "disk_memo" + str(i)
                    disk_memo = request.POST.get(disk_memo)

                    if disk_model and disk_capacity:
                        Disk.objects.create(asset = asset_data,model=disk_model,manufactory=disk_manufactory,iface_type=disk_iface_type,slot=disk_slot,
                        capacity=disk_capacity,sn=disk_sn,memo=disk_memo)
##raid卡
            raid_model0 = request.POST.get('raid_model0', '')
            if raid_model0:
                for i in range(2):
                    raid_model = "raid_model" + str(i)
                    raid_model = request.POST.get(raid_model)

                    raid_slot = "raid_slot" + str(i)
                    raid_slot = request.POST.get(raid_slot)

                    raid_sn = "raid_sn" + str(i)
                    raid_sn = request.POST.get(raid_sn)

                    raid_memo = "raid_memo" + str(i)
                    raid_memo = request.POST.get(raid_memo)

                    if raid_model and raid_slot:
                        RaidAdaptor.objects.create(asset = asset_data,model=raid_model,slot=raid_slot,
                        sn=raid_sn,memo=raid_memo)

            return HttpResponseRedirect('/allow/welcome/')
        else:
            ff_error.append("关键信息遗漏或格式错误")
    return render(request,'assets/server_add.html', locals())