Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bring juju/juju.py into life #546

Merged
merged 5 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions juju/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,6 @@ async def scale(self, scale=None, scale_change=None):
scale_change=scale_change)
])

def allocate(self, budget, value):
"""Allocate budget to this application.

:param str budget: Name of budget
:param int value: Budget limit

"""
raise NotImplementedError()

def attach(self, resource_name, file_path):
"""Upload a file as a resource for this application.

Expand Down
48 changes: 23 additions & 25 deletions juju/juju.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
from juju.controller import Controller
from juju.client.jujudata import FileJujuData
from juju.errors import JujuError


class Juju(object):

def __init__(self, jujudata=None):
self.jujudata = jujudata or FileJujuData()

def add_cloud(self, name, definition, replace=False):
"""Add a user-defined cloud to Juju from among known cloud types.

Expand Down Expand Up @@ -31,24 +40,12 @@ def autoload_credentials(self):
"""
raise NotImplementedError()

def create_budget(self):
"""Create a new budget.

"""
raise NotImplementedError()

def get_agreements(self):
cderici marked this conversation as resolved.
Show resolved Hide resolved
"""Return list of terms to which the current user has agreed.

"""
raise NotImplementedError()

def get_budgets(self):
"""Return list of available budgets.

"""
raise NotImplementedError()

def get_clouds(self):
"""Return list of all available clouds.

Expand All @@ -58,9 +55,8 @@ def get_clouds(self):
def get_controllers(self):
"""Return list of all available controllers.

(maybe move this to Cloud?)
"""
raise NotImplementedError()
return self.jujudata.controllers()

def get_plans(self, charm_url):
"""Return list of plans available for the specified charm.
Expand All @@ -78,15 +74,6 @@ def register(self, registration_string):
"""
raise NotImplementedError()

def set_budget(self, name, limit):
"""Set a monthly budget limit.

:param str name: Name of budget
:param int limit: Monthly limit

"""
raise NotImplementedError()

def get_cloud(self, name):
"""Get a cloud by name.

Expand All @@ -95,15 +82,26 @@ def get_cloud(self, name):
"""
raise NotImplementedError()

def get_controller(self, name, include_passwords=False):
async def get_controller(self, name, include_passwords=False):
"""Get a controller by name.

:param str name: Name of controller
:param bool include_passwords: Include passwords for accounts

(maybe move this to Cloud?)
cderici marked this conversation as resolved.
Show resolved Hide resolved
"""
raise NotImplementedError()

# check if name is in the controllers.yaml
controllers = self.jujudata.controllers()
assert isinstance(controllers, dict)
if name not in controllers:
raise JujuError('%s is not among the controllers: %s' % (name, controllers.keys()))

# make a new Controller object that's connected to the
# controller with the given name
controller = Controller()
await controller.connect(name)
return controller

def update_clouds(self):
"""Update public cloud info available to Juju.
Expand Down
8 changes: 0 additions & 8 deletions juju/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2243,14 +2243,6 @@ async def get_action_status(self, uuid_or_prefix=None, name=None):
results[tag.untag('action-', a.action.tag)] = a.status
return results

def get_budget(self, budget_name):
"""Get budget usage info.

:param str budget_name: Name of budget

"""
raise NotImplementedError()

async def get_status(self, filters=None, utc=False):
"""Return the status of the model.

Expand Down
21 changes: 21 additions & 0 deletions tests/integration/test_juju.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest

from juju.controller import Controller
from juju.juju import Juju
from .. import base


@base.bootstrapped
@pytest.mark.asyncio
async def test_get_controllers(event_loop):
async with base.CleanController() as controller:
j = Juju()

controllers = j.get_controllers()
assert isinstance(controllers, dict)
assert len(controllers) >= 1
assert controller.controller_name in controllers

cc = await j.get_controller(controller.controller_name)
assert isinstance(cc, Controller)
assert controller.connection().endpoint == cc.connection().endpoint