Permalink
Browse files

Add all the OpenNebula tools

  • Loading branch information...
Jaime Melis
Jaime Melis committed Jul 10, 2012
1 parent cbd1a37 commit 67eae2efcdb801798da2a368243048ea6d9aa364
Showing with 214 additions and 0 deletions.
  1. +68 −0 oneconf
  2. +2 −0 onedeploy
  3. +13 −0 oneinstantiate
  4. +83 −0 oneirb
  5. +30 −0 onereport
  6. +10 −0 onessh
  7. +8 −0 onevnc
View
68 oneconf
@@ -0,0 +1,68 @@
+#!/usr/bin/env ruby
+
+# This script prepares oned.conf and sched.conf
+
+require "fileutils"
+
+class String
+ def uncomment(string)
+ self.gsub!(string) do |m|
+ m.split("\n").map{|e| e.gsub(/^([\t\s]*)#+/,'\1')}.join("\n")
+ end
+ end
+end
+
+if ONE_LOCATION = ENV['ONE_LOCATION']
+ oned_conf = ONE_LOCATION + '/etc/oned.conf'
+ sched_conf = ONE_LOCATION + '/etc/sched.conf'
+else
+ oned_conf = '/etc/one/oned.conf'
+ sched_conf = '/etc/one/sched.conf'
+end
+
+now = Time.now.strftime('%Y%m%d%H%M%S').to_s
+
+FileUtils.cp(oned_conf, oned_conf + '.' + now)
+FileUtils.cp(sched_conf, sched_conf + '.' + now)
+
+# oned.conf
+
+conf = File.read(oned_conf)
+
+single_vals = {
+ :manager_timer => 5,
+ :host_monitoring_interval => 10,
+ :vm_polling_interval => 10
+}
+
+single_vals.each do |k,v|
+ k = k.to_s.upcase
+ v = v.to_s
+
+ if conf.match(/^#{k}/)
+ conf.gsub!(/^#{k}.*$/,"#{k} = #{v}")
+ else
+ conf << "\n#{k} = #{v}"
+ end
+end
+
+conf.uncomment('#TM_MAD = [
+# name = "tm_ssh",
+# executable = "one_tm",
+# arguments = "tm_ssh/tm_ssh.conf" ]')
+conf.uncomment('#TM_MAD = [
+# name = "tm_dummy",
+# executable = "one_tm",
+# arguments = "tm_dummy/tm_dummy.conf" ]')
+conf.uncomment('#IM_MAD = [ name="im_dummy", executable="one_im_dummy"]')
+conf.uncomment('#VM_MAD = [ name="vmm_dummy", executable="one_vmm_dummy", type="xml" ]')
+
+File.open(oned_conf,'w'){|f| f.write(conf)}
+
+# sched.conf
+
+conf = File.read(sched_conf)
+
+conf.gsub!('SCHED_INTERVAL = 30','SCHED_INTERVAL = 5')
+File.open(sched_conf,'w'){|f| f.write(conf)}
+
View
@@ -0,0 +1,2 @@
+#!/bin/bash
+onevm deploy `onevm create $1|awk '{print $2}'` `onehost list|awk 'END{print $1}'`
View
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+function getattr {
+ echo "$INFO"|grep -E "^$1\b"|awk '{print $3}'
+}
+
+INFO=$(onetemplate show $1)
+
+ID=`getattr ID`
+NAME=`getattr NAME`
+
+echo onetemplate instantiate $ID -n $NAME
+onetemplate instantiate $ID -n $NAME
View
83 oneirb
@@ -0,0 +1,83 @@
+#!/usr/bin/ruby
+
+ONE_LOCATION=ENV["ONE_LOCATION"]
+
+if !ONE_LOCATION
+ RUBY_LIB_LOCATION="/usr/lib/one/ruby"
+ VAR_LOCATION = "/var/lib/one"
+ TEMPLATE_LOCATION="/etc/one/occi_templates"
+ CONFIGURATION_FILE = "/etc/one/occi-server.conf"
+else
+ RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
+ VAR_LOCATION = ONE_LOCATION+"/var"
+ TEMPLATE_LOCATION=ONE_LOCATION+"/etc/occi_templates"
+ CONFIGURATION_FILE = ONE_LOCATION+"/etc/occi-server.conf"
+end
+
+OCCI_AUTH = VAR_LOCATION + "/.one/occi_auth"
+
+$: << RUBY_LIB_LOCATION
+$: << RUBY_LIB_LOCATION+"/cloud/occi"
+$: << RUBY_LIB_LOCATION+"/cloud" # For the Repository Manager
+
+
+
+################################################
+# Required libraries
+################################################
+require 'yaml'
+require 'erb'
+require 'tempfile'
+require 'fileutils'
+require 'json'
+
+require 'OpenNebula'
+include OpenNebula
+
+require 'VirtualMachineOCCI'
+require 'VirtualMachinePoolOCCI'
+require 'VirtualNetworkOCCI'
+require 'VirtualNetworkPoolOCCI'
+require 'ImageOCCI'
+require 'ImagePoolOCCI'
+require 'UserOCCI'
+require 'UserPoolOCCI'
+
+require 'pp'
+
+if ENV['ONE_AUTH']
+ authfile = ENV['ONE_AUTH']
+else
+ authfile = "ENV['HOME']/.one/one_auth"
+end
+
+# OpenNebula credentials
+CREDENTIALS = File.read(authfile).strip
+# XML_RPC endpoint where OpenNebula is listening
+ENDPOINT = "http://localhost:2633/RPC2"
+
+@client = Client.new(CREDENTIALS, ENDPOINT)
+
+begin
+ conf = YAML.load_file(CONFIGURATION_FILE)
+rescue Exception => e
+ puts "Error parsing config file #{CONFIGURATION_FILE}: #{e.message}"
+ exit 1
+end
+
+conf[:template_location] = TEMPLATE_LOCATION
+
+@config = conf
+require "irb"
+
+if __FILE__ == $0
+ IRB.start(__FILE__)
+else
+ # check -e option
+ if /^-e$/ =~ $0
+ IRB.start(__FILE__)
+ else
+ IRB.setup(__FILE__)
+ end
+end
+
View
@@ -0,0 +1,30 @@
+#!/usr/bin/env ruby
+
+require 'rexml/document'
+require 'pp'
+
+vmpool_x = `onevm list -x`
+vmpool = REXML::Document.new(vmpool_x).root
+
+first = true
+
+vmpool.elements.each("VM") do |vm|
+ puts unless first
+ first = false if first
+
+ puts "VM: " + vm.elements["ID"].text
+ puts "NAME: " + vm.elements["NAME"].text
+ if hostname = vm.elements["HISTORY_RECORDS/HISTORY/HOSTNAME"].text
+ puts "HOSTNAME: " + hostname
+ end
+ vm.elements.each("TEMPLATE/GRAPHICS") do |vnc|
+ if vnc_port = vnc.elements["PORT"]
+ puts "VNC PORT: " + vnc_port.text
+ end
+ end
+ vm.elements.each("TEMPLATE/NIC") do |nic|
+ if ip = nic.elements["IP"]
+ puts "IP: " + ip.text
+ end
+ end
+end
View
10 onessh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+VM=$1
+shift
+
+IP=$(onevm show $VM|grep IP=|grep -Eo '[0-9.]+'|head -n 1)
+
+ssh "$IP" "$*"
+
+
View
8 onevnc
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+PORT=$(onevm show $1|grep PORT|grep -o '[0-9]\+')
+if [ -n "$PORT" ]; then
+ vncviewer localhost::$PORT
+else
+ echo no port found.
+fi

0 comments on commit 67eae2e

Please sign in to comment.