Top Level Namespace

Defined Under Namespace

Modules: AETK Classes: HTTPDownloader, InstantDeployCLI, MyCLI, StreamingUploader, String, SystemCommands

Constant Summary collapse

JAVA_BIN =
"/usr/java/default/bin/java"
ABIQUO_BASE_DIR =
'/opt/abiquo'
TOMCAT_DIR =
'/opt/abiquo/tomcat'
TOMCAT_PID_FILE =
'/opt/abiquo/tomcat/work/catalina.pid'
ABIQUO_VERSION =
"1.6"
ABIQUO_SERVER_CONFIG =
'/opt/abiquo/config/server.xml'
ABIQUO_VIRTUALFACTORY_CONFIG =
'/opt/abiquo/config/virtualfactory.xml'
ABIQUO_VSM_CONFIG =
'/opt/abiquo/config/vsm.xml'
ABIQUO_NODECOLLECTOR_CONFIG =
'/opt/abiquo/config/nodecollector.xml'
ABIQUO_AM_CONFIG =
'/opt/abiquo/config/am.xml'
ABIQUO_BPMASYNC_CONFIG =
'/opt/abiquo/config/bpm-async.xml'
TOMCAT_SERVER_CONFIG =
'/opt/abiquo/tomcat/conf/Catalina/localhost/server.xml'
TOMCAT_SERVER_BUILTIN_CONFIG =
'/opt/abiquo/tomcat/webapps/server/META-INF/context.xml'
TOMCAT_API_CONFIG =
'/opt/abiquo/tomcat/conf/Catalina/localhost/api.xml'
TOMCAT_API_BUILTIN_CONFIG =
'/opt/abiquo/tomcat/webapps/api/META-INF/context.xml'
TOMCAT_BPMASYNC_CONFIG =
'/opt/abiquo/tomcat/conf/Catalina/localhost/bpm-async.xml'
TOMCAT_BPMASYNC_BUILTIN_CONFIG =
'/opt/abiquo/tomcat/webapps/bpm-async/META-INF/context.xml'

Instance Method Summary collapse

Methods included from AETK::OutputFormatters

#two_cols

Instance Method Details

#abiquo_am_configObject



112
113
114
115
116
117
# File 'lib/abiquo-etk.rb', line 112

def abiquo_am_config 
  cfg = nil
  if File.exist? ABIQUO_AM_CONFIG
    cfg = Nokogiri::XML(File.new(ABIQUO_AM_CONFIG))
  end
end

#abiquo_base_dirObject



49
50
51
# File 'lib/abiquo-etk.rb', line 49

def abiquo_base_dir
  return ABIQUO_BASE_DIR
end

#abiquo_bpmasync_configObject



119
120
121
122
123
124
125
# File 'lib/abiquo-etk.rb', line 119

def abiquo_bpmasync_config
  cfg = nil
  if File.exist? ABIQUO_BPMASYNC_CONFIG
    cfg = Nokogiri::XML(File.new(ABIQUO_BPMASYNC_CONFIG))
  end
  return cfg
end

#abiquo_components_installedObject



65
66
67
68
69
# File 'lib/abiquo-etk.rb', line 65

def abiquo_components_installed
  c = Dir["#{TOMCAT_DIR}/webapps/*"].find_all { |d| File.directory? d }
  c.map { |d| d.split('/').last }

end

#abiquo_editionObject



32
33
# File 'lib/abiquo-etk.rb', line 32

def abiquo_edition
end

#abiquo_installed?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/abiquo-etk.rb', line 57

def abiquo_installed?
  return (File.directory?('/opt/abiquo') && RPMUtils.rpm_installed?('abiquo-core'))
end

#abiquo_nodecollector_configObject



104
105
106
107
108
109
110
# File 'lib/abiquo-etk.rb', line 104

def abiquo_nodecollector_config 
  cfg = nil
  if File.exist? ABIQUO_NODECOLLECTOR_CONFIG
    cfg = Nokogiri::XML(File.new(ABIQUO_NODECOLLECTOR_CONFIG))
  end
  return cfg
end

#abiquo_rs_settings(file = '/opt/abiquo/config/abiquo.properties') ⇒ Object



45
46
47
# File 'lib/abiquo-etk.rb', line 45

def abiquo_rs_settings(file = '/opt/abiquo/config/abiquo.properties')
  abiquo_server_settings
end

#abiquo_schema_premium?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/checks/1.7.5/mysql.rb', line 16

