1 From: Stanislaw Kardach <stanislaw.kardach@caviumnetworks.com>
2 Date: Tue, 15 Mar 2016 15:01:34 +0100
3 Subject: [PATCH] upload_cirros: Add direct kernel boot support.
5 AArch64 currently only supports direct kernel boot, so add the
6 functionality of uploading and connecting kernel and initramfs
7 images (disk formats `AKI` and `ARI`).
9 Signed-off-by: Stanislaw Kardach <stanislaw.kardach@cavium.com>
11 .../osnailyfacter/modular/astute/upload_cirros.rb | 53 ++++++++++++++++++++--
12 1 file changed, 50 insertions(+), 3 deletions(-)
14 diff --git a/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb b/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
15 index f0441b0..cefc3ed 100755
16 --- a/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
17 +++ b/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
18 @@ -56,7 +56,7 @@ def image_list
19 fields = line.split('|').map { |f| f.chomp.strip }
20 next if fields[1] == 'ID'
22 - images << {fields[2] => fields[6]}
23 + images << {fields[2] => { :id => fields[1], :status => fields[6]}}
25 {:images => images, :exit_code => return_code}
27 @@ -78,6 +78,15 @@ EOF
28 [ stdout, return_code ]
31 +# Calls glance update-image with a given property and value
32 +def update_image(image_id, property, value)
33 + command = "/usr/bin/glance image-update --#{property} #{value} #{image_id}"
35 + stdout = `#{command}`
36 + return_code = $?.exitstatus
37 + [ stdout, return_code ]
40 # check if Glance is online
41 # waited until the glance is started because when vCenter used as a glance
42 # backend launch may takes up to 1 minute.
43 @@ -133,7 +142,7 @@ end
44 # return true if image has been uploaded and active
45 def check_image(image)
46 list_of_images = image_list
47 - if list_of_images[:exit_code] == 0 && list_of_images[:images].include?(image['img_name'] => "active")
48 + if list_of_images[:exit_code] == 0 && list_of_images[:images].select { |k,v| k == image['img_name'] and v[:status] == "active" }
52 @@ -157,6 +166,43 @@ def delete_image(image_name)
53 [ stdout, return_code ]
56 +# For each disk image try to find a kernel and initramfs images and
57 +# attach then to it via kernel_id and ramdisk_id glance properties.
58 +def connect_dependant_images(images)
60 + # get image id from glance
61 + img_list = image_list
62 + return_code = img_list[:exit_code]
64 + images.each do |image|
65 + img_list[:images].each do |k,v|
66 + if k == image['img_name']
67 + image['id'] = v[:id]
71 + # for each image that is not in [aki, ari]
72 + images.each do |image|
73 + next if ['aki', 'ari'].include?(image['disk_format'])
75 + # find aki/ari image whose name starts with this image's name
76 + if i['img_name'].start_with?(image['img_name'])
78 + if i['disk_format'] == 'aki'
79 + _, ret = update_image(image['id'], 'property',
80 + "kernel_id=#{i['id']}")
81 + elsif i['disk_format'] == 'ari'
82 + _, ret = update_image(image['id'], 'property',
83 + "ramdisk_id=#{i['id']}")
93 ########################
96 @@ -167,7 +213,8 @@ test_vm_images.each do |image|
97 # retry upload 5 times with a 1 minute sleep between tries
98 5.times.each do |retries|
99 if upload_image(image)
101 + if connect_dependant_images(test_vm_images) == 0