ccbuilder 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (7) hide show
  1. data/.gitignore +1 -0
  2. data/README.rdoc +6 -1
  3. data/Rakefile +10 -3
  4. data/VERSION +1 -1
  5. data/bin/befog +78 -0
  6. data/lib/ONEClient.rb +59 -0
  7. metadata +19 -9
data/.gitignore CHANGED
@@ -17,5 +17,6 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
+ *.gemspec
20
21
 
21
22
  ## PROJECT::SPECIFIC
@@ -1,6 +1,11 @@
1
1
  = ccbuilder
2
2
 
3
- Description goes here.
3
+ Some tools for dynamically creating clusters on top of OpenNebula. This project is a
4
+ playground and implementations will be most likely domain specific to my company
5
+ in early versions, although I try to abstract from that as much as possible.
6
+
7
+ This is WORK IN PROGRESS!
8
+ All versions <1.0.0 should be treated as development and unstable versions.
4
9
 
5
10
  == Note on Patches/Pull Requests
6
11
 
data/Rakefile CHANGED
@@ -5,11 +5,18 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "ccbuilder"
8
- gem.summary = %Q{Cloud Cluster Builder - describe your virtual cluster}
9
- gem.description = %Q{Currently works with Chef and OpenNebula.}
8
+ gem.summary = %Q{Cloud Cluster Builder}
9
+ gem.description = <<EOF
10
+ Some tools for dynamically creating clusters on top of OpenNebula. This project is a
11
+ playground and implementations will be most likely domain specific to my company
12
+ in early versions, although I try to abstract from that as much as possible.
13
+
14
+ This is WORK IN PROGRESS!
15
+ All versions <1.0.0 should be treated as development and unstable versions.
16
+ EOF
10
17
  gem.email = "d.klein@gsi.de"
11
18
  gem.homepage = "http://github.com/Reverand221/ccbuilder"
12
- gem.authors = ["Dennis Klein"]
19
+ gem.authors = ["Dennis Klein", "Victor Penso"]
13
20
  gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
