---
title: Charmhub | Deploy Harness Extensions using Charmhub - The Open Operator Collection
description: Deploy the latest version of Harness Extensions on any cloud.
url: https://charmhub.io/harness-extensions/libraries/networking
---

# Harness Extensions

[Pietro Pasotti](https://charmhub.io/publisher/ppasotti "View all packages from Pietro Pasotti")

* [Pietro Pasotti](https://charmhub.io/publisher/ppasotti "View all packages from Pietro Pasotti")

Platform:

20.04

beta 3

```
juju deploy harness-extensions --channel beta
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/harness-extensions/libraries/networking#drawer)

## charms.harness\_extensions.v0.networking

* [*Docstrings*Docstrings](https://charmhub.io/harness-extensions/libraries/networking)
  [*Code*Source code](https://charmhub.io/harness-extensions/libraries/networking/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.harness_extensions.v0.networking
    ```

    [Download networking.py](https://charmhub.io/harness-extensions/libraries/networking/download)
  + *Last updated* 29 Jun 2022
  + *Revision* Library version 0.4

This is a library providing a utility for adding networking mocking
capability to Harness.

Basic usage:

> > > from charms.harness\_extensions.v0 import networking
> > > networking.activate()

Advanced use cases:

#### let's pretend 'foo' is a relation:

> > > foo = charm.model.get\_relation('foo', 1)
> > > with networking(networks={foo: Network(private\_address="42.42.42.42")}):
> > > # the juju-info network is present by default unless you pass None
> > > assert c.model.get\_binding("juju-info").network.bind\_address == IPv4Address("1.1.1.1")
> > > # the custom foo endpoint is mocked:
> > > assert c.model.get\_binding(foo).network.bind\_address == IPv4Address("42.42.42.42")
> > > assert c.model.get\_binding('foo').network.bind\_address == IPv4Address("42.42.42.42")

CAVEAT: The patch is global; that is, if you instantiate two Harnesses (don't do that),
you won't be able to mock `network-get` calls on a per-harness basis.

---

Index

* [class NetworkingError](https://charmhub.io/harness-extensions/libraries/networking#networkingerror)
* [def activate(
  juju\_info\_network
  )](https://charmhub.io/harness-extensions/libraries/networking#activate)
* [def deactivate(
  )](https://charmhub.io/harness-extensions/libraries/networking#deactivate)
* [def add\_network(
  endpoint\_name,
  relation\_id,
  network,
  make\_default
  )](https://charmhub.io/harness-extensions/libraries/networking#add_network)
* [def remove\_network(
  endpoint\_name,
  relation\_id
  )](https://charmhub.io/harness-extensions/libraries/networking#remove_network)
* [def Network(
  private\_address,
  mac\_address,
  hostname,
  cidr,
  interface\_name,
  egress\_subnets,
  ingress\_addresses
  )](https://charmhub.io/harness-extensions/libraries/networking#network)
* [def networking(
  juju\_info\_network,
  networks,
  make\_default
  )](https://charmhub.io/harness-extensions/libraries/networking#networking)

#### class NetworkingError

Description

Base class for errors raised from this module. None

#### def activate(juju\_info\_network)

Description

Patches harness.backend.network\_get and initializes the juju-info binding. None

#### def deactivate()

Description

Undoes the patch. None

#### def add\_network(     endpoint\_name: str,     relation\_id,     network: \_Network,     make\_default )

Add a network to the harness.

Description

* `endpoint_name`: the relation name this network belongs to
* `relation_id`: ID of the relation this network belongs to. If None, this will
  be the default network for the relation.
* `network`: network data.
* `make_default`: Make this the default network for the endpoint.
  Equivalent to calling this again with `relation_id==None`.

#### def remove\_network(     endpoint\_name: str,     relation\_id )

Description

Remove a network from the harness. None

#### def Network(     private\_address: str,     mac\_address: str,     hostname: str,     cidr: str,     interface\_name: str,     egress\_subnets,     ingress\_addresses )

Description

Construct a network object. None

#### def networking(     juju\_info\_network,     networks,     make\_default: bool )

Context manager to activate/deactivate networking within a scope.

Arguments

- `juju\_info\_network`

network assigned to the implicit 'juju-info' endpoint.

- `networks`

mapping from endpoints (names, or relations) to networks.

- `make\_default`

whether the networks passed as relations should also
be interpreted as default networks for the endpoint.
