Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-image-creator
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-image-creator
Commits
c408053f
Commit
c408053f
authored
13 years ago
by
Nikos Skalkotos
Browse files
Options
Downloads
Patches
Plain Diff
Add input options and populate image metadata
Hooray! This is the first release that actually works!
parent
a1a5ca4b
No related branches found
Branches containing commit
Tags
0.7.2
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
image_creator/disk.py
+14
-1
14 additions, 1 deletion
image_creator/disk.py
image_creator/main.py
+77
-10
77 additions, 10 deletions
image_creator/main.py
image_creator/os_type/__init__.py
+4
-3
4 additions, 3 deletions
image_creator/os_type/__init__.py
with
95 additions
and
14 deletions
image_creator/disk.py
+
14
−
1
View file @
c408053f
...
...
@@ -59,7 +59,7 @@ class Disk(object):
def
get_device
(
self
):
"""
Returns a newly created DiskDevice instance.
This instance is a snapshot of the original source media of
the Disk instance.
"""
...
...
@@ -195,7 +195,20 @@ class DiskDevice(object):
start
=
last_partition
[
'
part_start
'
]
/
sector_size
end
=
start
+
(
block_size
*
block_cnt
)
/
sector_size
-
1
self
.
g
.
part_del
(
dev
,
last_partition
[
'
part_num
'
])
self
.
g
.
part_add
(
dev
,
'
p
'
,
start
,
end
)
return
(
end
+
1
)
*
sector_size
def
size
(
self
):
"""
Returns the
"
payload
"
size of the device.
The size returned by this method is the size of the space occupied by
the partitions (including the space before the first partition).
"""
dev
=
self
.
g
.
part_to_dev
(
self
.
root
)
last
=
self
.
g
.
part_list
(
dev
)[
-
1
]
return
last
[
'
part_end
'
]
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
This diff is collapsed.
Click to expand it.
image_creator/main.py
+
77
−
10
View file @
c408053f
...
...
@@ -32,35 +32,102 @@
# or implied, of GRNET S.A.
from
image_creator
import
get_os_class
from
image_creator
import
__version__
as
version
from
image_creator.disk
import
Disk
import
sys
import
os
import
optparse
from
pbs
import
dd
class
FatalError
(
Exception
):
pass
def
check_writable_dir
(
option
,
opt_str
,
value
,
parser
):
if
not
os
.
path
.
isdir
(
value
):
raise
OptionValueError
(
"
%s is not a valid directory name
"
%
value
)
setattr
(
parser
.
values
,
option
.
dest
,
value
)
def
parse_options
(
input_args
):
usage
=
"
Usage: %prog [options] <input_media> <name>
"
parser
=
optparse
.
OptionParser
(
version
=
version
,
usage
=
usage
)
parser
.
add_option
(
"
-o
"
,
"
--outdir
"
,
type
=
"
string
"
,
dest
=
"
outdir
"
,
default
=
"
.
"
,
action
=
"
callback
"
,
callback
=
check_writable_dir
,
help
=
"
Output files to DIR [default: working dir]
"
,
metavar
=
"
DIR
"
)
parser
.
add_option
(
"
-f
"
,
"
--force
"
,
dest
=
"
force
"
,
default
=
False
,
action
=
"
store_true
"
,
help
=
"
Overwrite output files if they exist
"
)
parser
.
add_option
(
"
--no-shrink
"
,
dest
=
"
shrink
"
,
default
=
True
,
help
=
"
Don
'
t shrink any partition before extracting the image
"
,
action
=
"
store_false
"
)
options
,
args
=
parser
.
parse_args
(
input_args
)
if
len
(
args
)
!=
2
:
parser
.
error
(
'
input media or name are missing
'
)
options
.
source
=
args
[
0
]
options
.
name
=
args
[
1
]
if
not
os
.
path
.
exists
(
options
.
source
):
parser
.
error
(
'
Input media is not accessible
'
)
return
options
def
main
():
if
len
(
sys
.
argv
)
!=
3
:
sys
.
exit
(
"
Usage: %s <source> <output_file>
"
%
os
.
path
.
basename
(
sys
.
argv
[
0
]))
source
=
sys
.
argv
[
1
]
dest
=
sys
.
argv
[
2
]
disk
=
Disk
(
source
)
options
=
parse_options
(
sys
.
argv
[
1
:])
if
os
.
geteuid
()
!=
0
:
raise
FatalError
(
"
You must run %s as root
"
\
%
os
.
path
.
basename
(
sys
.
argv
[
0
]))
if
not
options
.
force
:
for
ext
in
(
'
diskdump
'
,
'
meta
'
):
filename
=
"
%s/%s.%s
"
%
(
options
.
outdir
,
options
.
name
,
ext
)
if
os
.
path
.
exists
(
filename
):
raise
FatalError
(
"
Output file %s exists
"
"
(use --force to overwrite it).
"
%
filename
)
disk
=
Disk
(
options
.
source
)
try
:
dev
=
disk
.
get_device
()
dev
.
mount
()
osclass
=
get_os_class
(
dev
.
distro
,
dev
.
ostype
)
image_os
=
osclass
(
dev
.
root
,
dev
.
g
)
metadata
=
image_os
.
get_metadata
()
for
key
in
metadata
.
keys
():
print
"
%s=%s
"
%
(
key
,
metadata
[
key
])
image_os
.
data_cleanup
()
dev
.
umount
()
#dev.shrink()
size
=
options
.
shrink
and
dev
.
shrink
()
or
dev
.
size
()
metadata
[
'
size
'
]
=
str
(
size
//
2
**
20
)
dd
(
'
if=%s
'
%
dev
.
device
,
'
of=%s/%s.%s
'
%
(
options
.
outdir
,
options
.
name
,
'
diskdump
'
),
'
bs=4M
'
,
'
count=%d
'
%
((
size
+
1
)
//
2
**
22
))
f
=
open
(
'
%s/%s.%s
'
%
(
options
.
outdir
,
options
.
name
,
'
meta
'
),
'
w
'
)
for
key
in
metadata
.
keys
():
f
.
write
(
"
%s=%s
\n
"
%
(
key
,
metadata
[
key
]))
f
.
close
()
finally
:
disk
.
cleanup
()
return
0
COLOR_BLACK
=
"
\033
[00m
"
COLOR_RED
=
"
\033
[1;31m
"
if
__name__
==
'
__main__
'
:
main
()
try
:
ret
=
main
()
sys
.
exit
(
ret
)
except
FatalError
as
e
:
print
>>
sys
.
stderr
,
"
\n
%sError: %s%s
\n
"
%
(
COLOR_RED
,
e
,
COLOR_BLACK
)
sys
.
exit
(
1
)
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
This diff is collapsed.
Click to expand it.
image_creator/os_type/__init__.py
+
4
−
3
View file @
c408053f
...
...
@@ -71,9 +71,10 @@ class OSBase(object):
def
get_metadata
(
self
):
"""
Returns some descriptive metadata about the OS.
"""
meta
=
{}
meta
[
"
OSFAMILY
"
]
=
self
.
g
.
inspect_get_type
(
self
.
root
)
meta
[
"
OS
"
]
=
self
.
g
.
inspect_get_distro
(
self
.
root
)
meta
[
"
description
"
]
=
self
.
g
.
inspect_get_product_name
(
self
.
root
)
meta
[
'
ROOT_PARTITION
'
]
=
"
%d
"
%
self
.
g
.
part_to_partnum
(
self
.
root
)
meta
[
'
OSFAMILY
'
]
=
self
.
g
.
inspect_get_type
(
self
.
root
)
meta
[
'
OS
'
]
=
self
.
g
.
inspect_get_distro
(
self
.
root
)
meta
[
'
description
'
]
=
self
.
g
.
inspect_get_product_name
(
self
.
root
)
return
meta
...
...
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