Changeset 73db3090c34e51a2508cdc048d3ca2f4cf3da288
- Timestamp:
- 05/12/10 14:10:28 (2 years ago)
- Author:
- Frederic Lepied <frederic.lepied@…>
- Children:
- 36e3187115d175e2667c28737fdaccbd1fed1723
- Parents:
- a37e6686ba85de9cf2e143a6485dd63bceff9404
- git-committer:
- Frederic Lepied <frederic.lepied@…> (05/12/10 14:10:28)
- Message:
-
allow to use IP addresses and sub-adresses instead of mac addresses
- Location:
- pxe
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
ra37e668
|
r73db309
|
|
| 15 | 15 | from pxe.common import * |
| 16 | 16 | |
| 17 | | if len(sys.argv) < 2: |
| | 17 | if len(sys.argv) < 3: |
| 18 | 18 | error('Usage: %s <system name> <MAC> [<MAC2>...]' % sys.argv[0]) |
| 19 | 19 | |
| … |
… |
|
| 28 | 28 | |
| 29 | 29 | for addr in sys.argv[2:]: |
| 30 | | a = simplify_mac(addr) |
| | 30 | if addr.index('.') >= 0: |
| | 31 | a = simplify_ip(addr) |
| | 32 | else: |
| | 33 | a = simplify_mac(addr) |
| 31 | 34 | try: |
| 32 | 35 | mac = MacAddress.objects.get(mac=a) |
-
|
rfa9915f
|
r73db309
|
|
| 80 | 80 | create_symlink(prof, name_dst) |
| 81 | 81 | for m in MacAddress.objects.filter(system=system): |
| 82 | | dst = '%s/01-%s' % (settings.PXE_ROOT, mac2filename(m.mac)) |
| | 82 | if len(m.mac) == 12: |
| | 83 | dst = '%s/01-%s' % (settings.PXE_ROOT, mac2filename(m.mac)) |
| | 84 | else: |
| | 85 | dst = '%s/%s' % (settings.PXE_ROOT, m.mac) |
| 83 | 86 | create_symlink(system.name, dst) |
| 84 | 87 | |
| … |
… |
|
| 89 | 92 | log.save() |
| 90 | 93 | |
| | 94 | def simplify_ip(ip): |
| | 95 | '''Rertun a string containing the hexadecimal representation of an ipv4 address or a sub-part.''' |
| | 96 | l = ip.split('.') |
| | 97 | s = '' |
| | 98 | for e in l: |
| | 99 | s = s + '%02x' % int(e) |
| | 100 | return s |
| | 101 | |
| 91 | 102 | # common.py ends here |
-
|
r5fc8fc0
|
r73db309
|
|
| 13 | 13 | from pxe.models import * |
| 14 | 14 | |
| | 15 | def get_system(request, mac): |
| | 16 | try: |
| | 17 | return System.objects.get(macaddress__mac=simplify_mac(mac)) |
| | 18 | except System.DoesNotExist: |
| | 19 | pass |
| | 20 | |
| | 21 | addr = request.META['REMOTE_ADDR'] |
| | 22 | l = map(lambda x: '%02x' % int(x), addr.split('.')) |
| | 23 | for i in range(len(l), 1, -1): |
| | 24 | try: |
| | 25 | return System.objects.get(macaddress__mac=''.join(l[0:i])) |
| | 26 | except System.DoesNotExist: |
| | 27 | pass |
| | 28 | raise Http404 |
| | 29 | |
| 15 | 30 | def localboot1(request): |
| 16 | 31 | return localboot(request, get_mac(request)) |
| 17 | 32 | |
| 18 | 33 | def localboot(request, mac): |
| 19 | | system = get_object_or_404(System, macaddress__mac=simplify_mac(mac)) |
| | 34 | system = get_system(request, mac) |
| 20 | 35 | set_next_boot(system, settings.PXE_LOCAL) |
| 21 | 36 | return HttpResponse("Next boot set to local", mimetype="text/plain") |
| … |
… |
|
| 25 | 40 | |
| 26 | 41 | def profile(request, mac): |
| 27 | | system = get_object_or_404(System, macaddress__mac=simplify_mac(mac)) |
| | 42 | system = get_system(request, mac) |
| 28 | 43 | log = Log.objects.filter(system=system).order_by('-date')[0] |
| 29 | 44 | return HttpResponse(log.boot_name.name, mimetype="text/plain") |