Remove elasticsearch module, it is no longer needed
[mirror/dsa-puppet.git] / 3rdparty / modules / glance / ext / glance.rb
1 #!/usr/bin/env ruby
2 #
3 # test that we can upload and download files
4 #
5 require 'open3'
6 require 'fileutils'
7
8 keystone_public = '127.0.0.1'
9 image_dir='/tmp/images'
10
11 ENV['OS_USERNAME']='admin'
12 ENV['OS_TENANT_NAME']='admin'
13 ENV['OS_PASSWORD']='ChangeMe'
14 ENV['OS_AUTH_URL']='http://127.0.0.1:5000/v2.0/'
15 ENV['OS_REGION_NAME']='RegionOne'
16
17 FileUtils.mkdir_p(image_dir)
18 Dir.chdir(image_dir) do |dir|
19
20   kernel_id = nil
21   initrd_id = nil
22
23   remote_image_url='http://smoser.brickies.net/ubuntu/ttylinux-uec/ttylinux-uec-amd64-12.1_2.6.35-22_1.tar.gz; tar -zxvf ttylinux-uec-amd64-12.1_2.6.35-22_1.tar.gz'
24
25   wget_command = "wget #{remote_image_url}"
26
27   Open3.popen3(wget_command) do |stdin, stdout, stderr|
28     puts "wget stdout: #{stdout.read}"
29     puts "wget stderr: #{stderr.read}"
30   end
31
32   add_kernel='disk_format=aki container_format=aki < ttylinux-uec-amd64-12.1_2.6.35-22_1-vmlinuz'
33   kernel_name='tty-linux-kernel'
34   kernel_format='aki'
35
36   add_kernel_command="glance add name='#{kernel_name}' disk_format='#{kernel_format}' container_format=#{kernel_format} < ttylinux-uec-amd64-12.1_2.6.35-22_1-vmlinuz"
37
38   Open3.popen3(add_kernel_command) do |stdin, stdout, stderr|
39     stdout = stdout.read.split("\n")
40     stdout.each do |line|
41       if line =~ /Added new image with ID: (\w+)/
42         kernel_id = $1
43       end
44     end
45     puts stderr.read
46     puts stdout
47   end
48
49   raise(Exception, 'Did not add kernel successfully') unless kernel_id
50
51   initrd_id = nil
52   add_initrd_command="glance add name='tty-linux-ramdisk' disk_format=ari container_format=ari < ttylinux-uec-amd64-12.1_2.6.35-22_1-loader"
53
54   Open3.popen3(add_initrd_command) do |stdin, stdout, stderr|
55     stdout = stdout.read.split("\n")
56     stdout.each do |line|
57       if line =~ /Added new image with ID: (\w+)/
58         initrd_id = $1
59       end
60     end
61     puts stderr.read
62     puts stdout
63   end
64
65   raise(Exception, 'Did not add initrd successfully') unless initrd_id
66
67   add_image_command="glance add name='tty-linux' disk_format=ami container_format=ami kernel_id=#{kernel_id} ramdisk_id=#{initrd_id} < ttylinux-uec-amd64-12.1_2.6.35-22_1.img"
68
69   Open3.popen3(add_image_command) do |stdin, stdout, stderr|
70     stdout = stdout.read.split("\n")
71     stdout.each do |line|
72       if line =~ /Added new image with ID: (\w+)/
73         kernel_id = $1
74       end
75     end
76     puts stderr.read
77     puts stdout
78   end
79
80   get_index='glance index'
81
82   Open3.popen3(get_index) do |stdin, stdout, stderr|
83     puts stdout.read
84     puts stderr.read
85   end
86 end