~ack/landscape-client/sources.list-preserve-old-permissions

« back to all changes in this revision

Viewing changes to landscape/message_schemas.py

  • Committer: Christopher Armstrong
  • Date: 2008-06-10 10:56:01 UTC
  • Revision ID: radix@twistedmatrix.com-20080610105601-l9qfvqjf88e7j8b6
Import landscape-client into public branch

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
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(),
 
20
                                    "name": utf8,
 
21
                                    "state": String(),
 
22
                                    "sleep-average": Int(),
 
23
                                    "uid": Int(),
 
24
                                    "gid": Int(),
 
25
                                    "vm-size": Int(),
 
26
                                    "start-time": Int()},
 
27
                                   # Optional for backwards compatibility
 
28
                                   optional=["vm-size", "sleep-average"])),
 
29
     },
 
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"])
 
33
 
 
34
 
 
35
COMPUTER_UPTIME = Message(
 
36
    "computer-uptime",
 
37
    {"startup-times": List(Int()),
 
38
     "shutdown-times": List(Int())},
 
39
    # XXX Again, one or the other.
 
40
    optional=["startup-times", "shutdown-times"])
 
41
 
 
42
CLIENT_UPTIME = Message(
 
43
    "client-uptime",
 
44
    {"period": Tuple(Float(), Float()),
 
45
     "components": List(Int())},
 
46
    optional=["components"]) # just for backwards compatibility
 
47
 
 
48
OPERATION_RESULT = Message(
 
49
    "operation-result",
 
50
    {"operation-id": Int(),
 
51
     "status": Int(),
 
52
     "result-code": Int(),
 
53
     "result-text": utf8},
 
54
    optional=["result-code", "result-text"])
 
55
 
 
56
#ACTION_INFO is obsolete.
 
57
ACTION_INFO = Message(
 
58
    "action-info",
 
59
    {"response-id": Int(),
 
60
     "success": Bool(),
 
61
     "kind": String(),
 
62
     "parameters": String()})
 
63
 
 
64
COMPUTER_INFO = Message(
 
65
    "computer-info",
 
66
    {"hostname": utf8,
 
67
     "total-memory": Int(),
 
68
     "total-swap": Int()},
 
69
    # Not sure why these are all optional, but it's explicitly tested
 
70
    # in the server
 
71
    optional=["hostname", "total-memory", "total-swap"])
 
72
 
 
73
DISTRIBUTION_INFO = Message(
 
74
    "distribution-info",
 
75
    {"distributor-id": utf8,
 
76
     "description": utf8,
 
77
     "release": utf8,
 
78
     "code-name": utf8},
 
79
    # all optional because the lsb-release file may not have all data.
 
80
    optional=["distributor-id", "description", "release", "code-name"])
 
81
 
 
82
 
 
83
hal_data = Dict(Unicode(),
 
84
                Any(Unicode(), List(Unicode()), Bool(), Int(), Float()))
 
85
 
 
86
HARDWARE_INVENTORY = Message("hardware-inventory", {
 
87
    "devices": List(Any(Tuple(Constant("create"), hal_data),
 
88
                        Tuple(Constant("update"),
 
89
                              Unicode(), # udi,
 
90
                              hal_data, # creates,
 
91
                              hal_data, # updates,
 
92
                              hal_data), # deletes
 
93
                        Tuple(Constant("delete"),
 
94
                              Unicode()),
 
95
                        ),
 
96
                    )
 
97
    })
 
98
 
 
99
 
 
100
LOAD_AVERAGE = Message("load-average", {
 
101
    "load-averages": List(Tuple(Int(), Float())),
 
102
    })
 
103
 
 
104
 
 
105
MEMORY_INFO = Message("memory-info", {
 
106
    "memory-info": List(Tuple(Float(), Int(), Int())),
 
107
    })
 
108
 
 
109
RESYNCHRONIZE = Message(
 
110
    "resynchronize",
 
111
    {"operation-id": Int()},
 
112
    # operation-id is only there if it's a response to a server-initiated
 
113
    # resynchronize.
 
114
    optional=["operation-id"])
 
