#
#
-# Copyright (C) 2006, 2007, 2011 Google Inc.
+# Copyright (C) 2006, 2007, 2011, 2012 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
import time
import errno
import logging
-import warnings
+from ganeti import compat
from ganeti import serializer
from ganeti import constants
from ganeti import errors
from ganeti import utils
from ganeti import objects
+from ganeti import pathutils
KEY_METHOD = "method"
REQ_WAIT_FOR_JOB_CHANGE = "WaitForJobChange"
REQ_CANCEL_JOB = "CancelJob"
REQ_ARCHIVE_JOB = "ArchiveJob"
-REQ_AUTOARCHIVE_JOBS = "AutoArchiveJobs"
+REQ_CHANGE_JOB_PRIORITY = "ChangeJobPriority"
+REQ_AUTO_ARCHIVE_JOBS = "AutoArchiveJobs"
REQ_QUERY = "Query"
REQ_QUERY_FIELDS = "QueryFields"
REQ_QUERY_JOBS = "QueryJobs"
REQ_QUERY_INSTANCES = "QueryInstances"
REQ_QUERY_NODES = "QueryNodes"
REQ_QUERY_GROUPS = "QueryGroups"
+REQ_QUERY_NETWORKS = "QueryNetworks"
REQ_QUERY_EXPORTS = "QueryExports"
REQ_QUERY_CONFIG_VALUES = "QueryConfigValues"
REQ_QUERY_CLUSTER_INFO = "QueryClusterInfo"
REQ_QUERY_TAGS = "QueryTags"
-REQ_QUERY_LOCKS = "QueryLocks"
-REQ_QUEUE_SET_DRAIN_FLAG = "SetDrainFlag"
+REQ_SET_DRAIN_FLAG = "SetDrainFlag"
REQ_SET_WATCHER_PAUSE = "SetWatcherPause"
+#: List of all LUXI requests
+REQ_ALL = compat.UniqueFrozenset([
+ REQ_ARCHIVE_JOB,
+ REQ_AUTO_ARCHIVE_JOBS,
+ REQ_CANCEL_JOB,
+ REQ_CHANGE_JOB_PRIORITY,
+ REQ_QUERY,
+ REQ_QUERY_CLUSTER_INFO,
+ REQ_QUERY_CONFIG_VALUES,
+ REQ_QUERY_EXPORTS,
+ REQ_QUERY_FIELDS,
+ REQ_QUERY_GROUPS,
+ REQ_QUERY_INSTANCES,
+ REQ_QUERY_JOBS,
+ REQ_QUERY_NODES,
+ REQ_QUERY_NETWORKS,
+ REQ_QUERY_TAGS,
+ REQ_SET_DRAIN_FLAG,
+ REQ_SET_WATCHER_PAUSE,
+ REQ_SUBMIT_JOB,
+ REQ_SUBMIT_MANY_JOBS,
+ REQ_WAIT_FOR_JOB_CHANGE,
+ ])
+
DEF_CTMO = 10
DEF_RWTO = 60
request[KEY_VERSION] = version
# Serialize the request
- return serializer.DumpJson(request, indent=False)
+ return serializer.DumpJson(request)
def CallLuxiMethod(transport_cb, method, args, version=None):
"""
if address is None:
- address = constants.MASTER_SOCKET
+ address = pathutils.MASTER_SOCKET
self.address = address
self.timeouts = timeouts
self.transport_class = transport
"""Send a generic request and return the response.
"""
+ if not isinstance(args, (list, tuple)):
+ raise errors.ProgrammerError("Invalid parameter passed to CallMethod:"
+ " expected list, got %s" % type(args))
return CallLuxiMethod(self._SendMethodCall, method, args,
version=constants.LUXI_VERSION)
def SetQueueDrainFlag(self, drain_flag):
- return self.CallMethod(REQ_QUEUE_SET_DRAIN_FLAG, drain_flag)
+ return self.CallMethod(REQ_SET_DRAIN_FLAG, (drain_flag, ))
def SetWatcherPause(self, until):
- return self.CallMethod(REQ_SET_WATCHER_PAUSE, [until])
+ return self.CallMethod(REQ_SET_WATCHER_PAUSE, (until, ))
def SubmitJob(self, ops):
ops_state = map(lambda op: op.__getstate__(), ops)
- return self.CallMethod(REQ_SUBMIT_JOB, ops_state)
+ return self.CallMethod(REQ_SUBMIT_JOB, (ops_state, ))
def SubmitManyJobs(self, jobs):
jobs_state = []
for ops in jobs:
jobs_state.append([op.__getstate__() for op in ops])
- return self.CallMethod(REQ_SUBMIT_MANY_JOBS, jobs_state)
+ return self.CallMethod(REQ_SUBMIT_MANY_JOBS, (jobs_state, ))
def CancelJob(self, job_id):
- return self.CallMethod(REQ_CANCEL_JOB, job_id)
+ return self.CallMethod(REQ_CANCEL_JOB, (job_id, ))
def ArchiveJob(self, job_id):
- return self.CallMethod(REQ_ARCHIVE_JOB, job_id)
+ return self.CallMethod(REQ_ARCHIVE_JOB, (job_id, ))
+
+ def ChangeJobPriority(self, job_id, priority):
+ return self.CallMethod(REQ_CHANGE_JOB_PRIORITY, (job_id, priority))
def AutoArchiveJobs(self, age):
timeout = (DEF_RWTO - 1) / 2
- return self.CallMethod(REQ_AUTOARCHIVE_JOBS, (age, timeout))
+ return self.CallMethod(REQ_AUTO_ARCHIVE_JOBS, (age, timeout))
def WaitForJobChangeOnce(self, job_id, fields,
prev_job_info, prev_log_serial,
break
return result
- def Query(self, what, fields, filter_):
+ def Query(self, what, fields, qfilter):
"""Query for resources/items.
@param what: One of L{constants.QR_VIA_LUXI}
@type fields: List of strings
@param fields: List of requested fields
- @type filter_: None or list
- @param filter_: Query filter
+ @type qfilter: None or list
+ @param qfilter: Query filter
@rtype: L{objects.QueryResponse}
"""
- req = objects.QueryRequest(what=what, fields=fields, filter=filter_)
- result = self.CallMethod(REQ_QUERY, req.ToDict())
+ result = self.CallMethod(REQ_QUERY, (what, fields, qfilter))
return objects.QueryResponse.FromDict(result)
def QueryFields(self, what, fields):
@rtype: L{objects.QueryFieldsResponse}
"""
- req = objects.QueryFieldsRequest(what=what, fields=fields)
- result = self.CallMethod(REQ_QUERY_FIELDS, req.ToDict())
+ result = self.CallMethod(REQ_QUERY_FIELDS, (what, fields))
return objects.QueryFieldsResponse.FromDict(result)
def QueryJobs(self, job_ids, fields):
def QueryGroups(self, names, fields, use_locking):
return self.CallMethod(REQ_QUERY_GROUPS, (names, fields, use_locking))
+ def QueryNetworks(self, names, fields, use_locking):
+ return self.CallMethod(REQ_QUERY_NETWORKS, (names, fields, use_locking))
+
def QueryExports(self, nodes, use_locking):
return self.CallMethod(REQ_QUERY_EXPORTS, (nodes, use_locking))
return self.CallMethod(REQ_QUERY_CLUSTER_INFO, ())
def QueryConfigValues(self, fields):
- return self.CallMethod(REQ_QUERY_CONFIG_VALUES, fields)
+ return self.CallMethod(REQ_QUERY_CONFIG_VALUES, (fields, ))
def QueryTags(self, kind, name):
return self.CallMethod(REQ_QUERY_TAGS, (kind, name))
-
- def QueryLocks(self, fields, sync):
- warnings.warn("This LUXI call is deprecated and will be removed, use"
- " Query(\"%s\", ...) instead" % constants.QR_LOCK)
- return self.CallMethod(REQ_QUERY_LOCKS, (fields, sync))