Commit ceab32dd authored by Iustin Pop's avatar Iustin Pop
Browse files

Add submit function to lib/

This patch adds function that submit jobs or queries over the unix socket
interface to lib/ The will be used by the scripts instead of the
SubmitOpCode function.

Reviewed-by: ultrotter
parent 498ae1cc
......@@ -34,11 +34,13 @@ from ganeti import errors
from ganeti import mcpu
from ganeti import constants
from ganeti import opcodes
from ganeti import luxi
from optparse import (OptionParser, make_option, TitledHelpFormatter,
Option, OptionValueError, SUPPRESS_HELP)
__all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain", "SubmitOpCode",
__all__ = ["DEBUG_OPT", "NOHDR_OPT", "SEP_OPT", "GenericMain",
"SubmitOpCode", "SubmitJob", "SubmitQuery",
"cli_option", "GenerateTable", "AskUser",
......@@ -386,6 +388,22 @@ def SubmitOpCode(op, proc=None, feedback_fn=None):
return proc.ExecOpCode(op)
def SubmitJob(job, cl=None):
if cl is None:
cl = luxi.Client()
jid = cl.SubmitJob(job)
return jid
def SubmitQuery(data, cl=None):
if cl is None:
cl = luxi.Client()
result = cl.Query(data)
if not result['success']:
raise ValueError(result)
return result['result']
def FormatError(err):
"""Return a formatted error message for a given error.
......@@ -42,6 +42,7 @@ WATCHER_STATEFILE = DATA_DIR + "/"
SSH_KNOWN_HOSTS_FILE = DATA_DIR + "/known_hosts"
ETC_HOSTS = "/etc/hosts"
MASTER_SOCKET = RUN_DIR + "/master.sock"
NODE_INITD_SCRIPT = _autoconf.SYSCONFDIR + "/init.d/ganeti"
......@@ -35,6 +35,7 @@ import simplejson
import time
from ganeti import opcodes
from ganeti import constants
KEY_REQUEST = 'request'
......@@ -216,7 +217,7 @@ class Client(object):
implements data serialization/deserialization.
def __init__(self, address, timeouts=None, transport=Transport):
def __init__(self, address=None, timeouts=None, transport=Transport):
"""Constructor for the Client class.
......@@ -229,6 +230,8 @@ class Client(object):
class are used.
if address is None:
address = constants.MASTER_SOCKET
self.transport = transport(address, timeouts=timeouts)
def SendRequest(self, request, data):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment