simple_stack 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +67 -0
- data/lib/simple_stack/collection.rb +19 -8
- data/lib/simple_stack/connection.rb +6 -2
- data/lib/simple_stack/entity.rb +15 -6
- data/lib/simple_stack/guest.rb +3 -3
- data/lib/simple_stack/hypervisor.rb +39 -6
- data/lib/simple_stack/version.rb +1 -1
- data/lib/simple_stack.rb +1 -0
- data/simple_stack.gemspec +1 -1
- data/spec/simple_stack/connection_spec.rb +19 -0
- data/spec/simple_stack/hypervisor_spec.rb +19 -0
- data/spec/spec_helper.rb +2 -0
- metadata +34 -6
data/README.markdown
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Simple Stack Gem
|
2
|
+
|
3
|
+
A simple gem to deal with Simple Stack project.
|
4
|
+
|
5
|
+
Get a simplestack class:
|
6
|
+
|
7
|
+
stack = SimpleStack.new :url => url, :username => username, :password => password
|
8
|
+
|
9
|
+
Connecting to hypervisor:
|
10
|
+
|
11
|
+
vmware = stack.connect_to("vmware", :host => host, :username => username, :password => password)
|
12
|
+
|
13
|
+
Pool informations:
|
14
|
+
|
15
|
+
vmware.info
|
16
|
+
vmware.guests
|
17
|
+
|
18
|
+
# TODO:
|
19
|
+
# vmware.used_memory
|
20
|
+
# vmware.total_memory
|
21
|
+
# vmware.import vm_file
|
22
|
+
|
23
|
+
### Working with Guests
|
24
|
+
|
25
|
+
guest = vmware.guests.find(vm.uuid)
|
26
|
+
guest.info
|
27
|
+
guest.update(:name => "Guest name", :memory => 512)
|
28
|
+
guest.delete
|
29
|
+
|
30
|
+
Shutdown and power on and reboot
|
31
|
+
guest.stop
|
32
|
+
guest.start
|
33
|
+
guest.reboot
|
34
|
+
|
35
|
+
Force the guest shutdown
|
36
|
+
guest.force_stop
|
37
|
+
|
38
|
+
Resume and suspend guests
|
39
|
+
|
40
|
+
guest.resume
|
41
|
+
guest.pause
|
42
|
+
|
43
|
+
TODO:
|
44
|
+
|
45
|
+
file = guest.export :to => file_path
|
46
|
+
|
47
|
+
#### Snapshots
|
48
|
+
|
49
|
+
List snapshots
|
50
|
+
|
51
|
+
guest.snapshots
|
52
|
+
|
53
|
+
Find a snapshot
|
54
|
+
|
55
|
+
guest.snapshots.find(snap.uuid)
|
56
|
+
|
57
|
+
Create a new snapshot
|
58
|
+
|
59
|
+
snap = guest.snapshots.create :name => :snapshot_name
|
60
|
+
|
61
|
+
Delete a snapshot
|
62
|
+
|
63
|
+
snap.delete
|
64
|
+
|
65
|
+
Revert a snapshot
|
66
|
+
|
67
|
+
snap.use
|
@@ -1,30 +1,41 @@
|
|
1
1
|
module SimpleStack
|
2
2
|
class Collection
|
3
|
-
attr_accessor :url, :clazz
|
3
|
+
attr_accessor :hypervisor, :url, :clazz
|
4
4
|
|
5
|
-
def initialize(url, clazz)
|
6
|
-
self.
|
5
|
+
def initialize(hypervisor, url, clazz)
|
6
|
+
self.hypervisor = hypervisor
|
7
|
+
self.url = url.to_s
|
7
8
|
self.clazz = clazz
|
8
9
|
end
|
9
10
|
|
10
11
|
def to_a
|
11
|
-
@items
|
12
|
-
clazz.new "#{url}/#{item["id"]}"
|
12
|
+
@items = hypervisor.get(url).map do |item|
|
13
|
+
clazz.new hypervisor, "#{url}/#{item["id"]}"
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
def find(id)
|
17
|
-
clazz.new "#{url}/#{id}"
|
18
|
+
clazz.new hypervisor, "#{url}/#{id}"
|
18
19
|
end
|
19
20
|
|
20
21
|
def create(options={})
|
21
|
-
response =
|
22
|
-
|
22
|
+
response = hypervisor.post(url, options)
|
23
|
+
entity_path = response.headers["location"].sub(/^\//, "").sub(/\/$/, "")
|
24
|
+
entity_url = "#{connection.url}/#{entity_path}"
|
25
|
+
clazz.new hypervisor, entity_url
|
23
26
|
end
|
24
27
|
|
25
28
|
def method_missing(method, *args, &block)
|
26
29
|
to_a.send(method, *args, &block)
|
27
30
|
end
|
28
31
|
|
32
|
+
def inspect
|
33
|
+
to_a.inspect
|
34
|
+
end
|
35
|
+
|
36
|
+
def connection
|
37
|
+
hypervisor.connection
|
38
|
+
end
|
39
|
+
|
29
40
|
end
|
30
41
|
end
|
@@ -3,11 +3,15 @@ module SimpleStack
|
|
3
3
|
attr_accessor :url
|
4
4
|
|
5
5
|
def initialize(options = {})
|
6
|
-
self.url = options[:url]
|
6
|
+
self.url = options[:url].to_s.sub(/\/$/, "")
|
7
7
|
end
|
8
8
|
|
9
9
|
def connect_to(type, options)
|
10
|
-
SimpleStack::Hypervisor.new
|
10
|
+
SimpleStack::Hypervisor.new self, type, options
|
11
|
+
end
|
12
|
+
|
13
|
+
def token
|
14
|
+
"TODO"
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
data/lib/simple_stack/entity.rb
CHANGED
@@ -1,21 +1,30 @@
|
|
1
1
|
module SimpleStack
|
2
2
|
class Entity
|
3
|
-
attr_accessor :url
|
3
|
+
attr_accessor :hypervisor, :url
|
4
4
|
|
5
|
-
def initialize(url)
|
6
|
-
self.
|
5
|
+
def initialize(hypervisor, url)
|
6
|
+
self.hypervisor = hypervisor
|
7
|
+
self.url = url.to_s
|
7
8
|
end
|
8
9
|
|
9
10
|
def info
|
10
|
-
|
11
|
+
hypervisor.get url
|
11
12
|
end
|
12
13
|
|
13
14
|
def update(attributes = {})
|
14
|
-
|
15
|
+
hypervisor.put url, attributes
|
15
16
|
end
|
16
17
|
|
17
18
|
def delete
|
18
|
-
|
19
|
+
hypervisor.delete url
|
20
|
+
end
|
21
|
+
|
22
|
+
def inspect
|
23
|
+
"#<#{self.class} info=#{info.to_json}>"
|
24
|
+
end
|
25
|
+
|
26
|
+
def connection
|
27
|
+
hypervisor.connection
|
19
28
|
end
|
20
29
|
end
|
21
30
|
end
|
data/lib/simple_stack/guest.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module SimpleStack
|
2
2
|
class Guest < Entity
|
3
3
|
def snapshots
|
4
|
-
SimpleStack::Collection.new "#{url}/snapshots", SimpleStack::Snapshot
|
4
|
+
SimpleStack::Collection.new hypervisor, "#{url}/snapshots", SimpleStack::Snapshot
|
5
5
|
end
|
6
6
|
|
7
7
|
def reboot
|
8
|
-
|
8
|
+
hypervisor.put "#{url}/reboot"
|
9
9
|
end
|
10
10
|
|
11
11
|
def power_state=(state)
|
12
|
-
|
12
|
+
hypervisor.put "#{url}/power", :state => state
|
13
13
|
end
|
14
14
|
|
15
15
|
["start", "stop", "force_stop", "pause", "resume"].each do |state|
|
@@ -1,23 +1,56 @@
|
|
1
1
|
module SimpleStack
|
2
2
|
class Hypervisor
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :connection, :type, :host
|
4
4
|
|
5
|
-
def initialize(
|
6
|
-
self.
|
5
|
+
def initialize(connection, type, options)
|
6
|
+
self.connection = connection
|
7
7
|
self.type = type
|
8
8
|
self.host = options[:host]
|
9
9
|
end
|
10
10
|
|
11
11
|
def url
|
12
|
-
"#{
|
12
|
+
"#{connection.url}/#{type}/#{host}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def headers
|
16
|
+
{
|
17
|
+
"x-simplestack-version" => "1.0",
|
18
|
+
"x-simplestack-token" => connection.token,
|
19
|
+
"x-simplestack-hypervisor-token" => token,
|
20
|
+
"Content-Type" => "application/json"
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def token
|
25
|
+
"TODO"
|
13
26
|
end
|
14
27
|
|
15
28
|
def info
|
16
|
-
|
29
|
+
self.get url
|
17
30
|
end
|
18
31
|
|
19
32
|
def guests
|
20
|
-
SimpleStack::Collection.new "#{url}/guests", SimpleStack::Guest
|
33
|
+
SimpleStack::Collection.new self, "#{url}/guests", SimpleStack::Guest
|
34
|
+
end
|
35
|
+
|
36
|
+
def get(url)
|
37
|
+
HTTParty.get(url, :headers => headers, :no_follow => true)
|
38
|
+
end
|
39
|
+
|
40
|
+
def post(url, body)
|
41
|
+
HTTParty.post(url, :body => JSON.dump(body), :headers => headers, :no_follow => true)
|
42
|
+
end
|
43
|
+
|
44
|
+
def put(url, body)
|
45
|
+
HTTParty.put(url, :body => JSON.dump(body), :headers => headers, :no_follow => true)
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete(url)
|
49
|
+
HTTParty.delete(url, :headers => headers, :no_follow => true)
|
50
|
+
end
|
51
|
+
|
52
|
+
def inspect
|
53
|
+
"#<#{self.class} url=#{url}>"
|
21
54
|
end
|
22
55
|
end
|
23
56
|
end
|
data/lib/simple_stack/version.rb
CHANGED
data/lib/simple_stack.rb
CHANGED
data/simple_stack.gemspec
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe SimpleStack::Connection do
|
5
|
+
let(:url) {"http://simplestack.server"}
|
6
|
+
subject {SimpleStack::Connection.new :url => url}
|
7
|
+
|
8
|
+
it "should keep the connection url" do
|
9
|
+
subject.url.should == url
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should connect to a hypervisor" do
|
13
|
+
host = "hypervisor_host"
|
14
|
+
hypervisor = subject.connect_to :mock, host: host
|
15
|
+
hypervisor.type.should == :mock
|
16
|
+
hypervisor.host.should == host
|
17
|
+
hypervisor.url.should == "#{url}/mock/#{host}"
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe SimpleStack::Hypervisor do
|
5
|
+
let(:url) {"http://simplestack.server"}
|
6
|
+
let(:host) {"hypervisor_host"}
|
7
|
+
subject {SimpleStack::Connection.new(:url => url).connect_to :mock, host: host}
|
8
|
+
|
9
|
+
it "should keep the connection url" do
|
10
|
+
subject.url.should == "#{url}/mock/#{host}"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should connect to a hypervisor" do
|
14
|
+
subject.headers.should have_key("x-simplestack-version")
|
15
|
+
subject.headers.should have_key("x-simplestack-token")
|
16
|
+
subject.headers.should have_key("x-simplestack-hypervisor-token")
|
17
|
+
subject.headers["Content-Type"].should == "application/json"
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_stack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,27 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: httparty
|
16
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
17
33
|
none: false
|
18
34
|
requirements:
|
19
35
|
- - ! '>='
|
@@ -21,7 +37,12 @@ dependencies:
|
|
21
37
|
version: '0'
|
22
38
|
type: :runtime
|
23
39
|
prerelease: false
|
24
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
25
46
|
description: A Simple Stack gem
|
26
47
|
email:
|
27
48
|
- thiago.morello@locaweb.com.br
|
@@ -31,6 +52,7 @@ extra_rdoc_files: []
|
|
31
52
|
files:
|
32
53
|
- .gitignore
|
33
54
|
- Gemfile
|
55
|
+
- README.markdown
|
34
56
|
- Rakefile
|
35
57
|
- lib/simple_stack.rb
|
36
58
|
- lib/simple_stack/collection.rb
|
@@ -41,6 +63,9 @@ files:
|
|
41
63
|
- lib/simple_stack/snapshot.rb
|
42
64
|
- lib/simple_stack/version.rb
|
43
65
|
- simple_stack.gemspec
|
66
|
+
- spec/simple_stack/connection_spec.rb
|
67
|
+
- spec/simple_stack/hypervisor_spec.rb
|
68
|
+
- spec/spec_helper.rb
|
44
69
|
homepage: ''
|
45
70
|
licenses: []
|
46
71
|
post_install_message:
|
@@ -61,8 +86,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
86
|
version: '0'
|
62
87
|
requirements: []
|
63
88
|
rubyforge_project: simple_stack
|
64
|
-
rubygems_version: 1.8.
|
89
|
+
rubygems_version: 1.8.23
|
65
90
|
signing_key:
|
66
91
|
specification_version: 3
|
67
92
|
summary: A Simple Stack gem
|
68
|
-
test_files:
|
93
|
+
test_files:
|
94
|
+
- spec/simple_stack/connection_spec.rb
|
95
|
+
- spec/simple_stack/hypervisor_spec.rb
|
96
|
+
- spec/spec_helper.rb
|