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
Xiaowu Zhang
slapos.core
Commits
77035bfa
Commit
77035bfa
authored
Apr 23, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cli refactoring: console
parent
b41b981f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
30 deletions
+77
-30
setup.py
setup.py
+1
-0
slapos/cli/config.py
slapos/cli/config.py
+9
-0
slapos/cli/console.py
slapos/cli/console.py
+31
-0
slapos/client.py
slapos/client.py
+36
-30
No files found.
setup.py
View file @
77035bfa
...
@@ -77,6 +77,7 @@ setup(name=name,
...
@@ -77,6 +77,7 @@ setup(name=name,
'node bang = slapos.cli.bang:BangCommand'
,
'node bang = slapos.cli.bang:BangCommand'
,
'node format = slapos.cli.format:FormatCommand'
,
'node format = slapos.cli.format:FormatCommand'
,
'node register = slapos.cli.register:RegisterCommand'
,
'node register = slapos.cli.register:RegisterCommand'
,
'console = slapos.cli.console:ConsoleCommand'
,
]
]
},
},
test_suite
=
"slapos.tests"
,
test_suite
=
"slapos.tests"
,
...
...
slapos/cli/config.py
View file @
77035bfa
...
@@ -10,6 +10,8 @@ class ConfigError(Exception):
...
@@ -10,6 +10,8 @@ class ConfigError(Exception):
pass
pass
class
ConfigCommand
(
Command
):
class
ConfigCommand
(
Command
):
"Base class for commands that require a configuration file"
"Base class for commands that require a configuration file"
...
@@ -61,3 +63,10 @@ class ConfigCommand(Command):
...
@@ -61,3 +63,10 @@ class ConfigCommand(Command):
self
.
log
.
debug
(
'Loading config: %s'
%
cfg_path
)
self
.
log
.
debug
(
'Loading config: %s'
%
cfg_path
)
return
self
.
_get_config
(
cfg_path
,
required
=
True
)
return
self
.
_get_config
(
cfg_path
,
required
=
True
)
class
ClientConfigCommand
(
ConfigCommand
):
# XXX does not fallback to SLAPOS_CONFIGURATION
default_config_var
=
'SLAPOS_CLIENT_CONFIGURATION'
default_config_path
=
'~/.slapos/slapos.cfg'
slapos/cli/console.py
0 → 100644
View file @
77035bfa
# -*- coding: utf-8 -*-
import
logging
from
slapos.cli.config
import
ClientConfigCommand
from
slapos.client
import
init
,
do_console
,
ClientConfig
class
ConsoleCommand
(
ClientConfigCommand
):
"""
slapconsole allows you interact with slap API. You can play with the global
"slap" object and with the global "request" method.
examples :
>>> # Request instance
>>> request(kvm, "myuniquekvm")
>>> # Request software installation on owned computer
>>> supply(kvm, "mycomputer")
>>> # Fetch instance informations on already launched instance
>>> request(kvm, "myuniquekvm").getConnectionParameter("url")
"""
# XXX TODO: docstring is printed without newlines
log
=
logging
.
getLogger
(
__name__
)
def
take_action
(
self
,
args
):
configuration_parser
=
self
.
fetch_config
(
args
)
config
=
ClientConfig
(
args
,
configuration_parser
)
local
=
init
(
config
)
do_console
(
local
)
slapos/client.py
View file @
77035bfa
...
@@ -115,8 +115,18 @@ def check_request_args():
...
@@ -115,8 +115,18 @@ def check_request_args():
return
args
return
args
class
Config
:
def
get_config_parser
(
path
):
def
__init__
(
self
,
option_dict
,
configuration_file_path
=
None
):
configuration_parser
=
ConfigParser
.
SafeConfigParser
()
path
=
os
.
path
.
expanduser
(
path
)
if
not
os
.
path
.
isfile
(
path
):
raise
OSError
(
'Specified configuration file %s does not exist. Exiting.'
%
path
)
configuration_parser
.
read
(
path
)
return
configuration_parser
class
ClientConfig
(
object
):
def
__init__
(
self
,
option_dict
,
configuration_parser
=
None
):
"""
"""
Set options given by parameters.
Set options given by parameters.
"""
"""
...
@@ -124,14 +134,6 @@ class Config:
...
@@ -124,14 +134,6 @@ class Config:
for
option
,
value
in
option_dict
.
__dict__
.
items
():
for
option
,
value
in
option_dict
.
__dict__
.
items
():
setattr
(
self
,
option
,
value
)
setattr
(
self
,
option
,
value
)
# Load configuration file
configuration_parser
=
ConfigParser
.
SafeConfigParser
()
if
configuration_file_path
:
configuration_file_path
=
os
.
path
.
expanduser
(
configuration_file_path
)
if
not
os
.
path
.
isfile
(
configuration_file_path
):
raise
OSError
(
'Specified configuration file %s does not exist.'
' Exiting.'
%
configuration_file_path
)
configuration_parser
.
read
(
configuration_file_path
)
# Merges the arguments and configuration
# Merges the arguments and configuration
try
:
try
:
configuration_dict
=
dict
(
configuration_parser
.
items
(
'slapconsole'
))
configuration_dict
=
dict
(
configuration_parser
.
items
(
'slapconsole'
))
...
@@ -194,7 +196,7 @@ def request():
...
@@ -194,7 +196,7 @@ def request():
# Parse arguments and inititate needed parameters
# Parse arguments and inititate needed parameters
# XXX-Cedric: move argument parsing to main entry point
# XXX-Cedric: move argument parsing to main entry point
options
=
check_request_args
()
options
=
check_request_args
()
config
=
C
onfig
(
options
,
options
.
configuration_file
)
config
=
C
lientConfig
(
options
,
get_config_parser
(
options
.
configuration_file
)
)
local
=
init
(
config
)
local
=
init
(
config
)
# Request instance
# Request instance
print
(
"Requesting %s..."
%
config
.
reference
)
print
(
"Requesting %s..."
%
config
.
reference
)
...
@@ -257,7 +259,7 @@ def supply():
...
@@ -257,7 +259,7 @@ def supply():
help
=
"Target node"
)
help
=
"Target node"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
config
=
C
onfig
(
args
,
args
.
configuration_file
)
config
=
C
lientConfig
(
args
,
get_config_parser
(
args
.
configuration_file
)
)
_supply
(
args
.
software_url
,
args
.
node
,
init
(
config
))
_supply
(
args
.
software_url
,
args
.
node
,
init
(
config
))
def
remove
():
def
remove
():
...
@@ -274,27 +276,11 @@ def remove():
...
@@ -274,27 +276,11 @@ def remove():
help
=
"Target node"
)
help
=
"Target node"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
config
=
C
onfig
(
args
,
args
.
configuration_file
)
config
=
C
lientConfig
(
args
,
get_config_parser
(
args
.
configuration_file
)
)
_supply
(
args
.
software_url
,
args
.
node
,
init
(
config
),
remove
=
True
)
_supply
(
args
.
software_url
,
args
.
node
,
init
(
config
),
remove
=
True
)
def
slapconsole
():
def
do_console
(
local
):
"""Ran when invoking slapconsole"""
# Parse arguments
usage
=
"""usage: %s [options] CONFIGURATION_FILE
slapconsole allows you interact with slap API. You can play with the global
"slap" object and with the global "request" method.
examples :
>>> # Request instance
>>> request(kvm, "myuniquekvm")
>>> # Request software installation on owned computer
>>> supply(kvm, "mycomputer")
>>> # Fetch instance informations on already launched instance
>>> request(kvm, "myuniquekvm").getConnectionParameter("url")"""
%
sys
.
argv
[
0
]
config
=
Config
(
*
Parser
(
usage
=
usage
).
check_args
())
local
=
init
(
config
)
# try to enable readline with completion and history
# try to enable readline with completion and history
try
:
try
:
import
readline
import
readline
...
@@ -317,3 +303,23 @@ examples :
...
@@ -317,3 +303,23 @@ examples :
__import__
(
"code"
).
interact
(
banner
=
""
,
local
=
local
)
__import__
(
"code"
).
interact
(
banner
=
""
,
local
=
local
)
def
slapconsole
():
"""Ran when invoking slapconsole"""
# Parse arguments
usage
=
"""usage: %s [options] CONFIGURATION_FILE
slapconsole allows you interact with slap API. You can play with the global
"slap" object and with the global "request" method.
examples :
>>> # Request instance
>>> request(kvm, "myuniquekvm")
>>> # Request software installation on owned computer
>>> supply(kvm, "mycomputer")
>>> # Fetch instance informations on already launched instance
>>> request(kvm, "myuniquekvm").getConnectionParameter("url")"""
%
sys
.
argv
[
0
]
options
,
configuration_file_path
=
Parser
(
usage
=
usage
).
check_args
()
config
=
ClientConfig
(
options
,
get_config_parser
(
configuration_file_path
))
local
=
init
(
config
)
do_console
(
local
)
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