source: package_tags/sipb-xen-www/3.15/code/xen-ips @ 1339

Last change on this file since 1339 was 865, checked in by price, 16 years ago

finish sipb_xen_database -> invirt.database in web

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/usr/bin/python
2import random
3from invirt import database
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 = database.NIC(machine_id=None, mac_addr=randomMAC(), ip=ip, hostname=None)
41    database.ctx.current.save(n)
42    database.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    database.connect()
52    addip(ip)
Note: See TracBrowser for help on using the repository browser.