forked from pdxcat/ganeti_cloud-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_data.rb
executable file
·69 lines (54 loc) · 1.23 KB
/
cloud_data.rb
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
#!/usr/bin/ruby
require 'yaml'
require 'base64'
require 'uri'
require 'net/http'
$host = ENV['INSTANCE_NAME']
$variant = ENV['OS_VARIANT']
$osfamily, $osversion = $variant.split('-')
$config = {}
derp_file = "http://lsd.cat.pdx.edu/host/ks?name=#{URI.escape(ENV['INSTANCE_OS']).sub("+","%2B")}"
#puts derp_file
#Kernel.exit(0)
def get_kickstart(url)
location = URI.parse(url)
#puts location
response = Net::HTTP.get_response(location)
case response
when Net::HTTPSuccess then
response
else
return nil
end
end
def parse_kickstart(kickstart)
sections = {}
section = nil
kickstart.split("\n").each do |line|
if line =~ /^%([a-z]+)/
if $1 != "include"
section = $1
end
elsif section
if !sections[section]
sections[section] = []
end
sections[section].push line.gsub(ENV['INSTANCE_OS'],$host)
end
end
sections.keys.each do |key|
sections[key] = sections[key].join("\n")
end
return sections
end
kickstart = get_kickstart(derp_file)
if !kickstart
exit(1)
end
$kickstart = parse_kickstart(kickstart.body)
require './defaults.rb'
variant_file = "./variants/#{ENV['OS_VARIANT']}.rb"
if File.exist?(variant_file)
require variant_file
end
puts $config.to_yaml