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

Add submit function to lib/cli.py

This patch adds function that submit jobs or queries over the unix socket
interface to lib/cli.py. 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",
"ARGS_NONE", "ARGS_FIXED", "ARGS_ATLEAST", "ARGS_ANY", "ARGS_ONE",
"USEUNITS_OPT", "FIELDS_OPT", "FORCE_OPT",
......@@ -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 + "/watcher.data"
SSH_KNOWN_HOSTS_FILE = DATA_DIR + "/known_hosts"
ETC_HOSTS = "/etc/hosts"
DEFAULT_FILE_STORAGE_DIR = _autoconf.FILE_STORAGE_DIR
MASTER_SOCKET = RUN_DIR + "/master.sock"
NODE_INITD_SCRIPT = _autoconf.SYSCONFDIR + "/init.d/ganeti"
DEFAULT_NODED_PORT = 1811
......
......@@ -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.
Arguments:
......@@ -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