Skip to content

Commit 939a375

Browse files
committed
Add subordinate utilities for unit.Unit
Adds is_subordinate, principal_unit and get_subordinates
1 parent ead1b48 commit 939a375

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

juju/unit.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ def agent_status_since(self):
2626
"""
2727
return pyrfc3339.parse(self.safe_data['agent-status']['since'])
2828

29+
@property
30+
def is_subordinate(self):
31+
"""True if the unit is subordinate of another unit
32+
33+
"""
34+
return self.safe_data['subordinate']
35+
36+
@property
37+
def principal_unit(self):
38+
"""Returns the name of the unit of which this unit is a subordinate to.
39+
Returns '' for principal units themselves.
40+
"""
41+
return self.safe_data['principal']
42+
2943
@property
3044
def agent_status_message(self):
3145
"""Get the agent status message.
@@ -77,6 +91,14 @@ def public_address(self):
7791
def tag(self):
7892
return tag.unit(self.name)
7993

94+
def get_subordinates(self):
95+
"""Returns the unit objects that are subordinates to this unit
96+
97+
:return [Unit]
98+
"""
99+
return [u for u_name, u in self.model.units.items() if u.is_subordinate and
100+
u.principal_unit == self.name]
101+
80102
async def destroy(self):
81103
"""Destroy this unit.
82104

0 commit comments

Comments
 (0)