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
1
Merge Requests
1
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
Romain Courteaud
slapos.core
Commits
e4445111
Commit
e4445111
authored
11 years ago
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapproxy: optparse -> argparser
parent
0311e91b
master
20240521_variousimprovements
20240704
20240827
20240905_fixup
20240913
20240914
20240925
20240930
20241004
20241008
20241021
20241106
20241107
20241114
20241127
20241209
20241230
20250108
20250117_beforesquash_newapi
20250121
alain-message
allocation_consistency_instance_node
amarisoft
change_subscription_price
cleanup
cliff-cleanup
crm_fix
customprice
cygwin-link-local
event_attachment
feat/cmmi_cache
feat/openorderbasedsecurity
feat/statuscleanup
feat/testcase
feature/cgroups
feature/format-crumbled
feature/manager-cpuset
feature/option_create_tun
feature/tun-cgroup-cleanup
fix/slapos-ansible
format_loop
hosting_daily_invoice
hotfix/proxy-root-instance
localwip
manager_update_parameter
master-dev
message-box
new-api-master-client
panel_computer_guid
panel_filter_action_dict
py3_fixup
regulatisation_request_for_organisation
seb
slap_tool_less_sql_query
slapos-override-env
slapproxy-connection-parameter
speed_improvement
splitopenorder
subscription_change_request
tomo_fix_slapos_format
tomo_fix_slapos_node_boot
tomo_listbox_update
trigger_allocation_alarm
upgrade_decision_event
usage_report
wip
wip20210701
wip20210819
wip20220131
1.4.27
1.4.26
1.4.25
1.4.24
1.4.23
1.4.22
1.4.21
1.4.20
1.4.19
1.4.17
1.4.16
1.4.15
1.4.14
1.4.12
1.4.11
1.4.10
1.4.9
1.4.8
1.4.7
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.18
1.3.17
1.3.16
1.3.15
1.3.14
1.3.13
1.3.12
1.3.11
1.3.10
1.3.9
1.3.8
1.3.7
1.3.6.3
1.3.6.2
1.3.6.1
1.3.6
1.3.5
1.3.4
1.3.3
1.3.2
1.3.1
1.3.0
1.2.4.1
1.2.4
1.2.3.1
1.2.3
1.2.2
1.2.1
1.2.0
1.1.3
1.1.2
1.1.1
1.1.0
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0rc6
1.0.0rc5
1.0.0rc4
1.0.0rc3
1.0.0-rc1
master-20180917
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
47 deletions
+30
-47
slapos/proxy/__init__.py
slapos/proxy/__init__.py
+30
-47
No files found.
slapos/proxy/__init__.py
View file @
e4445111
...
...
@@ -29,49 +29,13 @@
import
os
import
sys
from
optparse
import
OptionParser
,
Option
import
argparse
import
logging
import
logging.handlers
import
ConfigParser
class
Parser
(
OptionParser
):
"""
Parse all arguments.
"""
def
__init__
(
self
,
usage
=
None
,
version
=
None
):
"""
Initialize all options possibles.
"""
OptionParser
.
__init__
(
self
,
usage
=
usage
,
version
=
version
,
option_list
=
[
Option
(
"-l"
,
"--log_file"
,
help
=
"The path to the log file used by the script."
,
type
=
str
),
Option
(
"-v"
,
"--verbose"
,
default
=
False
,
action
=
"store_true"
,
help
=
"Verbose output."
),
Option
(
"-c"
,
"--console"
,
default
=
False
,
action
=
"store_true"
,
help
=
"Console output."
),
Option
(
"-u"
,
"--database-uri"
,
type
=
str
,
help
=
"URI for sqlite database"
),
])
def
check_args
(
self
):
"""
Check arguments
"""
(
options
,
args
)
=
self
.
parse_args
()
if
len
(
args
)
!=
1
:
self
.
error
(
"Incorrect number of arguments"
)
return
options
,
args
[
0
]
class
Config
:
class
ProxyConfig
(
object
):
def
setConfig
(
self
,
option_dict
,
configuration_file_path
):
"""
Set options given by parameters.
...
...
@@ -94,6 +58,7 @@ class Config:
self
.
logger
=
logging
.
getLogger
(
"slapproxy"
)
self
.
logger
.
setLevel
(
logging
.
INFO
)
if
self
.
console
:
# XXX shouldn't this be default?
self
.
logger
.
addHandler
(
logging
.
StreamHandler
())
if
not
self
.
database_uri
:
...
...
@@ -115,25 +80,43 @@ class Config:
self
.
logger
.
setLevel
(
logging
.
DEBUG
)
self
.
logger
.
debug
(
"Verbose mode enabled."
)
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
():
"Run default configuration."
usage
=
"usage: %s [options] CONFIGURATION_FILE"
%
sys
.
argv
[
0
]
ap
=
argparse
.
ArgumentParser
()
try
:
# Parse arguments
config
=
Config
()
config
.
setConfig
(
*
Parser
(
usage
=
usage
).
check_args
())
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 shouldn't this be deprecated?
ap
.
add_argument
(
'-c'
,
'--console'
,
action
=
'store_true'
,
help
=
'Console output.'
)
ap
.
add_argument
(
'-u'
,
'--database-uri'
,
help
=
'URI for sqlite database'
)
run
(
config
)
ap
.
add_argument
(
'configuration_file'
,
help
=
'path to slapos.cfg'
)
args
=
ap
.
parse_args
()
try
:
conf
=
ProxyConfig
()
conf
.
setConfig
(
args
,
args
.
configuration_file
)
run
(
conf
)
return_code
=
0
except
SystemExit
,
err
:
# Catch exception raise by optparse
except
SystemExit
as
err
:
return_code
=
err
sys
.
exit
(
return_code
)
This diff is collapsed.
Click to expand it.
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