Commit ab4d13bd authored by Nikos Skalkotos's avatar Nikos Skalkotos

Merge branch 'release-0.7'

parents bfccc2ab b677f043
This diff is collapsed.
2014-09-16, v0.7rc3
* Support all QEMU supported disk image formats as input media
* Detect if a Windows input media is sysprepped
* Support VirtIO driver installation in Windows
* Do a major code cleanup
* Fix bugs
2014-06-10, v0.6.2
* Add support for Ubuntu 14.04
* Fix a bug in Windows image creation
......
include image_creator/help/*.rst
include README COPYRIGHT AUTHORS ChangeLog
include README.md COPYRIGHT AUTHORS ChangeLog
recursive-include docs *
prune docs/_build
snf-image-creator
=================
snf-image-creator is a command line tool for creating OS images to be used with
synnefo.
It comes in 2 variants:
* snf-image-creator: A user-friendly dialog-based program
* snf-mkimage: A non-interactive command line program
snf-image-creator
=================
Overview
--------
This is snf-image-creator, a command-line tool for creating OS Images to be
used with Synnefo.
It comes in two variants:
* snf-image-creator: A user-friendly dialog-based program
* snf-mkimage: A non-interactive command-line program
Project Page
------------
Please see the [official Synnefo site](http://www.synnefo.org) and the
[latest snf-image-creator docs](http://www.synnefo.org/docs/snf-image-creator/latest/index.html)
for more information.
Copyright and license
=====================
Copyright (C) 2011-2014 GRNET S.A.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
......@@ -6,7 +6,12 @@
Welcome to snf-image-creator's documentation!
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
snf-image-creator is an image creation tool for `Synnefo <https://code.grnet.gr/projects/synnefo>`_
This is snf-image-creator, a command-line tool for creating OS Images to be
used with `Synnefo <http://www.synnefo.org/>`_.
It comes in two variants:
* snf-image-creator: A user-friendly dialog-based program
* snf-mkimage: A non-interactive command-line program
Contents:
......
......@@ -44,31 +44,37 @@ Add the following line to */etc/apt/sources.list*:
deb http://apt.dev.grnet.gr wheezy/
Add the apt-dev GPG key to the list of trusted keys:
.. code-block:: console
# curl https://dev.grnet.gr/files/apt-grnetdev.pub | apt-key add -
And resynchronize the package index files from their sources:
.. code-block:: console
$ sudo apt-get update
# apt-get update
You should be able to list the package by calling:
.. code-block:: console
$ apt-cache showpkg snf-image-creator
# apt-cache showpkg snf-image-creator
And install the package with this command:
.. code-block:: console
$ apt-get install snf-image-creator
# apt-get install snf-image-creator
Ubuntu
------
For *Ubuntu 12.04 LTS*, *12.10* and *13.04* systems, you can use our official
For *Ubuntu 12.04 LTS* and *14.04 LTS* systems, you can use our official
packages found in *grnet/synnefo* Lauchpad PPA.
Add the synnefo PPA in your system:
Add the Synnefo PPA in your system:
.. code-block:: console
......@@ -77,7 +83,7 @@ Add the synnefo PPA in your system:
If *apt-add-repository* is missing, first install:
*software-properties-common* (Ubuntu 12.10 & 13.04):
*software-properties-common* (Ubuntu 14.04):
.. code-block:: console
......@@ -89,7 +95,7 @@ Or *python-software-properties* (Ubuntu 12.04):
$ sudo apt-get install python-software-properties
After the synnefo repository is set up, you should be able to list
After the Synnefo repository is set up, you should be able to list
snf-image-creator by calling:
.. code-block:: console
......@@ -109,27 +115,27 @@ Install the package by issuing:
Fedora
------
For *Fedora 17* you can use our official packages hosted at the *synnefo*
For *Fedora 20* you can use our official packages hosted at the *synnefo*
repository of the openSUSE Build Service.
Add the *synnefo* repository for *Fedora 17* to *yum*:
Add the *synnefo* repository for *Fedora 20* to *yum*:
.. code-block:: console
$ cd /etc/yum.repos.d
$ wget http://download.opensuse.org/repositories/home:/GRNET:/synnefo/Fedora_17/home:GRNET:synnefo.repo
# cd /etc/yum.repos.d
# wget http://download.opensuse.org/repositories/home:/GRNET:/synnefo/Fedora_20/home:GRNET:synnefo.repo
To list the *snf-image-creator* package use the following command:
.. code-block:: console
$ yum info snf-image-creator
# yum info snf-image-creator
Install the package by issuing:
.. code-block:: console
$ yum install snf-image-creator
# yum install snf-image-creator
CentOS
------
......@@ -141,41 +147,41 @@ Add the *synnefo* repository for *CentOS 6* to the yum repositories list:
.. code-block:: console
$ cd /etc/yum.repos.d
$ wget http://download.opensuse.org/repositories/home:/GRNET:/synnefo/CentOS_CentOS-6/home:GRNET:synnefo.repo
# cd /etc/yum.repos.d
# wget http://download.opensuse.org/repositories/home:/GRNET:/synnefo/CentOS_CentOS-6/home:GRNET:synnefo.repo
Check the `Fedora <#fedora>`_ instructions on how to install the software.
OpenSUSE
openSUSE
--------
For *OpenSUSE 12.3* you can use our official packages hosted at the *synnefo*
repository of the OpenSUSE Build Service.
For *openSUSE 13.1* you can use our official packages hosted at the *Synnefo*
repository of the openSUSE Build Service.
Add the *Virtualization* repository for *OpenSUSE 12.3* to *YaST* with the
Add the *Virtualization* repository for *openSUSE 13.1* to *YaST* with the
*Zypper* package manager:
.. code-block:: console
$ zypper ar -f http://download.opensuse.org/repositories/Virtualization/openSUSE_12.3/Virtualization.repo
# zypper ar -f http://download.opensuse.org/repositories/Virtualization/openSUSE_13.1/Virtualization.repo
Add the *synnefo* repository:
Add the *Synnefo* repository:
.. code-block:: console
$ zypper ar -f http://download.opensuse.org/repositories/home:/GRNET:/synnefo/openSUSE_12.3/home:GRNET:synnefo.repo
# zypper ar -f http://download.opensuse.org/repositories/home:/GRNET:/synnefo/openSUSE_13.1/home:GRNET:synnefo.repo
To list the *snf-image-creator* package use the following command:
.. code-block:: console
$ zypper se snf-image-creator
# zypper se snf-image-creator
Install the package by issuing:
.. code-block:: console
$ zypper in snf-image-creator
# zypper in snf-image-creator
Arch Linux
......@@ -200,13 +206,13 @@ the *yaourt* package:
$ tar -xvf package-query.tar.gz
$ cd package-query
$ makepkg -s
$ pacman -U package-query-<VERSION>-<ARCH>.pkg.tar.xz
$ su -c 'pacman -U package-query-<VERSION>-<ARCH>.pkg.tar.xz'
$ cd ..
$ wget https://aur.archlinux.org/packages/ya/yaourt/yaourt.tar.gz
$ tar -xvf yaourt.tar.gz
$ cd yaourt
$ makepkg -s
$ pacman -U yaourt-<VERSION>-<ARCH>.pkg.tar.xz
$ su -c 'pacman -U yaourt-<VERSION>-<ARCH>.pkg.tar.xz'
Install *snf-image-creator* using yaourt:
......@@ -282,7 +288,7 @@ kamaki Installation
-------------------
Refer to `./kamaki documentation <http://docs.dev.grnet.gr/kamaki/latest/installation.html>`_
for instructions. You may install kamaki from source inside the virtualenv
for instructions. You may install *./kamaki* from source inside the virtualenv
you've created above or by using binary packages if they are available for your
distribution.
......@@ -309,7 +315,7 @@ cloning its git repository:
$ python ./setup.py install
To do the latter, you'll need to have git (http://git-scm.com/) installed.
For ubuntu this can be done using:
For Ubuntu this can be done using:
.. code-block:: console
......
......@@ -23,5 +23,8 @@ Options
show this help message and exit
-l FILE, --logfile=FILE
log all messages to FILE
--no-snapshot
don't snapshot the input media. (THIS IS DANGEROUS AS IT WILL ALTER THE
ORIGINAL MEDIA!!!)
--tmpdir=DIR
create large temporary image files under DIR
......@@ -44,6 +44,9 @@ Options
--no-shrink
don't shrink any partition
--no-snapshot
don't snapshot the input media. (THIS IS DANGEROUS AS IT WILL ALTER THE
ORIGINAL MEDIA!!!)
--no-sysprep
don't perform any system preparation operation
......
......@@ -2,8 +2,12 @@ Overview
^^^^^^^^
snf-image-creator is a simple command-line tool for creating OS images. The
original media the image is created from, can be a block device, a regular
file that represents a hard disk or the host system itself.
original media, the image is created from, can be:
* a block device, representing a hard disk
* a disk image file, representing a hard disk (supports all image file formats
supported by QEMU)
* the host system itself
Snapshotting
============
......@@ -22,7 +26,7 @@ Those operations will:
* Shrink the image
* Clear out sensitive user data (passwords, ssh keys, history files, etc.)
* Prepare the guest OS for being deployed on a virtual environment (change
device names, remove persistent net rules, etc.)
device names, remove persistent net rules, install VirtIO drivers, etc.)
Creation
========
......
This diff is collapsed.
# -*- coding: utf-8 -*-
#
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright (C) 2011-2014 GRNET S.A.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Package for creating images to be used with Synnefo open source cloud
software.
......
# -*- coding: utf-8 -*-
#
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright (C) 2011-2014 GRNET S.A.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""This module hosts the code that performes the host bundling operation. By
"""This module hosts the code that performs the host bundling operation. By
using the create_image method of the BundleVolume class the user can create an
image out of the running system.
"""
......@@ -115,7 +97,7 @@ class BundleVolume(object):
yield FileSystemTableEntry(*entry)
def _get_root_partition(self):
"""Return the fstab entry accosiated with the root filesystem"""
"""Return the fstab entry associated with the root file system"""
for entry in self._read_fstable('/etc/fstab'):
if entry.mpoint == '/':
return entry.dev
......@@ -144,8 +126,8 @@ class BundleVolume(object):
"""Copy the partition table of the host system into the image"""
# Copy the MBR and the space between the MBR and the first partition.
# In msdos partition tables Grub Stage 1.5 is located there.
# In gpt partition tables the Primary GPT Header is there.
# In MSDOS partition tables GRUB Stage 1.5 is located there.
# In GUID partition tables the Primary GPT Header is there.
first_sector = self.disk.getPrimaryPartitions()[0].geometry.start
dd('if=%s' % self.disk.device.path, 'of=%s' % image,
......@@ -195,8 +177,6 @@ class BundleVolume(object):
shrink the partition before that. Make sure it can still host all the
files the corresponding host file system hosts
"""
new_end = self.disk.device.length
image_disk = parted.Disk(parted.Device(image))
is_extended = lambda p: p.type == parted.PARTITION_EXTENDED
......@@ -205,6 +185,7 @@ class BundleVolume(object):
partitions = self._get_partitions(self.disk)
last = partitions[-1]
new_end = last.end
if last.fs == 'linux-swap(v1)':
MB = 2 ** 20
size = (last.end - last.start + 1) * self.disk.device.sectorSize
......@@ -286,7 +267,7 @@ class BundleVolume(object):
try_fail_repeat(dmsetup, 'remove', dev.split('/dev/mapper/')[1])
def _mount(self, target, devs):
"""Mount a list of filesystems in mountpoints relative to target"""
"""Mount a list of file systems in mount points relative to target"""
devs.sort(key=lambda d: d[1])
for dev, mpoint, options in devs:
absmpoint = os.path.abspath(target + mpoint)
......@@ -299,7 +280,7 @@ class BundleVolume(object):
mount(dev, absmpoint)
def _umount_all(self, target):
"""Unmount all filesystems that are mounted under the directory target
"""Umount all file systems that are mounted under the target directory
"""
mpoints = []
for entry in self._read_fstable('/proc/mounts'):
......@@ -312,7 +293,7 @@ class BundleVolume(object):
def _to_exclude(self):
"""Find which directories to exclude during the image copy. This is
accompliced by checking which directories serve as mount points for
accomplished by checking which directories serve as mount points for
virtual file systems
"""
excluded = ['/tmp', '/var/tmp']
......@@ -350,7 +331,7 @@ class BundleVolume(object):
def _replace_uuids(self, target, new_uuid):
"""Replace UUID references in various files. This is needed after
copying system files of the host into a new filesystem
copying system files of the host into a new file system
"""
files = ['/etc/fstab',
......@@ -372,8 +353,8 @@ class BundleVolume(object):
lines = src.readlines()
with open(f, 'w') as dest:
for line in lines:
for i, uuid in new_uuid.items():
line = re.sub(orig[i], uuid, line)
for i, new in new_uuid.items():
line = re.sub(orig[i], new, line)
dest.write(line)
def _create_filesystems(self, image, partitions):
......@@ -413,8 +394,8 @@ class BundleVolume(object):
# Create the file systems
for i, dev in mapped.iteritems():
fs = filesystem[i].fs
self.out.output('Creating %s filesystem on partition %d ... ' %
(fs, i), False)
self.out.output('Creating %s file system on partition %d ... '
% (fs, i), False)
get_command('mkfs.%s' % fs)(*(MKFS_OPTS[fs] + [dev]))
# For ext[234] enable the default mount options
......@@ -455,10 +436,9 @@ class BundleVolume(object):
rsync.archive().hard_links().xattrs().sparse().acls()
rsync.run('/', target, 'host', 'temporary image')
# Create missing mountpoints. Since they are mountpoints, we
# cannot determine the ownership and the mode of the real
# directory. Make them inherit those properties from their
# parent dir
# Create missing mount points. We cannot determine the
# ownership and the mode of the real directory. Make them
# inherit those properties from their parent directory.
for excl in excluded:
dirname = os.path.dirname(excl)
stat = os.stat(dirname)
......@@ -467,7 +447,7 @@ class BundleVolume(object):
os.chown(target + excl, stat.st_uid, stat.st_gid)
# /tmp and /var/tmp are special cases. We exclude then even if
# they aren't mountpoints. Restore their permissions.
# they aren't mount points. Restore their permissions.
for excl in ('/tmp', '/var/tmp'):
if self._is_mpoint(excl):
os.chmod(target + excl, 041777)
......@@ -477,9 +457,9 @@ class BundleVolume(object):
os.chmod(target + excl, stat.st_mode)
os.chown(target + excl, stat.st_uid, stat.st_gid)
# We need to replace the old UUID referencies with the new
# ones in grub configuration files and /etc/fstab for file
# systems that have been recreated.
# We need to replace the old UUID references with the new ones
# in GRUB configuration files and /etc/fstab for file systems
# that have been recreated.
self._replace_uuids(target, new_uuid)
finally:
......@@ -513,7 +493,7 @@ class BundleVolume(object):
ptable = GPTPartitionTable(image)
size = ptable.shrink(size, old_size)
else:
# Alighn to 2048
# Align to 2048
end_sector = ((end_sector + 2047) // 2048) * 2048
size = (end_sector + 1) * self.disk.device.sectorSize
......
This diff is collapsed.
This diff is collapsed.
# -*- coding: utf-8 -*-
#
# Copyright 2012 GRNET S.A. All rights reserved.
# Copyright (C) 2011-2014 GRNET S.A.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Module providing useful functions for the dialog-based version of
snf-image-creator.
"""
import os
import stat
import re
import json
from image_creator.output.dialog import GaugeOutput
from image_creator.util import MD5
from image_creator.kamaki_wrapper import Kamaki
SMALL_WIDTH = 60
WIDTH = 70
def select_file(d, **kwargs):
"""Select a file or directory.
The following optional arguments can be applied:
* init: Initial file path. If this path is valid this will be returned
* ftype: Allowed file types. If the value of this argument is "br" only
block devices and regular files are valid. For a list of available
file types, see here:
http://libguestfs.org/guestfs.3.html#guestfs_readdir
* title: The dialog box title. The default one is: "Please select a file"
* bundle_host: This can be True or False. If this is True, an extra
"Bundle Host" button will be present if the file selection dialog.
"""
type_check = {'b': stat.S_ISBLK, # Block special
'c': stat.S_ISCHR, # Char special
'd': stat.S_ISDIR, # Directory
'f': stat.S_ISFIFO, # FIFO (named pipe)
'l': stat.S_ISLNK, # Symbolic link
'r': stat.S_ISREG, # Regular file
's': stat.S_ISSOCK} # Socket
fname = None if "init" not in kwargs else kwargs['init']
ftype = set(t for t in kwargs['ftype']) if 'ftype' in kwargs else set('r')
title = kwargs['title'] if 'title' in kwargs else 'Please select a file.'
bundle_host = kwargs['bundle_host'] if 'bundle_host' in kwargs else None
extra_button = 1 if bundle_host else 0
for t in ftype:
assert t in type_check, "Invalid ftype: %s" % t
# This is a special case
if bundle_host and fname == os.sep:
return os.sep
default = os.getcwd() + os.sep
while 1:
if fname is not None:
if not os.path.exists(fname):
d.msgbox("The file `%s' you choose does not exist." % fname,
width=SMALL_WIDTH)
else:
mode = os.stat(fname).st_mode
for i in ftype:
if type_check[i](mode):
return fname
if stat.S_ISDIR(mode):
default = fname
else:
d.msgbox("Invalid input.", width=SMALL_WIDTH)
(code, fname) = d.fselect(default, 10, 60, extra_button=extra_button,
title=title, extra_label="Bundle Host")
if code in (d.DIALOG_CANCEL, d.DIALOG_ESC):
return None
elif code == d.DIALOG_EXTRA:
return os.sep
return fname
def update_background_title(session):
"""Update the backgroud title of the dialog page"""
"""Update the background title of the dialog page"""
d = session['dialog']
disk = session['disk']
image = session['image']
......@@ -57,12 +107,11 @@ def update_background_title(session):
MB = 2 ** 20
size = (image.size + MB - 1) // MB
shrinked = 'shrinked' in session and session['shrinked']
postfix = " (shrinked)" if shrinked else ''
postfix = " (shrinked)" if image.os.shrinked else ''
title = "OS: %s, Distro: %s, Size: %dMB%s, Source: %s" % \
(image.ostype, image.distro, size, postfix,
os.path.abspath(disk.source))
(image.ostype.capitalize(), image.distro.capitalize(), size,
postfix, os.path.abspath(disk.source))
d.setBackgroundTitle(title)
......@@ -148,8 +197,7 @@ def extract_image(session):
out.add(gauge)
try:
if "checksum" not in session:
md5 = MD5(out)
session['checksum'] = md5.compute(image.device, image.size)
session['checksum'] = image.md5()
# Extract image file
image.dump(path)
......@@ -177,17 +225,17 @@ def extract_image(session):
return True
def _check_cloud(session, name, description, url, token):
def _check_cloud(session, name, url, token):
"""Checks if the provided info for a cloud are valid"""
d = session['dialog']
regexp = re.compile('^[~@#$:\-\w]+$')
regexp = re.compile(r'^[~@#$:\-\w]+$')
if not re.match(regexp, name):
d.msgbox("Allowed characters for name: a-zA-Z0-9_~@#$:-", width=WIDTH)
return False
if len(url) == 0:
d.msgbox("Url cannot be empty!", width=WIDTH)
d.msgbox("URL cannot be empty!", width=WIDTH)
return False
if len(token) == 0:
......@@ -232,7 +280,7 @@ def add_cloud(session):
url = url.strip()
token = token.strip()
if _check_cloud(session, name, description, url, token):
if _check_cloud(session, name, url, token):
if name in Kamaki.get_clouds().keys():
d.msgbox("A cloud with name `%s' already exists. If you want "
"to edit the existing cloud account, use the edit "
......@@ -277,7 +325,7 @@ def edit_cloud(session, name):
url = url.strip()
token = token.strip()
if _check_cloud(session, name, description, url, token):
if _check_cloud(session, name, url, token):
Kamaki.save_cloud(name, url, token, description)