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 | 52 +++++++++++++++++++++-
12 1 file changed, 50 insertions(+), 2 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..a619f3f 100755
16 --- a/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
17 +++ b/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
18 @@ -52,11 +52,11 @@ def image_list
19 stdout = `glance --verbose image-list`
20 return_code = $?.exitstatus
23 stdout.split("\n").each do |line|
24 fields = line.split('|').map { |f| f.chomp.strip }
25 next if fields[1] == 'ID'
27 - images << {fields[2] => fields[6]}
28 + images[fields[2]] = { :id => fields[1], :status => fields[6] }
30 {:images => images, :exit_code => return_code}
32 @@ -78,6 +78,16 @@ EOF
33 [ stdout, return_code ]
36 +# Calls glance update-image with a given property and value
37 +# Supported properties: 'kernel-id', 'ramdisk-id'
38 +def update_image(image_id, property, value)
39 + command = "/usr/bin/openstack image set --#{property}=#{value} #{image_id}"
41 + stdout = `#{command}`
42 + return_code = $?.exitstatus
43 + [ stdout, return_code ]
46 # check if Glance is online
47 # waited until the glance is started because when vCenter used as a glance
48 # backend launch may takes up to 1 minute.
49 @@ -133,7 +142,7 @@ end
50 # return true if image has been uploaded and active
51 def check_image(image)
52 list_of_images = image_list
53 - if list_of_images[:exit_code] == 0 && list_of_images[:images].include?(image['img_name'] => "active")
54 + if list_of_images[:exit_code] == 0 && list_of_images[:images].select { |k,v| k == image['img_name'] and v[:status] == "active" }.count > 0
58 @@ -142,7 +151,7 @@ end
60 def cleanup_image(image)
61 list_of_images = image_list
62 - unless list_of_images[:images].select { |img_hash| img_hash.key?(image['img_name']) }.empty?
63 + unless list_of_images[:images].select { |img_hash, v| img_hash == image['img_name'] }.count == 0
64 delete_image(image['img_name'])
67 @@ -157,6 +166,41 @@ def delete_image(image_name)
68 [ stdout, return_code ]
71 +# For each disk image try to find a kernel and initramfs images and
72 +# attach then to it via kernel_id and ramdisk_id glance properties.
73 +def connect_dependant_images(images)
75 + # get image id from glance
76 + img_list = image_list
77 + return_code = img_list[:exit_code]
79 + images.each do |image|
80 + img_list[:images].each do |k,v|
81 + if k == image['img_name']
82 + image['id'] = v[:id]
86 + # for each image that is not in [aki, ari]
87 + images.each do |image|
88 + next if ['aki', 'ari'].include?(image['disk_format'])
90 + # find aki/ari image whose name starts with this image's name
91 + if i['img_name'].start_with?(image['img_name'])
93 + if i['disk_format'] == 'aki'
94 + _, ret = update_image(image['id'], 'kernel-id', i['id'])
95 + elsif i['disk_format'] == 'ari'
96 + _, ret = update_image(image['id'], 'ramdisk-id', i['id'])
106 ########################
109 @@ -180,6 +226,8 @@ if errors > 0
113 +elsif connect_dependant_images(test_vm_images) > 0