+def MakeParamsDict(opts, params):
+ """Makes params dictionary out of a option set.
+
+ This function returns a dictionary needed for hv or be parameters. But only
+ those fields which provided in the option set. Takes parameters frozensets
+ from constants.
+
+ @type opts: dict
+ @param opts: selected options
+ @type params: frozenset
+ @param params: subset of options
+ @rtype: dict
+ @return: dictionary of options, filtered by given subset.
+
+ """
+ result = {}
+
+ for p in params:
+ try:
+ value = opts[p]
+ except KeyError:
+ continue
+ result[p] = value
+
+ return result
+
+
+def SubmitJob(op, cl=None):
+ """Generic wrapper for submit job, for better http compatibility.
+
+ @type op: list
+ @param op: the list of opcodes for the job
+ @type cl: None or luxi.Client
+ @param cl: optional luxi client to use
+ @rtype: string
+ @return: the job ID
+
+ """
+ try:
+ if cl is None:
+ cl = GetClient()
+ return cl.SubmitJob(op)
+ except errors.JobQueueFull:
+ raise http.HttpServiceUnavailable("Job queue is full, needs archiving")
+ except errors.JobQueueDrainError:
+ raise http.HttpServiceUnavailable("Job queue is drained, cannot submit")
+ except luxi.NoMasterError, err:
+ raise http.HttpBadGateway("Master seems to unreachable: %s" % str(err))
+ except luxi.TimeoutError, err:
+ raise http.HttpGatewayTimeout("Timeout while talking to the master"
+ " daemon. Error: %s" % str(err))
+
+def GetClient():
+ """Geric wrapper for luxi.Client(), for better http compatiblity.
+
+ """
+ try:
+ return luxi.Client()
+ except luxi.NoMasterError, err:
+ raise http.HttpBadGateway("Master seems to unreachable: %s" % str(err))
+
+
+def FeedbackFn(ts, log_type, log_msg): # pylint: disable-msg=W0613
+ """Feedback logging function for http case.
+
+ We don't have a stdout for printing log messages, so log them to the
+ http log at least.
+
+ @param ts: the timestamp (unused)
+
+ """
+ logging.info("%s: %s", log_type, log_msg)
+
+