def abiquo_schema_premium?
  File.exist? '/var/lib/mysql/kinton/virtualimage_conversions.frm'
end

#abiquo_schema_present?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/checks/1.7.5/mysql.rb', line 12

def abiquo_schema_present?
  File.directory? '/var/lib/mysql/kinton'
end

#abiquo_server_configObject



79
80
81
82
83
84
85
# File 'lib/abiquo-etk.rb', line 79

def abiquo_server_config
  cfg = nil
  if File.exist? ABIQUO_SERVER_CONFIG
    cfg = Nokogiri::XML(File.new(ABIQUO_SERVER_CONFIG))
  end
  return cfg 
end

#abiquo_server_settings(file = '/opt/abiquo/config/abiquo.properties') ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/abiquo-etk.rb', line 35

def abiquo_server_settings(file = '/opt/abiquo/config/abiquo.properties')
	settings = {}
  File.read(file).each_line do |l|
    next if l.strip.chomp.empty?
    key,val = l.strip.chomp.split('=')
    settings[key.strip.chomp] = val.strip.chomp rescue ''
  end
  settings
end

#abiquo_tomcat_running?Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
# File 'lib/checks/1.7.5/abiquo_service.rb', line 3

def abiquo_tomcat_running?
  return false if not File.exist?(TOMCAT_PID_FILE)

  pid = File.read(TOMCAT_PID_FILE)
  if `ps #{pid}`.lines.count > 1
    return true
  end
  false
end

#abiquo_virtualfactory_configObject



87
88
89
90
91
92
93
# File 'lib/abiquo-etk.rb', line 87

def abiquo_virtualfactory_config
  cfg  = nil
  if File.exist? ABIQUO_VIRTUALFACTORY_CONFIG
    cfg= Nokogiri::XML(File.new(ABIQUO_VIRTUALFACTORY_CONFIG))
  end
  return cfg
end

#abiquo_vsm_configObject



96
97
98
99
100
101
102
# File 'lib/abiquo-etk.rb', line 96

def abiquo_vsm_config
  cfg = nil
  if File.exist? ABIQUO_VSM_CONFIG
    cfg = Nokogiri::XML(File.new(ABIQUO_VSM_CONFIG))
  end
  return cfg
end

#config_get_attribute(cf, path, attrname) ⇒ Object



53
54
55
# File 'bin/abicli', line 53

def config_get_attribute(cf, path, attrname)
	cf.root.xpath(path).first[attrname] rescue nil
end

#config_get_node(cf, path) ⇒ Object



33
34
35
# File 'bin/abicli', line 33

def config_get_node(cf, path)
	cf.root.xpath(path).first.text rescue nil
end

#config_property(config, path) ⇒ Object



61
62
63
# File 'lib/abiquo-etk.rb', line 61

def config_property(config, path)
  config.root.xpath(path).text.chomp.strip
end

#config_set_attribute(file, path, attrname, val, write_changes = false) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'bin/abicli', line 37

def config_set_attribute(file, path, attrname, val, write_changes = false)
  if not File.exist?(file)
    AETK::Log.instance.error "config_set_attribute: file #{file} not found."
  end

  doc = Nokogiri::XML(File.new(file))
	doc.root.xpath(path).first[attrname] = (val||'')
  if write_changes
    File.open(file, 'w') do |f|
      f.puts doc.to_xml
    end
  end

  return doc
end

#config_set_node(file, path, val, write_changes = false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'bin/abicli', line 22

def config_set_node(file, path, val, write_changes = false)
  doc = Nokogiri::XML(File.new(file))
	doc.root.xpath(path).first.content = (val || '')
  if write_changes
    File.open(file, 'w') do |f|
      f.puts doc.to_xml
    end
  end
  return doc
end

#distribution_versionObject



279
280
281
282
283
# File 'lib/abicli/commands/instant-deploy.rb', line 279

def distribution_version
  /DISTRIB_DESCRIPTION="(.*)"/.match File.read('/etc/lsb-release')
  version = $1.splitp[1] || '0'
  version
end

#fw_rules_defined?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/checks/1.7.5/firewall.rb', line 3

def fw_rules_defined?
  not `iptables -nL | grep -iv ^chain | grep -iv ^target | grep -v ^$`.empty?
end

#helpObject



57
58
59
60
61
62
63
64
65
66
# File 'bin/abicli', line 57

def help
  path = File.dirname(__FILE__) + '/../lib/abicli/commands/*.rb'
  commands = Dir[path]
  commands.map! { |cmd| File.basename(cmd,'.rb') }
  puts "\n#{'ABICLI Usage'.bold}\n\n"
  puts "Available commands:\n\n"

  commands.sort.each { |cmd| puts "  #{cmd}\n" }
  puts ""