21
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
22
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "getoptlong"
5
+ require "lib/ONEClient"
6
+
7
+ help = <<EOF
8
+ Usage: befog [OPTIONS] COMMAND
9
+
10
+ -h, --help: Display this help
11
+
12
+ COMMANDS:
13
+
14
+ create FILE | create n virtual machines of type specified in FILE
15
+ -n, --repeat: Number of virtual machines, default n=1
16
+ FILE: Open Nebula virtual machine descriptor
17
+
18
+ list | show a list of your virtual machines
19
+
20
+ delete ID[..ID] | delete specified virtual machines
21
+ ID: single virtual machine ID
22
+ ID..ID: range of virtual machine IDs
23
+ EOF
24
+
25
+ begin
26
+
27
+ opts = GetoptLong.new(
28
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
29
+ [ '--repeat', '-n', GetoptLong::REQUIRED_ARGUMENT ]
30
+ )
31
+
32
+ # parse OPTIONS
33
+ repeat = 1
34
+ opts.each do |opt, arg|
35
+ case opt
36
+ when '--help'
37
+ puts help
38
+ exit
39
+ when '--repeat'
40
+ repeat = arg.to_i
41
+ end
42
+ end
43
+
44
+ # parse COMMAND
45
+ raise "Missing command (try --help)" if ARGV.length != 1
46
+ command = ARGV[0]
47
+
48
+ case command
49
+ when "create"
50
+ file = ARGV[1]
51
+ raise "Missing Open Nebula virtual machine decriptor FILE (try --help)" if !File.exists?(file)
52
+ one_client = CCBuilder::ONEClient.new
53
+ one_client.create(file, repeat)
54
+ when "list"
55
+ one_client = CCBuilder::ONEClient.new
56
+ one_client.list.each do |vm|
57
+ print vm['id'] + "\t" + vm['ip'] + "\t" + vm['host']
58
+ end
59
+ when "delete"
60
+ begin
61
+ id_low = ARGV[1].match(/^([12345679][:digit:]*)/)[0].to_i
62
+ id_high = ARGV[1].match(/\.\.([12345679][:digit:]*)?/)[0].to_i
63
+ rescue
64
+ raise "Illegal ID input (try --help)"
65
+ end
66
+ raise "Missing ID (try --help)" if id_low == 0
67
+ id_high = id_low if id_high < id_low
68
+ one_client = CCBuilder::ONEClient.new
69
+ one_client.delete(id_low, id_high)
70
+ else
71
+ raise "Unrecognized command: #{command} (try --help)"
72
+ end
73
+
74
+ # print errors
75
+ rescue SystemExit
76
+ rescue Exception => e
77
+ puts e.message
78
+ end
@@ -0,0 +1,59 @@
1
+ # ONEClient.rb
2
+ # wraps the Open Nebula XML RPC client
3
+ # author: Dennis Klein <d.klein@gsi.de>
4
+
5
+ ONE_LOCATION=ENV["ONE_LOCATION"]
6
+ RUBY_LIB_LOCATION = !ONE_LOCATION ? "/usr/lib/one/ruby" : ONE_LOCATION+"/lib/ruby"
7
+ $: << RUBY_LIB_LOCATION
8
+
9
+ require "OpenNebula"
10
+
11
+ module CCBuilder
12
+ class ONEClient
13
+
14
+ def initialize()
15
+ @one_client = OpenNebula::Client.new(nil)
16
+ rescue OpenNebula::Error => e
17
+ raise Error.new("OpenNebula: #{e.message}")
18
+ end
19
+
20
+ # API-method create
21
+ def create(one_vm_descriptor, n = 1)
22
+ n.times do |i|
23
+ create_single(one_vm_descriptor)
24
+ end
25
+ end
26
+
27
+ def create_single(one_vm_descriptor)
28
+ vm = OpenNebula::VirtualMachine.new(OpenNebula::VirtualMachine.build_xml, @one_client)
29
+ template=File.read(one_vm_descriptor)
30
+ vm.allocate(template)
31
+ rescue
32
+ raise Error.new("OpenNebula: Can not read template: #{one_vm_descriptor}")
33
+ end
34
+
35
+ # API-method list
36
+ def list
37
+ raise Error.new("not yet implemented")
38
+ end
39
+
40
+ # API-method delete
41
+ def delete(id_low, id_high = 0)
42
+ id_high = id_low if id_high < id_low
43
+ Range.new(id_low,id_high).each do |id|
44
+ delete_single(id)
45
+ end
46
+ end
47
+
48
+ def delete_single(id)
49
+ vm = OpenNebula::VirtualMachine.new_with_id(id, @one_client)
50
+ vm.finalize
51
+ rescue OpenNebula::Error => e
52
+ raise Error.new("OpenNebula: #{e.message}")
53
+ end
54
+
55
+ end
56
+
57
+ class Error < Exception end
58
+ end
59
+ end
metadata CHANGED
@@ -1,22 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccbuilder
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dennis Klein
14
+ - Victor Penso
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-08-06 00:00:00 +02:00
19
- default_executable:
19
+ date: 2010-08-16 00:00:00 +02:00
20
+ default_executable: befog
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
22
23
  name: thoughtbot-shoulda
@@ -32,10 +33,17 @@ dependencies:
32
33
  version: "0"
33
34
  type: :development
34
35
  version_requirements: *id001
35
- description: Currently works with Chef and OpenNebula.
36
- email: d.klein@gsi.de
37
- executables: []
36
+ description: |
37
+ Some tools for dynamically creating clusters on top of OpenNebula. This project is a
38
+ playground and implementations will be most likely domain specific to my company
39
+ in early versions, although I try to abstract from that as much as possible.
40
+
41
+ This is WORK IN PROGRESS!
42
+ All versions <1.0.0 should be treated as development and unstable versions.
38
43
 
44
+ email: d.klein@gsi.de
45
+ executables:
46
+ - befog
39
47
  extensions: []
40
48
 
41
49
  extra_rdoc_files:
@@ -48,6 +56,8 @@ files:
48
56
  - README.rdoc
49
57
  - Rakefile
50
58
  - VERSION
59
+ - bin/befog
60
+ - lib/ONEClient.rb
51
61
  - lib/ccbuilder.rb
52
62
  - test/helper.rb
53
63
  - test/test_ccbuilder.rb
@@ -84,7 +94,7 @@ rubyforge_project:
84
94
  rubygems_version: 1.3.7
85
95
  signing_key:
86
96
  specification_version: 3
87
- summary: Cloud Cluster Builder - describe your virtual cluster
97
+ summary: Cloud Cluster Builder
88
98
  test_files:
89
99
  - test/helper.rb
90
100
  - test/test_ccbuilder.rb