1
from landscape.schema import (
2
Message, KeyDict, Dict, List, Tuple,
3
Bool, Int, Float, String, Unicode, UnicodeOrString, Constant,
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.
10
# i.e. if I have USERS and I'm deprecating it, in API 2.2, then USERS becomes
13
utf8 = UnicodeOrString("utf-8")
15
process_info = KeyDict({"pid": Int(),
18
"sleep-average": Int(),
23
"percent-cpu": Float()},
24
# Optional for backwards compatibility
25
optional=["vm-size", "sleep-average", "percent-cpu"])
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)
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"])
39
COMPUTER_UPTIME = Message(
41
{"startup-times": List(Int()),
42
"shutdown-times": List(Int())},
43
# XXX Again, one or the other.
44
optional=["startup-times", "shutdown-times"])
46
CLIENT_UPTIME = Message(
48
{"period": Tuple(Float(), Float()),
49
"components": List(Int())},
50
optional=["components"]) # just for backwards compatibility
52
OPERATION_RESULT = Message(
54
{"operation-id": Int(),
58
optional=["result-code", "result-text"])
60
#ACTION_INFO is obsolete.
61
ACTION_INFO = Message(
63
{"response-id": Int(),
66
"parameters": String()})
68
COMPUTER_INFO = Message(
71
"total-memory": Int(),
73
# Not sure why these are all optional, but it's explicitly tested
75
optional=["hostname", "total-memory", "total-swap"])
77
DISTRIBUTION_INFO = Message(
79
{"distributor-id": utf8,
83
# all optional because the lsb-release file may not have all data.
84
optional=["distributor-id", "description", "release", "code-name"])
87
hal_data = Dict(Unicode(),
88
Any(Unicode(), List(Unicode()), Bool(), Int(), Float()))
90
HARDWARE_INVENTORY = Message("hardware-inventory", {
91
"devices": List(Any(Tuple(Constant("create"), hal_data),
92
Tuple(Constant("update"),
97
Tuple(Constant("delete"),
104
LOAD_AVERAGE = Message("load-average", {
105
"load-averages": List(Tuple(Int(), Float())),
109
MEMORY_INFO = Message("memory-info", {
110
"memory-info": List(Tuple(Float(), Int(), Int())),
113
RESYNCHRONIZE = Message(
115
{"operation-id": Int()},
116
# operation-id is only there if it's a response to a server-initiated
118
optional=["operation-id"])
120
MOUNT_ACTIVITY = Message("mount-activity", {
121
"activities": List(Tuple(Float(), utf8, Bool()))
124
MOUNT_INFO = Message("mount-info", {
125
"mount-info": List(Tuple(Float(),
126
KeyDict({"mount-point": utf8,
129
"total-space": Int()}),
133
FREE_SPACE = Message("free-space", {
134
"free-space": List(Tuple(Float(), utf8, Int()))
140
{"registration_password": Any(utf8, Constant(None)),
141
"computer_title": utf8,
143
"account_name": utf8},
144
# hostname wasn't around in old versions
145
optional=["registration_password", "hostname"])
147
TEMPERATURE = Message("temperature", {
148
"thermal-zone": utf8,
149
"temperatures": List(Tuple(Int(), Float())),
152
PROCESSOR_INFO = Message(
154
{"processors": List(KeyDict({"processor-id": Int(),
159
optional=["vendor", "cache-size"])),
162
user_data = KeyDict({
165
"name": Any(utf8, Constant(None)),
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"]
175
group_data = KeyDict({
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)),
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"])
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())),
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"])
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())),
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"])
234
opt_str = Any(utf8, Constant(None))
237
{"users": List(KeyDict({"username": utf8,
241
"home-phone": opt_str,
242
"work-phone": opt_str,
244
optional=["location", "home-phone", "work-phone"])),
245
"groups": List(KeyDict({"gid": Int(),
247
"members": List(utf8)}))
251
package_ids_or_ranges = List(Any(Tuple(Int(), Int()), Int()))
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"])
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"])
272
UNKNOWN_PACKAGE_HASHES = Message("unknown-package-hashes", {
273
"hashes": List(String()),
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)),
291
TEXT_MESSAGE = Message("text-message", {
297
{"greeting": String(),
298
"consistency-error": Bool(),
301
optional=["greeting", "consistency-error", "echo", "sequence"])
303
# The tuples are timestamp, value
304
GRAPH_DATA = KeyDict({"values": List(Tuple(Float(), Float())),
307
CUSTOM_GRAPH = Message("custom-graph", {
308
"data": Dict(Int(), GRAPH_DATA)})
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