Merge upstream libjuju
[osm/N2VC.git] / modules / libjuju / juju / delta.py
1 from .client import client
2
3
4 def get_entity_delta(d):
5 return _delta_types[d.entity](d.deltas)
6
7
8 def get_entity_class(entity_type):
9 return _delta_types[entity_type].get_entity_class()
10
11
12 class EntityDelta(client.Delta):
13 def get_id(self):
14 return self.data['id']
15
16 @classmethod
17 def get_entity_class(self):
18 return None
19
20
21 class ActionDelta(EntityDelta):
22 @classmethod
23 def get_entity_class(self):
24 from .action import Action
25 return Action
26
27
28 class ApplicationDelta(EntityDelta):
29 def get_id(self):
30 return self.data['name']
31
32 @classmethod
33 def get_entity_class(self):
34 from .application import Application
35 return Application
36
37
38 class AnnotationDelta(EntityDelta):
39 def get_id(self):
40 return self.data['tag']
41
42 @classmethod
43 def get_entity_class(self):
44 from .annotation import Annotation
45 return Annotation
46
47
48 class MachineDelta(EntityDelta):
49 @classmethod
50 def get_entity_class(self):
51 from .machine import Machine
52 return Machine
53
54
55 class UnitDelta(EntityDelta):
56 def get_id(self):
57 return self.data['name']
58
59 @classmethod
60 def get_entity_class(self):
61 from .unit import Unit
62 return Unit
63
64
65 class RelationDelta(EntityDelta):
66 @classmethod
67 def get_entity_class(self):
68 from .relation import Relation
69 return Relation
70
71
72 _delta_types = {
73 'action': ActionDelta,
74 'application': ApplicationDelta,
75 'annotation': AnnotationDelta,
76 'machine': MachineDelta,
77 'unit': UnitDelta,
78 'relation': RelationDelta,
79 }