Harness Extensions
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/beta | 3 | 05 Jul 2022 |
juju deploy harness-extensions --channel beta
Deploy universal operators easily with Juju, the Universal Operator Lifecycle Manager.
Platform:
charms.harness_extensions.v0.networking
-
- 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.
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 torelation_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 withrelation_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
network assigned to the implicit 'juju-info' endpoint.
mapping from endpoints (names, or relations) to networks.
whether the networks passed as relations should also be interpreted as default networks for the endpoint.