|
1 | 1 | # -*- coding: UTF-8 -*- |
2 | 2 | from pool import XMLElement, Pool, PoolElement, Template |
3 | 3 |
|
| 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 |
4 | 26 |
|
5 | 27 | class AddressRange(XMLElement): |
6 | 28 | XML_TYPES = { |
7 | 29 | 'id' : ["AR_ID", lambda xml: int(xml.text)], |
8 | 30 | 'size' : int, |
| 31 | + 'leases': ['LEASES', LeasesList], |
9 | 32 | #'template' : ['TEMPLATE', Template], |
10 | 33 | } |
11 | 34 |
|
@@ -125,10 +148,13 @@ class VirtualNetworkPool(Pool): |
125 | 148 | 'info' : 'vnpool.info', |
126 | 149 | } |
127 | 150 |
|
128 | | - def __init__(self, client): |
| 151 | + def __init__(self, client, preload_info=False): |
| 152 | + self.preload_info = preload_info |
129 | 153 | super(VirtualNetworkPool, self).__init__('VNET_POOL', 'VNET', client) |
130 | 154 |
|
131 | 155 | def _factory(self, xml): |
132 | 156 | v = VirtualNetwork(xml, self.client) |
133 | 157 | v._convert_types() |
| 158 | + if self.preload_info: |
| 159 | + v.info() |
134 | 160 | return v |
0 commit comments