Skip to content

Commit 5432642

Browse files
tmihocjames-garner-canonical
authored andcommitted
docs: move docs from juju.is
1 parent 619bb9f commit 5432642

93 files changed

Lines changed: 47825 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build/lib/juju/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright 2024 Canonical Ltd.
2+
# Licensed under the Apache V2, see LICENCE file for details.
3+
"""Python Library for Juju."""

build/lib/juju/access.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2023 Canonical Ltd.
2+
# Licensed under the Apache V2, see LICENCE file for details.
3+
4+
from .errors import JujuNotValid
5+
6+
# No permissions at all
7+
NO_ACCESS = ""
8+
9+
# Model permissions
10+
11+
READ_ACCESS = "read"
12+
WRITE_ACCESS = "write"
13+
CONSUME_ACCESS = "consume"
14+
ADMIN_ACCESS = "admin"
15+
MODEL_ACCESS_LEVELS = {READ_ACCESS, WRITE_ACCESS, CONSUME_ACCESS, ADMIN_ACCESS}
16+
17+
# Controller permissions
18+
19+
LOGIN_ACCESS = "login"
20+
ADD_MODEL_ACCESS = "add-model"
21+
SUPERUSER_ACCESS = "superuser"
22+
CONTROLLER_ACCESS_LEVELS = {LOGIN_ACCESS, ADD_MODEL_ACCESS, SUPERUSER_ACCESS}
23+
24+
OFFER_ACCESS_LEVELS = {READ_ACCESS, CONSUME_ACCESS, ADMIN_ACCESS}
25+
26+
ALL_ACCESS_LEVELS = MODEL_ACCESS_LEVELS.union(CONTROLLER_ACCESS_LEVELS)
27+
28+
29+
def validate_access_level(access):
30+
if access not in ALL_ACCESS_LEVELS:
31+
raise JujuNotValid("access level", access)
32+
33+
34+
def validate_offer_access(access):
35+
validate_access_level()
36+
if access not in OFFER_ACCESS_LEVELS:
37+
raise JujuNotValid("offer access level", access)
38+
39+
40+
def validate_model_access(access):
41+
validate_access_level(access)
42+
if access not in MODEL_ACCESS_LEVELS:
43+
raise JujuNotValid("model access level", access)
44+
45+
46+
def validate_controller_access(access):
47+
validate_access_level(access)
48+
if access not in CONTROLLER_ACCESS_LEVELS:
49+
raise JujuNotValid("controller access level", access)

build/lib/juju/action.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright 2023 Canonical Ltd.
2+
# Licensed under the Apache V2, see LICENCE file for details.
3+
4+
from . import model
5+
6+
7+
class Action(model.ModelEntity):
8+
def __init__(self, entity_id, model, history_index=-1, connected=True):
9+
super().__init__(entity_id, model, history_index, connected)
10+
self.results = {}
11+
self._status = self.data["status"]
12+
13+
@property
14+
def status(self):
15+
return self._status
16+
17+
async def fetch_output(self):
18+
completed_action = await self.model._get_completed_action(self.id)
19+
self.results = completed_action.output or {}
20+
self._status = completed_action.status
21+
22+
async def wait(self):
23+
self.results or await self.fetch_output()
24+
return self

build/lib/juju/annotation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2023 Canonical Ltd.
2+
# Licensed under the Apache V2, see LICENCE file for details.
3+
4+
import logging
5+
6+
from . import model
7+
8+
log = logging.getLogger(__name__)
9+
10+
11+
class Annotation(model.ModelEntity):
12+
pass

build/lib/juju/annotationhelper.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2023 Canonical Ltd.
2+
# Licensed under the Apache V2, see LICENCE file for details.
3+
4+
import logging
5+
6+
from .client import client
7+
from .errors import JujuError
8+
9+
log = logging.getLogger(__name__)
10+
11+
12+
async def _get_annotations(entity_tag, connection):
13+
"""Get annotations for the specified entity
14+
15+
:return dict: The annotations for the entity
16+
"""
17+
facade = client.AnnotationsFacade.from_connection(connection)
18+
result = (await facade.Get(entities=[{"tag": entity_tag}])).results[0]
19+
if result.error is not None:
20+
raise JujuError(result.error)
21+
return result.annotations
22+
23+
24+
async def _set_annotations(entity_tag, annotations, connection):
25+
"""Set annotations on the specified entity.
26+
27+
:param annotations map[string]string: the annotations as key/value
28+
pairs.
29+
"""
30+
# TODO: ensure annotations is dict with only string keys
31+
# and values.
32+
log.debug("Updating annotations on %s", entity_tag)
33+
facade = client.AnnotationsFacade.from_connection(connection)
34+
args = client.EntityAnnotations(
35+
entity=entity_tag,
36+
annotations=annotations,
37+
)
38+
return await facade.Set(annotations=[args])

0 commit comments

Comments
 (0)