diff --git a/setup.py b/setup.py index 90f5d8fcf05f6cefc2365fff88942212bd67a35d..24ce0ba537da797b8e66b73178b4447449ddd727 100644 --- a/setup.py +++ b/setup.py @@ -83,6 +83,9 @@ setup(name=name, 'node stop = slapos.cli.supervisorctl:SupervisorctlStopCommand', 'node restart = slapos.cli.supervisorctl:SupervisorctlRestartCommand', 'node tail = slapos.cli.supervisorctl:SupervisorctlTailCommand', + 'node report = slapos.cli.slapgrid:ReportCommand', + 'node software = slapos.cli.slapgrid:SoftwareCommand', + 'node instance = slapos.cli.slapgrid:InstanceCommand', 'console = slapos.cli.console:ConsoleCommand', 'supply = slapos.cli.supply:SupplyCommand', 'remove = slapos.cli.remove:RemoveCommand', diff --git a/slapos/cli/slapgrid.py b/slapos/cli/slapgrid.py new file mode 100644 index 0000000000000000000000000000000000000000..ced2f7c61277d971c2510cdd10c6bdc25f1072ba --- /dev/null +++ b/slapos/cli/slapgrid.py @@ -0,0 +1,117 @@ +# -*- coding: utf-8 -*- + +import logging + +from slapos.cli.config import ConfigCommand + +from slapos.grid.utils import setRunning, setFinished +from slapos.grid.slapgrid import (merged_options, check_missing_parameters, check_missing_files, + random_delay, create_slapgrid_object) + + +class SlapgridCommand(ConfigCommand): + + log = logging.getLogger(__name__) + + method_name = NotImplemented + default_pidfile = NotImplemented + + def get_parser(self, prog_name): + ap = super(SlapgridCommand, self).get_parser(prog_name) + + ap.add_argument('--instance-root', + help='The instance root directory location.') + ap.add_argument('--software-root', + help='The software_root directory location.') + ap.add_argument('--master-url', + help='The master server URL. Mandatory.') + ap.add_argument('--computer-id', + help='The computer id defined in the server.') + ap.add_argument('--supervisord-socket', + help='The socket supervisor will use.') + ap.add_argument('--supervisord-configuration-path', + help='The location where supervisord configuration will be stored.') + ap.add_argument('--buildout', default=None, + help='Location of buildout binary.') + ap.add_argument('--pidfile', + help='The location where pidfile will be created.') + ap.add_argument('--key_file', + help='SSL Authorisation key file.') + ap.add_argument('--cert_file', + help='SSL Authorisation certificate file.') + ap.add_argument('--signature_private_key_file', + help='Signature private key file.') + ap.add_argument('--master_ca_file', + help='Root certificate of SlapOS master key.') + ap.add_argument('--certificate_repository_path', + help='Path to directory where downloaded certificates would be stored.') + ap.add_argument('--maximum-periodicity', type=int, default=None, + help='Periodicity at which buildout should be run in instance.') + ap.add_argument('--promise-timeout', type=int, default=3, + help='Promise timeout in seconds.') + ap.add_argument('--now', action='store_true', + help='Launch slapgrid without delay. Default behavior.') + ap.add_argument('--all', action='store_true', + help='Launch slapgrid to process all Softare Releases ' + 'and/or Computer Partitions.') + ap.add_argument('--only-sr', + help='Force the update of a single software release (use url hash), ' + 'even if is already installed. This option will make all others ' + 'sofware releases be ignored.') + ap.add_argument('--only-cp', + help='Update a single or a list of computer partitions ' + '(ie.:slappartX, slappartY), ' + 'this option will make all others computer partitions be ignored.') + return ap + + + def take_action(self, args): + config = self.fetch_config(args) + options = merged_options(args, config) + + # XXX add formatter + # formatter = logging.Formatter(fmt='%(asctime)s %(name)-18s: ' + # '%(levelname)-8s %(message)s', + # datefmt='%Y-%m-%dT%H:%M:%S') + # + # handler.setFormatter(formatter) + + check_missing_parameters(options) + check_missing_files(options) + + # XXX this action is logging twice + + random_delay(options, logger=self.log) + + slapgrid_object = create_slapgrid_object(options, logger=self.log) + + pidfile = options.get('pidfile') or self.default_pidfile + + if pidfile: + setRunning(logger=self.log, pidfile=pidfile) + try: + return getattr(slapgrid_object, self.method_name)() + finally: + if pidfile: + setFinished(pidfile) + + +class SoftwareCommand(SlapgridCommand): + """Hook for entry point to process Software Releases""" + + method_name = 'processSoftwareReleaseList' + default_pidfile = '/opt/slapos/slapgrid-sr.pid' + + +class InstanceCommand(SlapgridCommand): + """Hook for entry point to process Computer Partitions""" + + method_name = 'processComputerPartitionList' + default_pidfile = '/opt/slapos/slapgrid-cp.pid' + + +class ReportCommand(SlapgridCommand): + """Hook for entry point to process Usage Reports""" + + method_name = 'agregateAndSendUsage' + default_pidfile = '/opt/slapos/slapgrid-ur.pid' diff --git a/slapos/cli_legacy/console.py b/slapos/cli_legacy/console.py index 9990f9c076fc5f70d8ad999938e11c986249494c..2bf80122cfa730bdfade85944bd395375f6e7c1e 100644 --- a/slapos/cli_legacy/console.py +++ b/slapos/cli_legacy/console.py @@ -21,7 +21,6 @@ examples : >>> # Fetch instance informations on already launched instance >>> request(kvm, "myuniquekvm").getConnectionParameter("url")""" % sys.argv[0] - ap = argparse.ArgumentParser(usage=usage) ap.add_argument('-u', '--master_url', @@ -48,4 +47,3 @@ examples : config = ClientConfig(args, get_config_parser(args.configuration_file)) local = init(config) do_console(local) - diff --git a/slapos/cli_legacy/entry.py b/slapos/cli_legacy/entry.py index b12eed1fcfc2b39046bc5bf2e100e73c3d430800..ec558c0e5fbac072711772887e96646686382ab1 100644 --- a/slapos/cli_legacy/entry.py +++ b/slapos/cli_legacy/entry.py @@ -61,6 +61,7 @@ class EntryPointNotImplementedError(NotImplementedError): def __init__(self, *args, **kw_args): NotImplementedError.__init__(self, *args, **kw_args) + def checkSlaposCfg(): """ Check if a slapos configuration file was given as a argument. @@ -78,6 +79,7 @@ def checkSlaposCfg(): return True return False + def checkOption(option): """ Check if a given option is already in call line @@ -93,6 +95,7 @@ def checkOption(option): sys.argv = sys.argv + option[1:] return True + def call(fun, config=False, option=None): """ Add missing options to sys.argv @@ -109,6 +112,7 @@ def call(fun, config=False, option=None): fun() sys.exit(0) + def dispatch(command, is_node_command): """ Dispatch to correct SlapOS module. Here we could use introspection to get rid of the big "if" statements, @@ -166,6 +170,7 @@ def dispatch(command, is_node_command): else: return False + def main(): """ Main entry point of SlapOS Node. Used to dispatch commands to python diff --git a/slapos/cli_legacy/request.py b/slapos/cli_legacy/request.py index fe942929825f2c6461dea5af1ec9e35ff7a99ec9..528968105f4352e32084d677abb309bbbcb126c4 100644 --- a/slapos/cli_legacy/request.py +++ b/slapos/cli_legacy/request.py @@ -28,18 +28,18 @@ def request(): ap.add_argument('software_url', help='Your software url') ap.add_argument('--node', - nargs = '*', - help = 'Node request option ' + nargs='*', + help='Node request option ' "'option1=value1 option2=value2'") ap.add_argument('--type', - type = str, - help = 'Define software type to be requested') + type=str, + help='Define software type to be requested') ap.add_argument('--slave', - action = 'store_true', default=False, - help = 'Ask for a slave instance') + action='store_true', default=False, + help='Ask for a slave instance') ap.add_argument('--configuration', - nargs = '*', - help = 'Give your configuration ' + nargs='*', + help='Give your configuration ' "'option1=value1 option2=value2'") args = ap.parse_args() diff --git a/slapos/cli_legacy/slapgrid.py b/slapos/cli_legacy/slapgrid.py index 765b18d6591dba105ac1100ceb842410b2eefebb..6245ebb905db2383a42152497aa912481a86d34e 100644 --- a/slapos/cli_legacy/slapgrid.py +++ b/slapos/cli_legacy/slapgrid.py @@ -6,7 +6,7 @@ import ConfigParser import logging import sys -from slapos.grid.utils import (setRunning, setFinished) +from slapos.grid.utils import setRunning, setFinished from slapos.grid.slapgrid import (merged_options, check_missing_parameters, check_missing_files, random_delay, create_slapgrid_object)