Skip to content

Commit 51e5aa5

Browse files
committed
Add a list of IP leases to virtual networks
1 parent 2abf9f0 commit 51e5aa5

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

oca/vn.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
# -*- coding: UTF-8 -*-
22
from pool import XMLElement, Pool, PoolElement, Template
33

4+
class Lease(XMLElement):
5+
XML_TYPES = {
6+
'ip' : str,
7+
'mac' : str,
8+
}
9+
10+
def __init__(self, xml):
11+
super(Lease, self).__init__(xml)
12+
self._convert_types()
13+
14+
class LeasesList(list):
15+
def __init__(self, xml):
16+
if xml is None:
17+
return
18+
self.xml = xml
19+
for element in self.xml:
20+
self.append(self._factory(element))
21+
22+
def _factory(self, xml):
23+
v = Lease(xml)
24+
v._convert_types()
25+
return v
426

527
class AddressRange(XMLElement):
628
XML_TYPES = {
729
'id' : ["AR_ID", lambda xml: int(xml.text)],
830
'size' : int,
31+
'leases': ['LEASES', LeasesList],
932
#'template' : ['TEMPLATE', Template],
1033
}
1134

@@ -125,10 +148,13 @@ class VirtualNetworkPool(Pool):
125148
'info' : 'vnpool.info',
126149
}
127150

128-
def __init__(self, client):
151+
def __init__(self, client, preload_info=False):
152+
self.preload_info = preload_info
129153
super(VirtualNetworkPool, self).__init__('VNET_POOL', 'VNET', client)
130154

131155
def _factory(self, xml):
132156
v = VirtualNetwork(xml, self.client)
133157
v._convert_types()
158+
if self.preload_info:
159+
v.info()
134160
return v

0 commit comments

Comments
 (0)