Revision ae48a082 image_creator/disk.py
b/image_creator/disk.py | ||
---|---|---|
1 |
#!/usr/bin/env python |
|
1 |
# Copyright 2012 GRNET S.A. All rights reserved. |
|
2 |
# |
|
3 |
# Redistribution and use in source and binary forms, with or |
|
4 |
# without modification, are permitted provided that the following |
|
5 |
# conditions are met: |
|
6 |
# |
|
7 |
# 1. Redistributions of source code must retain the above |
|
8 |
# copyright notice, this list of conditions and the following |
|
9 |
# disclaimer. |
|
10 |
# |
|
11 |
# 2. Redistributions in binary form must reproduce the above |
|
12 |
# copyright notice, this list of conditions and the following |
|
13 |
# disclaimer in the documentation and/or other materials |
|
14 |
# provided with the distribution. |
|
15 |
# |
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR |
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF |
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 |
# POSSIBILITY OF SUCH DAMAGE. |
|
28 |
# |
|
29 |
# The views and conclusions contained in the software and |
|
30 |
# documentation are those of the authors and should not be |
|
31 |
# interpreted as representing official policies, either expressed |
|
32 |
# or implied, of GRNET S.A. |
|
2 | 33 |
|
3 | 34 |
from image_creator.util import get_command |
4 | 35 |
from image_creator import FatalError |
... | ... | |
43 | 74 |
|
44 | 75 |
def _losetup(self, fname): |
45 | 76 |
loop = losetup('-f', '--show', fname) |
46 |
loop = loop.strip() # remove the new-line char |
|
77 |
loop = loop.strip() # remove the new-line char
|
|
47 | 78 |
self._add_cleanup(losetup, '-d', loop) |
48 | 79 |
return loop |
49 | 80 |
|
... | ... | |
109 | 140 |
|
110 | 141 |
|
111 | 142 |
def progress_generator(label=''): |
112 |
position = 0;
|
|
113 |
for i in progress.bar(range(100),label): |
|
143 |
position = 0 |
|
144 |
for i in progress.bar(range(100), label):
|
|
114 | 145 |
if i < position: |
115 | 146 |
continue |
116 | 147 |
position = yield |
117 |
yield #suppress the StopIteration exception
|
|
148 |
yield # suppress the StopIteration exception
|
|
118 | 149 |
|
119 | 150 |
|
120 | 151 |
class DiskDevice(object): |
... | ... | |
136 | 167 |
#self.g.set_verbose(1) |
137 | 168 |
|
138 | 169 |
self.guestfs_enabled = False |
139 |
|
|
170 |
|
|
140 | 171 |
def enable(self): |
141 | 172 |
"""Enable a newly created DiskDevice""" |
142 | 173 |
|
143 | 174 |
self.progressbar = progress_generator("VM lauch: ") |
144 | 175 |
self.progressbar.next() |
145 |
eh = self.g.set_event_callback(self.progress_callback, guestfs.EVENT_PROGRESS) |
|
176 |
eh = self.g.set_event_callback(self.progress_callback, |
|
177 |
guestfs.EVENT_PROGRESS) |
|
146 | 178 |
self.g.launch() |
147 | 179 |
self.guestfs_enabled = True |
148 | 180 |
self.g.delete_event_callback(eh) |
149 | 181 |
if self.progressbar is not None: |
150 | 182 |
self.progressbar.send(100) |
151 | 183 |
self.progressbar = None |
152 |
|
|
184 |
|
|
153 | 185 |
roots = self.g.inspect_os() |
154 | 186 |
if len(roots) == 0: |
155 | 187 |
raise FatalError("No operating system found") |
... | ... | |
174 | 206 |
position = array[2] |
175 | 207 |
total = array[3] |
176 | 208 |
|
177 |
self.progressbar.send((position * 100)//total)
|
|
209 |
self.progressbar.send((position * 100) // total)
|
|
178 | 210 |
|
179 | 211 |
if position == total: |
180 | 212 |
self.progressbar = None |
Also available in: Unified diff