simple_stack 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in simplestack.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ module SimpleStack
2
+ class Collection
3
+ attr_accessor :url, :clazz
4
+
5
+ def initialize(url, clazz)
6
+ self.url = url
7
+ self.clazz = clazz
8
+ end
9
+
10
+ def to_a
11
+ @items ||= SimpleStack.client.get(url).map do |item|
12
+ clazz.new "#{url}/#{item["id"]}"
13
+ end
14
+ end
15
+
16
+ def find(id)
17
+ clazz.new "#{url}/#{id}"
18
+ end
19
+
20
+ def create(options={})
21
+ response = SimpleStack.client.post(url, options)
22
+ clazz.new response.headers["location"]
23
+ end
24
+
25
+ def method_missing(method, *args, &block)
26
+ to_a.send(method, *args, &block)
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ module SimpleStack
2
+ class Connection
3
+ attr_accessor :url
4
+
5
+ def initialize(options = {})
6
+ self.url = options[:url]
7
+ end
8
+
9
+ def connect_to(type, options)
10
+ SimpleStack::Hypervisor.new url, type, options
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module SimpleStack
2
+ class Entity
3
+ attr_accessor :url
4
+
5
+ def initialize(url)
6
+ self.url = url
7
+ end
8
+
9
+ def info
10
+ SimpleStack.client.get url
11
+ end
12
+
13
+ def update(attributes = {})
14
+ SimpleStack.client.put url, attributes
15
+ end
16
+
17
+ def delete
18
+ SimpleStack.client.delete url
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ module SimpleStack
2
+ class Guest < Entity
3
+ def snapshots
4
+ SimpleStack::Collection.new "#{url}/snapshots", SimpleStack::Snapshot
5
+ end
6
+
7
+ def reboot
8
+ SimpleStack.client.put "#{url}/reboot"
9
+ end
10
+
11
+ def power_state=(state)
12
+ SimpleStack.client.put "#{url}/power", :state => state
13
+ end
14
+
15
+ ["start", "stop", "force_stop", "pause", "resume"].each do |state|
16
+ define_method(state) do
17
+ self.power_state = state
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ module SimpleStack
2
+ class Hypervisor
3
+ attr_accessor :main_url, :type, :host
4
+
5
+ def initialize(main_url, type, options)
6
+ self.main_url = main_url
7
+ self.type = type
8
+ self.host = options[:host]
9
+ end
10
+
11
+ def url
12
+ "#{main_url}/#{type}/#{host}"
13
+ end
14
+
15
+ def info
16
+ SimpleStack.client.get url
17
+ end
18
+
19
+ def guests
20
+ SimpleStack::Collection.new "#{url}/guests", SimpleStack::Guest
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ module SimpleStack
2
+ class Snapshot < Entity
3
+ def use
4
+ raise "Not Implemented"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleStack
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,14 @@
1
+ require "httparty"
2
+ require "simple_stack/version"
3
+ require "simple_stack/connection"
4
+ require "simple_stack/collection"
5
+ require "simple_stack/hypervisor"
6
+ require "simple_stack/entity"
7
+ require "simple_stack/guest"
8
+ require "simple_stack/snapshot"
9
+
10
+ module SimpleStack
11
+ def self.client
12
+ HTTParty
13
+ end
14
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "simple_stack/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "simple_stack"
7
+ s.version = SimpleStack::VERSION
8
+ s.authors = ["Thiago Morello"]
9
+ s.email = ["thiago.morello@locaweb.com.br"]
10
+ s.homepage = ""
11
+ s.summary = %q{A Simple Stack gem}
12
+ s.description = %q{A Simple Stack gem}
13
+
14
+ s.rubyforge_project = "simple_stack"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "httparty"
24
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_stack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thiago Morello
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &2151814400 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2151814400
25
+ description: A Simple Stack gem
26
+ email:
27
+ - thiago.morello@locaweb.com.br
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - lib/simple_stack.rb
36
+ - lib/simple_stack/collection.rb
37
+ - lib/simple_stack/connection.rb
38
+ - lib/simple_stack/entity.rb
39
+ - lib/simple_stack/guest.rb
40
+ - lib/simple_stack/hypervisor.rb
41
+ - lib/simple_stack/snapshot.rb
42
+ - lib/simple_stack/version.rb
43
+ - simple_stack.gemspec
44
+ homepage: ''
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project: simple_stack
64
+ rubygems_version: 1.8.10
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: A Simple Stack gem
68
+ test_files: []