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
e0732b36
Commit
e0732b36
authored
17 years ago
by
Michael Hanselmann
Browse files
Options
Downloads
Patches
Plain Diff
Remove support for Pickle configuration files
Reviewed-by: iustinp
parent
1c2d87fc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/cfgupgrade
+2
-63
2 additions, 63 deletions
tools/cfgupgrade
with
2 additions
and
63 deletions
tools/cfgupgrade
+
2
−
63
View file @
e0732b36
...
...
@@ -22,8 +22,7 @@
"""
Tool to upgrade the configuration file.
This code handles only the types supported by simplejson. As an example,
"
set
"
is a
"
list
"
. Old Pickle based configurations files are converted to JSON during
the process.
is a
"
list
"
.
"""
...
...
@@ -31,7 +30,6 @@ the process.
import
os
import
os.path
import
sys
import
re
import
optparse
import
tempfile
import
simplejson
...
...
@@ -49,72 +47,13 @@ class Error(Exception):
pass
# {{{ Support for old Pickle files
class
UpgradeDict
(
dict
):
"""
Base class for internal config classes.
"""
def
__setstate__
(
self
,
state
):
self
.
update
(
state
)
def
__getstate__
(
self
):
return
self
.
copy
()
def
FindGlobal
(
module
,
name
):
"""
Wraps Ganeti config classes to internal ones.
This function may only return types supported by simplejson.
"""
if
module
==
"
ganeti.objects
"
:
return
UpgradeDict
elif
module
==
"
__builtin__
"
and
name
==
"
set
"
:
return
list
return
getattr
(
sys
.
modules
[
module
],
name
)
def
ReadPickleFile
(
f
):
"""
Reads an old Pickle configuration.
"""
import
cPickle
loader
=
cPickle
.
Unpickler
(
f
)
loader
.
find_global
=
FindGlobal
return
loader
.
load
()
def
IsPickleFile
(
f
):
"""
Checks whether a file is using the Pickle format.
"""
magic
=
f
.
read
(
128
)
try
:
return
not
re
.
match
(
'
^\s*\{
'
,
magic
)
finally
:
f
.
seek
(
-
len
(
magic
),
1
)
# }}}
def
ReadJsonFile
(
f
):
"""
Reads a JSON file.
"""
return
simplejson
.
load
(
f
)
def
ReadConfig
(
path
):
"""
Reads configuration file.
"""
f
=
open
(
path
,
'
r
'
)
try
:
if
IsPickleFile
(
f
):
return
ReadPickleFile
(
f
)
else
:
return
ReadJsonFile
(
f
)
return
simplejson
.
load
(
f
)
finally
:
f
.
close
()
...
...
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