~ubuntu-branches/ubuntu/raring/maas/raring

« back to all changes in this revision

Viewing changes to src/maastesting/factory.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-17 08:28:36 UTC
  • mfrom: (1.1.16)
  • Revision ID: package-import@ubuntu.com-20120717082836-ucb2vou8tqg353eq
Tags: 0.1+bzr777+dfsg-0ubuntu1
* New upstream release
* Only run 'maas' command as root. (LP: #974046)
  - debian/extras/maas: Check id.
  - debian/maas.install: Install in 'sbin'.
* debian/maas.postinst:
  - restart apache2 after everything gets processed.
  - Update version to handle upgrades.
* debian/extras/maas-provision: Add wrapper to access 'maasprovisiong'
  command line.
* debian/patches/99_temporary_fix_path.patch: Dropped. No longer needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import string
28
28
import time
29
29
 
 
30
from netaddr import (
 
31
    IPAddress,
 
32
    IPNetwork,
 
33
    )
 
34
 
30
35
 
31
36
class Factory:
32
37
 
66
71
        octets = islice(self.random_octets, 4)
67
72
        return b'%d.%d.%d.%d' % tuple(octets)
68
73
 
 
74
    def getRandomNetwork(self, slash=None):
 
75
        ip = self.getRandomIPAddress()
 
76
        if slash is None:
 
77
            # Create a *small* network.
 
78
            slash = random.randint(24, 30)
 
79
        return IPNetwork('%s/%s' % (ip, slash))
 
80
 
 
81
    def getRandomIPInNetwork(self, network):
 
82
        return str(IPAddress(
 
83
            random.randint(network.first, network.last)))
 
84
 
69
85
    def getRandomMACAddress(self):
70
86
        octets = islice(self.random_octets, 6)
71
87
        return b":".join(format(octet, b"02x") for octet in octets)