simple_stack 0.0.4 → 0.0.5
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.
- data/lib/simple_stack/cacheable.rb +20 -0
- data/lib/simple_stack/collection.rb +14 -7
- data/lib/simple_stack/entity.rb +12 -4
- data/lib/simple_stack/guest.rb +17 -1
- data/lib/simple_stack/hypervisor.rb +8 -4
- data/lib/simple_stack/snapshot.rb +5 -1
- data/lib/simple_stack/version.rb +1 -1
- data/lib/simple_stack.rb +2 -0
- data/spec/simple_stack/hypervisor_spec.rb +6 -0
- metadata +8 -17
@@ -1,16 +1,19 @@
|
|
1
1
|
module SimpleStack
|
2
2
|
class Collection
|
3
|
-
|
3
|
+
include SimpleStack::Cacheable
|
4
4
|
|
5
|
-
|
5
|
+
attr_accessor :hypervisor, :parent, :url, :clazz
|
6
|
+
|
7
|
+
def initialize(hypervisor, parent, url, clazz)
|
6
8
|
self.hypervisor = hypervisor
|
9
|
+
self.parent = parent
|
7
10
|
self.url = url.to_s
|
8
11
|
self.clazz = clazz
|
9
12
|
end
|
10
13
|
|
11
14
|
def to_a
|
12
|
-
|
13
|
-
clazz.new hypervisor, "#{url}/#{item["id"]}"
|
15
|
+
cached_attributes[:items] ||= hypervisor.get(url).map do |item|
|
16
|
+
clazz.new hypervisor, parent, "#{url}/#{item["id"]}"
|
14
17
|
end
|
15
18
|
end
|
16
19
|
|
@@ -22,7 +25,12 @@ module SimpleStack
|
|
22
25
|
response = hypervisor.post(url, options)
|
23
26
|
entity_path = response.headers["location"].sub(/^\//, "").sub(/\/$/, "")
|
24
27
|
entity_url = "#{connection.url}/#{entity_path}"
|
25
|
-
clazz.new hypervisor, entity_url
|
28
|
+
new_item = clazz.new hypervisor, parent, entity_url
|
29
|
+
if cacheable?
|
30
|
+
cached_attributes[:items] ||= []
|
31
|
+
cached_attributes[:items] << self
|
32
|
+
end
|
33
|
+
new_item
|
26
34
|
end
|
27
35
|
|
28
36
|
def method_missing(method, *args, &block)
|
@@ -36,6 +44,5 @@ module SimpleStack
|
|
36
44
|
def connection
|
37
45
|
hypervisor.connection
|
38
46
|
end
|
39
|
-
|
40
47
|
end
|
41
|
-
end
|
48
|
+
end
|
data/lib/simple_stack/entity.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
module SimpleStack
|
2
2
|
class Entity
|
3
|
-
|
3
|
+
include SimpleStack::Cacheable
|
4
4
|
|
5
|
-
|
5
|
+
attr_accessor :hypervisor, :parent, :url
|
6
|
+
|
7
|
+
def initialize(hypervisor, parent, url)
|
6
8
|
self.hypervisor = hypervisor
|
9
|
+
self.parent = parent
|
7
10
|
self.url = url.to_s
|
8
11
|
end
|
9
12
|
|
10
13
|
def info
|
11
|
-
hypervisor.get url
|
14
|
+
cached_attributes[:info] ||= hypervisor.get url
|
12
15
|
end
|
13
16
|
|
14
17
|
def update(attributes = {})
|
@@ -16,7 +19,12 @@ module SimpleStack
|
|
16
19
|
end
|
17
20
|
|
18
21
|
def delete
|
19
|
-
hypervisor.delete url
|
22
|
+
response = hypervisor.delete url
|
23
|
+
if cacheable?
|
24
|
+
parent.cached_attributes[:items] ||= []
|
25
|
+
parent.cached_attributes[:items].delete self
|
26
|
+
end
|
27
|
+
response
|
20
28
|
end
|
21
29
|
|
22
30
|
def inspect
|
data/lib/simple_stack/guest.rb
CHANGED
@@ -1,13 +1,29 @@
|
|
1
1
|
module SimpleStack
|
2
2
|
class Guest < Entity
|
3
3
|
def snapshots
|
4
|
-
SimpleStack::Collection.new hypervisor, "#{url}/snapshots", SimpleStack::Snapshot
|
4
|
+
cached_attributes[:snapshots] ||= SimpleStack::Collection.new hypervisor, self, "#{url}/snapshots", SimpleStack::Snapshot
|
5
|
+
end
|
6
|
+
|
7
|
+
def tags
|
8
|
+
cached_attributes[:tags] ||= hypervisor.get("#{url}/tags").parsed_response
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_tag(tag)
|
12
|
+
hypervisor.post "#{url}/tags", :name => tag
|
13
|
+
end
|
14
|
+
|
15
|
+
def remove_tag(tag)
|
16
|
+
hypervisor.delete "#{url}/tags/#{tag}"
|
5
17
|
end
|
6
18
|
|
7
19
|
def reboot(opts={:force => false})
|
8
20
|
hypervisor.put "#{url}/reboot", :force => opts[:force]
|
9
21
|
end
|
10
22
|
|
23
|
+
def revert_to(snapshot)
|
24
|
+
snapshot.revert
|
25
|
+
end
|
26
|
+
|
11
27
|
def power_state=(state)
|
12
28
|
hypervisor.put "#{url}/power", :state => state
|
13
29
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
module SimpleStack
|
2
2
|
class Hypervisor
|
3
|
-
|
3
|
+
include SimpleStack::Cacheable
|
4
|
+
|
5
|
+
attr_accessor :connection, :type, :host, :username, :password
|
4
6
|
|
5
7
|
def initialize(connection, type, options)
|
6
8
|
self.connection = connection
|
7
9
|
self.type = type
|
8
10
|
self.host = options[:host]
|
11
|
+
self.username = options[:username]
|
12
|
+
self.password = options[:password]
|
9
13
|
end
|
10
14
|
|
11
15
|
def url
|
@@ -22,15 +26,15 @@ module SimpleStack
|
|
22
26
|
end
|
23
27
|
|
24
28
|
def token
|
25
|
-
"
|
29
|
+
Base64.encode64("#{username}:#{password}").split("\n").join("")
|
26
30
|
end
|
27
31
|
|
28
32
|
def info
|
29
|
-
self.get url
|
33
|
+
cached_attributes[:info] ||= self.get url
|
30
34
|
end
|
31
35
|
|
32
36
|
def guests
|
33
|
-
SimpleStack::Collection.new self, "#{url}/guests", SimpleStack::Guest
|
37
|
+
cached_attributes[:guests] ||= SimpleStack::Collection.new self, self, "#{url}/guests", SimpleStack::Guest
|
34
38
|
end
|
35
39
|
|
36
40
|
def get(url)
|
data/lib/simple_stack/version.rb
CHANGED
data/lib/simple_stack.rb
CHANGED
@@ -16,4 +16,10 @@ describe SimpleStack::Hypervisor do
|
|
16
16
|
subject.headers.should have_key("x-simplestack-hypervisor-token")
|
17
17
|
subject.headers["Content-Type"].should == "application/json"
|
18
18
|
end
|
19
|
+
|
20
|
+
it "should have a base64 encoded username:password token for now" do
|
21
|
+
subject.username = "admin"
|
22
|
+
subject.password = "secret"
|
23
|
+
subject.token.should == "YWRtaW46c2VjcmV0"
|
24
|
+
end
|
19
25
|
end
|
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.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2161072020 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,15 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
24
|
+
version_requirements: *2161072020
|
30
25
|
- !ruby/object:Gem::Dependency
|
31
26
|
name: httparty
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &2161071580 !ruby/object:Gem::Requirement
|
33
28
|
none: false
|
34
29
|
requirements:
|
35
30
|
- - ! '>='
|
@@ -37,12 +32,7 @@ dependencies:
|
|
37
32
|
version: '0'
|
38
33
|
type: :runtime
|
39
34
|
prerelease: false
|
40
|
-
version_requirements:
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ! '>='
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
35
|
+
version_requirements: *2161071580
|
46
36
|
description: A Simple Stack gem
|
47
37
|
email:
|
48
38
|
- thiago.morello@locaweb.com.br
|
@@ -55,6 +45,7 @@ files:
|
|
55
45
|
- README.markdown
|
56
46
|
- Rakefile
|
57
47
|
- lib/simple_stack.rb
|
48
|
+
- lib/simple_stack/cacheable.rb
|
58
49
|
- lib/simple_stack/collection.rb
|
59
50
|
- lib/simple_stack/connection.rb
|
60
51
|
- lib/simple_stack/entity.rb
|
@@ -86,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
77
|
version: '0'
|
87
78
|
requirements: []
|
88
79
|
rubyforge_project: simple_stack
|
89
|
-
rubygems_version: 1.8.
|
80
|
+
rubygems_version: 1.8.10
|
90
81
|
signing_key:
|
91
82
|
specification_version: 3
|
92
83
|
summary: A Simple Stack gem
|