1 from collections
import namedtuple
3 from .facade
import ReturnMapping
, Type
, TypeEncoder
18 """A single websocket delta.
20 :ivar entity: The entity name, e.g. 'unit', 'application'
23 :ivar type: The delta type, e.g. 'add', 'change', 'remove'
26 :ivar data: The raw delta data
29 NOTE: The 'data' variable above is being incorrectly cross-linked by a
30 Sphinx bug: https://github.com/sphinx-doc/sphinx/issues/2549
33 _toSchema
= {'deltas': 'deltas'}
34 _toPy
= {'deltas': 'deltas'}
36 def __init__(self
, deltas
=None):
38 :param deltas: [str, str, object]
43 Change
= namedtuple('Change', 'entity type data')
44 change
= Change(*self
.deltas
)
46 self
.entity
= change
.entity
47 self
.type = change
.type
48 self
.data
= change
.data
51 def from_json(cls
, data
):
52 return cls(deltas
=data
)
55 class ResourcesFacade(Type
):
56 """Patch parts of ResourcesFacade to make it work.
59 @ReturnMapping(_client
.AddPendingResourcesResult
)
60 async def AddPendingResources(self
, application_tag
, charm_url
, resources
):
61 """Fix the calling signature of AddPendingResources.
63 The ResourcesFacade doesn't conform to the standard facade pattern in
64 the Juju source, which leads to the schemagened code not matching up
65 properly with the actual calling convention in the API. There is work
66 planned to fix this in Juju, but we have to work around it for now.
70 resources : typing.Sequence<+T_co>[~CharmResource]<~CharmResource>
71 Returns -> typing.Union[_ForwardRef('ErrorResult'),
72 typing.Sequence<+T_co>[str]]
74 # map input types to rpc msg
76 msg
= dict(type='Resources',
77 request
='AddPendingResources',
80 _params
['tag'] = application_tag
81 _params
['url'] = charm_url
82 _params
['resources'] = resources
83 reply
= await self
.rpc(msg
)
86 class AllWatcherFacade(Type
):
88 Patch rpc method of allwatcher to add in 'id' stuff.
91 async def rpc(self
, msg
):
92 if not hasattr(self
, 'Id'):
93 client
= _client
.ClientFacade
.from_connection(self
.connection
)
95 result
= await client
.WatchAll()
96 self
.Id
= result
.watcher_id
99 result
= await self
.connection
.rpc(msg
, encoder
=TypeEncoder
)