How to manage units
> See also: juju:unit
Add a unit
To add a unit in python-libjuju client, you simply call add_unit() on your Application object, as follows:
my_app.add_unit(count=3)
> See more: Application (module), Application.add_unit(), Application.scale()
Control the number of units
To control the number of units of an application in python-libjuju client, you can use the Application.add_unit() and Application.destroy_units() methods, or the Application.scale() method, depending on whether you’re working on a CAAS system (e.g. Kubernetes), or an IAAS system (e.g. lxd).
If you’re on an IAAS system (machine applications):
u = my_app.add_unit()
my_app.destroy_units(u.name) # Note that the argument is the name of the unit
# You may give multiple unit names to destroy at once
my_app.destroy_units(u1.name, u2.name)
If you're on a CAAS system (k8s applications):
my_app.scale(4)
> See more: Application (module), Application.add_unit(), Application.scale(), Application.destroy_units()
Show details about a unit
To see details about a unit in python-libjuju client, you can use various fields and methods of a Unit object. For example, to get the public_address of a unit:
my_unit.get_public_address()
Or, to see if the unit is a leader:
my_unit.is_leader_from_status()
> See more: Unit (methods), Unit.get_public_address(), Unit.is_leader_from_status()
Show the status of a unit
To get the status of a unit on pylibjuju-client, you can use various (dynamically updated) status fields defined on a Unit object, such as:
workload_st = my_unit.workload_status
agent_st = my_unit.agent_status
> See more: Unit status, Unit (methods), Unit.workload_status (field), Unit.agent_status (field)
Mark unit errors as resolved
To mark unit errors as resolved in the python-libjuju client, you can call the resolved() method on a Unit object:
await my_unit.resolved()
> See more: `Unit.resolved() https://pythonlibjuju.readthedocs.io/en/latest/api/juju.unit.html#juju.unit.Unit.resolved`_
Remove a unit
To remove individual units on python-libjuju client, simply use the Application.destroy_units() method:
my_app.destroy_units(u.name) # Note that the argument is the name of the unit
# You may give multiple unit names to destroy at once
my_app.destroy_units(u1.name, u2.name)
> See more: Application (module), Application.destroy_units()