Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Guillaume Hervier
slapos.core
Commits
ec3146d1
Commit
ec3146d1
authored
Apr 18, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cli refactoring: node bang
parent
e533396a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
24 deletions
+52
-24
setup.py
setup.py
+2
-1
slapos/bang.py
slapos/bang.py
+25
-19
slapos/cli/bang.py
slapos/cli/bang.py
+21
-0
slapos/cli/cache.py
slapos/cli/cache.py
+4
-4
No files found.
setup.py
View file @
ec3146d1
...
@@ -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"
,
...
...
slapos/bang.py
View file @
ec3146d1
# -*- 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,11 +32,31 @@ import slapos.slap.slap
...
@@ -31,11 +32,31 @@ 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."
)
parser
.
add_argument
(
"configuration_file"
,
nargs
=
1
,
type
=
argparse
.
FileType
(),
parser
.
add_argument
(
"configuration_file"
,
nargs
=
1
,
type
=
argparse
.
FileType
(),
help
=
"SlapOS configuration file."
)
help
=
"SlapOS configuration file."
)
if
len
(
args
)
==
0
:
if
len
(
args
)
==
0
:
argument
=
parser
.
parse_args
()
argument
=
parser
.
parse_args
()
else
:
else
:
...
@@ -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
slapos/cli/bang.py
0 → 100644
View file @
ec3146d1
# -*- 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
)
slapos/cli/cache.py
View file @
ec3146d1
...
@@ -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
CacheLookup
Command
(
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
(
CacheLookup
Command
,
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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment