Add slapos-request entry point, implement it

parent 77d89dbb
...@@ -46,6 +46,7 @@ setup(name=name, ...@@ -46,6 +46,7 @@ setup(name=name,
entry_points={ entry_points={
'console_scripts': [ 'console_scripts': [
'slapconsole = slapos.console:run', 'slapconsole = slapos.console:run',
'slapos-request = slapos.console:request',
'slapformat = slapos.format:main', 'slapformat = slapos.format:main',
'slapgrid = slapos.grid.slapgrid:run', 'slapgrid = slapos.grid.slapgrid:run',
'slapgrid-sr = slapos.grid.slapgrid:runSoftwareRelease', 'slapgrid-sr = slapos.grid.slapgrid:runSoftwareRelease',
......
...@@ -58,10 +58,10 @@ class Parser(OptionParser): ...@@ -58,10 +58,10 @@ class Parser(OptionParser):
Check arguments Check arguments
""" """
(options, args) = self.parse_args() (options, args) = self.parse_args()
if len(args) != 1: #if len(args) != 1:
self.error("Incorrect number of arguments") # self.error("Incorrect number of arguments")
return options, args[0] return options, args
class Config: class Config:
def setConfig(self, option_dict, configuration_file_path): def setConfig(self, option_dict, configuration_file_path):
...@@ -85,25 +85,57 @@ class Config: ...@@ -85,25 +85,57 @@ class Config:
setattr(self, 'master_url', configuration_dict['master_url']) setattr(self, 'master_url', configuration_dict['master_url'])
if not self.master_url: if not self.master_url:
raise ValueError('master-url is required.') raise ValueError('master_url is required.')
def run(): def init(config):
usage = "usage: %s [options] CONFIGURATION_FILE" % sys.argv[0] """Initialize Slap instance, connects to server and create
# Parse arguments aliases to common software releases"""
config = Config()
config.setConfig(*Parser(usage=usage).check_args())
slap = slapos.slap.slap() slap = slapos.slap.slap()
slap.initializeConnection('https://slap.vifib.com', slap.initializeConnection(config.master_url,
key_file=config.key_file, cert_file=config.cert_file) key_file=config.key_file, cert_file=config.cert_file)
local = globals() local = globals().copy()
local['slap'] = slap local['slap'] = slap
alias = config.alias.split('\n') alias = config.alias.split('\n')
software_list = []
for software in alias: for software in alias:
if software is not '': if software is not '':
name, url = software.split(' ') name, url = software.split(' ')
software_list.append(name)
local[name] = url local[name] = url
local['software_list'] = software_list
# XXX-Cedric Maybe we should generate a new OpenOrder for each request? # XXX-Cedric Maybe we should generate a new OpenOrder for each request?
local['request'] = slap.registerOpenOrder().request local['request'] = slap.registerOpenOrder().request
return local
def request():
"""Ran when invoking slapos-request"""
# Parse arguments
usage = "usage: %s [options] CONFIGURATION_FILE" % sys.argv[0]
config = Config()
arguments = Parser(usage=usage).check_args()[1]
config.setConfig(*Parser(usage=usage).check_args())
local = init(config)
# Request instance
# XXX-Cedric : support things like :
# --instance-type std --configuration-size 23 --computer-region europe/france
# XXX-Cedric : add support for xml_parameter
software_url = arguments[1]
partition_reference = arguments[2]
print("Requesting %s..." % software_url)
if software_url in local:
software_url = local[software_url]
local['slap'].registerOpenOrder().request(software_url, partition_reference)
print("done.")
def run():
"""Ran when invoking slapconsole"""
# Parse arguments
usage = "usage: %s [options] CONFIGURATION_FILE" % sys.argv[0]
config = Config()
config.setConfig(*Parser(usage=usage).check_args())
__import__("code").interact(banner="", local=globals()) local = init(config)
__import__("code").interact(banner="", local=local)
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