3 from invirt import database
4 import sqlalchemy.exceptions
7 # stolen directly from xend/server/netif.py
9 """Generate a random MAC address.
11 Uses OUI (Organizationally Unique Identifier) 00-16-3E, allocated to
12 Xensource, Inc. The OUI list is available at
13 http://standards.ieee.org/regauth/oui/oui.txt.
15 The remaining 3 fields are random, with the first bit of the first
18 @return: MAC address string
20 mac = [ 0x00, 0x16, 0x3e,
21 random.randint(0x00, 0x7f),
22 random.randint(0x00, 0xff),
23 random.randint(0x00, 0xff) ]
24 return ':'.join(map(lambda x: "%02x" % x, mac))
26 # ... and stolen from xend/uuid.py
28 """Generate a random UUID."""
30 return [ random.randint(0, 255) for _ in range(0, 16) ]
33 return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2,
34 "%02x" * 6]) % tuple(u)
38 print >> sys.stderr, "USAGE: " + sys.argv[0] + " <ip>"
42 n = database.NIC(machine=None, mac_addr=randomMAC(), ip=ip, hostname=None)
43 database.session.save(n)
44 database.session.flush()
45 except sqlalchemy.exceptions.IntegrityError:
49 if __name__ == '__main__':
50 if len(sys.argv) == 2: