33from __future__ import division
44from __future__ import absolute_import
55
6- from upcloud_api import Network , Interface , Router
6+ from upcloud_api import Network , Interface , Router , IpNetwork
77
88
99class NetworkManager (object ):
@@ -16,25 +16,28 @@ def get_networks(self, zone=None):
1616 Get a list of all networks.
1717 Zone can be passed to return networks in a specific zone
1818 """
19- url = '/network/?zone={0}' .format (zone ) if zone else '/network/ '
19+ url = '/network/?zone={0}' .format (zone ) if zone else '/network'
2020 res = self .get_request (url )
21- print (res )
22- return [Network (** network ) for network in res ['networks' ]['network' ]]
21+ networks = [Network (** network ) for network in res ['networks' ]['network' ]]
22+ for network in networks :
23+ network .ip_networks = [IpNetwork (** n ) for n in network .ip_networks .get ('ip_network' )]
24+ return networks
2325
2426 def get_network (self , uuid ):
2527 """
2628 Retrieves the details of a specific network.
2729 """
2830 url = '/network/{0}' .format (uuid )
2931 res = self .get_request (url )
30- print (res )
31- return Network (** res ['network' ])
32+ network = Network (** res ['network' ])
33+ network .ip_networks = [IpNetwork (** n ) for n in network .ip_networks .get ('ip_network' )]
34+ return network
3235
3336 def create_network (self , name , zone , address , dhcp , family , router = None , dhcp_default_route = None , dhcp_dns = None , dhcp_bootfile_url = None , gateway = None ):
3437 """
3538 Creates a new SDN private network that cloud servers from the same zone can be attached to.
3639 """
37- url = '/network/ '
40+ url = '/network'
3841 body = {
3942 'network' : {
4043 'name' : name ,
@@ -52,13 +55,13 @@ def create_network(self, name, zone, address, dhcp, family, router=None, dhcp_de
5255 if router :
5356 body ['network' ]['router' ] = router
5457 if dhcp_default_route :
55- body ['network' ]['ip_networks' ]['network ' ]['dhcp_default_route' ] = dhcp_default_route
58+ body ['network' ]['ip_networks' ]['ip_network ' ]['dhcp_default_route' ] = dhcp_default_route
5659 if dhcp_dns :
57- body ['network' ]['ip_networks' ]['network ' ]['dhcp_dns' ] = dhcp_dns
60+ body ['network' ]['ip_networks' ]['ip_network ' ]['dhcp_dns' ] = dhcp_dns
5861 if dhcp_bootfile_url :
59- body ['network' ]['ip_networks' ]['network ' ]['dhcp_bootfile_url' ] = dhcp_bootfile_url
62+ body ['network' ]['ip_networks' ]['ip_network ' ]['dhcp_bootfile_url' ] = dhcp_bootfile_url
6063 if gateway :
61- body ['network' ]['ip_networks' ]['network ' ]['gateway' ] = gateway
64+ body ['network' ]['ip_networks' ]['ip_network ' ]['gateway' ] = gateway
6265 res = self .post_request (url , body )
6366 return Network (** res ['network' ])
6467
@@ -89,7 +92,9 @@ def modify_network(self, uuid, dhcp, family, name=None, router=None, dhcp_defaul
8992 if gateway :
9093 body ['network' ]['ip_networks' ]['ip_network' ]['gateway' ] = gateway
9194 res = self .put_request (url , body )
92- return Network (** res ['network' ])
95+ network = Network (** res ['network' ])
96+ network .ip_networks = [IpNetwork (** n ) for n in network .ip_networks .get ('ip_network' )]
97+ return network
9398
9499 def delete_network (self , uuid ):
95100 """
0 commit comments