networks

Model for Network resources.

Example

with PodmanClient(base_url=”unix:///run/user/1000/podman/podman.sock”) as client:
net = client.networks.get(“db_network”)

print(net.name, “

“)

class Network(attrs: Mapping[str, Any] | None = None, client: APIClient | None = None, collection: Manager | None = None)[source]

Bases: PodmanResource

Details and configuration for a networks managed by the Podman service.

attrs

Attributes of Network reported from Podman service

Type:

Dict[str, Any]

Initialize base class for PodmanResource’s.

Parameters:
  • attrs – Mapping of attributes for resource from Podman service.

  • client – Configured connection to a Podman service.

  • collection – Manager of this category of resource, named collection for compatibility

connect(container: str | Container, *_, **kwargs) None[source]

Connect given container to this network.

Parameters:

container – To add to this Network

Keyword Arguments:
  • aliases (List[str]) – Aliases to add for this endpoint

  • driver_opt (Dict[str, Any]) – Options to provide to network driver

  • ipv4_address (str) – IPv4 address for given Container on this network

  • ipv6_address (str) – IPv6 address for given Container on this network

  • link_local_ips (List[str]) – list of link-local addresses

  • links (List[Union[str, Containers]]) – Ignored

Raises:

APIError – when Podman service reports an error

disconnect(container: str | Container, **kwargs) None[source]

Disconnect given container from this network.

Parameters:

container – To remove from this Network

Keyword Arguments:

force (bool) – Force operation

Raises:

APIError – when Podman service reports an error

reload()[source]

Refresh this object’s data from the service.

remove(force: bool | None = None, **kwargs) None[source]

Remove this network.

Parameters:

force – Remove network and any associated containers

Raises:

APIError – when Podman service reports an error

property containers

Returns list of Containers connected to network.

Type:

List[Container]

property id

Returns the identifier of the network.

Type:

str

property name

Returns the name of the network.

Type:

str

property short_id

Returns truncated identifier. ‘sha256’ preserved when included in the id.

No attempt is made to ensure the returned value is semantically meaningful for all resources.

Type:

str