Skip to content

Commit

Permalink
Merge branch 'master' of github.com:juju/python-libjuju into charmhub…
Browse files Browse the repository at this point in the history
…-compatability
  • Loading branch information
addyess committed Mar 10, 2022
2 parents 88c36ed + ea8f5a6 commit 0244669
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 523 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.9.6
2.9.7
12 changes: 10 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
Changelog
---------

2.9.6
2.9.7
^^^^^

Thursday January 27 2022
Friday February 11 2022

## What's Changed

* [JUJU-556] Facade schemas for Juju 2.9.24 by @cderici in https://github.com/juju/python-libjuju/pull/626
* Provide extra metadata with charmstore.entity(...) by @addyess in https://github.com/juju/python-libjuju/pull/635

2.9.6
^^^^^

Thursday January 27 2022

* [JUJU-320] Unit public address by @SimonRichardson in https://github.com/juju/python-libjuju/pull/600
* [JUJU-244] Add attach-resource by @cderici in https://github.com/juju/python-libjuju/pull/601
* [JUJU-140] Model.wait_for_idle -- for apps with no units yet by @cderici in https://github.com/juju/python-libjuju/pull/575
Expand Down
40 changes: 0 additions & 40 deletions juju/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,21 +175,6 @@ async def scale(self, scale=None, scale_change=None):
scale_change=scale_change)
])

def attach(self, resource_name, file_path):
"""Upload a file as a resource for this application.
:param str resource: Name of the resource
:param str file_path: Path to the file to upload
"""
raise NotImplementedError()

def collect_metrics(self):
"""Collect metrics on this application.
"""
raise NotImplementedError()

async def destroy_relation(self, local_relation, remote_relation):
"""Remove a relation to another application.
Expand Down Expand Up @@ -582,31 +567,6 @@ async def set_constraints(self, constraints):

return await app_facade.SetConstraints(application=self.name, constraints=constraints)

def set_meter_status(self, status, info=None):
"""Set the meter status on this status.
:param str status: Meter status, e.g. 'RED', 'AMBER'
:param str info: Extra info message
"""
raise NotImplementedError()

def set_plan(self, plan_name):
"""Set the plan for this application, effective immediately.
:param str plan_name: Name of plan
"""
raise NotImplementedError()

def update_allocation(self, allocation):
"""Update existing allocation for this application.
:param int allocation: The allocation to set
"""
raise NotImplementedError()

async def refresh(
self, channel=None, force=False, force_series=False, force_units=False,
path=None, resources=None, revision=None, switch=None):
Expand Down
3 changes: 1 addition & 2 deletions juju/charmstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def _entity(self, *args, **kwargs):
result['Meta']['resources'] = resources
return result

def _files(self, entity_id, manifest=None, filename=None,
read_file=False, channel=None):
def _files(self, entity_id, manifest=None, filename=None, read_file=False, channel=None):
'''
Overloads the files method from theblues.charmstore.CharmStore
that method used APIs which are no longer implemented
Expand Down
62 changes: 0 additions & 62 deletions juju/client/jujudata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,6 @@ class NoModelException(Exception):
class JujuData:
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def current_controller(self):
'''Return the current controller name'''
raise NotImplementedError()

@abc.abstractmethod
def controllers(self):
'''Return all the currently known controllers as a dict
mapping controller name to a dict containing the
following string keys:
uuid: The UUID of the controller
api-endpoints: A list of host:port addresses for the controller.
ca-cert: the PEM-encoded CA cert of the controller (optional)
This is compatible with the "controllers" entry in the YAML-unmarshaled data
stored in ~/.local/share/juju/controllers.yaml.
'''
raise NotImplementedError()

@abc.abstractmethod
def models(self):
'''Return all the currently known models as a dict
containing a key for each known controller,
each holding a dict value containing an optional "current-model"
key (the name of the current model for that controller,
if there is one), and a dict mapping fully-qualified
model names to a dict containing a "uuid" key with the
key for that model.
This is compatible with the YAML-unmarshaled data
stored in ~/.local/share/juju/models.yaml.
'''
raise NotImplementedError()

@abc.abstractmethod
def accounts(self):
'''Return the currently known accounts, as a dict
containing a key for each known controller, with
each value holding a dict with the following keys:
user: The username to use when logging into the controller (str)
password: The password to use when logging into the controller (str, optional)
'''
raise NotImplementedError()

@abc.abstractmethod
def cookies_for_controller(self, controller_name):
'''Return the cookie jar to use when connecting to the
controller with the given name.
:return http.cookiejar.CookieJar
'''
raise NotImplementedError()

@abc.abstractmethod
def current_model(self, controller_name=None, model_only=False):
'''Return the current model, qualified by its controller name.
If controller_name is specified, the current model for
that controller will be returned.
If model_only is true, only the model name, not qualified by
its controller name, will be returned.
'''
raise NotImplementedError()

def parse_model(self, model):
"""Split the given model_name into controller and model parts.
If the controller part is empty, the current controller will be used.
Expand Down
8 changes: 5 additions & 3 deletions juju/client/proxy/proxy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from abc import abstractmethod

