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
ACTIVE_PROCESS_INFO = Message(
16
"active-process-info",
17
{"kill-processes": List(Int()),
18
"kill-all-processes": Bool(),
19
"add-processes": List(KeyDict({"pid": Int(),
22
"sleep-average": Int(),
27
# Optional for backwards compatibility
28
optional=["vm-size", "sleep-average"])),
30
# XXX Really we don't want all three of these keys to be optional:
31
# we always want _something_...
32
optional=["add-processes", "kill-processes", "kill-all-processes"])
35
COMPUTER_UPTIME = Message(
37
{"startup-times": List(Int()),
38
"shutdown-times": List(Int())},
39
# XXX Again, one or the other.
40
optional=["startup-times", "shutdown-times"])
42
CLIENT_UPTIME = Message(
44
{"period": Tuple(Float(), Float()),
45
"components": List(Int())},
46
optional=["components"]) # just for backwards compatibility
48
OPERATION_RESULT = Message(
50
{"operation-id": Int(),
54
optional=["result-code", "result-text"])
56
#ACTION_INFO is obsolete.
57
ACTION_INFO = Message(
59
{"response-id": Int(),
62
"parameters": String()})
64
COMPUTER_INFO = Message(
67
"total-memory": Int(),
69
# Not sure why these are all optional, but it's explicitly tested
71
optional=["hostname", "total-memory", "total-swap"])
73
DISTRIBUTION_INFO = Message(
75
{"distributor-id": utf8,
79
# all optional because the lsb-release file may not have all data.
80
optional=["distributor-id", "description", "release", "code-name"])
83
hal_data = Dict(Unicode(),
84
Any(Unicode(), List(Unicode()), Bool(), Int(), Float()))
86
HARDWARE_INVENTORY = Message("hardware-inventory", {
87
"devices": List(Any(Tuple(Constant("create"), hal_data),
88
Tuple(Constant("update"),
93
Tuple(Constant("delete"),
100
LOAD_AVERAGE = Message("load-average", {
101
"load-averages": List(Tuple(Int(), Float())),
105
MEMORY_INFO = Message("memory-info", {
106
"memory-info": List(Tuple(Float(), Int(), Int())),
109
RESYNCHRONIZE = Message(
111
{"operation-id": Int()},
112
# operation-id is only there if it's a response to a server-initiated
114
optional=["operation-id"])
116
MOUNT_ACTIVITY = Message("mount-activity", {
117
"activities": List(Tuple(Float(), utf8, Bool()))
120
MOUNT_INFO = Message("mount-info", {
121
"mount-info": List(Tuple(Float(),
122
KeyDict({"mount-point": utf8,
125
"total-space": Int()}),
129
FREE_SPACE = Message("free-space", {
130
"free-space": List(Tuple(Float(), utf8, Int()))
136
{"registration_password": Any(utf8, Constant(None)),
137
"computer_title": utf8,
139
"account_name": utf8},
140
# hostname wasn't around in old versions
141
optional=["registration_password", "hostname"])
143
TEMPERATURE = Message("temperature", {
144
"thermal-zone": utf8,
145
"temperatures": List(Tuple(Int(), Float())),
148
PROCESSOR_INFO = Message(
150
{"processors": List(KeyDict({"processor-id": Int(),
155
optional=["vendor", "cache-size"])),
158
user_data = KeyDict({
161
"name": Any(utf8, Constant(None)),
163
"location": Any(utf8, Constant(None)),
164
"home-phone": Any(utf8, Constant(None)),
165
"work-phone": Any(utf8, Constant(None)),
166
"primary-gid": Any(Int(), Constant(None)),
167
"primary-groupname": utf8},
168
optional=["primary-groupname", "primary-gid"]
171
group_data = KeyDict({
178
{"operation-id": Int(),
179
"create-users": List(user_data),
180
"update-users": List(user_data),
181
"delete-users": List(utf8),
182
"create-groups": List(group_data),
183
"update-groups": List(group_data),
184
"delete-groups": List(utf8),
185
"create-group-members": Dict(utf8, List(utf8)),
186
"delete-group-members": Dict(utf8, List(utf8)),
188
# operation-id is only there for responses, and all other are
189
# optional as long as one of them is there (no way to say that yet)
190
optional=["operation-id", "create-users", "update-users", "delete-users",
191
"create-groups", "update-groups", "delete-groups",
192
"create-group-members", "delete-group-members"])
196
{"operation-id": Int(),
197
"create-users": List(user_data),
198
"update-users": List(user_data),
199
"delete-users": List(Int()),
200
"create-groups": List(group_data),
201
"update-groups": List(group_data),
202
"delete-groups": List(Int()),
203
"create-group-members": Dict(Int(), List(Int())),
204
"delete-group-members": Dict(Int(), List(Int())),
206
# operation-id is only there for responses, and all other are
207
# optional as long as one of them is there (no way to say that yet)
208
optional=["operation-id", "create-users", "update-users", "delete-users",
209
"create-groups", "update-groups", "delete-groups",
210
"create-group-members", "delete-group-members"])
214
{"operation-id": Int(),
215
"create-users": List(user_data),
216
"update-users": List(user_data),
217
"delete-users": List(Int()),
218
"create-groups": List(group_data),
219
"update-groups": List(group_data),
220
"delete-groups": List(Int()),
221
"create-group-members": Dict(Int(), List(Int())),
222
"delete-group-members": Dict(Int(), List(Int())),
224
# operation-id is only there for responses, and all other are
225
# optional as long as one of them is there (no way to say that yet)
226
optional=["operation-id", "create-users", "update-users", "delete-users",
227
"create-groups", "update-groups", "delete-groups",
228
"create-group-members", "delete-group-members"])
230
opt_str = Any(utf8, Constant(None))
233
{"users": List(KeyDict({"username": utf8,
237
"home-phone": opt_str,
238
"work-phone": opt_str,
240
optional=["location", "home-phone", "work-phone"])),
241
"groups": List(KeyDict({"gid": Int(),
243
"members": List(utf8)}))
247
package_ids_or_ranges = List(Any(Tuple(Int(), Int()), Int()))
250
{"installed": package_ids_or_ranges,
251
"available": package_ids_or_ranges,
252
"available-upgrades": package_ids_or_ranges,
253
"not-installed": package_ids_or_ranges,
254
"not-available": package_ids_or_ranges,
255
"not-available-upgrades": package_ids_or_ranges},
256
optional=["installed", "available", "available-upgrades",
257
"not-available", "not-installed", "not-available-upgrades"])
259
CHANGE_PACKAGES_RESULT = Message(
260
"change-packages-result",
261
{"operation-id": Int(),
262
"must-install": List(Any(Int(), Constant(None))),
263
"must-remove": List(Any(Int(), Constant(None))),
264
"result-code": Int(),
265
"result-text": utf8},
266
optional=["result-text", "must-install", "must-remove"])
268
UNKNOWN_PACKAGE_HASHES = Message("unknown-package-hashes", {
269
"hashes": List(String()),
273
ADD_PACKAGES = Message("add-packages", {
274
"packages": List(KeyDict({"name": utf8,
275
"description": Unicode(),
276
"section": Unicode(),
277
"relations": List(Tuple(Int(), utf8)),
278
"summary": Unicode(),
279
"installed-size": Any(Int(), Constant(None)),
280
"size": Any(Int(), Constant(None)),
287
TEXT_MESSAGE = Message("text-message", {
293
{"greeting": String(),
294
"consistency-error": Bool(),
297
optional=["greeting", "consistency-error", "echo", "sequence"])
300
for schema in [ACTIVE_PROCESS_INFO, COMPUTER_UPTIME, CLIENT_UPTIME,
301
OPERATION_RESULT, COMPUTER_INFO, DISTRIBUTION_INFO,
302
HARDWARE_INVENTORY, LOAD_AVERAGE, MEMORY_INFO,
303
RESYNCHRONIZE, MOUNT_ACTIVITY, MOUNT_INFO, FREE_SPACE,
304
REGISTER, TEMPERATURE, PROCESSOR_INFO, USERS, PACKAGES,
305
CHANGE_PACKAGES_RESULT, UNKNOWN_PACKAGE_HASHES,
306
ADD_PACKAGES, TEXT_MESSAGE, TEST]:
307
message_schemas[schema.type] = schema