Skip to content

Commit 1a77394

Browse files
authored
Merge pull request #449 from achilleasa/support-new-expose-params-for-applications
#449 This PR adds support for granular, per-endpoint expose parameters to the expose/unexpose methods of the Application model as well as an example for using the new feature. For more details on using this feature please refer to https://discourse.juju.is/t/granular-control-of-application-expose-parameters-in-the-upcoming-2-9-juju-release/3597
2 parents ad3c449 + e35de01 commit 1a77394

7 files changed

Lines changed: 602 additions & 36 deletions

File tree

examples/expose-application.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""
2+
This example:
3+
4+
1. Connects to the current model.
5+
2. Deploys a charm and waits until it reports itself active.
6+
3. Demonstrates exposing application endpoints to space and CIDR combinations.
7+
3. Demonstrates unexposing application endpoints.
8+
9+
NOTE: this test must be run against a 2.9 controller.
10+
"""
11+
from juju import loop
12+
from juju.model import Model
13+
from juju.application import ExposedEndpoint
14+
15+
16+
async def main():
17+
model = Model()
18+
print('Connecting to model')
19+
# connect to current model with current user, per Juju CLI
20+
await model.connect()
21+
22+
try:
23+
print('Deploying ubuntu')
24+
application = await model.deploy(
25+
'cs:~jameinel/ubuntu-lite-7',
26+
application_name='ubuntu',
27+
series='trusty',
28+
channel='stable',
29+
)
30+
31+
print('Waiting for active')
32+
await model.block_until(
33+
lambda: all(unit.workload_status == 'active'
34+
for unit in application.units))
35+
36+
print('Expose all opened port ranges')
37+
await application.expose()
38+
39+
print('Expose all opened port ranges to the CIDRs that correspond to a list of spaces')
40+
await application.expose(exposed_endpoints={
41+
"": ExposedEndpoint(to_spaces=["alpha"])
42+
})
43+
44+
print('Expose all opened port ranges to a list of CIDRs')
45+
await application.expose(exposed_endpoints={
46+
"": ExposedEndpoint(to_cidrs=["10.0.0.0/24"])
47+
})
48+
49+
print('Expose all opened port ranges to a list of spaces and CIDRs')
50+
await application.expose(exposed_endpoints={
51+
"": ExposedEndpoint(to_spaces=["alpha"], to_cidrs=["10.0.0.0/24"])
52+
})
53+
54+
print('Expose individual endpoints to different space/CIDR combinations')
55+
await application.expose(exposed_endpoints={
56+
"": ExposedEndpoint(to_spaces=["alpha"], to_cidrs=["10.0.0.0/24"]),
57+
"ubuntu": ExposedEndpoint(to_cidrs=["10.42.42.0/24"])
58+
})
59+
60+
print('Unexpose individual endpoints (other endpoints remain exposed)')
61+
await application.unexpose(exposed_endpoints=["ubuntu"])
62+
63+
print('Unexpose application')
64+
await application.unexpose()
65+
66+
print('Removing ubuntu')
67+
await application.remove()
68+
finally:
69+
print('Disconnecting from model')
70+
await model.disconnect()
71+
72+
73+
if __name__ == '__main__':
74+
loop.run(main())

0 commit comments

Comments
 (0)