I updated my existing objects in IWHD by doing e.g.
$> cat > update.js <<EOF
db.main.update({ _bucket : "images" }, { \$set: { _bucket :
"target_images" } }, false, true)
db.main.update({ _bucket : "images", object_type : "image" }, {
\$set: { object_type : "target_image" } }, false, true)
db.main.find({ _bucket : "provider_images", object_type :
"provider_image" }).forEach(function upd(pi) { pi.target_image=pi.image;
db.main.save(pi); })
db.main.update({ _bucket : "provider_images", object_type :
"provider_image" }, { \$unset: { image : 1 } }, false, true)
EOF
$> mongo --port 27018 repo update.js
$> mv _fs/images _fs/provider_images
---
Documentation/man/imgfac.1 | 6 +-
imagefactory.conf | 2 +-
imagefactory/ApplicationConfiguration.py | 4 +-
imagefactory/BuildDispatcher.py | 4 +-
imagefactory/ImageWarehouse.py | 33 ++++++-------
imagefactory/Template.py | 6 +-
imagefactory/builders/BaseBuilder.py | 4 +-
imagefactory/builders/FedoraBuilder.py | 76 +++++++++++++++---------------
imagefactory/builders/IBuilder.py | 2 +-
imagefactory/builders/MockBuilder.py | 8 ++--
imagefactory/qmfagent/ImageFactory.py | 8 ++-
tests/testImageWarehouse.py | 34 +++++++-------
tests/testTemplate.py | 2 +-
13 files changed, 95 insertions(+), 94 deletions(-)
diff --git a/Documentation/man/imgfac.1 b/Documentation/man/imgfac.1
index 366c629..137fbd9 100644
--- a/Documentation/man/imgfac.1
+++ b/Documentation/man/imgfac.1
@@ -12,7 +12,7 @@ Currently supported private cloud services: RHEV-M, KVM.
.B [imgdir IMGDIR] [--timeout TIMEOUT] [--qmf] [--qpidd QPIDD]
.B [--template TEMPLATE] [--target TARGET] [--image IMAGE]
.B [--provider PROVIDER] [--credentials CREDENTIALS]
-.B [--warehouse WAREHOUSE] [--image_bucket IMAGE_BUCKET]
+.B [--warehouse WAREHOUSE] [--target_bucket TARGET_BUCKET]
.B [--template_bucket TEMPLATE_BUCKET]
.B [--icicle_bucket ICICLE_BUCKET]
.B [--provider_bucket PROVIDER_BUCKET]
@@ -90,8 +90,8 @@ section at the bottom.
.B --warehouse WAREHOUSE
URL of the warehouse location to store images. (default:
http://localhost:9090/)
-.B --image_bucket IMAGE_BUCKET
-Name of warehouse bucket to look in for images. (default: None)
+.B --target_bucket TARGET_BUCKET
+Name of warehouse bucket to look in for target images. (default: None)
.B --template_bucket TEMPLATE_BUCKET
Name of warehouse bucket to look in for templates. (default: None)
diff --git a/imagefactory.conf b/imagefactory.conf
index e260700..b98de71 100644
--- a/imagefactory.conf
+++ b/imagefactory.conf
@@ -1,6 +1,6 @@
{
"warehouse": "http://localhost:9090/",
- "image_bucket": "images",
+ "target_bucket": "target_images",
"template_bucket": "templates",
"icicle_bucket": "icicles",
"provider_bucket": "provider_images",
diff --git a/imagefactory/ApplicationConfiguration.py
b/imagefactory/ApplicationConfiguration.py
index 8c113de..57b668a 100644
--- a/imagefactory/ApplicationConfiguration.py
+++ b/imagefactory/ApplicationConfiguration.py
@@ -77,7 +77,7 @@ class ApplicationConfiguration(object):
group_push.add_argument('--credentials', help='Cloud provider
credentials')
group_warehouse = argparser.add_argument_group(title='Image Warehouse',
description=warehouse_description)
group_warehouse.add_argument('--warehouse',
default='http://localhost:9090/', help='URL of the warehouse location to store
images. (default: %(default)s)')
- group_warehouse.add_argument('--image_bucket', help='Name of
warehouse bucket to look in for images. (default: %(default)s)')
+ group_warehouse.add_argument('--target_bucket', help='Name of
warehouse bucket to look in for target images. (default: %(default)s)')
group_warehouse.add_argument('--template_bucket', help='Name of
warehouse bucket to look in for templates. (default: %(default)s)')
group_warehouse.add_argument('--icicle_bucket', help='Name of
warehouse bucket to look in for icicles. (default: %(default)s)')
group_warehouse.add_argument('--provider_bucket', help='Name of
warehouse bucket to look in for provider image instances. (default: %(default)s)')
@@ -93,7 +93,7 @@ class ApplicationConfiguration(object):
elif(sys.argv[0].endswith("imgfac.py")):
return self.argparser.parse_args()
elif(sys.argv[0].endswith("unittest")):
- return self.argparser.parse_args('--image_bucket unittests_images
--template_bucket unittests_templates --icicle_bucket unittests_icicles --provider_bucket
unittests_provider_images'.split())
+ return self.argparser.parse_args('--target_bucket unittests_target_images
--template_bucket unittests_templates --icicle_bucket unittests_icicles --provider_bucket
unittests_provider_images'.split())
else:
return self.argparser.parse_args([])
diff --git a/imagefactory/BuildDispatcher.py b/imagefactory/BuildDispatcher.py
index 87adb9d..fe9743a 100644
--- a/imagefactory/BuildDispatcher.py
+++ b/imagefactory/BuildDispatcher.py
@@ -49,8 +49,8 @@ class BuildDispatcher(object):
def build_image(self):
self._start_builder_thread("build_image")
- def push_image(self, image_id, provider, credentials):
- kwargs = dict(image_id=image_id, provider=provider, credentials=credentials)
+ def push_image(self, target_image_id, provider, credentials):
+ kwargs = dict(target_image_id=target_image_id, provider=provider,
credentials=credentials)
self._start_builder_thread("push_image", arg_dict=kwargs)
def abort(self):
diff --git a/imagefactory/ImageWarehouse.py b/imagefactory/ImageWarehouse.py
index 0a67f99..a5e74e5 100644
--- a/imagefactory/ImageWarehouse.py
+++ b/imagefactory/ImageWarehouse.py
@@ -31,7 +31,7 @@ from imagefactory.ApplicationConfiguration import
ApplicationConfiguration
class ImageWarehouse(object):
url = props.prop("_url", "The url property.")
- image_bucket = props.prop("_image_bucket", "The image_bucket
property.")
+ target_image_bucket = props.prop("_target_image_bucket", "The
target_image_bucket property.")
template_bucket = props.prop("_template_bucket", "The template_bucket
property.")
icicle_bucket = props.prop("_icicle_bucket", "The icicle_bucket
property.")
provider_image_bucket = props.prop("_provider_image_bucket", "The
provider_image_bucket property.")
@@ -40,7 +40,7 @@ class ImageWarehouse(object):
return "%s - %r" % (super(ImageWarehouse, self).__repr__(),
self.__dict__)
def __str__(self):
- return "%s - buckets(%s, %s, %s, %s)" % (self.url, self.image_bucket,
self.template_bucket, self.icicle_bucket, self.provider_image_bucket)
+ return "%s - buckets(%s, %s, %s, %s)" % (self.url,
self.target_image_bucket, self.template_bucket, self.icicle_bucket,
self.provider_image_bucket)
def __init__(self, url=None):
self.log = logging.getLogger('%s.%s' % (__name__,
self.__class__.__name__))
@@ -51,7 +51,7 @@ class ImageWarehouse(object):
url = ApplicationConfiguration().configuration['warehouse']
self.log.debug("Property (url) not specified. Pulling from application
configuration: %s" % (url, ))
- self.image_bucket =
ApplicationConfiguration().configuration['image_bucket']
+ self.target_image_bucket =
ApplicationConfiguration().configuration['target_bucket']
self.template_bucket =
ApplicationConfiguration().configuration['template_bucket']
self.icicle_bucket =
ApplicationConfiguration().configuration['icicle_bucket']
self.provider_image_bucket =
ApplicationConfiguration().configuration['provider_bucket']
@@ -112,8 +112,8 @@ class ImageWarehouse(object):
metadata = {}
return obj, metadata
- def object_for_image_id(self, image_id, object_type, metadata_keys=()):
- object_url = self.__url_for_id_of_type(image_id, "image",
create=False)
+ def object_for_target_image_id(self, target_image_id, object_type,
metadata_keys=()):
+ object_url = self.__url_for_id_of_type(target_image_id, "target_image",
create=False)
object_id = self._http_get("%s/%s" % (object_url, object_type))
the_object, metadata = self.object_with_id_of_type(object_id, object_type,
metadata_keys)
@@ -152,8 +152,8 @@ class ImageWarehouse(object):
metadata.update( { item : self._http_get("%s/%s" % (object_url,
item)) } )
return metadata
- def store_image(self, image_id, image_file_path, metadata=None):
- object_url = self.__url_for_id_of_type(image_id, "image")
+ def store_target_image(self, target_image_id, image_file_path, metadata=None):
+ object_url = self.__url_for_id_of_type(target_image_id,
"target_image")
try:
image_file = open(image_file_path)
@@ -171,7 +171,7 @@ class ImageWarehouse(object):
except Exception, e:
raise WarehouseError("Problem encountered trying to reach image
warehouse. Please check that iwhd is running and reachable.\nException text: %s" %
(e, ))
- meta_data = dict(uuid=image_id, object_type="image")
+ meta_data = dict(uuid=target_image_id, object_type="image")
if(metadata):
meta_data.update(metadata)
self.set_metadata_for_object_at_url(meta_data, object_url)
@@ -222,17 +222,17 @@ class ImageWarehouse(object):
def icicle_with_id(self, icicle_id, metadata_keys=()):
return self.object_with_id_of_type(icicle_id, "icicle", metadata_keys)
- def icicle_for_image_id(self, image_id, metadata_keys=()):
- return self.object_for_image_id(image_id, "icicle", metadata_keys)
+ def icicle_for_target_image_id(self, target_image_id, metadata_keys=()):
+ return self.object_for_target_image_id(target_image_id, "icicle",
metadata_keys)
def template_with_id(self, template_id, metadata_keys=()):
return self.object_with_id_of_type(template_id, "template",
metadata_keys)
- def template_for_image_id(self, image_id, metadata_keys=()):
- return self.object_for_image_id(image_id, "template", metadata_keys)
+ def template_for_target_image_id(self, target_image_id, metadata_keys=()):
+ return self.object_for_target_image_id(target_image_id, "template",
metadata_keys)
- def image_with_id(self, image_id, metadata_keys=()):
- return self.object_with_id_of_type(image_id, "image", metadata_keys)
+ def target_image_with_id(self, target_image_id, metadata_keys=()):
+ return self.object_with_id_of_type(target_image_id, "target_image",
metadata_keys)
def remove_template_with_id(self, template_id):
return self.delete_object_with_id_of_type(template_id, "template")
@@ -240,9 +240,8 @@ class ImageWarehouse(object):
def remove_icicle_with_id(self, icicle_id):
return self.delete_object_with_id_of_type(icicle_id, "icicle")
- def remove_image_with_id(self, image_id):
- return self.delete_object_with_id_of_type(image_id, "image")
-
+ def remove_target_image_with_id(self, target_image_id):
+ return self.delete_object_with_id_of_type(target_image_id,
"target_image")
class WarehouseError(Exception):
"""Error related to image warehouse interactions."""
diff --git a/imagefactory/Template.py b/imagefactory/Template.py
index 263dccc..faecb8a 100644
--- a/imagefactory/Template.py
+++ b/imagefactory/Template.py
@@ -102,12 +102,12 @@ class Template(object):
if(xml_string and self.__string_is_xml_template(xml_string)):
return uuid_string, xml_string
else:
- self.log.debug("Unable to fetch a valid template given template id
%s:\n%s\nWill try fetching template id from an image with this id..." % (uuid_string,
self.__abbreviated_template(xml_string)))
- template_id, xml_string, metadata =
self.warehouse.template_for_image_id(uuid_string)
+ self.log.debug("Unable to fetch a valid template given template id
%s:\n%s\nWill try fetching template id from a target image with this id..." %
(uuid_string, self.__abbreviated_template(xml_string)))
+ template_id, xml_string, metadata =
self.warehouse.template_for_target_image_id(uuid_string)
if(template_id and xml_string and
self.__string_is_xml_template(xml_string)):
return template_id, xml_string
else:
- self.log.debug("Unable to fetch a valid template given an image id
%s:\n%s\n" % (uuid_string, self.__abbreviated_template(xml_string)))
+ self.log.debug("Unable to fetch a valid template given a target
image id %s:\n%s\n" % (uuid_string, self.__abbreviated_template(xml_string)))
return None, None
def __string_is_xml_template(self, text):
diff --git a/imagefactory/builders/BaseBuilder.py b/imagefactory/builders/BaseBuilder.py
index 5df6eb4..32499a7 100644
--- a/imagefactory/builders/BaseBuilder.py
+++ b/imagefactory/builders/BaseBuilder.py
@@ -139,9 +139,9 @@ class BaseBuilder(object):
template_id = self.warehouse.store_template(self.template.xml,
self.template.identifier)
icicle_id = self.warehouse.store_icicle(self.output_descriptor)
metadata = dict(template=template_id, target=self.target, icicle=icicle_id,
target_parameters=target_parameters)
- self.warehouse.store_image(self.new_image_id, self.image, metadata=metadata)
+ self.warehouse.store_target_image(self.new_image_id, self.image,
metadata=metadata)
- def push_image(self, image_id, provider, credentials):
+ def push_image(self, target_image_id, provider, credentials):
"""Prep the image for the provider and deploy. This method is
implemented by subclasses of the
BaseBuilder to handle OS/Provider specific mechanics."""
raise NotImplementedError
diff --git a/imagefactory/builders/FedoraBuilder.py
b/imagefactory/builders/FedoraBuilder.py
index 75e0c12..aa3b637 100644
--- a/imagefactory/builders/FedoraBuilder.py
+++ b/imagefactory/builders/FedoraBuilder.py
@@ -467,15 +467,15 @@ class FedoraBuilder(BaseBuilder):
# TODO: Based on architecture associate one of two XML blocks that contain the
correct
# regional AKIs for pvgrub
- def push_image(self, image_id, provider, credentials):
+ def push_image(self, target_image_id, provider, credentials):
try:
if self.target in self.upload_clouds or (self.target == "ec2" and
self.app_config["ec2_build_style"] == "upload"):
#No need to have an image object here
#self.init_guest("local")
- self.push_image_upload(image_id, provider, credentials)
+ self.push_image_upload(target_image_id, provider, credentials)
elif self.target in self.nonul_clouds or (self.target == "ec2" and
self.app_config["ec2_build_style"] == "snapshot"):
self.init_guest("remote")
- self.push_image_snapshot(image_id, provider, credentials)
+ self.push_image_snapshot(target_image_id, provider, credentials)
else:
raise ImageFactoryException("Invalid build target (%s) passed to
build_image()" % (self.target))
except:
@@ -486,13 +486,13 @@ class FedoraBuilder(BaseBuilder):
self.status="FAILED"
- def push_image_snapshot(self, image_id, provider, credentials):
+ def push_image_snapshot(self, target_image_id, provider, credentials):
if provider == "rackspace":
- self.push_image_snapshot_rackspace(image_id, provider, credentials)
+ self.push_image_snapshot_rackspace(target_image_id, provider, credentials)
else:
- self.push_image_snapshot_ec2(image_id, provider, credentials)
+ self.push_image_snapshot_ec2(target_image_id, provider, credentials)
- def push_image_snapshot_rackspace(self,image_id, provider, credentials):
+ def push_image_snapshot_rackspace(self, target_image_id, provider, credentials):
doc = libxml2.parseDoc(credentials)
ctxt = doc.xpathNewContext()
@@ -589,7 +589,7 @@ class FedoraBuilder(BaseBuilder):
snap_image = cloudservers.images.get(snap_image.id)
self.log.debug("Storing Rackspace image ID (%s) and details in
Warehouse" % (snap_image.id))
- metadata = dict(image=image_id, provider=provider, icicle="none",
target_identifier=snap_image.id)
+ metadata = dict(target_image=target_image_id, provider=provider,
icicle="none", target_identifier=snap_image.id)
self.warehouse.create_provider_image(self.new_image_id, metadata=metadata)
finally:
@@ -599,7 +599,7 @@ class FedoraBuilder(BaseBuilder):
self.percent_complete=100
self.status = "COMPLETED"
- def push_image_snapshot_ec2(self, image_id, provider, credentials):
+ def push_image_snapshot_ec2(self, target_image_id, provider, credentials):
self.log.debug("Being asked to push for provider %s" % (provider))
self.log.debug("distro: %s - update: %s - arch: %s" %
(self.tdlobj.distro, self.tdlobj.update, self.tdlobj.arch))
self.ec2_decode_credentials(credentials)
@@ -835,26 +835,26 @@ chmod 600 /root/.ssh/authorized_keys
ami_id = m.group(1)
self.log.debug("Extracted AMI ID: %s " % (ami_id))
- metadata = dict(image=image_id, provider=provider, icicle="none",
target_identifier=ami_id)
+ metadata = dict(target_image=target_image_id, provider=provider,
icicle="none", target_identifier=ami_id)
self.warehouse.create_provider_image(self.new_image_id, metadata=metadata)
finally:
self.log.debug("Stopping EC2 instance and deleting temp security
group")
instance.stop()
factory_security_group.delete()
- self.log.debug("FedoraBuilder instance %s pushed image with uuid %s to
provider_image UUID (%s) and set metadata: %s" % (id(self), image_id,
self.new_image_id, str(metadata)))
+ self.log.debug("FedoraBuilder instance %s pushed image with uuid %s to
provider_image UUID (%s) and set metadata: %s" % (id(self), target_image_id,
self.new_image_id, str(metadata)))
self.percent_complete=100
self.status="COMPLETED"
- def condorcloud_push_image_upload(self, image_id, provider, credentials):
+ def condorcloud_push_image_upload(self, target_image_id, provider, credentials):
# condorcloud is a simple local cloud instance using Condor
# The push action in this case simply requires that we copy the image to a known
# location and then move it to another known loacation
# This is where the image should be after a local build
- input_image = self.app_config["imgdir"] + "/base-image-" +
image_id + ".dsk"
+ input_image = self.app_config["imgdir"] + "/base-image-" +
target_image_id + ".dsk"
# Grab from Warehouse if it isn't here
- self.retrieve_image(image_id, input_image)
+ self.retrieve_image(target_image_id, input_image)
storage = "/home/cloud/images"
if not os.path.isdir(storage):
@@ -877,7 +877,7 @@ chmod 600 /root/.ssh/authorized_keys
image_xml_base="/condorimage-" + self.new_image_id + ".xml"
image_xml_file= storage + image_xml_base
- image_metadata =
self.warehouse.metadata_for_id_of_type(("target_parameters",), image_id,
"image")
+ image_metadata =
self.warehouse.metadata_for_id_of_type(("target_parameters",), target_image_id,
"target_image")
self.log.debug("Got metadata output of: %s", repr(image_metadata))
libvirt_xml = image_metadata["target_parameters"]
@@ -891,11 +891,11 @@ chmod 600 /root/.ssh/authorized_keys
if subprocess.call(["mv", "-f", staging_image,
final_image]):
raise ImageFactoryException("Move of condorcloud image to final location
(%s) failed" % (final_image))
- metadata = dict(image=image_id, provider=provider, icicle="none",
target_identifier=self.new_image_id)
+ metadata = dict(target_image=target_image_id, provider=provider,
icicle="none", target_identifier=self.new_image_id)
self.warehouse.create_provider_image(self.new_image_id, metadata=metadata)
self.percent_complete = 100
- def vmware_push_image_upload(self, image_id, provider, credentials):
+ def vmware_push_image_upload(self, target_image_id, provider, credentials):
# Decode the config file, verify that the provider is in it - err out if not
# TODO: Make file location CONFIG value
cfg_file = open("/etc/vmware.json","r")
@@ -909,9 +909,9 @@ chmod 600 /root/.ssh/authorized_keys
raise ImageFactoryException("VMWare instance (%s) not found in local
configuraiton file /etc/vmware.json" % (provider))
# This is where the image should be after a local build
- input_image = self.app_config['imgdir'] + "/vmware-image-" +
image_id + ".vmdk"
+ input_image = self.app_config['imgdir'] + "/vmware-image-" +
target_image_id + ".vmdk"
# Grab from Warehouse if it isn't here
- self.retrieve_image(image_id, input_image)
+ self.retrieve_image(target_image_id, input_image)
# Example of some JSON for westford_esx
# {"westford_esx": {"api-url":
"https://vsphere.virt.bos.redhat.com/sdk", "username":
"Administrator", "password": "changeme",
@@ -924,12 +924,12 @@ chmod 600 /root/.ssh/authorized_keys
guest_id='otherLinux64Guest', imagefilename=input_image)
# Create the provdier image
- metadata = dict(image=image_id, provider=provider, icicle="none",
target_identifier=vm_name)
+ metadata = dict(target_image=target_image_id, provider=provider,
icicle="none", target_identifier=vm_name)
self.warehouse.create_provider_image(self.new_image_id, metadata=metadata)
self.percent_complete = 100
- def rhevm_push_image_upload(self, image_id, provider, credentials):
+ def rhevm_push_image_upload(self, target_image_id, provider, credentials):
# Decode the config file, verify that the provider is in it - err out if not
# TODO: Make file location CONFIG value
file = open("/etc/rhevm.json","r")
@@ -949,34 +949,34 @@ chmod 600 /root/.ssh/authorized_keys
# The RHEV-M UUID is stored as a new piece of metadata with a key of
"ami-id"
# This is not thread-safe
# TODO: Coordinate with Pete when he changes this to return the AMI ID as the
body
- response = self.warehouse.post_on_object_with_id_of_type(image_id,
"image", post_data)
+ response = self.warehouse.post_on_object_with_id_of_type(target_image_id,
"target_image", post_data)
# TODO: Remove this when the change mentioned above has been made
- image_metadata = self.warehouse.metadata_for_id_of_type(("ami-id",),
image_id, "image")
+ image_metadata = self.warehouse.metadata_for_id_of_type(("ami-id",),
target_image_id, "target_image")
self.log.debug("Got metadata output of: %s", repr(image_metadata))
m = re.match("OK ([a-fA-F0-9-]+)", image_metadata["ami-id"])
rhevm_uuid = m.group(1)
self.log.debug("Extracted RHEVM UUID: %s " % (rhevm_uuid))
# Create the provdier image
- metadata = dict(image=image_id, provider=provider, icicle="none",
target_identifier=rhevm_uuid)
+ metadata = dict(target_image=target_image_id, provider=provider,
icicle="none", target_identifier=rhevm_uuid)
self.warehouse.create_provider_image(self.new_image_id, metadata=metadata)
self.percent_complete = 100
- def push_image_upload(self, image_id, provider, credentials):
+ def push_image_upload(self, target_image_id, provider, credentials):
# TODO: RHEV-M and VMWare
self.status="PUSHING"
self.percent_complete=0
try:
if self.target == "ec2":
- self.ec2_push_image_upload(image_id, provider, credentials)
+ self.ec2_push_image_upload(target_image_id, provider, credentials)
elif self.target == "condorcloud":
- self.condorcloud_push_image_upload(image_id, provider, credentials)
+ self.condorcloud_push_image_upload(target_image_id, provider,
credentials)
elif self.target == "rhev-m":
- self.rhevm_push_image_upload(image_id, provider, credentials)
+ self.rhevm_push_image_upload(target_image_id, provider, credentials)
elif self.target == "vmware":
- self.vmware_push_image_upload(image_id, provider, credentials)
+ self.vmware_push_image_upload(target_image_id, provider, credentials)
else:
raise ImageFactoryException("Invalid upload push requested for
target (%s) and provider (%s)" % (self.target, provider))
except:
@@ -1028,13 +1028,13 @@ chmod 600 /root/.ssh/authorized_keys
self.ec2_key_file_object.flush()
self.ec2_key_file=self.ec2_key_file_object.name
- def retrieve_image(self, image_id, local_image_file):
- # Grab image_id from warehouse unless it is already present as local_image_file
+ def retrieve_image(self, target_image_id, local_image_file):
+ # Grab target_image_id from warehouse unless it is already present as
local_image_file
# TODO: Use Warehouse class instead
if not os.path.isfile(local_image_file):
if not (self.app_config['warehouse']):
raise ImageFactoryException("No warehouse configured - cannot
retrieve image")
- url = "%simages/%s" % (self.app_config['warehouse'],
image_id)
+ url = "%simages/%s" % (self.app_config['warehouse'],
target_image_id)
self.log.debug("Image %s not present locally - Fetching from %s" %
(local_image_file, url))
fp = open(local_image_file, "wb")
curl = pycurl.Curl()
@@ -1047,15 +1047,15 @@ chmod 600 /root/.ssh/authorized_keys
self.log.debug("Image file %s already present - skipping warehouse
download" % (local_image_file))
- def ec2_push_image_upload(self, image_id, provider, credentials):
+ def ec2_push_image_upload(self, target_image_id, provider, credentials):
self.ec2_decode_credentials(credentials)
# if the image is already here, great, otherwise grab it from the warehouse
input_image_path=self.app_config['imgdir'] + "/"
- input_image_name="ec2-image-" + image_id + ".dsk"
+ input_image_name="ec2-image-" + target_image_id + ".dsk"
input_image=input_image_path + input_image_name
- self.retrieve_image(image_id, input_image)
+ self.retrieve_image(target_image_id, input_image)
bundle_destination=self.app_config['imgdir']
@@ -1159,12 +1159,12 @@ chmod 600 /root/.ssh/authorized_keys
# Use new warehouse wrapper to do everything
# TODO: Generate and store ICICLE
self.status = "PUSHING"
- metadata = dict(image=image_id, provider=provider, icicle="none",
target_identifier=ami_id)
+ metadata = dict(target_image=target_image_id, provider=provider,
icicle="none", target_identifier=ami_id)
self.warehouse.create_provider_image(self.new_image_id, metadata=metadata)
#self.output_descriptor="unknown"
- #metadata = dict(uuid=self.new_image_id, type="provider_image",
template=self.template, target=self.target, icicle=self.output_descriptor, image=image_id,
provider=provider, target_identifier=ami_id)
- self.log.debug("FedoraBuilder instance %s pushed image with uuid %s to
provider_image UUID (%s) and set metadata: %s" % (id(self), image_id,
self.new_image_id, str(metadata)))
+ #metadata = dict(uuid=self.new_image_id, type="provider_image",
template=self.template, target=self.target, icicle=self.output_descriptor,
target_image=target_image_id, provider=provider, target_identifier=ami_id)
+ self.log.debug("FedoraBuilder instance %s pushed image with uuid %s to
provider_image UUID (%s) and set metadata: %s" % (id(self), target_image_id,
self.new_image_id, str(metadata)))
self.percent_complete=100
def abort(self):
diff --git a/imagefactory/builders/IBuilder.py b/imagefactory/builders/IBuilder.py
index 1485cbf..15a75d8 100644
--- a/imagefactory/builders/IBuilder.py
+++ b/imagefactory/builders/IBuilder.py
@@ -66,5 +66,5 @@ class IBuilder(Interface):
def abort():
"""Tell the builder to stop building the image."""
- def push_image(image_id, provider, credentials):
+ def push_image(target_image_id, provider, credentials):
"""Deploy an image to the cloud provider."""
diff --git a/imagefactory/builders/MockBuilder.py b/imagefactory/builders/MockBuilder.py
index b9e57bd..05851a1 100644
--- a/imagefactory/builders/MockBuilder.py
+++ b/imagefactory/builders/MockBuilder.py
@@ -85,11 +85,11 @@ class MockBuilder(BaseBuilder):
self.store_image()
- def push_image(self, image_id, provider, credentials):
+ def push_image(self, target_image_id, provider, credentials):
self.status = "INITIALIZING"
try:
self.status = "PENDING"
- image, image_metadata = self.warehouse.image_with_id(image_id,
metadata_keys=("icicle", ))
+ image, image_metadata = self.warehouse.target_image_with_id(target_image_id,
metadata_keys=("icicle", ))
# write the provider image out to the filesystem
image_path = "%s/deltacloud-%s/%s/images/%s.yml" %
(self.app_config['imgdir'], os.getlogin(), provider, self.new_image_id)
self.log.debug("Storing mock image for %s at path: %s" % (provider,
image_path))
@@ -100,10 +100,10 @@ class MockBuilder(BaseBuilder):
image_file.write(image)
image_file.close()
# push the provider image up to the warehouse
- metadata = dict(image=image_id, provider=provider,
icicle=image_metadata["icicle"], target_identifier="Mock_%s_%s" %
(provider, self.new_image_id))
+ metadata = dict(target_image=target_image_id, provider=provider,
icicle=image_metadata["icicle"], target_identifier="Mock_%s_%s" %
(provider, self.new_image_id))
self.warehouse.create_provider_image(self.new_image_id, txt=image,
metadata=metadata)
self.status = "FINISHING"
- self.log.debug("MockBuilder instance %s pushed image with uuid %s to
warehouse (%s/%s) and set metadata: %s" % (id(self), image_id, self.warehouse.url,
self.warehouse.provider_image_bucket, metadata))
+ self.log.debug("MockBuilder instance %s pushed image with uuid %s to
warehouse (%s/%s) and set metadata: %s" % (id(self), target_image_id,
self.warehouse.url, self.warehouse.provider_image_bucket, metadata))
self.status = "COMPLETED"
except Exception, e:
failing_thread = FailureThread(target=self,
kwargs=dict(message="%s" % (e, )))
diff --git a/imagefactory/qmfagent/ImageFactory.py
b/imagefactory/qmfagent/ImageFactory.py
index a07d441..ba1c11b 100644
--- a/imagefactory/qmfagent/ImageFactory.py
+++ b/imagefactory/qmfagent/ImageFactory.py
@@ -83,14 +83,16 @@ class ImageFactory(object):
build_adaptor.build_image()
return build_adaptor
- def provider_image(self,image_id, provider, credentials):
- image_metadata = self.warehouse.metadata_for_id_of_type(("template",
"target"), image_id, "image")
+ def provider_image(self, image_id, provider, credentials):
+ target_image_id = image_id
+
+ image_metadata = self.warehouse.metadata_for_id_of_type(("template",
"target"), target_image_id, "target_image")
template_id = image_metadata["template"]
target = image_metadata["target"]
if (template_id and target):
build_adaptor =
BuildAdaptor.BuildAdaptor(Template(uuid=template_id),target,self.agent)
- build_adaptor.push_image(image_id, provider, credentials)
+ build_adaptor.push_image(target_image_id, provider, credentials)
return build_adaptor
else:
raise RuntimeError("Could not return build_adaptor!\nimage_metadata:
%s\ntemplate_id: %s\ntemplate: %s\n" % (image_metadata, template_id, target))
diff --git a/tests/testImageWarehouse.py b/tests/testImageWarehouse.py
index 1545490..a63d3a8 100644
--- a/tests/testImageWarehouse.py
+++ b/tests/testImageWarehouse.py
@@ -36,20 +36,20 @@ class testImageWarehouse(unittest.TestCase):
del self.metadata
def testImageWarehouseMethods(self):
- """Tests CRUD operations on images, templates, icicles, and
metadata on those objects..."""
- # IMAGE
- # store an image
- image_id = str(uuid.uuid4())
- file_content = "This is just to test storing an image in warehouse. There
is not much to see here."
- file_path = "/tmp/testImageWarehouse_testStoreAndFetchImage.%s" %
(image_id, )
+ """Tests CRUD operations on target images, templates, icicles, and
metadata on those objects..."""
+ # TARGET IMAGE
+ # store a target image
+ target_image_id = str(uuid.uuid4())
+ file_content = "This is just to test storing a target image in warehouse.
There is not much to see here."
+ file_path = "/tmp/testImageWarehouse_testStoreAndFetchTargetImage.%s" %
(target_image_id, )
with open(file_path, 'w') as test_file:
test_file.write(file_content)
test_file.close()
- self.warehouse.store_image(image_id, file_path, metadata=self.metadata)
- # now fetch that image
- image, metadata = self.warehouse.image_with_id(image_id,
metadata_keys=self.metadata.keys())
+ self.warehouse.store_target_image(target_image_id, file_path,
metadata=self.metadata)
+ # now fetch that target image
+ target_image, metadata = self.warehouse.target_image_with_id(target_image_id,
metadata_keys=self.metadata.keys())
# now make the assertions
- self.assertEqual(file_content, image)
+ self.assertEqual(file_content, target_image)
self.assertEqual(self.metadata, metadata)
# TEMPLATE
@@ -66,9 +66,9 @@ class testImageWarehouse(unittest.TestCase):
self.assertEqual(template_content, fetched_template_content)
fetched_template_content2, template_metadata2 =
self.warehouse.template_with_id(template_id_known)
self.assertEqual(template_content, fetched_template_content2)
- # set the template id for an image and fetch it back
- self.warehouse.set_metadata_for_id_of_type(dict(template=template_id), image_id,
"image")
- template_id3, fetched_template_content3, template_metadata3 =
self.warehouse.template_for_image_id(image_id)
+ # set the template id for a target image and fetch it back
+ self.warehouse.set_metadata_for_id_of_type(dict(template=template_id),
target_image_id, "target_image")
+ template_id3, fetched_template_content3, template_metadata3 =
self.warehouse.template_for_target_image_id(target_image_id)
self.assertEqual(template_id, template_id3)
self.assertEqual(template_content, fetched_template_content3)
@@ -86,13 +86,13 @@ class testImageWarehouse(unittest.TestCase):
self.assertEqual(icicle_content, fetched_icicle_content)
fetched_icicle_content2, icicle_metadata2 =
self.warehouse.icicle_with_id(icicle_id_known)
self.assertEqual(icicle_content, fetched_icicle_content2)
- # set the icicle id for an image and fetch it back
- self.warehouse.set_metadata_for_id_of_type(dict(icicle=icicle_id), image_id,
"image")
- icicle_id3, fetched_icicle_content3, icicle_metadata3 =
self.warehouse.icicle_for_image_id(image_id)
+ # set the icicle id for a target image and fetch it back
+ self.warehouse.set_metadata_for_id_of_type(dict(icicle=icicle_id),
target_image_id, "target_image")
+ icicle_id3, fetched_icicle_content3, icicle_metadata3 =
self.warehouse.icicle_for_target_image_id(target_image_id)
self.assertEqual(icicle_id, icicle_id3)
self.assertEqual(icicle_content, fetched_icicle_content3)
- self.assertTrue(self.warehouse.remove_image_with_id(image_id))
+ self.assertTrue(self.warehouse.remove_target_image_with_id(target_image_id))
self.assertTrue(self.warehouse.remove_template_with_id(template_id))
self.assertTrue(self.warehouse.remove_template_with_id(template_id2))
self.assertTrue(self.warehouse.remove_icicle_with_id(icicle_id))
diff --git a/tests/testTemplate.py b/tests/testTemplate.py
index 7b4dcce..66164a9 100644
--- a/tests/testTemplate.py
+++ b/tests/testTemplate.py
@@ -52,7 +52,7 @@ class testTemplate(unittest.TestCase):
builder = MockBuilder(self.template_xml, target)
builder.build_image()
metadata = dict(template=template_id, target=target, icicle="None",
target_parameters="None")
- self.warehouse.store_image(builder.new_image_id, builder.image,
metadata=metadata)
+ self.warehouse.store_target_image(builder.new_image_id, builder.image,
metadata=metadata)
image_template = Template(builder.new_image_id)
self.assertEqual(template_id, image_template.identifier)
self.assertEqual(self.template_xml, image_template.xml)
--
1.7.4.4