backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / services / protocols / ovsdb / event.py
1 # Copyright (c) 2014 Rackspace Hosting
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 from ryu.controller import event as ryu_event
17 from ryu.controller import handler
18
19
20 class EventRowBase(ryu_event.EventBase):
21     def __init__(self, system_id, table, row, event_type):
22         super(EventRowBase, self).__init__()
23         self.system_id = system_id
24         self.table = table
25         self.row = row
26         self.event_type = event_type
27
28     def __str__(self):
29         return '%s<system_id=%s table=%s, uuid=%s>' % (self.__class__.__name__,
30                                                        self.system_id,
31                                                        self.table,
32                                                        self.row['_uuid'])
33
34
35 class EventRowDelete(EventRowBase):
36     def __init__(self, system_id, table, row):
37         super(EventRowDelete, self).__init__(system_id, table, row, 'Deleted')
38
39
40 class EventRowInsert(EventRowBase):
41     def __init__(self, system_id, table, row):
42         super(EventRowInsert, self).__init__(system_id, table, row, 'Inserted')
43
44
45 class EventRowUpdate(ryu_event.EventBase):
46     def __init__(self, system_id, table, old, new):
47         super(EventRowUpdate, self).__init__()
48         self.system_id = system_id
49         self.table = table
50         self.old = old
51         self.new = new
52         self.event_type = 'Updated'
53
54     def __str__(self):
55         return '%s<system_id=%s table=%s, uuid=%s>' % (self.__class__.__name__,
56                                                        self.system_id,
57                                                        self.table,
58                                                        self.old['_uuid'])
59
60
61 class EventModifyRequest(ryu_event.EventRequestBase):
62     """ Dispatch a modify function to OVSDB
63
64     `func` must be a callable that accepts an insert fucntion and the
65     IDL.tables object. It can then modify the tables as needed. For inserts,
66     specify a UUID for each insert, and return a tuple of the temporary
67     UUID's. The execution of `func` will be wrapped in a single transaction
68     and the reply will include a dict of temporary UUID to real UUID mappings.
69
70     e.g.
71
72         new_port_uuid = uuid.uuid4()
73
74         def modify(tables, insert):
75             bridges = tables['Bridge'].rows
76             bridge = None
77             for b in bridges:
78                 if b.name == 'my-bridge':
79                     bridge = b
80
81             if not bridge:
82                 return
83
84             port = insert('Port', new_port_uuid)
85
86             bridge.ports = bridge.ports + [port]
87
88             return (new_port_uuid, )
89
90         request = EventModifyRequest(system_id, modify)
91         reply = send_request(request)
92
93         port_uuid = reply.insert_uuids[new_port_uuid]
94     """
95
96     def __init__(self, system_id, func):
97         super(EventModifyRequest, self).__init__()
98         self.dst = 'OVSDB'
99         self.system_id = system_id
100         self.func = func
101
102     def __str__(self):
103         return '%s<system_id=%s>' % (self.__class__.__name__, self.system_id)
104
105
106 class EventModifyReply(ryu_event.EventReplyBase):
107     def __init__(self, system_id, status, insert_uuids, err_msg):
108         self.system_id = system_id
109         self.status = status
110         self.insert_uuids = insert_uuids
111         self.err_msg = err_msg
112
113     def __str__(self):
114         return ('%s<system_id=%s, status=%s, insert_uuids=%s, error_msg=%s>'
115                 % (self.__class__.__name__,
116                    self.system_id,
117                    self.status,
118                    self.insert_uuids,
119                    self.err_msg))
120
121
122 class EventNewOVSDBConnection(ryu_event.EventBase):
123     def __init__(self, client):
124         super(EventNewOVSDBConnection, self).__init__()
125         self.client = client
126
127     def __str__(self):
128         return '%s<system_id=%s>' % (self.__class__.__name__,
129                                      self.client.system_id)
130
131     @property
132     def system_id(self):
133         return self.client.system_id
134
135
136 class EventReadRequest(ryu_event.EventRequestBase):
137     def __init__(self, system_id, func):
138         self.system_id = system_id
139         self.func = func
140         self.dst = 'OVSDB'
141
142
143 class EventReadReply(ryu_event.EventReplyBase):
144     def __init__(self, system_id, result, err_msg=''):
145         self.system_id = system_id
146         self.result = result
147         self.err_msg = err_msg
148
149
150 class EventRowInsertedBase(EventRowInsert):
151     def __init__(self, ev):
152         super(EventRowInsertedBase, self).__init__(ev.system_id,
153                                                    ev.table,
154                                                    ev.row)
155
156
157 class EventRowDeletedBase(EventRowDelete):
158     def __init__(self, ev):
159         super(EventRowDeletedBase, self).__init__(ev.system_id,
160                                                   ev.table,
161                                                   ev.row)
162
163
164 class EventRowUpdatedBase(EventRowUpdate):
165     def __init__(self, ev):
166         super(EventRowUpdatedBase, self).__init__(ev.system_id,
167                                                   ev.table,
168                                                   ev.old,
169                                                   ev.new)
170
171
172 class EventPortInserted(EventRowInsertedBase):
173     pass
174
175
176 class EventPortDeleted(EventRowDeletedBase):
177     pass
178
179
180 class EventPortUpdated(EventRowUpdatedBase):
181     pass
182
183
184 class EventInterfaceInserted(EventRowInsertedBase):
185     pass
186
187
188 class EventInterfaceDeleted(EventRowDeletedBase):
189     pass
190
191
192 class EventInterfaceUpdated(EventRowUpdatedBase):
193     pass
194
195
196 handler.register_service('ryu.services.protocols.ovsdb.manager')