NetworksClient
- class NetworksClient(client: Client)[source]
- actions: ResourceActionsClient
Networks scoped actions client
- Type:
- add_route(network: Network | BoundNetwork, route: NetworkRoute) BoundAction[source]
Adds a route entry to a network.
- Parameters:
network –
BoundNetworkorNetworkroute –
NetworkRouteThe NetworkRoute you want to add to the Network
- Returns:
- add_subnet(network: Network | BoundNetwork, subnet: NetworkSubnet) BoundAction[source]
Adds a subnet entry to a network.
- Parameters:
network –
BoundNetworkorNetworksubnet –
NetworkSubnetThe NetworkSubnet you want to add to the Network
- Returns:
- change_ip_range(network: Network | BoundNetwork, ip_range: str) BoundAction[source]
Changes the IP range of a network.
- Parameters:
network –
BoundNetworkorNetworkip_range – str The new prefix for the whole network.
- Returns:
- change_protection(network: Network | BoundNetwork, delete: bool | None = None) BoundAction[source]
Changes the protection configuration of a network.
- Parameters:
network –
BoundNetworkorNetworkdelete – boolean If True, prevents the network from being deleted
- Returns:
- create(name: str, ip_range: str, subnets: list[NetworkSubnet] | None = None, routes: list[NetworkRoute] | None = None, expose_routes_to_vswitch: bool | None = None, labels: dict[str, str] | None = None) BoundNetwork[source]
Creates a network with range ip_range.
- Parameters:
name – str Name of the network
ip_range – str IP range of the whole network which must span all included subnets and route destinations
subnets – List[
NetworkSubnet] Array of subnets allocatedroutes – List[
NetworkRoute] Array of routes set in this networkexpose_routes_to_vswitch – Optional[bool] Indicates if the routes from this network should be exposed to the vSwitch connection. The exposing only takes effect if a vSwitch connection is active.
labels – Dict[str, str] (optional) User-defined labels (key-value pairs)
- Returns:
- delete(network: Network | BoundNetwork) bool[source]
Deletes a network.
- Parameters:
network –
BoundNetworkorNetwork- Returns:
boolean
- delete_route(network: Network | BoundNetwork, route: NetworkRoute) BoundAction[source]
Removes a route entry to a network.
- Parameters:
network –
BoundNetworkorNetworkroute –
NetworkRouteThe NetworkRoute you want to remove from the Network
- Returns:
- delete_subnet(network: Network | BoundNetwork, subnet: NetworkSubnet) BoundAction[source]
Removes a subnet entry from a network
- Parameters:
network –
BoundNetworkorNetworksubnet –
NetworkSubnetThe NetworkSubnet you want to remove from the Network
- Returns:
- get_actions(network: Network | BoundNetwork, status: list[Literal['running', 'success', 'error']] | None = None, sort: list[Literal['id', 'id:asc', 'id:desc', 'command', 'command:asc', 'command:desc', 'status', 'status:asc', 'status:desc', 'started', 'started:asc', 'started:desc', 'finished', 'finished:asc', 'finished:desc']] | None = None) list[BoundAction][source]
Returns all Actions for a Network.
- Parameters:
network – Network to get the Actions for.
status – Filter the Actions by status.
sort – Sort Actions by field and direction.
- get_actions_list(network: Network | BoundNetwork, status: list[Literal['running', 'success', 'error']] | None = None, sort: list[Literal['id', 'id:asc', 'id:desc', 'command', 'command:asc', 'command:desc', 'status', 'status:asc', 'status:desc', 'started', 'started:asc', 'started:desc', 'finished', 'finished:asc', 'finished:desc']] | None = None, page: int | None = None, per_page: int | None = None) ActionsPageResult[source]
Returns a paginated list of Actions for a Network.
- Parameters:
network – Network to get the Actions for.
status – Filter the Actions by status.
sort – Sort Actions by field and direction.
page – Page number to get.
per_page – Maximum number of Actions returned per page.
- get_all(name: str | None = None, label_selector: str | None = None) list[BoundNetwork][source]
Get all networks from this account
- Parameters:
name – str (optional) Can be used to filter networks by their name.
label_selector – str (optional) Can be used to filter networks by labels. The response will only contain networks matching the label selector.
- Returns:
List[
BoundNetwork]
- get_by_id(id: int) BoundNetwork[source]
Get a specific network
- Parameters:
id – int
- Returns:
- get_by_name(name: str) BoundNetwork | None[source]
Get network by name
- Parameters:
name – str Used to get network by name.
- Returns:
- get_list(name: str | None = None, label_selector: str | None = None, page: int | None = None, per_page: int | None = None) NetworksPageResult[source]
Get a list of networks from this account
- Parameters:
name – str (optional) Can be used to filter networks by their name.
label_selector – str (optional) Can be used to filter networks by labels. The response will only contain networks matching the label selector.
page – int (optional) Specifies the page to fetch
per_page – int (optional) Specifies how many results are returned by page
- Returns:
(List[
BoundNetwork],Meta)
- update(network: Network | BoundNetwork, name: str | None = None, expose_routes_to_vswitch: bool | None = None, labels: dict[str, str] | None = None) BoundNetwork[source]
Updates a network. You can update a network’s name and a network’s labels.
- Parameters:
network –
BoundNetworkorNetworkname – str (optional) New name to set
expose_routes_to_vswitch – Optional[bool] Indicates if the routes from this network should be exposed to the vSwitch connection. The exposing only takes effect if a vSwitch connection is active.
labels – Dict[str, str] (optional) User-defined labels (key-value pairs)
- Returns:
- class BoundNetwork(client: NetworksClient, data: dict[str, Any], complete: bool = True)[source]
- add_route(route: NetworkRoute) BoundAction[source]
Adds a route entry to a network.
- Parameters:
route –
NetworkRouteThe NetworkRoute you want to add to the Network- Returns:
- add_subnet(subnet: NetworkSubnet) BoundAction[source]
Adds a subnet entry to a network.
- Parameters:
subnet –
NetworkSubnetThe NetworkSubnet you want to add to the Network- Returns:
- change_ip_range(ip_range: str) BoundAction[source]
Changes the IP range of a network.
- Parameters:
ip_range – str The new prefix for the whole network.
- Returns:
- change_protection(delete: bool | None = None) BoundAction[source]
Changes the protection configuration of a network.
- Parameters:
delete – boolean If True, prevents the network from being deleted
- Returns:
- delete_route(route: NetworkRoute) BoundAction[source]
Removes a route entry to a network.
- Parameters:
route –
NetworkRouteThe NetworkRoute you want to remove from the Network- Returns:
- delete_subnet(subnet: NetworkSubnet) BoundAction[source]
Removes a subnet entry from a network
- Parameters:
subnet –
NetworkSubnetThe NetworkSubnet you want to remove from the Network- Returns:
- get_actions(status: list[Literal['running', 'success', 'error']] | None = None, sort: list[Literal['id', 'id:asc', 'id:desc', 'command', 'command:asc', 'command:desc', 'status', 'status:asc', 'status:desc', 'started', 'started:asc', 'started:desc', 'finished', 'finished:asc', 'finished:desc']] | None = None) list[BoundAction][source]
Returns all Actions for a Network.
- Parameters:
status – Filter the Actions by status.
sort – Sort Actions by field and direction.
- get_actions_list(status: list[Literal['running', 'success', 'error']] | None = None, sort: list[Literal['id', 'id:asc', 'id:desc', 'command', 'command:asc', 'command:desc', 'status', 'status:asc', 'status:desc', 'started', 'started:asc', 'started:desc', 'finished', 'finished:asc', 'finished:desc']] | None = None, page: int | None = None, per_page: int | None = None) ActionsPageResult[source]
Returns a paginated list of Actions for a Network.
- Parameters:
status – Filter the Actions by status.
sort – Sort Actions by field and direction.
page – Page number to get.
per_page – Maximum number of Actions returned per page.
- update(name: str | None = None, expose_routes_to_vswitch: bool | None = None, labels: dict[str, str] | None = None) BoundNetwork[source]
Updates a network. You can update a network’s name and a networks’s labels.
- Parameters:
name – str (optional) New name to set
expose_routes_to_vswitch – Optional[bool] Indicates if the routes from this network should be exposed to the vSwitch connection. The exposing only takes effect if a vSwitch connection is active.
labels – Dict[str, str] (optional) User-defined labels (key-value pairs)
- Returns:
- class Network(id: int, name: str | None = None, created: str | None = None, ip_range: str | None = None, subnets: list[NetworkSubnet] | None = None, routes: list[NetworkRoute] | None = None, expose_routes_to_vswitch: bool | None = None, servers: list[BoundServer] | None = None, protection: NetworkProtection | None = None, labels: dict[str, str] | None = None)[source]
Network Domain
- Parameters:
id – int ID of the network
name – str Name of the network
ip_range – str IPv4 prefix of the whole network
subnets – List[
NetworkSubnet] Subnets allocated in this networkroutes – List[
NetworkRoute] Routes set in this networkexpose_routes_to_vswitch – bool Indicates if the routes from this network should be exposed to the vSwitch connection.
servers – List[
BoundServer] Servers attached to this networkprotection – dict Protection configuration for the network
labels – dict User-defined labels (key-value pairs)
- class NetworkSubnet(ip_range: str, type: str | None = None, network_zone: str | None = None, gateway: str | None = None, vswitch_id: int | None = None)[source]
Network Subnet Domain
- Parameters:
type – str Type of sub network.
ip_range – str Range to allocate IPs from.
network_zone – str Name of network zone.
gateway – str Gateway for the route.
vswitch_id – int ID of the vSwitch.
- TYPE_CLOUD = 'cloud'
Used to connect cloud servers and load balancers.
- property TYPE_SERVER: str
Used to connect cloud servers and load balancers.
Deprecated since version 2.2.0: Use
NetworkSubnet.TYPE_CLOUDinstead.
- TYPE_VSWITCH = 'vswitch'
Used to connect cloud servers and load balancers with dedicated servers.
See https://docs.hetzner.com/networking/networks/connect-dedi-vswitch/
- class NetworkRoute(destination: str, gateway: str)[source]
Network Route Domain
- Parameters:
destination – str Destination network or host of this route.
gateway – str Gateway for the route.
- class CreateNetworkResponse(network: BoundNetwork, action: BoundAction)[source]
Create Network Response Domain
- Parameters:
network –
BoundNetworkThe network which was createdaction –
BoundActionThe Action which shows the progress of the network Creation