source: trunk/web/xen-ips @ 182

Last change on this file since 182 was 113, checked in by ecprice, 17 years ago

Initial import of web interface.

  • Property svn:executable set to *
File size: 1.3 KB
RevLine 
[113]1#!/usr/bin/python
2import random
3from sipb_xen_database import *
4import sys
5
6# stolen directly from xend/server/netif.py
7def randomMAC():
8    """Generate a random MAC address.
9
10    Uses OUI (Organizationally Unique Identifier) 00-16-3E, allocated to
11    Xensource, Inc. The OUI list is available at
12    http://standards.ieee.org/regauth/oui/oui.txt.
13
14    The remaining 3 fields are random, with the first bit of the first
15    random field set 0.
16
17    @return: MAC address string
18    """
19    mac = [ 0x00, 0x16, 0x3e,
20            random.randint(0x00, 0x7f),
21            random.randint(0x00, 0xff),
22            random.randint(0x00, 0xff) ]
23    return ':'.join(map(lambda x: "%02x" % x, mac))
24
25# ... and stolen from xend/uuid.py
26def randomUUID():
27    """Generate a random UUID."""
28
29    return [ random.randint(0, 255) for _ in range(0, 16) ]
30
31def uuidToString(u):
32    return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2,
33                     "%02x" * 6]) % tuple(u)
34
35
36def usage():
37    print >> sys.stderr, "USAGE: " + sys.argv[0] + " <ip>"
38
39def addip(ip):
40    n = NIC(None, randomMAC(), ip, None)
41    ctx.current.save(n)
42    ctx.current.flush()
43
44
45if __name__ == '__main__':
46    if len(sys.argv) == 2:
47        ip = sys.argv[1]
48    else:
49        usage()
50        sys.exit(1)
51    connect('postgres://sipb-xen@sipb-xen-dev/sipb_xen')
52    addip(ip)
Note: See TracBrowser for help on using the repository browser.