end

#install_iso(params = {}) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/abicli/commands/instant-deploy.rb', line 197

def install_iso(params = {})
  target_dir = params[:target_dir] || "abiquo-instant-deploy-#{Time.now.strftime "%s"}"
  disk_file = params[:disk_file] || "#{target_dir}/abiquo.qcow2"
  iso_url = params[:iso_url]
  mem = params[:mem]
  tomcat_port = params[:tomcat_port]
  ssh_port = params[:ssh_port]
  graphics = ''
  vm_name = params[:vm_name]

  if params[:vnc]
    graphics = "--vnc :#{params[:vnc_display]}"
  end
  # Create target directory
  begin
    FileUtils.mkdir(target_dir)
  rescue Exception
    $stderr.puts "\nError creating directory #{target_dir}. Aborting.\n\n"
    exit 1
  end

  # Create qemu img
  if File.exist? disk_file 
    raise Exception.new("Image #{disk_file} already exists")
  end
  `/usr/bin/qemu-img create -f qcow2 #{disk_file} 20GB`


  if iso_url =~ /http:\/\//
    # Download the iso
    downloader = HTTPDownloader.new
    puts "Downloading Abiquo ISO..."
    cdrom = ""
    begin
      r = downloader.download! iso_url, File.new(target_dir + '/instant-deploy.iso', 'w')
      if r.class != Net::HTTPOK
        raise Exception
      end
      cdrom = target_dir + '/instant-deploy.iso'
    rescue Exception
      $stderr.puts "\nError downloading Abiquo ISO. Aborting."
      exit
    end
  else
    if iso_url =~ /file:/
      iso_url.gsub!('file://','')
    end
    if not File.exist? iso_url
      $stderr.puts "The ISO file specified does not exist."
      exit 1
    else
      cdrom = iso_url
    end
  end

  # Boot
  puts "\nAfter the install process, open the browser and type:\n"
  puts "\nhttp://127.0.0.1:#{tomcat_port}/client-premium\n\n"
  puts "To open the Abiquo Web Console."
  puts "\nTo SSH to the Abiquo VM type:"
  puts "ssh -p #{ssh_port} localhost\n\n"
  puts "\nBooting the Installer...\n\n"
  File.open(target_dir + '/run.sh', 'w') do |f|
    f.puts "#!/bin/sh"
    f.puts "MEM=#{mem}"
    f.puts "TAP=vtap0"
    f.puts ""
    f.puts "#{SystemCommands.kvm} -name #{vm_name} #{graphics} -m $MEM -drive file=#{File.basename(disk_file)} -net user,hostfwd=tcp:0.0.0.0:#{tomcat_port}-:80,hostfwd=tcp:0.0.0.0:#{ssh_port}-:22 -net nic -boot order=c > /dev/null"
    f.puts ""
    f.puts "#"
    f.puts "# Comment the above line and uncomment this to use bridged networking."
    f.puts "# You will need to have a working bridge setup in order to use this."
    f.puts "# Update TAP variable above to fill your needs."
    f.puts "#"
    f.puts "#sudo #{SystemCommands.kvm} -name #{vm_name} #{graphics} -m $MEM -drive file=#{File.basename(disk_file)} -net tap,ifname=$TAP -net nic -boot order=c > /dev/null 2>&1"
  end
  output = `#{SystemCommands.kvm} -name #{vm_name} #{graphics} -m 1024 -drive file=#{disk_file} -net user,hostfwd=tcp:0.0.0.0:#{tomcat_port}-:80,hostfwd=tcp:0.0.0.0:#{ssh_port}-:22 -net nic -drive file=#{cdrom},media=cdrom -boot order=cd -boot once=d 2>&1 `
  if $? != 0
    puts "Error booting the VM: #{output}"
  end
end

#java_ok?Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/checks/1.7.5/java.rb', line 3

def java_ok?
  log = AETK::Log.instance
  if not File.exist? JAVA_BIN
    log.error "Java binary not found in #{JAVA_BIN}"
    return false
  end

  if `java -version 2>&1 | grep '64-Bit Server'`.empty?
    log.error "Java 64-Bit runtime not found"
    return false
  end

  return true
end

#local_ipObject



8
9
10
11
12
13
14
15
16
# File 'bin/ciab-setup', line 8

