@@ -30,17 +30,29 @@ def __init__(self, client, data, complete=True):
3030
3131 super ().__init__ (client , data , complete )
3232
33- def update (self , name = None , labels = None ):
34- # type: (Optional[str], Optional[Dict[str, str]]) -> BoundNetwork
33+ def update (
34+ self ,
35+ name = None , # type: Optional[str]
36+ expose_routes_to_vswitch = None , # type: Optional[bool]
37+ labels = None , # type: Optional[Dict[str, str]]
38+ ): # type: (...) -> BoundNetwork
3539 """Updates a network. You can update a network’s name and a networks’s labels.
3640
3741 :param name: str (optional)
3842 New name to set
43+ :param expose_routes_to_vswitch: Optional[bool]
44+ Indicates if the routes from this network should be exposed to the vSwitch connection.
45+ The exposing only takes effect if a vSwitch connection is active.
3946 :param labels: Dict[str, str] (optional)
4047 User-defined labels (key-value pairs)
4148 :return: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>`
4249 """
43- return self ._client .update (self , name , labels )
50+ return self ._client .update (
51+ self ,
52+ name = name ,
53+ expose_routes_to_vswitch = expose_routes_to_vswitch ,
54+ labels = labels ,
55+ )
4456
4557 def delete (self ):
4658 # type: () -> BoundAction
@@ -217,6 +229,7 @@ def create(
217229 ip_range , # type: str
218230 subnets = None , # type: Optional[List[NetworkSubnet]]
219231 routes = None , # type: Optional[List[NetworkRoute]]
232+ expose_routes_to_vswitch = None , # type: Optional[bool]
220233 labels = None , # type: Optional[Dict[str, str]]
221234 ):
222235 """Creates a network with range ip_range.
@@ -229,48 +242,68 @@ def create(
229242 Array of subnets allocated
230243 :param routes: List[:class:`NetworkRoute <hcloud.networks.domain.NetworkRoute>`]
231244 Array of routes set in this network
245+ :param expose_routes_to_vswitch: Optional[bool]
246+ Indicates if the routes from this network should be exposed to the vSwitch connection.
247+ The exposing only takes effect if a vSwitch connection is active.
232248 :param labels: Dict[str, str] (optional)
233249 User-defined labels (key-value pairs)
234250 :return: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>`
235251 """
236252 data = {"name" : name , "ip_range" : ip_range }
237253 if subnets is not None :
238- data ["subnets" ] = [
239- {
254+ data_subnets = []
255+ for subnet in subnets :
256+ data_subnet = {
240257 "type" : subnet .type ,
241258 "ip_range" : subnet .ip_range ,
242259 "network_zone" : subnet .network_zone ,
243260 }
244- for subnet in subnets
245- ]
261+ if subnet .vswitch_id is not None :
262+ data_subnet ["vswitch_id" ] = subnet .vswitch_id
263+
264+ data_subnets .append (data_subnet )
265+ data ["subnets" ] = data_subnets
266+
246267 if routes is not None :
247268 data ["routes" ] = [
248269 {"destination" : route .destination , "gateway" : route .gateway }
249270 for route in routes
250271 ]
272+
273+ if expose_routes_to_vswitch is not None :
274+ data ["expose_routes_to_vswitch" ] = expose_routes_to_vswitch
275+
251276 if labels is not None :
252277 data ["labels" ] = labels
253278
254279 response = self ._client .request (url = "/networks" , method = "POST" , json = data )
255280
256281 return BoundNetwork (self , response ["network" ])
257282
258- def update (self , network , name = None , labels = None ):
259- # type:(Network, Optional[str], Optional[Dict[str, str]]) -> BoundNetwork
283+ def update (self , network , name = None , expose_routes_to_vswitch = None , labels = None ):
284+ # type:(Network, Optional[str], Optional[bool], Optional[Dict[str, str]]) -> BoundNetwork
260285 """Updates a network. You can update a network’s name and a network’s labels.
261286
262287 :param network: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>` or :class:`Network <hcloud.networks.domain.Network>`
263288 :param name: str (optional)
264289 New name to set
290+ :param expose_routes_to_vswitch: Optional[bool]
291+ Indicates if the routes from this network should be exposed to the vSwitch connection.
292+ The exposing only takes effect if a vSwitch connection is active.
265293 :param labels: Dict[str, str] (optional)
266294 User-defined labels (key-value pairs)
267295 :return: :class:`BoundNetwork <hcloud.networks.client.BoundNetwork>`
268296 """
269297 data = {}
270298 if name is not None :
271299 data .update ({"name" : name })
300+
301+ if expose_routes_to_vswitch is not None :
302+ data ["expose_routes_to_vswitch" ] = expose_routes_to_vswitch
303+
272304 if labels is not None :
273305 data .update ({"labels" : labels })
306+
274307 response = self ._client .request (
275308 url = f"/networks/{ network .id } " ,
276309 method = "PUT" ,
0 commit comments