summaryrefslogtreecommitdiffstats
path: root/patches/fuel-library/0006-direct-kernel-boot-for-cirros.patch
blob: 0c1104305e53877b327fdc122d090df9333e2c58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
From: Stanislaw Kardach <stanislaw.kardach@caviumnetworks.com>
Date: Tue, 15 Mar 2016 15:01:34 +0100
Subject: [PATCH] direct kernel boot for cirros

---
 .../osnailyfacter/modular/astute/upload_cirros.rb  | 58 +++++++++++++++++++++-
 .../puppet/osnailyfacter/templates/vm_libvirt.erb  |  8 ++-
 2 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb b/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
index 04d597c..c342830 100755
--- a/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
+++ b/deployment/puppet/osnailyfacter/modular/astute/upload_cirros.rb
@@ -1,6 +1,7 @@
 #!/usr/bin/env ruby
 require 'hiera'
 
+
 ENV['LANG'] = 'C'
 
 hiera = Hiera.new(:config => '/etc/hiera.yaml')
@@ -56,11 +57,17 @@ def image_list
     fields = line.split('|').map { |f| f.chomp.strip }
     next if fields[1] == 'ID'
     next unless fields[2]
-    images << fields[2]
+    images << [fields[1], fields[2]]
   end
   {:images => images, :exit_code => return_code}
 end
 
+def image_name_list
+  images = image_list
+  images[:images].map! { |i| i[1] }
+  images
+end
+
 # TODO degorenko: remove --os-image-api-version after liberty (fuel-8.0) release
 def image_create(image_hash)
   command = <<-EOF
@@ -79,6 +86,15 @@ EOF
   [ stdout, return_code ]
 end
 
+# Calls glance update-image with a given property and value
+def update_image(image_id, property, value)
+  command = "/usr/bin/glance image-update --#{property} #{value} #{image_id}"
+  puts command
+  stdout = `#{command}`
+  return_code = $?.exitstatus
+  [ stdout, return_code ]
+end
+
 # check if Glance is online
 # waited until the glance is started because when vCenter used as a glance
 # backend launch may takes up to 1 minute.
@@ -93,7 +109,7 @@ end
 # upload image to Glance
 # if it have not been already uploaded
 def upload_image(image)
-  list_of_images = image_list
+  list_of_images = image_name_list
   if list_of_images[:images].include?(image['img_name']) && list_of_images[:exit_code] == 0
     puts "Image '#{image['img_name']}' is already present!"
     return 0
@@ -109,6 +125,43 @@ def upload_image(image)
   return return_code
 end
 
+# For each disk image try to find a kernel and initramfs images and
+# attach then to it via kernel_id and ramdisk_id glance properties.
+def connect_dependant_images(images)
+  # for each image
+  # get image id from glance
+  img_list = image_list
+  return_code = img_list[:exit_code]
+  if return_code == 0
+    images.each do |image|
+      img_list[:images].each do |il|
+        if il[1] == image['img_name']
+          image['id'] = il[0]
+        end
+      end
+    end
+    # for each image that is not in [aki, ari]
+    images.each do |image|
+      next if ['aki', 'ari'].include?(image['disk_format'])
+      images.each do |i|
+        # find aki/ari image whose name starts with this image's name
+        if i['img_name'].start_with?(image['img_name'])
+          ret = 0
+          if i['disk_format'] == 'aki'
+            _, ret = update_image(image['id'], 'property',
+                                        "kernel_id=#{i['id']}")
+          elsif i['disk_format'] == 'ari'
+            _, ret = update_image(image['id'], 'property',
+                                        "ramdisk_id=#{i['id']}")
+          end
+          return_code += ret
+        end
+      end
+    end
+  end
+  return return_code
+end
+
 ########################
 
 wait_for_glance
@@ -117,6 +170,7 @@ errors = 0
 test_vm_images.each do |image|
   errors += upload_image(image)
 end
+errors = connect_dependant_images(test_vm_images) unless errors != 0
 
 exit 1 unless errors == 0
 
diff --git a/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb b/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb
index 88b2c73..65e9400 100644
--- a/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb
+++ b/deployment/puppet/osnailyfacter/templates/vm_libvirt.erb
@@ -3,9 +3,15 @@
   <memory unit='GiB'><%= @details['mem'] %></memory>
   <vcpu placement='static'><%= @details['cpu'] %></vcpu>
   <os>
-    <type arch='<%= @machine_arch %>' machine='<%= @machine_type %>'>hvm</type>
+  <type arch='<%= @machine_arch %>' machine='<%= @machine_type %>'>hvm</type>
+  <% if $machine_arch == 'aarch64' %>
+    <kernel>/var/lib/nova/<%= @details['id'] %>_vm.kernel</kernel>
+    <initrd>/var/lib/nova/<%= @details['id'] %>_vm.initramfs</initrd>
+    <cmdline>root=/dev/vda1 rw rootwait console=tty0 console=ttyS0 console=ttyAMA0</cmdline>
+  <% else %>
     <boot dev='network'/>
     <boot dev='hd'/>
+  <% end %>
   </os>
   <features>
     <acpi/>