source: trunk/packages/invirt-web/code/xen-ips @ 1692

Last change on this file since 1692 was 1318, checked in by price, 16 years ago

sipb-xen-www -> invirt-web

  • Property svn:executable set to *
File size: 1.3 KB
RevLine 
[113]1#!/usr/bin/python
2import random
[865]3from invirt import database
[113]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):
[1156]40    n = database.NIC(machine=None, mac_addr=randomMAC(), ip=ip, hostname=None)
41    database.session.save(n)
42    database.session.flush()
[113]43
44
45if __name__ == '__main__':
46    if len(sys.argv) == 2:
47        ip = sys.argv[1]
48    else:
49        usage()
50        sys.exit(1)
[865]51    database.connect()
[113]52    addip(ip)
Note: See TracBrowser for help on using the repository browser.