hypercube 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 004b68e731d1e479aac2a2911ad608c78ef77f6a
4
+ data.tar.gz: e55de248c832999f3137f34f25e76507764a4ee8
5
+ SHA512:
6
+ metadata.gz: b19dd1e19bc1aabd95796224ec7b2247629bf1c66988736855bc3ac2df19da67f5a738d73a4fc7ce4570f7d4624af5be79cc2bd0bb8c103607336b9a41fc6c47
7
+ data.tar.gz: 80e6346b5e7e821e75455944dae1d80859d6f432951547b65ee5a99f8b0e3c3a5efc298564dbac90fdb030c5b044fba23d0ffc7760494f4b5c376629099ef0d3
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create ruby-2.0.0-p0@hypercube
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hypercube.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Anthony Cook
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,34 @@
1
+ Hypercube
2
+ =========
3
+
4
+ A virtual machine manager that doesn't suck!
5
+
6
+ Installation
7
+ ------------
8
+
9
+ To use Hypercube as a library,
10
+ just add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'hypercube'
14
+ ```
15
+
16
+ Or if you'r ejust interested in the command line tools,
17
+ install it yourself with:
18
+
19
+ ```shell
20
+ $ gem install hypercube
21
+ ```
22
+
23
+ Usage
24
+ -----
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/hypercube ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler'
4
+ Bundler.require(:default)
5
+ require 'hypercube'
6
+
7
+ manager = Hypercube::Manager.new
8
+
9
+ result = manager.run ARGV
10
+
11
+ puts result
12
+
data/hypercube.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hypercube/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'hypercube'
8
+ gem.version = Hypercube::VERSION
9
+ gem.authors = ['Anthony Cook']
10
+ gem.email = ['anthonymichaelcook@gmail.com']
11
+ gem.description = %q{A virtual machine manager that doesn't suck as much as doing everything manually.}
12
+ gem.summary = %q{Virtual machine management that doesn't suck (as much).}
13
+ gem.homepage = 'http://github.com/acook/hypercube'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'systemu'
21
+
22
+ gem.add_development_dependency 'rspec'
23
+ gem.add_development_dependency 'pry'
24
+ gem.add_development_dependency 'pry-theme'
25
+ end
data/lib/hypercube.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ Bundler.require :default
3
+ require 'systemu'
4
+
5
+ require 'hypercube/version'
6
+ require 'hypercube/manager'
7
+
8
+ module Hypercube
9
+ end
@@ -0,0 +1,74 @@
1
+ module Hypercube
2
+ module Backend
3
+ module VirtualBox
4
+ module_function
5
+
6
+ def run *command
7
+ command = command.flatten
8
+
9
+ if command.first == 'set' then
10
+ _, vm, attribute, value = command
11
+ command = ["#{attribute}=", vm, value]
12
+ end
13
+
14
+ #raise NotImplementedError unless Commands.instance_methods(false).include?(command)
15
+
16
+ status, stdout, stderr = systemu [executable, Commands.send(*command)].join(' ')
17
+
18
+ raise stderr unless status.exitstatus == 0
19
+
20
+ $last_status = status.exitstatus
21
+ $last_out = stdout
22
+ $last_error = stderr
23
+
24
+ stdout
25
+ end
26
+
27
+ def executable
28
+ 'VBoxManage'
29
+ end
30
+
31
+ module Commands
32
+ #include CommandTemplate
33
+ module_function
34
+
35
+ def list
36
+ "list vms"
37
+ end
38
+
39
+ def create vm
40
+ "createvm --name #{vm} --register"
41
+ end
42
+
43
+ def destroy vm
44
+ "unregistervm #{vm} --delete"
45
+ end
46
+
47
+ def hd= vm, path
48
+ "modifyvm #{vm} --sataport1 \"#{path}\""
49
+ end
50
+
51
+ def info vm, attribute = nil
52
+ output = "showvminfo #{vm} #{ attribute && '-machinereadable' }"
53
+
54
+ if attribute then
55
+ local_name = attribute_map[attribute]
56
+ output.split("\n").detect{|line| line =~ /#{local_name}/}
57
+ else
58
+ output
59
+ end
60
+ end
61
+
62
+ def attribute_map
63
+ {
64
+ 'hd' => 'SATA-0-0'
65
+ }
66
+ end
67
+
68
+ def add_drive vm
69
+ "storagectl #{vm} --name SATA --add SATA --controller IntelAhci"
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,39 @@
1
+ module Hypercube
2
+ class Manager
3
+ def initialize backend = :virtual_box
4
+ @backend = backend
5
+ end
6
+
7
+ def backend
8
+ get_backend @backend
9
+ end
10
+
11
+ def run *args
12
+ backend.run *args
13
+ end
14
+
15
+ private
16
+
17
+ def get_backend name
18
+ if name.is_a? Module then
19
+ name
20
+ else
21
+ require backend_path(name)
22
+ constantize camelize name
23
+ end
24
+ end
25
+
26
+ def constantize name, constant = Hypercube::Backend
27
+ constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
28
+ end
29
+
30
+ def camelize name
31
+ capitalized = name.to_s.sub(/^[a-z\d]*/) { $&.capitalize }
32
+ capitalized.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
33
+ end
34
+
35
+ def backend_path name
36
+ Pathname.new(__FILE__).dirname.join('backends', name.to_s)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Hypercube
2
+ VERSION = '0.0.1'
3
+ end
Binary file
@@ -0,0 +1,49 @@
1
+ require_relative 'spec_helper'
2
+ require 'hypercube/manager'
3
+
4
+ describe Hypercube::Manager do
5
+ subject(:manager){ Hypercube::Manager.new }
6
+ let(:vm){ 'bobbyzzz' }
7
+
8
+ it 'finds its ass with two hands' do
9
+ manager.backend.should == Hypercube::Backend::VirtualBox
10
+ end
11
+
12
+ it 'basic vm lifecycles' do
13
+ manager.run ['create', vm]
14
+ create_list = manager.run 'list'
15
+ manager.run ['destroy', vm]
16
+ destroy_list = manager.run 'list'
17
+
18
+ create_list.should =~ /#{vm}/
19
+ destroy_list.should_not =~ /#{vm}/
20
+ end
21
+
22
+ context 'with vm' do
23
+ before do
24
+ manager.run ['create', vm]
25
+ end
26
+
27
+ after do
28
+ manager.run ['destroy', vm]
29
+ end
30
+
31
+ context 'vm info' do
32
+ subject(:info){ manager.run ['info', vm] }
33
+
34
+ it 'displays info' do
35
+ info.should =~ /#{vm}/
36
+ end
37
+
38
+ xit 'displays hd info' do
39
+ end
40
+ end
41
+
42
+ context 'modify vm' do
43
+ it 'sets hard drives' do
44
+ #mananger.run ['set', vm]
45
+ binding.pry
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Dir.chdir File.dirname(__FILE__)
7
+
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hypercube
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Cook
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: systemu
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-theme
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A virtual machine manager that doesn't suck as much as doing everything
70
+ manually.
71
+ email:
72
+ - anthonymichaelcook@gmail.com
73
+ executables:
74
+ - hypercube
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - .gitignore
79
+ - .rvmrc
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.markdown
83
+ - Rakefile
84
+ - bin/hypercube
85
+ - hypercube.gemspec
86
+ - lib/hypercube.rb
87
+ - lib/hypercube/backends/virtual_box.rb
88
+ - lib/hypercube/manager.rb
89
+ - lib/hypercube/version.rb
90
+ - spec/fixtures/test_hd.vdi
91
+ - spec/manager_spec.rb
92
+ - spec/spec_helper.rb
93
+ homepage: http://github.com/acook/hypercube
94
+ licenses: []
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.0.0
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Virtual machine management that doesn't suck (as much).
116
+ test_files:
117
+ - spec/fixtures/test_hd.vdi
118
+ - spec/manager_spec.rb
119
+ - spec/spec_helper.rb