[virt-tools-list] [PATCH 03/11] Created the network configuration class.

Darryl L. Pierce dpierce at redhat.com
Thu Apr 14 18:06:02 UTC 2011


---
 src/virtlib/config.py |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/src/virtlib/config.py b/src/virtlib/config.py
index 82c86cd..5f35c71 100644
--- a/src/virtlib/config.py
+++ b/src/virtlib/config.py
@@ -60,3 +60,35 @@ class DomainConfig:
         self.virt_type = None
         self.architecture = None
 
+from IPy import IP
+
+class NetworkConfig:
+    '''
+    Describes a virtual network.
+    '''
+
+    def __init__(self, address, device):
+        self.name = "Undefined"
+        self.set_ipv4_address(address)
+        self.physical_device = device
+
+    def set_ipv4_address(self, address):
+        '''
+        Deconstructs the supplied address and sets the fields.
+
+        address -- The address mask; i.e., aaa.bbb.ccc.ddd/nn
+        '''
+
+        self.ipv4_address_raw = IP(address)
+        self.ipv4_address = self.ipv4_address_raw.strNormal()
+        self.ipv4_netmask = self.ipv4_address_raw.netmask().strNormal()
+        self.ipv4_gateway = str(self.ipv4_address_raw[1])
+        self.ipv4_broadcast = self.ipv4_address_raw.broadcast().strNormal()
+
+        start = int(self.ipv4_address_raw.len() / 2)
+        end   = self.ipv4_address_raw.len() - 2
+        self.ipv4_start_address = str(self.ipv4_address_raw[start])
+        self.ipv4_end_address   = str(self.ipv4_address_raw[end])
+
+        self.public_ipv4_network = (self.ipv4_address_raw.iptype() == "PUBLIC")
+
-- 
1.7.4.2




More information about the virt-tools-list mailing list