Contents |
IMG (Image Me Give) is a small python client/server application suite, its sole job is to get a kickstart file from a user, via a web interface, command line or BOSS process. Then it runs Moblin-Image-Creator, either in a host or in a VM. IMG also has the capability to run as a BOSS participant and thus be a part of a build process.
(FIXME: Which rpms provide which services and where should they be installed? What is the expected network layout - in particular does a single img-web control a pool of img workers? What about the participant? lbt 27/Dec)
The application consists of two parts, django frontend and the actual image creation application. Both of them are connected via AMQP, RabbitMQ is used as the server.
So an example workflow, in AMQP:
Installing IMG via RPM for OpenSUSE 11.2.
The following repos are needed : MeeGo-Infra, opensuse python and MeeGo tools:
zypper ar http://download.opensuse.org/repositories/Maemo:/MeeGo-Infra/openSUSE_11.2-plus/Maemo:MeeGo-Infra.repo zypper ar http://download.opensuse.org/repositories/devel:/languages:/python/openSUSE_11.2/devel:languages:python.repo zypper ar http://repo.meego.com/MeeGo/tools/repos/opensuse/11.2/meego-tools.repo zypper ref
Then install the core IMG package and the amqp listener:
zypper in img-core img-amqp img-boss
The worker code is provided by img-core and is responsible for running mic2 either locally or on a virtual machine. The initialisation code takes care of creating the necessary command stubs for mic2 use for either implementations. It also handles the KVM creation command stubs.
In KVM mode, it first creates an overlay image from the base image (not distributed) and then starts it using the overlay image as the hard disk. Virtio is used as a speed optimisation method for KVM. When a specific amount of time has passed, it will copy the kickstart and mic2 config file to the guest VM. Then it runs mic2 in the VM with parameters specified in the init method. After mic2 has run, the image is copied from the guest using scp.
In local mode, only mic2 is run on the host machine. It will create the image based on the options in the init method along with the kickstart file.
A worker needs a queueing mechanism to accept jobs. The primary solution is expected to be the BOSS participant (img-boss) but there is a plain amqp client too (img-amqp).
The general design of the client is pretty much the same as the AMQP server, since they both get activated and then call the worker code to create the image, with or without KVM. The worker code is described in the section above.
More information about BOSS Infrastructure/BOSS.
See boss_build_image.py for the source code.
See boss_img_client.py for example BOSS client.
(Is this the img-amqp usage? lbt 27/Dec)
Usage: boss_client.py -n|--name <name> -t|--type <imagetype> -e|--email <author@email> -r|--release <release> -a|--arch <arch >-s|--submit -k <kickstart_file.ks>
boss_client.py Sends a message (poll for result later) to the BOSS, using <kickstart.ks> as the kickstart file.
Options:
-h, --help show this help message and exit
-s, --submit Submit to BOSS, takes no options
-k KICKSTART, --kickstart=KICKSTART
Kickstart file
-t TYPE, --type=TYPE Image type
-n NAME, --name=NAME Image name
-e EMAIL, --email=EMAIL
Author email
-r RELEASE --release Image release, goes directly to mic2
-a ARCH --arch Architecture to use
See build_image.py for example server.
This section documents the server component of IMG.
'error': Contains the error message of the exception received from the python subprocess call. 'id': identification string of the original message sent to "image_queue" queue 'url': Contains the URL from which one can download the log
'url': Contains the URL from which one can download the image
'id': identification string of the original message sent to "image_queue" queue
Queues for exchange "image_exchange":
Queues for exchange "django_result_exchange":
For demonstration see img_client.py for example client.
img_client.py -p|--poll <id> -n|--name <name> -t|--type <imagetype> -e|--email <author@email> -r|--release -a|--arch s|--submit -k <kickstart_file.ks>"
where:
This client version uses AMQP as the message bus to communicate with the server. The format for the messages is described in the next part of this document.
The general message format is JSON encoded dictionary.
To initialize the actual image building, send a JSON formatted message as follows:
{'email':email, 'id':id, 'imagetype':imagetype, 'ksfile':ksfile, 'name': name, 'arch':arch, 'release':release}
where:
url(r'submit/$', 'meego_img.app.views.submit', name='img-app-submit'), url(r'queue/$', 'meego_img.app.views.queue', name='img-app-queue'), url(r'job/(?P<msgid>\S+)$', 'meego_img.app.views.job', name='img-app-job'), url(r'images/(?P<msgid>\S+)$', 'meego_img.app.views.download',name='img-app-download'),
IMG currently has only one model, !ImageJob, here is the Django code for it:
# Create your models here.
class ImageJob(models.Model):
email = models.CharField(max_length=40)
filename = models.CharField(max_length=40)
logfile = models.CharField(max_length=50)
task_id = models.CharField(max_length=30)
imagefile = models.CharField(max_length=50)
created = models.DateTimeField(auto_now_add=True)
error = models.CharField(max_length=500)
type = models.CharField(max_length=10)
status = models.CharField(max_length=30)
def delete(self, *args, **kwargs):
if self.logfile:
if os.path.exists(self.logfile):
os.remove(self.logfile)
os.remove(self.logfile.replace("-log", ""))
print "Removed %s"%self.logfile
super(ImageJob, self).delete(*args, **kwargs)
As can be seen in the delete method, this model cleans up all image creation related files, like the kickstarter file and log file.
Contains the following fields
The configuration file is to be installed in /etc/imger/img.conf and a sample file is here.
base_url: A base URL that has a direct access to the base_dir via HTTP, example http://127.0.0.1 base_dir: A directory to put the finished images, example /var/www/images num_workers: Number of workers to start, OBSOLETE, USE INITSCRIPT OR MANUALLY RUN MANY PARTICIPANTS post_creation: Path to a script to run after the image is created use_kvm: Wether to use a virtual machine, values are "yes" or "no"
mic_opts: Example, mic_opts = --save-kernel, --use_comps, so comma separated options
amqp_host: Host that runs BOSS amqp_user: Username to tap into the BOSS virtual host amqp_pwd: Password amqp_vhost: The actual virtual host to connect to
The KVM image must be created in such a way that it has openssh and mic2, along with having ssh-key based login for root, which uses a certain ssh public key.
The format of the image is recommended to be qcow2, with preallocation and cluster_size=2M as the qemu-img options. This is because the worker code uses qcow2 to create the overlay, thus saving time if the image is in the same format.
If the host is using openSUSE, please enable the following things for zypper repositories:
http://download.opensuse.org/repositories/Kernel:/openSUSE-11.3/openSUSE_11.2/ http://download.opensuse.org/repositories/Virtualization/openSUSE_11.2/
And add kvm-intel to /etc/sysconfig/kernel.
Currently, IMGer can run the MIC2 jobs inside a KVM virtual machine, the only prerequisites are that image is located in /usr/share/img/base.img (configurable in the future) path and that the virtual machine has MIC2 installed and configured.
Suse studio is one way to create the images, just make sure that you have a rpm repository which contains mic2, python-xml and qemu-static-arm to make mic2 run properly on the image.
One must also confirm that the image SSH-keys in the source distribution are configured in the virtual machine and both keys exist in /usr/share/img (configurable in the future). During the runtime of IMGer, it is possible that ssh-keys inside the image may change, this is already handled by IMGer by ignoring the host key checking.
The following defines the input dictionary for the participant:
"kickstart" : a kickstart file, in raw, not a path "email": email address, not parsed so can be a dummy address "id": a simple UUID, eg. from pythons uuid library "type":type, from values: livecd, liveusb, loop, raw, nand, mrstnand, vdi or vmdk "name":name, a simple string for the image name "arch":architecture, for image "release":release
The work item can contain the following dictionary entries:
Status: Status, is either "DONE" or "ERROR" in the final workitem, depending on success/failure URL: URL to a image/log/kickstart file location on the worker Error: An error string with details of the error, if any Image: A direct URL to the finished image Log: A direct URL to the log file of the mic2 output