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
Lu Xu
slapos.core
Commits
17740909
Commit
17740909
authored
May 10, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved old entry point for slapproxy
parent
896d98c6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
71 deletions
+86
-71
setup.py
setup.py
+1
-1
slapos/cli_legacy/proxy.py
slapos/cli_legacy/proxy.py
+72
-0
slapos/proxy/__init__.py
slapos/proxy/__init__.py
+13
-70
No files found.
setup.py
View file @
17740909
...
@@ -57,7 +57,7 @@ setup(name=name,
...
@@ -57,7 +57,7 @@ setup(name=name,
'console_scripts'
:
[
'console_scripts'
:
[
# One entry point to control them all
# One entry point to control them all
'slapos-watchdog = slapos.grid.watchdog:main'
,
'slapos-watchdog = slapos.grid.watchdog:main'
,
'slapproxy = slapos.proxy:main'
,
'slapproxy = slapos.
cli_legacy.
proxy:main'
,
'slapproxy-query = slapos.proxy.query:main'
,
'slapproxy-query = slapos.proxy.query:main'
,
'slapos = slapos.cli.entry:main'
,
'slapos = slapos.cli.entry:main'
,
# Deprecated entry points
# Deprecated entry points
...
...
slapos/cli_legacy/proxy.py
0 → 100644
View file @
17740909
# -*- coding: utf-8 -*-
# vim: set et sts=2:
import
argparse
import
ConfigParser
import
logging
import
os
import
sys
from
slapos.proxy
import
ProxyConfig
,
do_proxy
class
UsageError
(
Exception
):
pass
def
main
():
ap
=
argparse
.
ArgumentParser
()
ap
.
add_argument
(
'-l'
,
'--log_file'
,
help
=
'The path to the log file used by the script.'
)
ap
.
add_argument
(
'-v'
,
'--verbose'
,
action
=
'store_true'
,
help
=
'Verbose output.'
)
# XXX not used anymore, deprecated
ap
.
add_argument
(
'-c'
,
'--console'
,
action
=
'store_true'
,
help
=
'Console output.'
)
ap
.
add_argument
(
'-u'
,
'--database-uri'
,
help
=
'URI for sqlite database'
)
ap
.
add_argument
(
'configuration_file'
,
help
=
'path to slapos.cfg'
)
args
=
ap
.
parse_args
()
logger
=
logging
.
getLogger
(
'slapproxy'
)
logger
.
addHandler
(
logging
.
StreamHandler
())
if
args
.
verbose
:
logger
.
setLevel
(
logging
.
DEBUG
)
else
:
logger
.
setLevel
(
logging
.
INFO
)
conf
=
ProxyConfig
(
logger
)
configp
=
ConfigParser
.
SafeConfigParser
()
if
configp
.
read
(
args
.
configuration_file
)
!=
[
args
.
configuration_file
]:
raise
UsageError
(
'Cannot find or parse configuration file: %s'
%
args
.
configuration_file
)
conf
.
mergeConfig
(
args
,
configp
)
if
conf
.
log_file
:
if
not
os
.
path
.
isdir
(
os
.
path
.
dirname
(
conf
.
log_file
)):
raise
ValueError
(
'Please create directory %r to store %r log file'
%
(
os
.
path
.
dirname
(
conf
.
log_file
),
conf
.
log_file
))
file_handler
=
logging
.
FileHandler
(
conf
.
log_file
)
file_handler
.
setFormatter
(
logging
.
Formatter
(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
))
logger
.
addHandler
(
file_handler
)
logger
.
info
(
'Configured logging to file %r'
%
conf
.
log_file
)
conf
.
setConfig
()
try
:
do_proxy
(
conf
=
conf
)
return_code
=
0
except
SystemExit
as
err
:
return_code
=
err
sys
.
exit
(
return_code
)
slapos/proxy/__init__.py
View file @
17740909
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# vim: set et sts=2:
##############################################################################
##############################################################################
#
#
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
# Copyright (c) 2010, 2011, 2012 Vifib SARL and Contributors.
...
@@ -27,91 +28,33 @@
...
@@ -27,91 +28,33 @@
#
#
##############################################################################
##############################################################################
import
os
import
sys
import
argparse
import
logging
import
logging.handlers
import
ConfigParser
class
ProxyConfig
(
object
):
class
ProxyConfig
(
object
):
def
setConfig
(
self
,
option_dict
,
configuration_file_path
):
def
__init__
(
self
,
logger
):
"""
self
.
logger
=
logger
Set options given by parameters.
"""
def
mergeConfig
(
self
,
args
,
configp
):
# Set options parameters
# Set options parameters
for
option
,
value
in
option_dict
.
__dict__
.
items
():
for
option
,
value
in
args
.
__dict__
.
items
():
setattr
(
self
,
option
,
value
)
setattr
(
self
,
option
,
value
)
# Load configuration file
configuration_parser
=
ConfigParser
.
SafeConfigParser
()
configuration_parser
.
read
(
configuration_file_path
)
# Merges the arguments and configuration
# Merges the arguments and configuration
for
section
in
(
"slapproxy"
,
"slapos"
):
for
section
in
(
"slapproxy"
,
"slapos"
):
configuration_dict
=
dict
(
config
uration_parser
.
items
(
section
))
configuration_dict
=
dict
(
config
p
.
items
(
section
))
for
key
in
configuration_dict
:
for
key
in
configuration_dict
:
if
not
getattr
(
self
,
key
,
None
):
if
not
getattr
(
self
,
key
,
None
):
setattr
(
self
,
key
,
configuration_dict
[
key
])
setattr
(
self
,
key
,
configuration_dict
[
key
])
# set up logging
self
.
logger
=
logging
.
getLogger
(
"slapproxy"
)
self
.
logger
.
setLevel
(
logging
.
INFO
)
self
.
logger
.
addHandler
(
logging
.
StreamHandler
())
def
setConfig
(
self
):
if
not
self
.
database_uri
:
if
not
self
.
database_uri
:
raise
ValueError
(
'database-uri is required.'
)
raise
ValueError
(
'database-uri is required.'
)
if
self
.
log_file
:
if
not
os
.
path
.
isdir
(
os
.
path
.
dirname
(
self
.
log_file
)):
raise
ValueError
(
'Please create directory %r to store %r log file'
%
(
os
.
path
.
dirname
(
self
.
log_file
),
self
.
log_file
))
else
:
file_handler
=
logging
.
FileHandler
(
self
.
log_file
)
file_handler
.
setFormatter
(
logging
.
Formatter
(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
))
self
.
logger
.
addHandler
(
file_handler
)
self
.
logger
.
info
(
'Configured logging to file %r'
%
self
.
log_file
)
if
self
.
verbose
:
self
.
logger
.
setLevel
(
logging
.
DEBUG
)
def
run
(
config
):
from
views
import
app
app
.
config
[
'computer_id'
]
=
config
.
computer_id
app
.
config
[
'DATABASE_URI'
]
=
config
.
database_uri
app
.
run
(
host
=
config
.
host
,
port
=
int
(
config
.
port
))
def
main
():
ap
=
argparse
.
ArgumentParser
()
ap
.
add_argument
(
'-l'
,
'--log_file'
,
help
=
'The path to the log file used by the script.'
)
ap
.
add_argument
(
'-v'
,
'--verbose'
,
action
=
'store_true'
,
help
=
'Verbose output.'
)
# XXX not used anymore, deprecated
ap
.
add_argument
(
'-c'
,
'--console'
,
action
=
'store_true'
,
help
=
'Console output.'
)
ap
.
add_argument
(
'-u'
,
'--database-uri'
,
help
=
'URI for sqlite database'
)
ap
.
add_argument
(
'configuration_file'
,
help
=
'path to slapos.cfg'
)
args
=
ap
.
parse_args
()
def
do_proxy
(
conf
):
from
slapos.proxy.views
import
app
app
.
config
[
'computer_id'
]
=
conf
.
computer_id
app
.
config
[
'DATABASE_URI'
]
=
conf
.
database_uri
app
.
run
(
host
=
conf
.
host
,
port
=
int
(
conf
.
port
))
try
:
conf
=
ProxyConfig
()
conf
.
setConfig
(
args
,
args
.
configuration_file
)
run
(
conf
)
return_code
=
0
except
SystemExit
as
err
:
return_code
=
err
sys
.
exit
(
return_code
)
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