FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-libjuju/examples/crossmodel_controller.py at master · Maxcode123/python-libjuju · GitHub
Maxcode123
python-libjuju
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-libjuju
/
examples
/
crossmodel_controller.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
85 lines (65 loc) · 2.41 KB
Breadcrumbs
python-libjuju
/
examples
/
crossmodel_controller.py
Copy path
File metadata and controls
85 lines (65 loc) · 2.41 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""
This example:
1. Connects to test and test2 controllers
2. Creates models on each controllers
3. Deploys a charm and waits until it reports itself active
4. Creates an offer
5. Lists the offer
6. Consumes the offer
7. Exports the bundle
8. Removes the SAAS
9. Removes the offer
10. Destroys models and disconnects
"""
import
tempfile
from
logging
import
getLogger
from
juju
import
jasyncio
from
juju
.
controller
import
Controller
log
=
getLogger
(
__name__
)
async
def
main
():
controller1
=
Controller
()
print
(
"Connecting to controller"
)
await
controller1
.
connect
(
"test"
)
controller2
=
Controller
()
print
(
"Connecting to controller"
)
await
controller2
.
connect
(
"test2"
)
try
:
print
(
'Creating models'
)
offering_model
=
await
controller1
.
add_model
(
'test-cmr-1'
)
consuming_model
=
await
controller2
.
add_model
(
'test-cmr-2'
)
print
(
'Deploying mysql'
)
application
=
await
offering_model
.
deploy
(
'ch:mysql'
,
application_name
=
'mysql'
,
series
=
'trusty'
,
channel
=
'stable'
,
)
print
(
'Waiting for active'
)
await
offering_model
.
block_until
(
lambda
:
all
(
unit
.
workload_status
==
'active'
for
unit
in
application
.
units
))
print
(
'Adding offer'
)
await
offering_model
.
create_offer
(
"mysql:db"
)
offers
=
await
offering_model
.
list_offers
()
print
(
'Show offers'
,
', '
.
join
(
"%s: %s"
%
item
for
offer
in
offers
.
results
for
item
in
vars
(
offer
).
items
()))
print
(
'Consuming offer'
)
await
consuming_model
.
consume
(
"admin/test-cmr-1.mysql"
,
controller_name
=
"test"
)
print
(
'Exporting bundle'
)
with
tempfile
.
TemporaryDirectory
()
as
dirpath
:
await
offering_model
.
export_bundle
(
"{}/bundle.yaml"
.
format
(
dirpath
))
print
(
"Remove SAAS"
)
await
consuming_model
.
remove_saas
(
"mysql"
)
print
(
'Removing offer'
)
await
offering_model
.
remove_offer
(
"admin/test-cmr-1.mysql"
,
force
=
True
)
print
(
'Destroying models'
)
await
controller1
.
destroy_model
(
offering_model
.
info
.
uuid
)
await
controller2
.
destroy_model
(
consuming_model
.
info
.
uuid
)
except
Exception
:
log
.
exception
(
"Example failed!"
)
raise
finally
:
print
(
'Disconnecting from controller'
)
await
controller1
.
disconnect
()
await
controller2
.
disconnect
()
if
__name__
==
'__main__'
:
jasyncio
.
run
(
main
())
Back
|
FazBrowse Home
|
New Git URL