uv_proxmox 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 maxschulze
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = uv_proxmox
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 maxschulze. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,61 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
5
+
6
+
7
+ begin
8
+ require 'jeweler'
9
+ Jeweler::Tasks.new do |gem|
10
+ gem.name = "uv_proxmox"
11
+ gem.summary = %Q{A ruby api for working with the proxmox virtual machine manager}
12
+ gem.description = %Q{A ruby api for working with the proxmox virtual machine manager}
13
+ gem.email = "max.schulze@gmail.com"
14
+ gem.homepage = "http://github.com/maxschulze/uv_proxmox"
15
+ gem.authors = ["maxschulze"]
16
+ gem.require_paths = %w(lib)
17
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
18
+ gem.add_dependency "net-ssh", ">= 0"
19
+ gem.add_dependency "blockenspiel", ">= 0"
20
+ gem.add_dependency "activesupport", ">= 3.0.0"
21
+ gem.files += Dir.glob("lib/**/*")
22
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
23
+ end
24
+ Jeweler::GemcutterTasks.new
25
+ rescue LoadError
26
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
27
+ end
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ begin
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ end
43
+ rescue LoadError
44
+ task :rcov do
45
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
46
+ end
47
+ end
48
+
49
+ task :test => :check_dependencies
50
+
51
+ task :default => :test
52
+
53
+ require 'rake/rdoctask'
54
+ Rake::RDocTask.new do |rdoc|
55
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
56
+
57
+ rdoc.rdoc_dir = 'rdoc'
58
+ rdoc.title = "uv_proxmox #{version}"
59
+ rdoc.rdoc_files.include('README*')
60
+ rdoc.rdoc_files.include('lib/**/*.rb')
61
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,23 @@
1
+ require 'uv_proxmox'
2
+
3
+ connection = Uv::Proxmox::Connection.new
4
+ connection.user = 'root'
5
+ connection.password = ''
6
+ connection.ip_address = 'vm1.mo-stud.io'
7
+
8
+ Uv::Proxmox.connection = connection
9
+
10
+ Uv::Proxmox::VirtualMachine.create do
11
+ id 1001
12
+ template 'debian-6.0-standard_6.0-2_amd64.tar.gz'
13
+ memory 1024
14
+ swap 1024
15
+ cpus 2
16
+ cpu_units 500
17
+ boot 1
18
+ disk 10
19
+ end
20
+
21
+ puts Uv::Proxmox.commands.inspect
22
+
23
+ Uv::Proxmox.run
data/lib/uv_proxmox.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/core_ext/module'
4
+
5
+ $: << Dir.getwd
6
+
7
+ begin
8
+ require 'uv_proxmox/virtual_machine'
9
+ require 'uv_proxmox/connection'
10
+ rescue => e
11
+ raise e
12
+ end
13
+
14
+ module Uv
15
+ module Proxmox
16
+
17
+ mattr_accessor :commands
18
+ @@commands = []
19
+
20
+ mattr_accessor :connection
21
+ @@connection = nil
22
+
23
+ # assign a connection first
24
+ def self.run
25
+ self.commands.each do |cmd|
26
+ puts self.connection.execute(cmd)
27
+ end
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ require 'rubygems'
2
+ require 'net/ssh'
3
+
4
+ module Uv
5
+ module Proxmox
6
+
7
+ class Connection
8
+ attr_accessor :ip_address
9
+ attr_accessor :user
10
+ attr_accessor :password
11
+ attr_accessor :port
12
+ @port = 22
13
+
14
+ def initialize
15
+
16
+ end
17
+
18
+ def execute(cmd)
19
+ Net::SSH.start(self.ip_address, self.user, :password => self.password, :port => self.port) do |ssh|
20
+ @command_output = ssh.exec!(cmd)
21
+ end
22
+
23
+ return @command_output
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,73 @@
1
+ require 'blockenspiel'
2
+
3
+ module Uv
4
+ module Proxmox
5
+
6
+ class VirtualMachine
7
+ include Blockenspiel::DSL
8
+
9
+ # the operating system template to use
10
+ dsl_attr_accessor :template
11
+
12
+ # memory in mega bytes to assign to the VM
13
+ dsl_attr_accessor :memory
14
+
15
+ # swap in mega bytes to assign to the VM
16
+ dsl_attr_accessor :swap
17
+
18
+ # disk space in giga bytes to assign to the VM
19
+ dsl_attr_accessor :disk
20
+
21
+ # the number of cpu's to assign to the VM
22
+ dsl_attr_accessor :cpus
23
+
24
+ # CPU units to assign between 8 - 500000
25
+ dsl_attr_accessor :cpu_units
26
+
27
+ # Shall the VM start on the system boot
28
+ dsl_attr_accessor :boot
29
+
30
+ # id of the node
31
+ dsl_attr_accessor :id
32
+
33
+ attr_accessor :operation
34
+
35
+ def self.create(&block)
36
+ @vm = Uv::Proxmox::VirtualMachine.new
37
+ Blockenspiel.invoke(block, @vm)
38
+
39
+ @vm.operation = 'create'
40
+ Uv::Proxmox.commands << @vm.to_command
41
+ end
42
+
43
+ def self.update(&block)
44
+ @vm = Uv::Proxmox::VirtualMachine.new
45
+ Blockenspiel.invoke(block, @vm)
46
+
47
+ @vm.operation = 'update'
48
+ Uv::Proxmox.commands << @vm.to_command
49
+ end
50
+
51
+ def to_command
52
+ raise ArgumentError, 'missing vmid' if id.blank?
53
+ raise ArgumentError, 'missing template' if template.blank? and self.operation == 'create'
54
+
55
+ commands = []
56
+ commands << "--ostemplate #{template}" unless template.blank?
57
+ commands << "--mem #{memory}" unless memory.blank?
58
+ commands << "--swap #{swap}" unless swap.blank?
59
+ commands << "--disk #{disk}" unless disk.blank?
60
+ commands << "--cpus #{cpus}" unless cpus.blank?
61
+ commands << "--cpuunits #{cpu_units}" unless cpu_units.blank?
62
+ commands << "--onboot #{boot}" unless boot.blank?
63
+
64
+ task = 'vzcreate' if self.operation == 'create'
65
+ task = 'vzset' if self.operation == 'update'
66
+
67
+ "pvectl #{task} #{id} #{commands.join(" ")}"
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'uv_proxmox'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestUvProxmox < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{uv_proxmox}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["maxschulze"]
12
+ s.date = %q{2010-09-25}
13
+ s.description = %q{A ruby api for working with the proxmox virtual machine manager}
14
+ s.email = %q{max.schulze@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "examples/create_new_virtual_machine.rb",
27
+ "lib/uv_proxmox.rb",
28
+ "lib/uv_proxmox/connection.rb",
29
+ "lib/uv_proxmox/virtual_machine.rb",
30
+ "test/helper.rb",
31
+ "test/test_uv_proxmox.rb",
32
+ "uv_proxmox.gemspec"
33
+ ]
34
+ s.homepage = %q{http://github.com/maxschulze/uv_proxmox}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.7}
38
+ s.summary = %q{A ruby api for working with the proxmox virtual machine manager}
39
+ s.test_files = [
40
+ "test/helper.rb",
41
+ "test/test_uv_proxmox.rb",
42
+ "examples/create_new_virtual_machine.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ s.add_runtime_dependency(%q<net-ssh>, [">= 0"])
52
+ s.add_runtime_dependency(%q<blockenspiel>, [">= 0"])
53
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0"])
54
+ else
55
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ s.add_dependency(%q<net-ssh>, [">= 0"])
57
+ s.add_dependency(%q<blockenspiel>, [">= 0"])
58
+ s.add_dependency(%q<activesupport>, [">= 3.0.0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
62
+ s.add_dependency(%q<net-ssh>, [">= 0"])
63
+ s.add_dependency(%q<blockenspiel>, [">= 0"])
64
+ s.add_dependency(%q<activesupport>, [">= 3.0.0"])
65
+ end
66
+ end
67
+
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uv_proxmox
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - maxschulze
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-25 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: net-ssh
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: blockenspiel
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: activesupport
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 7
72
+ segments:
73
+ - 3
74
+ - 0
75
+ - 0
76
+ version: 3.0.0
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ description: A ruby api for working with the proxmox virtual machine manager
80
+ email: max.schulze@gmail.com
81
+ executables: []
82
+
83
+ extensions: []
84
+
85
+ extra_rdoc_files:
86
+ - LICENSE
87
+ - README.rdoc
88
+ files:
89
+ - .document
90
+ - .gitignore
91
+ - LICENSE
92
+ - README.rdoc
93
+ - Rakefile
94
+ - VERSION
95
+ - examples/create_new_virtual_machine.rb
96
+ - lib/uv_proxmox.rb
97
+ - lib/uv_proxmox/connection.rb
98
+ - lib/uv_proxmox/virtual_machine.rb
99
+ - test/helper.rb
100
+ - test/test_uv_proxmox.rb
101
+ - uv_proxmox.gemspec
102
+ has_rdoc: true
103
+ homepage: http://github.com/maxschulze/uv_proxmox
104
+ licenses: []
105
+
106
+ post_install_message:
107
+ rdoc_options:
108
+ - --charset=UTF-8
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project:
132
+ rubygems_version: 1.3.7
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: A ruby api for working with the proxmox virtual machine manager
136
+ test_files:
137
+ - test/helper.rb
138
+ - test/test_uv_proxmox.rb
139
+ - examples/create_new_virtual_machine.rb