115
 
 
116
MOUNT_ACTIVITY = Message("mount-activity", {
 
117
    "activities": List(Tuple(Float(), utf8, Bool()))
 
118
    })
 
119
 
 
120
MOUNT_INFO = Message("mount-info", {
 
121
    "mount-info": List(Tuple(Float(),
 
122
                             KeyDict({"mount-point": utf8,
 
123
                                      "device": utf8,
 
124
                                      "filesystem": utf8,
 
125
                                      "total-space": Int()}),
 
126
                             )),
 
127
    })
 
128
 
 
129
FREE_SPACE = Message("free-space", {
 
130
    "free-space": List(Tuple(Float(), utf8, Int()))
 
131
    })
 
132
 
 
133
 
 
134
REGISTER = Message(
 
135
    "register",
 
136
    {"registration_password": Any(utf8, Constant(None)),
 
137
     "computer_title": utf8,
 
138
     "hostname": utf8,
 
139
     "account_name": utf8},
 
140
    # hostname wasn't around in old versions
 
141
    optional=["registration_password", "hostname"])
 
142
 
 
143
TEMPERATURE = Message("temperature", {
 
144
    "thermal-zone": utf8,
 
145
    "temperatures": List(Tuple(Int(), Float())),
 
146
    })
 
147
 
 
148
PROCESSOR_INFO = Message(
 
149
    "processor-info",
 
150
    {"processors": List(KeyDict({"processor-id": Int(),
 
151
                                 "vendor": utf8,
 
152
                                 "model": utf8,
 
153
                                 "cache-size": Int(),
 
154
                                 },
 
155
                                optional=["vendor", "cache-size"])),
 
156
    })
 
157
 
 
158
user_data = KeyDict({
 
159
    "uid": Int(),
 
160
    "username": utf8,
 
161
    "name": Any(utf8, Constant(None)),
 
162
    "enabled": Bool(),
 
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"]
 
169
    )
 
170
 
 
171
group_data = KeyDict({
 
172
    "gid": Int(),
 
173
    "name": utf8
 
174
    })
 
175
 
 
176
USERS = Message(
 
177
    "users",
 
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)),
 
187
     },
 
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"])
 
193
 
 
194
USERS_2_1 = Message(
 
195
    "users",
 
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())),
 
205
     },
 
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"])
 
211
 
 
212
USERS_2_0 = Message(
 
213
    "users",
 
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())),
 
223
     },
 
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"])
 
229
 
 
230
opt_str = Any(utf8, Constant(None))
 
231
OLD_USERS = Message(
 
232
    "users",
 
233
    {"users": List(KeyDict({"username": utf8,
 
234
                            "uid": Int(),
 
235
                            "realname": opt_str,
 
236
                            "location": opt_str,
 
237
                            "home-phone": opt_str,
 
238
                            "work-phone": opt_str,
 
239
                            "enabled": Bool()},
 
240
                           optional=["location", "home-phone", "work-phone"])),
 
241
     "groups": List(KeyDict({"gid": Int(),
 
242
                             "name": utf8,
 
243
                             "members": List(utf8)}))
 
244
     },
 
245
    optional=["groups"])
 
246
 
 
247
package_ids_or_ranges = List(Any(Tuple(Int(), Int()), Int()))
 
248
PACKAGES = Message(
 
249
    "packages",
 
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"])
 
258
 
 
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"])
 
267
 
 
268
UNKNOWN_PACKAGE_HASHES = Message("unknown-package-hashes", {
 
269
    "hashes": List(String()),
 
270
    "request-id": Int(),
 
271
    })
 
272
 
 
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)),
 
281
                              "version": utf8,
 
282
                              "type": Int(),
 
283
                              })),
 
284
    "request-id": Int(),
 
285
    })
 
286
 
 
287
TEXT_MESSAGE = Message("text-message", {
 
288
    "message": Unicode()
 
289
    })
 
290
 
 
291
TEST = Message(
 
292
    "test",
 
293
    {"greeting": String(),
 
294
     "consistency-error": Bool(),
 
295
     "echo": String(),
 
296
     "sequence": Int()},
 
297
    optional=["greeting", "consistency-error", "echo", "sequence"])
 
298
 
 
299
message_schemas = {}
 
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