网络

网络资源模型。

示例

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, podman_client: PodmanClient | None = None)[source]

基类:PodmanResource

Podman 服务管理的网络的详细信息和配置。

attrs

Podman 服务报告的网络属性

类型:

dict[str, Any]

初始化 PodmanResource 的基类。

参数:
  • attrs – Podman 服务资源属性的映射。

  • client – Podman 服务的配置连接。

  • collection – 此类资源的管理器,为了兼容性命名为 collection

  • podman_client – 配置为连接到 Podman 对象的 PodmanClient()。

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

将给定容器连接到此网络。

参数:

container – 要添加到此网络的容器

关键字参数:
  • aliases (list[str]) – 要为此端点添加的别名

  • driver_opt (dict[str, Any]) – 提供给网络驱动程序的选项

  • ipv4_address (str) – 此网络上给定容器的 IPv4 地址

  • ipv6_address (str) – 此网络上给定容器的 IPv6 地址

  • link_local_ips (list[str]) – 链路本地地址列表

  • links (list[Union[str, Containers]]) – 忽略

抛出:

APIError – 当 Podman 服务报告错误时

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

将给定容器从此网络断开连接。

参数:

container – 要从此网络中删除的容器

关键字参数:

force (bool) – 强制操作

抛出:

APIError – 当 Podman 服务报告错误时

reload()[source]

从服务刷新此对象的数据。

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

删除此网络。

参数:

force – 删除网络和所有关联的容器

抛出:

APIError – 当 Podman 服务报告错误时

property containers

返回连接到网络的容器列表。

类型:

list[Container]

property id

返回网络的标识符。

类型:

str

property name

返回网络的名称。

类型:

str

property short_id

返回截断的标识符。当包含在 id 中时,保留“sha256”。

不尝试确保返回的值对所有资源都具有语义意义。

类型:

str