1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 """Module for the LUXI protocol
32
33 This module implements the local unix socket protocol. You only need
34 this module and the opcodes module in the client program in order to
35 communicate with the master.
36
37 The module is also used by the master daemon.
38
39 """
40
41 from ganeti import constants
42 from ganeti import objects
43 import ganeti.rpc.client as cl
44 from ganeti.rpc.errors import RequestError
45 from ganeti.rpc.transport import Transport
46
47 __all__ = [
48
49 "Client"
50 ]
51
52 REQ_SUBMIT_JOB = constants.LUXI_REQ_SUBMIT_JOB
53 REQ_SUBMIT_JOB_TO_DRAINED_QUEUE = constants.LUXI_REQ_SUBMIT_JOB_TO_DRAINED_QUEUE
54 REQ_SUBMIT_MANY_JOBS = constants.LUXI_REQ_SUBMIT_MANY_JOBS
55 REQ_PICKUP_JOB = constants.LUXI_REQ_PICKUP_JOB
56 REQ_WAIT_FOR_JOB_CHANGE = constants.LUXI_REQ_WAIT_FOR_JOB_CHANGE
57 REQ_CANCEL_JOB = constants.LUXI_REQ_CANCEL_JOB
58 REQ_ARCHIVE_JOB = constants.LUXI_REQ_ARCHIVE_JOB
59 REQ_CHANGE_JOB_PRIORITY = constants.LUXI_REQ_CHANGE_JOB_PRIORITY
60 REQ_AUTO_ARCHIVE_JOBS = constants.LUXI_REQ_AUTO_ARCHIVE_JOBS
61 REQ_QUERY = constants.LUXI_REQ_QUERY
62 REQ_QUERY_FIELDS = constants.LUXI_REQ_QUERY_FIELDS
63 REQ_QUERY_JOBS = constants.LUXI_REQ_QUERY_JOBS
64 REQ_QUERY_INSTANCES = constants.LUXI_REQ_QUERY_INSTANCES
65 REQ_QUERY_NODES = constants.LUXI_REQ_QUERY_NODES
66 REQ_QUERY_GROUPS = constants.LUXI_REQ_QUERY_GROUPS
67 REQ_QUERY_NETWORKS = constants.LUXI_REQ_QUERY_NETWORKS
68 REQ_QUERY_EXPORTS = constants.LUXI_REQ_QUERY_EXPORTS
69 REQ_QUERY_CONFIG_VALUES = constants.LUXI_REQ_QUERY_CONFIG_VALUES
70 REQ_QUERY_CLUSTER_INFO = constants.LUXI_REQ_QUERY_CLUSTER_INFO
71 REQ_QUERY_TAGS = constants.LUXI_REQ_QUERY_TAGS
72 REQ_SET_DRAIN_FLAG = constants.LUXI_REQ_SET_DRAIN_FLAG
73 REQ_SET_WATCHER_PAUSE = constants.LUXI_REQ_SET_WATCHER_PAUSE
74 REQ_ALL = constants.LUXI_REQ_ALL
75
76 DEF_RWTO = constants.LUXI_DEF_RWTO
77 WFJC_TIMEOUT = constants.LUXI_WFJC_TIMEOUT
78
79
80 -class Client(cl.AbstractClient):
81 """High-level client implementation.
82
83 This uses a backing Transport-like class on top of which it
84 implements data serialization/deserialization.
85
86 """
96
99
102
105
109
113
119
120 @staticmethod
122 try:
123 return int(job_id)
124 except ValueError:
125 raise RequestError("Invalid parameter passed to %s as job id: "
126 " expected integer, got value %s" %
127 (request_name, job_id))
128
132
136
140
144
148 """Waits for changes on a job.
149
150 @param job_id: Job ID
151 @type fields: list
152 @param fields: List of field names to be observed
153 @type prev_job_info: None or list
154 @param prev_job_info: Previously received job information
155 @type prev_log_serial: None or int/long
156 @param prev_log_serial: Highest log serial number previously received
157 @type timeout: int/float
158 @param timeout: Timeout in seconds (values larger than L{WFJC_TIMEOUT} will
159 be capped to that value)
160
161 """
162 assert timeout >= 0, "Timeout can not be negative"
163 return self.CallMethod(REQ_WAIT_FOR_JOB_CHANGE,
164 (job_id, fields, prev_job_info,
165 prev_log_serial,
166 min(WFJC_TIMEOUT, timeout)))
167
176
177 - def Query(self, what, fields, qfilter):
178 """Query for resources/items.
179
180 @param what: One of L{constants.QR_VIA_LUXI}
181 @type fields: List of strings
182 @param fields: List of requested fields
183 @type qfilter: None or list
184 @param qfilter: Query filter
185 @rtype: L{objects.QueryResponse}
186
187 """
188 result = self.CallMethod(REQ_QUERY, (what, fields, qfilter))
189 return objects.QueryResponse.FromDict(result)
190
192 """Query for available fields.
193
194 @param what: One of L{constants.QR_VIA_LUXI}
195 @type fields: None or list of strings
196 @param fields: List of requested fields
197 @rtype: L{objects.QueryFieldsResponse}
198
199 """
200 result = self.CallMethod(REQ_QUERY_FIELDS, (what, fields))
201 return objects.QueryFieldsResponse.FromDict(result)
202
205
208
209 - def QueryNodes(self, names, fields, use_locking):
211
214
217
220
223
226
229