Commit ec3146d1 authored by Marco Mariani's avatar Marco Mariani

cli refactoring: node bang

parent e533396a
...@@ -73,7 +73,8 @@ setup(name=name, ...@@ -73,7 +73,8 @@ setup(name=name,
'slap2 = slapos.cli.entry:main', 'slap2 = slapos.cli.entry:main',
], ],
'slapos.cli': [ 'slapos.cli': [
'cache lookup = slapos.cli.cache:CacheLookup', 'cache lookup = slapos.cli.cache:CacheLookupCommand',
'node bang = slapos.cli.bang:BangCommand',
] ]
}, },
test_suite="slapos.tests", test_suite="slapos.tests",
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# vim: set et sts=2:
############################################################################## ##############################################################################
# #
# Copyright (c) 2011, 2012 Vifib SARL and Contributors. # Copyright (c) 2011, 2012 Vifib SARL and Contributors.
...@@ -31,6 +32,26 @@ import slapos.slap.slap ...@@ -31,6 +32,26 @@ import slapos.slap.slap
import argparse import argparse
import ConfigParser import ConfigParser
def do_bang(config, message):
computer_id = config.get('slapos', 'computer_id')
master_url = config.get('slapos', 'master_url')
if config.has_option('slapos', 'key_file'):
key_file = config.get('slapos', 'key_file')
else:
key_file = None
if config.has_option('slapos', 'cert_file'):
cert_file = config.get('slapos', 'cert_file')
else:
cert_file = None
slap = slapos.slap.slap()
slap.initializeConnection(master_url, key_file=key_file, cert_file=cert_file)
computer = slap.registerComputer(computer_id)
print 'Banging to %r' % master_url
computer.bang(message)
print 'Bang with message %r' % message
def main(*args): def main(*args):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-m", "--message", default='', help="Message for bang.") parser.add_argument("-m", "--message", default='', help="Message for bang.")
...@@ -43,21 +64,6 @@ def main(*args): ...@@ -43,21 +64,6 @@ def main(*args):
configuration_file = argument.configuration_file[0] configuration_file = argument.configuration_file[0]
message = argument.message message = argument.message
# Loads config (if config specified) # Loads config (if config specified)
configuration = ConfigParser.SafeConfigParser() config = ConfigParser.SafeConfigParser()
configuration.readfp(configuration_file) config.readfp(configuration_file)
computer_id = configuration.get('slapos', 'computer_id') do_bang(config, message)
master_url = configuration.get('slapos', 'master_url')
if configuration.has_option('slapos', 'key_file'):
key_file = configuration.get('slapos', 'key_file')
else:
key_file = None
if configuration.has_option('slapos', 'cert_file'):
cert_file = configuration.get('slapos', 'cert_file')
else:
cert_file = None
slap = slapos.slap.slap()
slap.initializeConnection(master_url, key_file=key_file, cert_file=cert_file)
computer = slap.registerComputer(computer_id)
print 'Banging to %r' % master_url
computer.bang(message)
print 'Bang with message %r' % message
# -*- coding: utf-8 -*-
import logging
from slapos.cli.config import ConfigCommand
from slapos.bang import do_bang
class BangCommand(ConfigCommand):
log = logging.getLogger(__name__)
def get_parser(self, prog_name):
parser = super(BangCommand, self).get_parser(prog_name)
parser.add_argument('-m', '--message',
help='Message for bang')
return parser
def take_action(self, args):
config = self.fetch_config(args)
do_bang(config, args.message)
...@@ -6,15 +6,15 @@ from slapos.cli.config import ConfigCommand ...@@ -6,15 +6,15 @@ from slapos.cli.config import ConfigCommand
from slapos.cache import do_lookup from slapos.cache import do_lookup
class CacheLookup(ConfigCommand): class CacheLookupCommand(ConfigCommand):
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def get_parser(self, prog_name): def get_parser(self, prog_name):
parser = super(CacheLookup, self).get_parser(prog_name) parser = super(CacheLookupCommand, self).get_parser(prog_name)
# XXX this argument could use a better name # XXX this argument could use a better name
parser.add_argument("software_url", parser.add_argument('software_url',
help="Your software url or MD5 hash") help='Your software url or MD5 hash')
return parser return parser
def take_action(self, args): def take_action(self, args):
......
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