17
17
# License along with this library; if not, write to the Free Software
18
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
import copy
20
+ import ipaddress
20
21
import time
21
22
22
- import ipaddr
23
23
import libvirt
24
24
from libvirt import VIR_INTERFACE_XML_INACTIVE
25
25
from wok .exception import InvalidOperation
@@ -130,7 +130,7 @@ def _get_available_address(self, addr_pools=None):
130
130
network = NetworkModel .get_network (self .conn .get (), net_name )
131
131
xml = network .XMLDesc (0 )
132
132
subnet = NetworkModel .get_network_from_xml (xml )['subnet' ]
133
- subnet and invalid_addrs .append (ipaddr . IPNetwork (subnet ))
133
+ subnet and invalid_addrs .append (ipaddress . IPv4Network (subnet , False ))
134
134
addr_pools = addr_pools if addr_pools else netinfo .PrivateNets
135
135
return netinfo .get_one_free_network (invalid_addrs , addr_pools )
136
136
@@ -143,17 +143,15 @@ def _set_network_subnet(self, params):
143
143
raise OperationFailed ('KCHNET0009E' , {'name' : params ['name' ]})
144
144
145
145
try :
146
- ip = ipaddr . IPNetwork (netaddr )
146
+ ip = ipaddress . IPv4Network (netaddr , False )
147
147
except ValueError :
148
148
raise InvalidParameter (
149
149
'KCHNET0003E' , {'subnet' : netaddr , 'network' : params ['name' ]}
150
150
)
151
151
152
- if ip .ip == ip .network :
153
- ip .ip = ip .ip + 1
154
-
155
- dhcp_start = str (ip .network + int (ip .numhosts / 2 ))
156
- dhcp_end = str (ip .network + int (ip .numhosts - 3 ))
152
+ ip .network_address = ip .network_address + 1
153
+ dhcp_start = str (ip .network_address + int (ip .num_addresses / 2 ))
154
+ dhcp_end = str (ip .network_address + int (ip .num_addresses - 3 ))
157
155
params .update (
158
156
{'net' : str (ip ), 'dhcp' : {
159
157
'range' : {'start' : dhcp_start , 'end' : dhcp_end }}}
@@ -384,8 +382,8 @@ def lookup(self, name):
384
382
# libvirt use format 192.168.0.1/24, standard should be 192.168.0.0/24
385
383
# http://www.ovirt.org/File:Issue3.png
386
384
if subnet :
387
- subnet = ipaddr . IPNetwork (subnet )
388
- subnet = '%s/%s' % (subnet .network , subnet .prefixlen )
385
+ subnet = ipaddress . IPv4Network (subnet , False )
386
+ subnet = '%s/%s' % (subnet .network_address , subnet .prefixlen )
389
387
390
388
if connection in ['passthrough' , 'vepa' ]:
391
389
interfaces = xpath_get_text (xml , '/network/forward/interface/@dev' )
0 commit comments