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
bf1ec145
Commit
bf1ec145
authored
Apr 29, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos.xml backup: handle corrupted zip files
Conflicts: slapos/format.py
parent
fec25846
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
3 deletions
+17
-3
slapos/format.py
slapos/format.py
+17
-3
No files found.
slapos/format.py
View file @
bf1ec145
...
@@ -39,12 +39,14 @@ import netifaces
...
@@ -39,12 +39,14 @@ import netifaces
import
os
import
os
import
pwd
import
pwd
import
random
import
random
import
shutil
import
socket
import
socket
import
struct
import
struct
import
subprocess
import
subprocess
import
sys
import
sys
import
threading
import
threading
import
time
import
time
import
traceback
import
zipfile
import
zipfile
import
lxml.etree
import
lxml.etree
...
@@ -262,7 +264,7 @@ class Computer(object):
...
@@ -262,7 +264,7 @@ class Computer(object):
"SlapOS Master. Please make sure computer_id of slapos.cfg looks "
"SlapOS Master. Please make sure computer_id of slapos.cfg looks "
"like 'COMP-123' and is correct.
\
n
Error is : 404 Not Found."
%
error
)
"like 'COMP-123' and is correct.
\
n
Error is : 404 Not Found."
%
error
)
def
dump
(
self
,
path_to_xml
,
path_to_json
):
def
dump
(
self
,
path_to_xml
,
path_to_json
,
logger
):
"""
"""
Dump the computer object to an xml file via xml_marshaller.
Dump the computer object to an xml file via xml_marshaller.
...
@@ -290,7 +292,18 @@ class Computer(object):
...
@@ -290,7 +292,18 @@ class Computer(object):
return
return
if
os
.
path
.
exists
(
path_to_xml
):
if
os
.
path
.
exists
(
path_to_xml
):
try
:
self
.
backup_xml
(
path_to_archive
,
path_to_xml
)
self
.
backup_xml
(
path_to_archive
,
path_to_xml
)
except
:
# might be a corrupted zip file. let's move it out of the way and retry.
shutil
.
move
(
path_to_archive
,
path_to_archive
+
time
.
strftime
(
'_broken_%Y%m%d-%H:%M'
))
try
:
self
.
backup_xml
(
path_to_archive
,
path_to_xml
)
except
:
# give up trying
logger
.
warning
(
"Can't backup %s: %s"
%
(
path_to_xml
,
traceback
.
format_exc
()))
with
open
(
path_to_xml
,
'wb'
)
as
fout
:
with
open
(
path_to_xml
,
'wb'
)
as
fout
:
fout
.
write
(
new_pretty_xml
)
fout
.
write
(
new_pretty_xml
)
...
@@ -1066,7 +1079,8 @@ def do_format(config):
...
@@ -1066,7 +1079,8 @@ def do_format(config):
# Dumping and sending to the erp5 the current configuration
# Dumping and sending to the erp5 the current configuration
if
not
config
.
dry_run
:
if
not
config
.
dry_run
:
computer
.
dump
(
path_to_xml
=
config
.
computer_xml
,
computer
.
dump
(
path_to_xml
=
config
.
computer_xml
,
path_to_json
=
config
.
computer_json
)
path_to_json
=
config
.
computer_json
,
logger
=
config
.
logger
)
config
.
logger
.
info
(
'Posting information to %r'
%
config
.
master_url
)
config
.
logger
.
info
(
'Posting information to %r'
%
config
.
master_url
)
computer
.
send
(
config
)
computer
.
send
(
config
)
config
.
logger
.
info
(
'slapformat successfully prepared computer.'
)
config
.
logger
.
info
(
'slapformat successfully prepared computer.'
)
...
...
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