Commit a99e2e16 authored by Marco Mariani's avatar Marco Mariani

moved supply, request, remove under cli/

parent 46bf6586
......@@ -20,7 +20,7 @@ def looks_like_md5(s):
return re.match('[0-9a-f]{32}', s)
def do_lookup(configp, software_url, logger):
def do_lookup(logger, configp, software_url):
cache_dir = configp.get('networkcache', 'download-binary-dir-url')
if looks_like_md5(software_url):
......
......@@ -27,4 +27,4 @@ class CacheLookupCommand(ConfigCommand):
def take_action(self, args):
configp = self.fetch_config(args)
do_lookup(configp, args.software_url, logger=self.app.log)
do_lookup(self.app.log, configp, args.software_url)
......@@ -3,7 +3,7 @@
import logging
from slapos.cli.config import ClientConfigCommand
from slapos.client import init, do_remove, ClientConfig
from slapos.client import init, ClientConfig
class RemoveCommand(ClientConfigCommand):
......@@ -28,4 +28,21 @@ class RemoveCommand(ClientConfigCommand):
configp = self.fetch_config(args)
conf = ClientConfig(args, configp)
local = init(conf)
do_remove(args.software_url, args.node, local)
do_remove(self.app.log, args.software_url, args.node, local)
def do_remove(logger, software_url, computer_id, local):
"""
Request deletion of Software Release
'software_url' from computer 'computer_id'.
"""
logger.info('Requesting deletion of %s Software Release...', software_url)
if software_url in local:
software_url = local[software_url]
local['slap'].registerSupply().supply(
software_release=software_url,
computer_guid=computer_id,
state='destroyed'
)
logger.info('Done.')
# -*- coding: utf-8 -*-
import logging
import pprint
from slapos.cli.config import ClientConfigCommand
from slapos.client import init, do_request, ClientConfig
from slapos.client import init, ClientConfig
from slapos.slap import ResourceNotReady
def parse_option_dict(options):
......@@ -65,4 +67,28 @@ class RequestCommand(ClientConfigCommand):
conf = ClientConfig(args, configp)
local = init(conf)
do_request(conf, local)
do_request(self.app.log, conf, local)
def do_request(logger, conf, local):
logger.info('Requesting %s...', conf.reference)
if conf.software_url in local:
conf.software_url = local[conf.software_url]
try:
partition = local['slap'].registerOpenOrder().request(
software_release=conf.software_url,
partition_reference=conf.reference,
partition_parameter_kw=conf.parameters,
software_type=conf.type,
filter_kw=conf.node,
state=conf.state,
shared=conf.slave
)
logger.info('Instance requested.\nState is : %s.', partition.getState())
logger.info('Connection parameters of instance are:')
logger.info(pprint.pformat(partition.getConnectionParameterDict()))
logger.info('You can rerun command to get up-to-date informations.')
except ResourceNotReady:
logger.warning('Instance requested. Master is provisioning it. Please rerun in a '
'couple of minutes to get connection informations.')
exit(2)
......@@ -3,7 +3,7 @@
import logging
from slapos.cli.config import ClientConfigCommand
from slapos.client import init, do_supply, ClientConfig
from slapos.client import init, ClientConfig
class SupplyCommand(ClientConfigCommand):
......@@ -28,4 +28,23 @@ class SupplyCommand(ClientConfigCommand):
configp = self.fetch_config(args)
conf = ClientConfig(args, configp)
local = init(conf)
do_supply(args.software_url, args.node, local)
do_supply(self.app.log, args.software_url, args.node, local)
def do_supply(logger, software_url, computer_id, local):
"""
Request installation of Software Release
'software_url' on computer 'computer_id'.
"""
# XXX-Cedric Implement software_group support
# XXX-Cedric Implement computer_group support
logger.info('Requesting installation of %s Software Release...', software_url)
if software_url in local:
software_url = local[software_url]
local['slap'].registerSupply().supply(
software_release=software_url,
computer_guid=computer_id,
state='available'
)
logger.info('Done.')
......@@ -30,10 +30,8 @@
import atexit
import ConfigParser
import os
import pprint
import slapos.slap.slap
from slapos.slap import ResourceNotReady
class ClientConfig(object):
......@@ -72,7 +70,7 @@ class ClientConfig(object):
self.cert_file is None:
raise ValueError("No option 'key_file' and/or 'cert_file'")
else:
setattr(self, 'master_url', master_url)
self.master_url = master_url
if self.key_file:
self.key_file = os.path.expanduser(self.key_file)
......@@ -117,60 +115,6 @@ def init(conf):
return local
def do_request(conf, local):
print("Requesting %s..." % conf.reference)
if conf.software_url in local:
conf.software_url = local[conf.software_url]
try:
partition = local['slap'].registerOpenOrder().request(
software_release=conf.software_url,
partition_reference=conf.reference,
partition_parameter_kw=conf.parameters,
software_type=conf.type,
filter_kw=conf.node,
state=conf.state,
shared=conf.slave
)
print "Instance requested.\nState is : %s." % partition.getState()
print "Connection parameters of instance are:"
pprint.pprint(partition.getConnectionParameterDict())
print "You can rerun command to get up-to-date informations."
except ResourceNotReady:
print("Instance requested. Master is provisioning it. Please rerun in a "
"couple of minutes to get connection informations.")
exit(2)
def do_supply(software_url, computer_id, local, remove=False):
"""
Request installation of Software Release
'software_url' on computer 'computer_id'.
if destroy argument is True, request deletion of Software Release.
"""
# XXX-Cedric Implement software_group support
# XXX-Cedric Implement computer_group support
if not remove:
state = 'available'
print 'Requesting installation of %s Software Release...' % software_url
else:
state = 'destroyed'
print 'Requesting deletion of %s Software Release...' % software_url
if software_url in local:
software_url = local[software_url]
local['slap'].registerSupply().supply(
software_release=software_url,
computer_guid=computer_id,
state=state,
)
print 'Done.'
def do_remove(software_url, node, local):
do_supply(software_url, node, local, remove=True)
def do_console(local):
# try to enable readline with completion and history
try:
......
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