Revision d8ff0ec1
b/ci/utils.py | ||
---|---|---|
12 | 12 |
import fabric.api as fabric |
13 | 13 |
import subprocess |
14 | 14 |
import tempfile |
15 |
from ConfigParser import ConfigParser, DuplicateSectionError
|
|
15 |
from ConfigParser import ConfigParser |
|
16 | 16 |
|
17 | 17 |
from kamaki.cli import config as kamaki_config |
18 | 18 |
from kamaki.clients.astakos import AstakosClient |
... | ... | |
250 | 250 |
|
251 | 251 |
# Find a build_id to use |
252 | 252 |
if self.build_id is None: |
253 |
# If build_id is given use this, else .. |
|
254 |
# Find a uniq build_id to use |
|
255 |
ids = self.temp_config.sections() |
|
256 |
if ids: |
|
257 |
max_id = int(max(self.temp_config.sections(), key=int)) |
|
258 |
self.build_id = max_id + 1 |
|
259 |
else: |
|
260 |
self.build_id = 1 |
|
261 |
self.logger.debug("New build id \"%s\" was created" |
|
262 |
% _green(self.build_id)) |
|
253 |
self._create_new_build_id() |
|
263 | 254 |
|
264 | 255 |
# Find an image to use |
265 | 256 |
image_id = self._find_image(image) |
... | ... | |
476 | 467 |
else: |
477 | 468 |
self.logger.debug("No ssh keys found") |
478 | 469 |
|
470 |
def _create_new_build_id(self): |
|
471 |
"""Find a uniq build_id to use""" |
|
472 |
with filelocker.lock("%s.lock" % self.temp_config_file, |
|
473 |
filelocker.LOCK_EX): |
|
474 |
# Read temp_config again to get any new entries |
|
475 |
self.temp_config.read(self.temp_config_file) |
|
476 |
|
|
477 |
# Find a uniq build_id to use |
|
478 |
ids = self.temp_config.sections() |
|
479 |
if ids: |
|
480 |
max_id = int(max(self.temp_config.sections(), key=int)) |
|
481 |
self.build_id = max_id + 1 |
|
482 |
else: |
|
483 |
self.build_id = 1 |
|
484 |
self.logger.debug("New build id \"%s\" was created" |
|
485 |
% _green(self.build_id)) |
|
486 |
|
|
487 |
# Create a new section |
|
488 |
self.temp_config.add_section(str(self.build_id)) |
|
489 |
creation_time = \ |
|
490 |
time.strftime("%a, %d %b %Y %X", time.localtime()) |
|
491 |
self.temp_config.set(str(self.build_id), |
|
492 |
"created", str(creation_time)) |
|
493 |
|
|
494 |
# Write changes back to temp config file |
|
495 |
with open(self.temp_config_file, 'wb') as tcf: |
|
496 |
self.temp_config.write(tcf) |
|
497 |
|
|
479 | 498 |
def write_temp_config(self, option, value): |
480 | 499 |
"""Write changes back to config file""" |
481 | 500 |
# Acquire the lock to write to temp_config_file |
... | ... | |
485 | 504 |
# Read temp_config again to get any new entries |
486 | 505 |
self.temp_config.read(self.temp_config_file) |
487 | 506 |
|
488 |
# If build_id section doesn't exist create a new one |
|
489 |
try: |
|
490 |
self.temp_config.add_section(str(self.build_id)) |
|
491 |
creation_time = \ |
|
492 |
time.strftime("%a, %d %b %Y %X", time.localtime()) |
|
493 |
self.temp_config.set(str(self.build_id), |
|
494 |
"created", str(creation_time)) |
|
495 |
except DuplicateSectionError: |
|
496 |
pass |
|
497 | 507 |
self.temp_config.set(str(self.build_id), option, str(value)) |
498 | 508 |
curr_time = time.strftime("%a, %d %b %Y %X", time.localtime()) |
499 | 509 |
self.temp_config.set(str(self.build_id), "modified", curr_time) |
510 |
|
|
511 |
# Write changes back to temp config file |
|
500 | 512 |
with open(self.temp_config_file, 'wb') as tcf: |
501 | 513 |
self.temp_config.write(tcf) |
502 | 514 |
|
Also available in: Unified diff