Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-ganeti
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
itminedu
snf-ganeti
Commits
16a8967d
Commit
16a8967d
authored
16 years ago
by
Michael Hanselmann
Browse files
Options
Downloads
Patches
Plain Diff
rapi: Convert to new HTTP server class
Requests are no longer logged to a separate file. Reviewed-by: amishchenko
parent
c5e2d3b9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
daemons/ganeti-rapi
+20
-42
20 additions, 42 deletions
daemons/ganeti-rapi
lib/constants.py
+0
-1
0 additions, 1 deletion
lib/constants.py
lib/rapi/baserlib.py
+1
-3
1 addition, 3 deletions
lib/rapi/baserlib.py
with
21 additions
and
46 deletions
daemons/ganeti-rapi
+
20
−
42
View file @
16a8967d
...
...
@@ -32,58 +32,42 @@ from ganeti import logger
from
ganeti
import
constants
from
ganeti
import
errors
from
ganeti
import
http
from
ganeti
import
daemon
from
ganeti
import
ssconf
from
ganeti
import
utils
from
ganeti.rapi
import
connector
class
R
ESTRequestHandler
(
http
.
HTTPRequestHandl
er
):
class
R
emoteApiHttpServer
(
http
.
HttpServ
er
):
"""
REST Request Handler Class.
"""
def
setup
(
self
):
super
(
RESTRequestHandler
,
self
).
setup
(
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
http
.
HttpServer
.
__init__
(
self
,
*
args
,
**
kwargs
)
self
.
_resmap
=
connector
.
Mapper
()
def
HandleRequest
(
self
):
"""
Hand
e
ls a request.
def
HandleRequest
(
self
,
req
):
"""
Handl
e
s a request.
"""
(
HandlerClass
,
items
,
args
)
=
self
.
_resmap
.
getController
(
self
.
path
)
handler
=
HandlerClass
(
self
,
items
,
args
,
self
.
post_data
)
(
HandlerClass
,
items
,
args
)
=
self
.
_resmap
.
getController
(
req
.
request_
path
)
handler
=
HandlerClass
(
items
,
args
,
req
.
request_
post_data
)
command
=
self
.
comman
d
.
upper
()
method
=
req
.
request_metho
d
.
upper
()
try
:
fn
=
getattr
(
handler
,
comman
d
)
fn
=
getattr
(
handler
,
metho
d
)
except
AttributeError
,
err
:
raise
http
.
HTTPBadRequest
()
try
:
try
:
result
=
fn
()
except
:
logging
.
exception
(
"
Error while handling the %s request
"
,
command
)
raise
except
errors
.
OpPrereqError
,
err
:
# TODO: "Not found" is not always the correct error. Ganeti's core must
# differentiate between different error types.
raise
http
.
HTTPNotFound
(
message
=
str
(
err
))
result
=
fn
()
except
:
logging
.
exception
(
"
Error while handling the %s request
"
,
method
)
raise
return
result
class
RESTHttpServer
(
http
.
HTTPServer
):
def
serve_forever
(
self
):
"""
Handle one request at a time until told to quit.
"""
sighandler
=
utils
.
SignalHandler
([
signal
.
SIGINT
,
signal
.
SIGTERM
])
try
:
while
not
sighandler
.
called
:
self
.
handle_request
()
finally
:
sighandler
.
Reset
()
def
ParseOptions
():
"""
Parse the command line options.
...
...
@@ -144,22 +128,16 @@ def main():
stderr_logging
=
not
options
.
fork
)
utils
.
WritePidFile
(
constants
.
RAPI_PID
)
log_fd
=
open
(
constants
.
LOG_RAPIACCESS
,
'
a
'
)
try
:
apache_log
=
http
.
ApacheLogfile
(
log_fd
)
httpd
=
REST
HttpServer
((
""
,
options
.
port
)
,
RESTRequestHandler
,
httplog
=
apache_log
)
mainloop
=
daemon
.
Mainloop
(
)
server
=
RemoteApi
HttpServer
(
mainloop
,
(
""
,
options
.
port
)
)
server
.
Start
(
)
try
:
httpd
.
serve_forever
()
mainloop
.
Run
()
finally
:
httpd
.
server_close
()
utils
.
RemovePidFile
(
constants
.
RAPI_PID
)
server
.
Stop
()
finally
:
log_fd
.
close
()
sys
.
exit
(
0
)
utils
.
RemovePidFile
(
constants
.
RAPI_PID
)
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
lib/constants.py
+
0
−
1
View file @
16a8967d
...
...
@@ -127,7 +127,6 @@ LOG_NODESERVER = LOG_DIR + "node-daemon.log"
LOG_WATCHER
=
LOG_DIR
+
"
watcher.log
"
LOG_MASTERDAEMON
=
LOG_DIR
+
"
master-daemon.log
"
LOG_RAPISERVER
=
LOG_DIR
+
"
rapi-daemon.log
"
LOG_RAPIACCESS
=
LOG_DIR
+
"
rapi-access.log
"
LOG_COMMANDS
=
LOG_DIR
+
"
commands.log
"
LOG_BURNIN
=
LOG_DIR
+
"
burnin.log
"
...
...
This diff is collapsed.
Click to expand it.
lib/rapi/baserlib.py
+
1
−
3
View file @
16a8967d
...
...
@@ -126,16 +126,14 @@ class R_Generic(object):
"""
Generic class for resources.
"""
def
__init__
(
self
,
request
,
items
,
queryargs
,
post_data
):
def
__init__
(
self
,
items
,
queryargs
,
post_data
):
"""
Generic resource constructor.
Args:
request: HTTPRequestHandler object
items: a list with variables encoded in the URL
queryargs: a dictionary with additional options from URL
"""
self
.
request
=
request
self
.
items
=
items
self
.
queryargs
=
queryargs
self
.
post_data
=
post_data
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment