Rebase: ODL Fuel plugin arm64 support patch.
[armband.git] / patches / fuel-library / 0006-direct-kernel-boot-for-cirros.patch
1 From: Stanislaw Kardach <stanislaw.kardach@caviumnetworks.com>
2 Date: Tue, 15 Mar 2016 15:01:34 +0100
3 Subject: [PATCH] direct kernel boot for cirros
4
5 ---
6  .../osnailyfacter/modular/astute/upload_cirros.rb  | 51 +++++++++++++++++++++-
7  1 file changed, 49 insertions(+), 2 deletions(-)
8
9 diff --git a/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb b/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
10 index 53d75fc..8a75356 100755
11 --- a/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
12 +++ b/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
13 @@ -56,7 +56,7 @@ def image_list
14      fields = line.split('|').map { |f| f.chomp.strip }
15      next if fields[1] == 'ID'
16      next unless fields[2]
17 -    images << {fields[2] => fields[6]}
18 +    images << {fields[2] => { :id => fields[1], :status => fields[6]}}
19    end
20    {:images => images, :exit_code => return_code}
21  end
22 @@ -78,6 +78,15 @@ EOF
23    [ stdout, return_code ]
24  end
25  
26 +# Calls glance update-image with a given property and value
27 +def update_image(image_id, property, value)
28 +  command = "/usr/bin/glance image-update --#{property} #{value} #{image_id}"
29 +  puts command
30 +  stdout = `#{command}`
31 +  return_code = $?.exitstatus
32 +  [ stdout, return_code ]
33 +end
34 +
35  # check if Glance is online
36  # waited until the glance is started because when vCenter used as a glance
37  # backend launch may takes up to 1 minute.
38 @@ -93,7 +102,7 @@ end
39  # if it have not been already uploaded
40  def upload_image(image)
41    list_of_images = image_list
42 -  if list_of_images[:images].include?(image['img_name'] => "active") && list_of_images[:exit_code] == 0
43 +  if list_of_images[:images].select { |k,v| k == image['img_name'] and v[:status] == "active" } && list_of_images[:exit_code] == 0
44      puts "Image '#{image['img_name']}' is already present!"
45      return 0
46    end
47 @@ -114,6 +123,43 @@ def upload_image(image)
48    return return_code
49  end
50  
51 +# For each disk image try to find a kernel and initramfs images and
52 +# attach then to it via kernel_id and ramdisk_id glance properties.
53 +def connect_dependant_images(images)
54 +  # for each image
55 +  # get image id from glance
56 +  img_list = image_list
57 +  return_code = img_list[:exit_code]
58 +  if return_code == 0
59 +    images.each do |image|
60 +      img_list[:images].each do |k,v|
61 +        if k == image['img_name']
62 +          image['id'] = v[:id]
63 +        end
64 +      end
65 +    end
66 +    # for each image that is not in [aki, ari]
67 +    images.each do |image|
68 +      next if ['aki', 'ari'].include?(image['disk_format'])
69 +      images.each do |i|
70 +        # find aki/ari image whose name starts with this image's name
71 +        if i['img_name'].start_with?(image['img_name'])
72 +          ret = 0
73 +          if i['disk_format'] == 'aki'
74 +            _, ret = update_image(image['id'], 'property',
75 +                                        "kernel_id=#{i['id']}")
76 +          elsif i['disk_format'] == 'ari'
77 +            _, ret = update_image(image['id'], 'property',
78 +                                        "ramdisk_id=#{i['id']}")
79 +          end
80 +          return_code += ret
81 +        end
82 +      end
83 +    end
84 +  end
85 +  return return_code
86 +end
87 +
88  ########################
89  
90  wait_for_glance
91 @@ -122,6 +168,7 @@ errors = 0
92  test_vm_images.each do |image|
93    errors += upload_image(image)
94  end
95 +errors = connect_dependant_images(test_vm_images) unless errors != 0
96  
97  exit 1 unless errors == 0
98