Network: factor out some parts for future Container
This commit is contained in:
parent
25b0b714e1
commit
5f3e504913
2 changed files with 30 additions and 17 deletions
|
@ -4,35 +4,20 @@ from . import settings
|
|||
from . import util
|
||||
from .xml_template import XMLTemplate
|
||||
|
||||
import uuid
|
||||
import libvirt
|
||||
|
||||
|
||||
class Network(util.NumberedClass):
|
||||
class Network(util.LibvirtObject):
|
||||
class AlreadyExists(Exception):
|
||||
def __str__(self):
|
||||
return "This network is already instanciated"
|
||||
|
||||
class TooMany(Exception):
|
||||
def __init__(self, count):
|
||||
self.count = count
|
||||
|
||||
def __str__(self):
|
||||
return (
|
||||
"Limit number reached. The current instance #{} does not fit in IPv4"
|
||||
).format(self.count)
|
||||
|
||||
def __init__(self, conn, name=None):
|
||||
super().__init__()
|
||||
|
||||
if self.id > 250:
|
||||
raise self.TooMany(self.id)
|
||||
super().__init__(conn)
|
||||
|
||||
if not name:
|
||||
name = str(self.id)
|
||||
|
||||
self.conn = conn
|
||||
self.uuid = uuid.uuid4()
|
||||
self.name = settings.PREFIX + "_" + name
|
||||
self.bridge_id = settings.NETWORK_ID * 0xFF + self.id
|
||||
self.bridge_mac = util.MACAddress(self.id, None)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
""" Various utils """
|
||||
|
||||
from . import settings
|
||||
import uuid
|
||||
|
||||
|
||||
class NumberedClass:
|
||||
|
@ -18,6 +19,33 @@ class NumberedClass:
|
|||
self.id = self.get_id()
|
||||
|
||||
|
||||
class LibvirtObject(NumberedClass):
|
||||
""" A class that has the basic attributes of a libvirt objects:
|
||||
* id
|
||||
* uuid
|
||||
and the applicable restrictions
|
||||
"""
|
||||
|
||||
class TooMany(Exception):
|
||||
def __init__(self, count):
|
||||
self.count = count
|
||||
|
||||
def __str__(self):
|
||||
return (
|
||||
"Limit number reached. The current instance #{} does not fit in IPv4"
|
||||
).format(self.count)
|
||||
|
||||
def __init__(self, conn):
|
||||
super().__init__()
|
||||
|
||||
self.conn = conn
|
||||
|
||||
if self.id > 250:
|
||||
raise self.TooMany(self.id)
|
||||
|
||||
self.uuid = uuid.uuid4()
|
||||
|
||||
|
||||
class MACAddress:
|
||||
""" A MAC address for a NIC or bridge """
|
||||
|
||||
|
|
Loading…
Reference in a new issue