Hey,
Jay pointed out that we want the CLI to support:
$> aeolus-image build --image $image_id
Which would cause the image to be rebuilt using the template and targets from latest build.
Cheers, Mark.
If an empty template is supplied to build_image, we should attempt to build the image using an existing template associated with the image. --- imagefactory/BuildDispatcher.py | 26 +++++++++++++++++++++++++- 1 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/imagefactory/BuildDispatcher.py b/imagefactory/BuildDispatcher.py index f2317d1..0292067 100644 --- a/imagefactory/BuildDispatcher.py +++ b/imagefactory/BuildDispatcher.py @@ -31,7 +31,7 @@ class BuildDispatcher(Singleton): self.warehouse = ImageWarehouse(ApplicationConfiguration().configuration['warehouse'])
def build_image_for_targets(self, image_id, build_id, template, targets, job_cls = BuildJob, *args, **kwargs): - template = Template(template) + template = self._load_template(image_id, build_id, template)
image_id = self._ensure_image(image_id, template) build_id = self._ensure_build(image_id, build_id) @@ -89,15 +89,39 @@ class BuildDispatcher(Singleton): return build_id return self.warehouse.store_build(None, dict(image = image_id))
+ def _load_template(self, image_id, build_id, template): + if not template: + if build_id: + template = self._template_for_build_id(build_id) + if not template and image_id: + template = self._template_for_image_id(image_id) + return Template(template) + + def _latest_build(self, image_id): + return self.warehouse.metadata_for_id_of_type(['latest_build'], image_id, 'image')['latest_build'] + def _latest_unpushed(self, image_id): return self.warehouse.metadata_for_id_of_type(['latest_unpushed'], image_id, 'image')['latest_unpushed']
+ def _target_images_for_build(self, build_id): + return self.warehouse.query("target_image", "$build == "%s"" % (build_id,)) + def _target_image_for_build_and_target(self, build_id, target): return self.warehouse.query("target_image", "$build == "%s" && $target == "%s"" % (build_id, target))[0]
def _template_for_target_image_id(self, target_image_id): return self.warehouse.metadata_for_id_of_type(['template'], target_image_id, 'target_image')['template']
+ def _template_for_build_id(self, build_id): + target_image_ids = self._target_images_for_build(build_id) + return self._template_for_target_image_id(target_image_ids[0]) if target_image_ids else None + + def _template_for_image_id(self, image_id): + build_id = self._latest_build(image_id) + if not build_id: + build_id = self._latest_unpushed(image_id) + return self._template_for_build_id(build_id) if build_id else None + def _is_rhevm_provider(self, provider): rhevm_json = '/etc/rhevm.json' if not os.path.exists(rhevm_json):
ACK
On Jun 15, 2011, at 6:56 AM, Mark McLoughlin wrote:
If an empty template is supplied to build_image, we should attempt to build the image using an existing template associated with the image.
imagefactory/BuildDispatcher.py | 26 +++++++++++++++++++++++++- 1 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/imagefactory/BuildDispatcher.py b/imagefactory/BuildDispatcher.py index f2317d1..0292067 100644 --- a/imagefactory/BuildDispatcher.py +++ b/imagefactory/BuildDispatcher.py @@ -31,7 +31,7 @@ class BuildDispatcher(Singleton): self.warehouse = ImageWarehouse(ApplicationConfiguration().configuration['warehouse'])
def build_image_for_targets(self, image_id, build_id, template, targets, job_cls = BuildJob, *args, **kwargs):
template = Template(template)
template = self._load_template(image_id, build_id, template) image_id = self._ensure_image(image_id, template) build_id = self._ensure_build(image_id, build_id)
@@ -89,15 +89,39 @@ class BuildDispatcher(Singleton): return build_id return self.warehouse.store_build(None, dict(image = image_id))
def _load_template(self, image_id, build_id, template):
if not template:
if build_id:
template = self._template_for_build_id(build_id)
if not template and image_id:
template = self._template_for_image_id(image_id)
return Template(template)
def _latest_build(self, image_id):
return self.warehouse.metadata_for_id_of_type(['latest_build'], image_id, 'image')['latest_build']
def _latest_unpushed(self, image_id): return self.warehouse.metadata_for_id_of_type(['latest_unpushed'], image_id, 'image')['latest_unpushed']
def _target_images_for_build(self, build_id):
return self.warehouse.query("target_image", "$build == \"%s\"" % (build_id,))
def _target_image_for_build_and_target(self, build_id, target): return self.warehouse.query("target_image", "$build == "%s" && $target == "%s"" % (build_id, target))[0]
def _template_for_target_image_id(self, target_image_id): return self.warehouse.metadata_for_id_of_type(['template'], target_image_id, 'target_image')['template']
def _template_for_build_id(self, build_id):
target_image_ids = self._target_images_for_build(build_id)
return self._template_for_target_image_id(target_image_ids[0]) if target_image_ids else None
def _template_for_image_id(self, image_id):
build_id = self._latest_build(image_id)
if not build_id:
build_id = self._latest_unpushed(image_id)
return self._template_for_build_id(build_id) if build_id else None
def _is_rhevm_provider(self, provider): rhevm_json = '/etc/rhevm.json' if not os.path.exists(rhevm_json):
-- 1.7.4.4
If an target list is supplied to build_image, we should attempt to build the image using the targets the image was previously built for. --- imagefactory/BuildDispatcher.py | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/imagefactory/BuildDispatcher.py b/imagefactory/BuildDispatcher.py index 0292067..5e1ac4b 100644 --- a/imagefactory/BuildDispatcher.py +++ b/imagefactory/BuildDispatcher.py @@ -31,6 +31,9 @@ class BuildDispatcher(Singleton): self.warehouse = ImageWarehouse(ApplicationConfiguration().configuration['warehouse'])
def build_image_for_targets(self, image_id, build_id, template, targets, job_cls = BuildJob, *args, **kwargs): + if image_id and not targets: + targets = self._targets_for_image_id(image_id) + template = self._load_template(image_id, build_id, template)
image_id = self._ensure_image(image_id, template) @@ -103,6 +106,18 @@ class BuildDispatcher(Singleton): def _latest_unpushed(self, image_id): return self.warehouse.metadata_for_id_of_type(['latest_unpushed'], image_id, 'image')['latest_unpushed']
+ def _targets_for_build_id(self, build_id): + targets = [] + for target_image_id in self._target_images_for_build(build_id): + targets.append(self.warehouse.metadata_for_id_of_type(['target'], target_image_id, 'target_image')['target']) + return targets + + def _targets_for_image_id(self, image_id): + build_id = self._latest_build(image_id) + if not build_id: + build_id = self._latest_unpushed(image_id) + return self._targets_for_build_id(build_id) if build_id else [] + def _target_images_for_build(self, build_id): return self.warehouse.query("target_image", "$build == "%s"" % (build_id,))
ACK
On Jun 15, 2011, at 6:56 AM, Mark McLoughlin wrote:
If an target list is supplied to build_image, we should attempt to build the image using the targets the image was previously built for.
imagefactory/BuildDispatcher.py | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/imagefactory/BuildDispatcher.py b/imagefactory/BuildDispatcher.py index 0292067..5e1ac4b 100644 --- a/imagefactory/BuildDispatcher.py +++ b/imagefactory/BuildDispatcher.py @@ -31,6 +31,9 @@ class BuildDispatcher(Singleton): self.warehouse = ImageWarehouse(ApplicationConfiguration().configuration['warehouse'])
def build_image_for_targets(self, image_id, build_id, template, targets, job_cls = BuildJob, *args, **kwargs):
if image_id and not targets:
targets = self._targets_for_image_id(image_id)
template = self._load_template(image_id, build_id, template) image_id = self._ensure_image(image_id, template)
@@ -103,6 +106,18 @@ class BuildDispatcher(Singleton): def _latest_unpushed(self, image_id): return self.warehouse.metadata_for_id_of_type(['latest_unpushed'], image_id, 'image')['latest_unpushed']
- def _targets_for_build_id(self, build_id):
targets = []
for target_image_id in self._target_images_for_build(build_id):
targets.append(self.warehouse.metadata_for_id_of_type(['target'], target_image_id, 'target_image')['target'])
return targets
- def _targets_for_image_id(self, image_id):
build_id = self._latest_build(image_id)
if not build_id:
build_id = self._latest_unpushed(image_id)
return self._targets_for_build_id(build_id) if build_id else []
- def _target_images_for_build(self, build_id): return self.warehouse.query("target_image", "$build == "%s"" % (build_id,))
-- 1.7.4.4
--- imgfac.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/imgfac.py b/imgfac.py index 0a7562a..daa6e71 100755 --- a/imgfac.py +++ b/imgfac.py @@ -147,7 +147,7 @@ class Application(Singleton): self.app_config['foreground'] = True self.setup_logging()
- if (self.app_config['template'] and self.app_config['target']): + if (self.app_config['template'] and self.app_config['target']) or (self.app_config['image'] and not self.app_config['provider']): dispatchers = BuildDispatcher().build_image_for_targets(self.app_config['image'], None, self.app_config['template'], self.app_config['target']) for dispatcher in dispatchers: print("Building build %s of image %s to target %s" % (dispatcher.build_id, dispatcher.image_id, dispatcher.target))
ACK
On Jun 15, 2011, at 6:56 AM, Mark McLoughlin wrote:
imgfac.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/imgfac.py b/imgfac.py index 0a7562a..daa6e71 100755 --- a/imgfac.py +++ b/imgfac.py @@ -147,7 +147,7 @@ class Application(Singleton): self.app_config['foreground'] = True self.setup_logging()
if (self.app_config['template'] and self.app_config['target']):
if (self.app_config['template'] and self.app_config['target']) or (self.app_config['image'] and not self.app_config['provider']): dispatchers = BuildDispatcher().build_image_for_targets(self.app_config['image'], None, self.app_config['template'], self.app_config['target']) for dispatcher in dispatchers: print("Building build %s of image %s to target %s" % (dispatcher.build_id, dispatcher.image_id, dispatcher.target))
-- 1.7.4.4
aeolus-devel@lists.fedorahosted.org