According to ops/model.py's Model.get_binding(), it will accept either a Relation instance, or a relation name:
def get_binding(self, binding_key):
"""Get a network space binding.
binding_key -- The relation name or instance to obtain bindings for.
If binding_key is a relation name, the method returns the default binding for that
relation. If a relation instance is provided, the method first looks up a more specific
binding for that specific relation ID, and if none is found falls back to the default
binding for the relation name.
"""
return self._bindings.get(binding_key)
However, if I pass it a string, set to an appropriate relation name:
Traceback (most recent call last):
File "/var/lib/juju/agents/unit-wordpress-0/charm/hooks/config-changed", line 276, in <module>
main(Wordpress)
File "lib/ops/main.py", line 195, in main
_emit_charm_event(charm, juju_event_name)
File "lib/ops/main.py", line 120, in _emit_charm_event
event_to_emit.emit(*args, **kwargs)
File "lib/ops/framework.py", line 199, in emit
framework._emit(event)
File "lib/ops/framework.py", line 633, in _emit
self._reemit(event_path)
File "lib/ops/framework.py", line 668, in _reemit
custom_handler(event)
File "/var/lib/juju/agents/unit-wordpress-0/charm/hooks/config-changed", line 50, in on_config_changed
self.configure_pod(event)
File "/var/lib/juju/agents/unit-wordpress-0/charm/hooks/config-changed", line 270, in configure_pod
if self.first_install():
File "/var/lib/juju/agents/unit-wordpress-0/charm/hooks/config-changed", line 131, in first_install
if not self.is_pod_up("website"):
File "/var/lib/juju/agents/unit-wordpress-0/charm/hooks/config-changed", line 236, in is_pod_up
ingress = self.get_service_ip(endpoint)
File "/var/lib/juju/agents/unit-wordpress-0/charm/hooks/config-changed", line 232, in get_service_ip
return self.model.get_binding("website").network.ingress_address
File "lib/ops/model.py", line 65, in get_binding
return self._bindings.get(relation)
File "lib/ops/model.py", line 263, in get
raise ModelError('expected Relation instance, got {}'.format(type(relation).__name__))
ops.model.ModelError: expected Relation instance, got str
ERROR juju.worker.uniter.operation hook "config-changed" failed: exit status 1
According to ops/model.py's Model.get_binding(), it will accept either a Relation instance, or a relation name:
However, if I pass it a string, set to an appropriate relation name: