~ahasenack/landscape-client/landscape-client-1.5.5-0ubuntu0.9.04.0

« back to all changes in this revision

Viewing changes to landscape/message_schemas.py

  • Committer: Bazaar Package Importer
  • Author(s): Rick Clark
  • Date: 2008-09-08 16:35:57 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080908163557-l3ixzj5dxz37wnw2
Tags: 1.0.18-0ubuntu1
New upstream release 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from landscape.schema import (
 
2
    Message, KeyDict, Dict, List, Tuple,
 
3
    Bool, Int, Float, String, Unicode, UnicodeOrString, Constant,
 
4
    Any)
 
5
 
 
6
# When adding a new schema, which deprecates an older schema, the recommended
 
7
# naming convention, is to name it SCHEMA_NAME_ and the last API version that
 
8
# the schema works with.
 
9
#
 
10
# i.e. if I have USERS and I'm deprecating it, in API 2.2, then USERS becomes
 
11
# USERS_2_1
 
12
 
 
13
utf8 = UnicodeOrString("utf-8")
 
14
 
 
15
process_info = KeyDict({"pid": Int(),
 
16
                        "name": utf8,
 
17
                        "state": String(),
 
18
                        "sleep-average": Int(),
 
19
                        "uid": Int(),
 
20
                        "gid": Int(),
 
21
                        "vm-size": Int(),
 
22
                        "start-time": Int(),
 
23
                        "percent-cpu": Float()},
 
24
                       # Optional for backwards compatibility
 
25
                       optional=["vm-size", "sleep-average", "percent-cpu"])
 
26
 
 
27
ACTIVE_PROCESS_INFO = Message(
 
28
    "active-process-info",
 
29
    {"kill-processes": List(Int()),
 
30
     "kill-all-processes": Bool(),
 
31
     "add-processes": List(process_info),
 
32
     "update-processes": List(process_info)
 
33
     },
 
34
    # XXX Really we don't want all three of these keys to be optional:
 
35
    # we always want _something_...
 
36
    optional=["add-processes", "update-processes", "kill-processes",
 
37
              "kill-all-processes"])
 
38
 
 
39
COMPUTER_UPTIME = Message(
 
40
    "computer-uptime",
 
41
    {"startup-times": List(Int()),
 
42
     "shutdown-times": List(Int())},
 
43
    # XXX Again, one or the other.
 
44
    optional=["startup-times", "shutdown-times"])
 
45
 
 
46
CLIENT_UPTIME = Message(
 
47
    "client-uptime",
 
48
    {"period": Tuple(Float(), Float()),
 
49
     "components": List(Int())},
 
50
    optional=["components"]) # just for backwards compatibility
 
51
 
 
52
OPERATION_RESULT = Message(
 
53
    "operation-result",
 
54
    {"operation-id": Int(),
 
55
     "status": Int(),
 
56
     "result-code": Int(),
 
57
     "result-text": utf8},
 
58
    optional=["result-code", "result-text"])
 
59
 
 
60
#ACTION_INFO is obsolete.
 
61
ACTION_INFO = Message(
 
62
    "action-info",
 
63
    {"response-id": Int(),
 
64
     "success": Bool(),
 
65
     "kind": String(),
 
66
     "parameters": String()})
 
67
 
 
68
COMPUTER_INFO = Message(
 
69
    "computer-info",
 
70
    {"hostname": utf8,
 
71
     "total-memory": Int(),
 
72
     "total-swap": Int()},
 
73
    # Not sure why these are all optional, but it's explicitly tested
 
74
    # in the server
 
75
    optional=["hostname", "total-memory", "total-swap"])
 
76
 
 
77
DISTRIBUTION_INFO = Message(
 
78
    "distribution-info",
 
79
    {"distributor-id": utf8,
 
80
     "description": utf8,
 
81
     "release": utf8,
 
82
     "code-name": utf8},
 
83
    # all optional because the lsb-release file may not have all data.
 
84
    optional=["distributor-id", "description", "release", "code-name"])
 
85
 
 
86
 
 
87
hal_data = Dict(Unicode(),
 
88
                Any(Unicode(), List(Unicode()), Bool(), Int(), Float()))
 
89
 
 
90
HARDWARE_INVENTORY = Message("hardware-inventory", {
 
91
    "devices": List(Any(Tuple(Constant("create"), hal_data),
 
92
                        Tuple(Constant("update"),
 
93
                              Unicode(), # udi,
 
94
                              hal_data, # creates,
 
95
                              hal_data, # updates,
 
96
                              hal_data), # deletes
 
97
                        Tuple(Constant("delete"),
 
98
                              Unicode()),
 
99
                        ),
 
100
                    )
 
101
    })
 
102
 
 
103
 
 
104
LOAD_AVERAGE = Message("load-average", {
 
105
    "load-averages": List(Tuple(Int(), Float())),
 
106
    })
 
107
 
 
108
 
 
109
MEMORY_INFO = Message("memory-info", {
 
110
    "memory-info": List(Tuple(Float(), Int(), Int())),
 
111
    })
 
112
 
 
113
RESYNCHRONIZE = Message(
 
114
    "resynchronize",
 
115
    {"operation-id": Int()},
 
116
    # operation-id is only there if it's a response to a server-initiated
 
117
    # resynchronize.
 
118
    optional=["operation-id"])
 
119
 
 
120
MOUNT_ACTIVITY = Message("mount-activity", {
 
121
    "activities": List(Tuple(Float(), utf8, Bool()))
 
122
    })
 
123
 
 
124
MOUNT_INFO = Message("mount-info", {
 
125
    "mount-info": List(Tuple(Float(),
 
126
                             KeyDict({"mount-point": utf8,
 
127
                                      "device": utf8,
 
128
                                      "filesystem": utf8,
 
129
                                      "total-space": Int()}),
 
130
                             )),
 
131
    })
 
132
 
 
133
FREE_SPACE = Message("free-space", {
 
134
    "free-space": List(Tuple(Float(), utf8, Int()))
 
135
    })
 
136
 
 
137
 
 
138
REGISTER = Message(
 
139
    "register",
 
140
    {"registration_password": Any(utf8, Constant(None)),
 
141
     "computer_title": utf8,
 
142
     "hostname": utf8,
 
143
     "account_name": utf8},
 
144
    # hostname wasn't around in old versions
 
145
    optional=["registration_password", "hostname"])
 
146
 
 
147
TEMPERATURE = Message("temperature", {
 
148
    "thermal-zone": utf8,
 
149
    "temperatures": List(Tuple(Int(), Float())),
 
150
    })
 
151
 
 
152
PROCESSOR_INFO = Message(
 
153
    "processor-info",
 
154
    {"processors": List(KeyDict({"processor-id": Int(),
 
155
                                 "vendor": utf8,
 
156
                                 "model": utf8,
 
157
                                 "cache-size": Int(),
 
158
                                 },
 
159
                                optional=["vendor", "cache-size"])),
 
160
    })
 
161
 
 
162
user_data = KeyDict({
 
163
    "uid": Int(),
 
164
    "username": utf8,
 
165
    "name": Any(utf8, Constant(None)),
 
166
    "enabled": Bool(),
 
167
    "location": Any(utf8, Constant(None)),
 
168
    "home-phone": Any(utf8, Constant(None)),
 
169
    "work-phone": Any(utf8, Constant(None)),
 
170
    "primary-gid": Any(Int(), Constant(None)),
 
171
    "primary-groupname": utf8},
 
172
    optional=["primary-groupname", "primary-gid"]
 
173
    )
 
174
 
 
175
group_data = KeyDict({
 
176
    "gid": Int(),
 
177
    "name": utf8
 
178
    })
 
179
 
 
180
USERS = Message(
 
181
    "users",
 
182
    {"operation-id": Int(),
 
183
     "create-users": List(user_data),
 
184
     "update-users": List(user_data),
 
185
     "delete-users": List(utf8),
 
186
     "create-groups": List(group_data),
 
187
     "update-groups": List(group_data),
 
188
     "delete-groups": List(utf8),
 
189
     "create-group-members": Dict(utf8, List(utf8)),
 
190
     "delete-group-members": Dict(utf8, List(utf8)),
 
191
     },
 
192
    # operation-id is only there for responses, and all other are
 
193
    # optional as long as one of them is there (no way to say that yet)
 
194
    optional=["operation-id", "create-users", "update-users", "delete-users",
 
195
              "create-groups", "update-groups", "delete-groups",
 
196
              "create-group-members", "delete-group-members"])
 
197
 
 
198
USERS_2_1 = Message(
 
199
    "users",
 
200
    {"operation-id": Int(),
 
201
     "create-users": List(user_data),
 
202
     "update-users": List(user_data),
 
203
     "delete-users": List(Int()),
 
204
     "create-groups": List(group_data),
 
205
     "update-groups": List(group_data),
 
206
     "delete-groups": List(Int()),
 
207
     "create-group-members": Dict(Int(), List(Int())),
 
208
     "delete-group-members": Dict(Int(), List(Int())),
 
209
     },
 
210
    # operation-id is only there for responses, and all other are
 
211
    # optional as long as one of them is there (no way to say that yet)
 
212
    optional=["operation-id", "create-users", "update-users", "delete-users",
 
213
              "create-groups", "update-groups", "delete-groups",
 
214
              "create-group-members", "delete-group-members"])
 
215
 
 
216
USERS_2_0 = Message(
 
217
    "users",
 
218
    {"operation-id": Int(),
 
219
     "create-users": List(user_data),
 
220
     "update-users": List(user_data),
 
221
     "delete-users": List(Int()),
 
222
     "create-groups": List(group_data),
 
223
     "update-groups": List(group_data),
 
224
     "delete-groups": List(Int()),
 
225
     "create-group-members": Dict(Int(), List(Int())),
 
226
     "delete-group-members": Dict(Int(), List(Int())),
 
227
     },
 
228
    # operation-id is only there for responses, and all other are
 
229
    # optional as long as one of them is there (no way to say that yet)
 
230
    optional=["operation-id", "create-users", "update-users", "delete-users",
 
231
              "create-groups", "update-groups", "delete-groups",
 
232
              "create-group-members", "delete-group-members"])
 
233
 
 
234
opt_str = Any(utf8, Constant(None))
 
235
OLD_USERS = Message(
 
236
    "users",
 
237
    {"users": List(KeyDict({"username": utf8,
 
238
                            "uid": Int(),
 
239
                            "realname": opt_str,
 
240
                            "location": opt_str,
 
241
                            "home-phone": opt_str,
 
242
                            "work-phone": opt_str,
 
243
                            "enabled": Bool()},
 
244
                           optional=["location", "home-phone", "work-phone"])),
 
245
     "groups": List(KeyDict({"gid": Int(),
 
246
                             "name": utf8,
 
247
                             "members": List(utf8)}))
 
248
     },
 
249
    optional=["groups"])
 
250
 
 
251
package_ids_or_ranges = List(Any(Tuple(Int(), Int()), Int()))
 
252
PACKAGES = Message(
 
253
    "packages",
 
254
    {"installed": package_ids_or_ranges,
 
255
     "available": package_ids_or_ranges,
 
256
     "available-upgrades": package_ids_or_ranges,
 
257
     "not-installed": package_ids_or_ranges,
 
258
     "not-available": package_ids_or_ranges,
 
259
     "not-available-upgrades": package_ids_or_ranges},
 
260
    optional=["installed", "available", "available-upgrades",
 
261
              "not-available", "not-installed", "not-available-upgrades"])
 
262
 
 
263
CHANGE_PACKAGES_RESULT = Message(
 
264
    "change-packages-result",
 
265
    {"operation-id": Int(),
 
266
     "must-install": List(Any(Int(), Constant(None))),
 
267
     "must-remove": List(Any(Int(), Constant(None))),
 
268
     "result-code": Int(),
 
269
     "result-text": utf8},
 
270
    optional=["result-text", "must-install", "must-remove"])
 
271
 
 
272
UNKNOWN_PACKAGE_HASHES = Message("unknown-package-hashes", {
 
273
    "hashes": List(String()),
 
274
    "request-id": Int(),
 
275
    })
 
276
 
 
277
ADD_PACKAGES = Message("add-packages", {
 
278
    "packages": List(KeyDict({"name": utf8,
 
279
                              "description": Unicode(),
 
280
                              "section": Unicode(),
 
281
                              "relations": List(Tuple(Int(), utf8)),
 
282
                              "summary": Unicode(),
 
283
                              "installed-size":  Any(Int(), Constant(None)),
 
284
                              "size":  Any(Int(), Constant(None)),
 
285
                              "version": utf8,
 
286
                              "type": Int(),
 
287
                              })),
 
288
    "request-id": Int(),
 
289
    })
 
290
 
 
291
TEXT_MESSAGE = Message("text-message", {
 
292
    "message": Unicode()
 
293
    })
 
294
 
 
295
TEST = Message(
 
296
    "test",
 
297
    {"greeting": String(),
 
298
     "consistency-error": Bool(),
 
299
     "echo": String(),
 
300
     "sequence": Int()},
 
301
    optional=["greeting", "consistency-error", "echo", "sequence"])
 
302
 
 
303
# The tuples are timestamp, value
 
304
GRAPH_DATA = KeyDict({"values": List(Tuple(Float(), Float())),
 
305
                      "error": Unicode()})
 
306
 
 
307
CUSTOM_GRAPH = Message("custom-graph", {
 
308
    "data": Dict(Int(), GRAPH_DATA)})
 
309
 
 
310
message_schemas = {}
 
311
for schema in [ACTIVE_PROCESS_INFO, COMPUTER_UPTIME, CLIENT_UPTIME,
 
312
               OPERATION_RESULT, COMPUTER_INFO, DISTRIBUTION_INFO,
 
313
               HARDWARE_INVENTORY, LOAD_AVERAGE, MEMORY_INFO,
 
314
               RESYNCHRONIZE, MOUNT_ACTIVITY, MOUNT_INFO, FREE_SPACE,
 
315
               REGISTER, TEMPERATURE, PROCESSOR_INFO, USERS, PACKAGES,
 
316
               CHANGE_PACKAGES_RESULT, UNKNOWN_PACKAGE_HASHES,
 
317
               ADD_PACKAGES, TEXT_MESSAGE, TEST, CUSTOM_GRAPH]:
 
318
    message_schemas[schema.type] = schema