def local_ip
  orig, Socket.do_not_reverse_lookup = Socket.do_not_reverse_lookup, true  # turn off reverse DNS resolution temporarily
  UDPSocket.open do |s|
    s.connect '64.233.187.99', 1
    s.addr.last
  end
ensure
  Socket.do_not_reverse_lookup = orig
end

#mysqld_installed?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/checks/1.7.5/mysql.rb', line 8

def mysqld_installed?
  RPMUtils.rpm_installed?('mysql-server')
end

#mysqld_running?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/checks/1.7.5/mysql.rb', line 4

def mysqld_running?
  return true if `service mysqld status`.strip.chomp != 'mysqld is stopped'
end

#nfs_server_running?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/checks/1.7.5/nfs.rb', line 4

def nfs_server_running?
  return ((`exportfs`.lines.first.strip.chomp == '/opt/vm_repository') rescue false)
end

#os_versionObject



1
2
3
# File 'lib/checks/1.7.5/os_version.rb', line 1

def os_version
  File.read('/etc/redhat-release').strip.chomp rescue 'Unknown'
end

#pfcheck_redhatObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/abicli/commands/instant-deploy.rb', line 156

def pfcheck_redhat
  if File.read('/etc/redhat-release') !~ /^(FrameOS|CentOS|Red Hat Enterprise|Fedora)/
    $stderr.puts "\nRHEL not found. Your distribution is not supported.\n\n"
    exit
  end
  
  #
  # Check if KVM installed
  #
  if `which /usr/libexec/qemu-kvm`.strip.chomp.empty?
    $stderr.puts "\nKVM not found. Install it first:\n\n"
    $stderr.puts "yum install kvm\n\n"
    exit
  end
  
  SystemCommands.kvm = '/usr/libexec/qemu-kvm'
end

#pfcheck_ubuntuObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/abicli/commands/instant-deploy.rb', line 138

def pfcheck_ubuntu
  if (File.read('/etc/lsb-release') !~ /DISTRIB_ID=Ubuntu/)
    $stderr.puts "\nUbuntu not found. Your distribution is not supported.\n\n"
    exit
  end
  
  #
  # Check if KVM installed
  #
  if `which /usr/bin/kvm`.strip.chomp.empty?
    $stderr.puts "\nKVM not found. Install it first:\n\n"
    $stderr.puts "sudo apt-get install kvm\n\n"
    exit
  end
  
  SystemCommands.kvm = '/usr/bin/kvm'
end

#preflight_checkObject



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/abicli/commands/instant-deploy.rb', line 174

def preflight_check
  #
  # Check if this is Ubuntu
  #
  if File.exist?('/etc/lsb-release')
    pfcheck_ubuntu
  elsif File.exist?('/etc/redhat-release')
    pfcheck_redhat
  else
    $stderr.puts "\nOnly Ubuntu and RHEL distributions are supported.\n\n"
    exit
  end

  #
  # Check if qemu-img installed
  #
  if `which /usr/bin/qemu-img`.strip.chomp.empty?
    $stderr.puts "\nqemu-img not found. Install it first:\n\n"
    $stderr.puts "sudo apt-get install kvm\n\n"
    exit
  end
end

#service_installed?(service_name) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/abiquo-etk.rb', line 75

def service_installed?(service_name)
  File.exist?("/etc/rc.d/init.d/#{service_name}")
end

#system_service_on?(service) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/abiquo-etk.rb', line 71

def system_service_on?(service)
  not `/sbin/chkconfig --list #{service}|grep 3:on`.empty?
end

#tomcat_base_dirObject



53
54
55
# File 'lib/abiquo-etk.rb', line 53

def tomcat_base_dir
  return TOMCAT_DIR
end

#tomcat_mem_limitsObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/checks/1.7.5/abiquo_service.rb', line 13

def tomcat_mem_limits
  return ['unknown','unknown', 'unknown'] if not File.exist?(TOMCAT_PID_FILE)
  pid = File.read(TOMCAT_PID_FILE)
  `ps #{pid}` =~ /-XX:MaxPermSize=(.*?)\s/
  perm_size = $1 || 'unknown'
  `ps #{pid}` =~ /-Xms(.*?)\s/
  xms = $1 || 'unknown'
  `ps #{pid}` =~ /-Xmx(.*?)\s/
  xmx = $1 || 'unknown'
  [perm_size, xms, xmx]
end

#vbox_installed?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/checks/1.7.5/virtualbox.rb', line 5

def vbox_installed?
  RPMUtils.rpm_installed? 'vboxmanage'
end