from juju.errors import AbstractMethodError


class ProxyNotConnectedError(Exception):
pass
Expand All @@ -12,12 +14,12 @@ class Proxy():

@abstractmethod
def connect(self):
raise NotImplementedError()
raise AbstractMethodError()

@abstractmethod
def close(self):
raise NotImplementedError()
raise AbstractMethodError()

@abstractmethod
def socket(self):
raise NotImplementedError()
raise AbstractMethodError()
95 changes: 41 additions & 54 deletions juju/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,13 +479,6 @@ async def enable_user(self, username):
entity = client.Entity(tag.user(username))
return await user_facade.EnableUser(entities=[entity])

def kill(self):
"""Forcibly terminate all machines and other associated resources for
this controller.
"""
raise NotImplementedError()

async def cloud(self, name=None):
"""Get Cloud
Expand Down Expand Up @@ -524,79 +517,73 @@ async def get_cloud(self):
cloud = list(result.clouds.keys())[0] # only lives on one cloud
return tag.untag('cloud-', cloud)

async def get_models(self, all_=False, username=None):
async def get_models(self, all=False, username=None):
"""
.. deprecated:: 0.7.0
Use :meth:`.list_models` instead.
"""
controller_facade = client.ControllerFacade.from_connection(
self.connection())
for attempt in (1, 2, 3):
try:
return await controller_facade.AllModels()
except errors.JujuAPIError as e:
# retry concurrency error until resolved in Juju
# see: https://bugs.launchpad.net/juju/+bug/1721786
if 'has been removed' not in e.message or attempt == 3:
raise
return await self.list_models(username, all)

async def model_uuids(self, username=None, all=False):
"""Return a mapping of model names to UUIDs the given user can access.
async def model_uuids(self):
"""Return a mapping of model names to UUIDs.
:param str username: Optional username argument, defaults to
current connected user.
:param bool all: Flag to list all models, regardless of
user accessibility (administrative users only)
:returns: {str name : str UUID}
"""
controller_facade = client.ControllerFacade.from_connection(
self.connection())

if all:
facade = client.ControllerFacade.from_connection(
self.connection())
else:
facade = client.ModelManagerFacade.from_connection(
self.connection())
u_name = username if username else self.get_current_username()
user = tag.user(u_name)

for attempt in (1, 2, 3):
try:
response = await controller_facade.AllModels()
if all:
userModelList = await facade.AllModels()
else:
userModelList = await facade.ListModels(tag=user)

return {um.model.name: um.model.uuid
for um in response.user_models}
for um in userModelList.user_models}
except errors.JujuAPIError as e:
# retry concurrency error until resolved in Juju
# see: https://bugs.launchpad.net/juju/+bug/1721786
if 'has been removed' not in e.message or attempt == 3:
raise
await jasyncio.sleep(attempt)

async def list_models(self):
async def list_models(self, username=None, all=False):
"""Return list of names of the available models on this controller.
Equivalent to ``sorted((await self.model_uuids()).keys())``
"""
uuids = await self.model_uuids()
uuids = await self.model_uuids(username, all)
return sorted(uuids.keys())

def get_payloads(self, *patterns):
"""Return list of known payloads.
:param str *patterns: Patterns to match against
Each pattern will be checked against the following info in Juju::
- unit name
- machine id
- payload type
- payload class
- payload id
- payload tag
- payload status
"""
raise NotImplementedError()

def login(self):
"""Log in to this controller.
async def get_current_user(self, secret_key=None):
"""Returns the user object associated with the current connection.
:param str secret_key: Issued by juju when add or reset user
password
:returns: A :class:`~juju.user.User` instance
"""
raise NotImplementedError()

def logout(self, force=False):
"""Log out of this controller.
return await self.get_user(self.connection().username)

:param bool force: Don't fail even if user not previously logged in
with a password
def get_current_username(self):
"""Returns the username associated with the current connection.
:returns: :str: username of the connected user
"""
raise NotImplementedError()
return self.connection().username

async def get_model(self, model):
"""Get a model by name or UUID.
Expand Down Expand Up @@ -687,7 +674,7 @@ async def revoke(self, username, acl='login'):
controller_facade = client.ControllerFacade.from_connection(
self.connection())
user = tag.user(username)
changes = client.ModifyControllerAccess('login', 'revoke', user)
changes = client.ModifyControllerAccess(acl, 'revoke', user)
return await controller_facade.ModifyControllerAccess(changes=[changes])

async def grant_model(self, username, model_uuid, acl='read'):
Expand Down
4 changes: 4 additions & 0 deletions juju/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ class JujuApplicationConfigError(JujuConfigError):

class JujuModelConfigError(JujuConfigError):
pass


class AbstractMethodError(Exception):
pass
Loading

0 comments on commit 0244669

Please sign in to comment.