librato_silverline_api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +23 -0
- data/LICENSE +19 -0
- data/README.md +40 -0
- data/Rakefile +28 -0
- data/config/librato_silverline_api.example.yml +6 -0
- data/lib/librato_silverline_api.rb +209 -0
- data/lib/librato_silverline_api/version.rb +3 -0
- data/librato_silverline_api.gemspec +25 -0
- data/samples/templates.rb +27 -0
- data/test/functional_test.rb +85 -0
- data/test/unit/axis-test.rb +47 -0
- data/test/unit/container-test.rb +52 -0
- data/test/unit/template-test.rb +27 -0
- metadata +130 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
librato_silverline_api (0.0.1)
|
5
|
+
json
|
6
|
+
rest-client (= 1.6.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
json (1.4.6)
|
12
|
+
mime-types (1.16)
|
13
|
+
rest-client (1.6.1)
|
14
|
+
mime-types (>= 1.16)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
bundler (>= 1.0.0)
|
21
|
+
json
|
22
|
+
librato_silverline_api!
|
23
|
+
rest-client (= 1.6.1)
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2011 Librato Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Silverline API Gem
|
2
|
+
|
3
|
+
Ruby wrapper for the Librato Silverline API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
sudo gem install librato_silverline_api
|
8
|
+
|
9
|
+
## Description
|
10
|
+
|
11
|
+
This gem conists of three classes: Template, Container and Axis.
|
12
|
+
The interaction with the API happens exclusively through the Template class. It offers very basic Active Resource methods to find, create, save and update templates. Templates contains Containers and they again contain Axes.
|
13
|
+
|
14
|
+
## Example Usage
|
15
|
+
|
16
|
+
# Configure API Access
|
17
|
+
SilverlineAPI.username = "example@librato.com"
|
18
|
+
SilverlineAPI.key = "YOUR_API_TOKEN"
|
19
|
+
|
20
|
+
# Retrieve Templates
|
21
|
+
templates = SilverlineAPI::Templates.find(:all) # returns a maximum of 100 templates
|
22
|
+
|
23
|
+
templates = SilverlineAPI::Templates.find(:all, :length => 10, :offset => 20) # returns the 3rd page and contains 10 templates
|
24
|
+
|
25
|
+
templates = SilverlineAPI::Templates.find(:all, :name => "foo") # returns a maximum of 100 templates which partially match the name
|
26
|
+
|
27
|
+
SilverlineAPI.last_response # holds the information of the last response, e.g. the amount of templates, pagination and search detail, etc.
|
28
|
+
|
29
|
+
# create a template with the default containers
|
30
|
+
template = SilverlineAPI::Template.new(:name => "foo", :min_cpu => 200, :min_mem => 128)
|
31
|
+
template.save # saves the newly created template
|
32
|
+
|
33
|
+
# add a special container
|
34
|
+
container = SilverlineAPI::Container.new(:name => "bar", :cpu => {:allocation => 40}, :mem => {:allocation => 64, :max => 64})
|
35
|
+
template.containers.push(container)
|
36
|
+
template.save
|
37
|
+
|
38
|
+
### Copyright
|
39
|
+
|
40
|
+
Copyright (c) 2011 [Librato Inc.](http://librato.com). See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
desc "Check settings"
|
5
|
+
task :check_settings do
|
6
|
+
unless ENV["SILVERLINE_API_SITE"] && ENV["SILVERLINE_API_USERNAME"] && ENV["SILVERLINE_API_KEY"]
|
7
|
+
puts "Please configure your environment."
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
desc "Run functional tests"
|
13
|
+
task :run_functional_tests do
|
14
|
+
Rake::Task["check_settings"].invoke
|
15
|
+
exec("ruby test/functional_test.rb")
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run unit tests"
|
19
|
+
task :run_unit_tests do
|
20
|
+
Rake::Task["check_settings"].invoke
|
21
|
+
exec("ruby test/unit/axis-test.rb; ruby test/unit/container-test.rb; ruby test/unit/template-test.rb")
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Run all tests"
|
25
|
+
task :run_all_tests do
|
26
|
+
Rake::Task["check_settings"].invoke
|
27
|
+
exec("rcov test/unit/axis-test.rb test/unit/container-test.rb test/unit/template-test.rb test/functional_test.rb")
|
28
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
# Copy this file to config/remote.yml and make adjustments as necessary.
|
2
|
+
#
|
3
|
+
# Note: Remote tests will only work when configured to run on a test site that uses the Bogus gateway.
|
4
|
+
# Warning: all data in the site specified by 'subdomain' will be cleared and replaced with test data.
|
5
|
+
username: xxx
|
6
|
+
key: xxx
|
@@ -0,0 +1,209 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rest_client"
|
3
|
+
require "cgi"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
def symbolize_keys(arg)
|
7
|
+
case arg
|
8
|
+
when Array
|
9
|
+
arg.map { |elem| symbolize_keys elem }
|
10
|
+
when Hash
|
11
|
+
Hash[
|
12
|
+
arg.map do |key, value|
|
13
|
+
k = key.is_a?(String) ? key.to_sym : key
|
14
|
+
v = symbolize_keys(value)
|
15
|
+
[k,v]
|
16
|
+
end
|
17
|
+
]
|
18
|
+
else
|
19
|
+
arg
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module SilverlineAPI
|
24
|
+
class << self
|
25
|
+
attr_accessor :username, :key, :site, :last_response
|
26
|
+
attr_reader :url
|
27
|
+
|
28
|
+
def url
|
29
|
+
@url ||= url!
|
30
|
+
end
|
31
|
+
|
32
|
+
def username=(new_username)
|
33
|
+
@username = CGI.escape(new_username)
|
34
|
+
url!
|
35
|
+
end
|
36
|
+
|
37
|
+
def key=(new_key)
|
38
|
+
@key = new_key
|
39
|
+
url!
|
40
|
+
end
|
41
|
+
|
42
|
+
def site=(new_site)
|
43
|
+
@site = new_site
|
44
|
+
url!
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def url!
|
50
|
+
if @site
|
51
|
+
protocol, domain = /(https?:\/\/)(.+)/.match(@site).captures
|
52
|
+
else
|
53
|
+
protocol = "https://"
|
54
|
+
domain = "api.librato.com/v1"
|
55
|
+
end
|
56
|
+
@url = "#{protocol}#{@username}:#{@key}@#{domain}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Template
|
61
|
+
attr_accessor :id, :name, :min_cpu, :min_mem, :min_network_rbw, :min_network_wbw, :min_storage_rbw, :min_storage_wbw, :containers
|
62
|
+
attr_reader :errors
|
63
|
+
|
64
|
+
def initialize(args = {})
|
65
|
+
@id = args[:id] if args[:id]
|
66
|
+
@name = args[:name] if args[:name]
|
67
|
+
@min_cpu = args[:min_cpu] if args[:min_cpu]
|
68
|
+
@min_mem = args[:min_mem] if args[:min_mem]
|
69
|
+
@min_network_rbw = args[:min_network_rbw] if args[:min_network_rbw]
|
70
|
+
@min_network_wbw = args[:min_network_wbw] if args[:min_network_wbw]
|
71
|
+
@min_storage_rbw = args[:min_storage_rbw] if args[:min_storage_rbw]
|
72
|
+
@min_storage_wbw = args[:min_storage_wbw] if args[:min_storage_wbw]
|
73
|
+
@containers = []
|
74
|
+
if args[:containers]
|
75
|
+
args[:containers].each do |container|
|
76
|
+
container.map {|k, v| container[k.to_sym] = v}
|
77
|
+
@containers.push(Container.new(container))
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if @containers.size == 0
|
82
|
+
@containers.push(Container.new(:name => "system"))
|
83
|
+
@containers.push(Container.new(:name => "harvest", :cpu => {:allocation => 0}))
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def new?
|
88
|
+
@id.nil?
|
89
|
+
end
|
90
|
+
|
91
|
+
def save
|
92
|
+
@errors = []
|
93
|
+
parameters = {
|
94
|
+
:name => @name,
|
95
|
+
:min_cpu => @min_cpu,
|
96
|
+
:min_mem => @min_mem,
|
97
|
+
:min_network_rbw => @min_network_rbw,
|
98
|
+
:min_network_wbw => @min_network_wbw,
|
99
|
+
:min_storage_rbw => @min_storage_rbw,
|
100
|
+
:min_storage_wbw => @min_storage_wbw,
|
101
|
+
:containers => @containers
|
102
|
+
}.to_json
|
103
|
+
|
104
|
+
if @id
|
105
|
+
begin
|
106
|
+
x = RestClient.put("#{SilverlineAPI.url}/templates/#{@id}.json", parameters, :content_type => :json)
|
107
|
+
rescue RestClient::UnprocessableEntity => e
|
108
|
+
@errors = JSON.parse(e.http_body)["errors"]
|
109
|
+
return false
|
110
|
+
end
|
111
|
+
else
|
112
|
+
begin
|
113
|
+
x = RestClient.post("#{SilverlineAPI.url}/templates.json", parameters, :content_type => :json)
|
114
|
+
rescue RestClient::UnprocessableEntity => e
|
115
|
+
@errors = JSON.parse(e.http_body)["errors"]
|
116
|
+
return false
|
117
|
+
end
|
118
|
+
@id = x.headers[:location].scan(/\d+/).last
|
119
|
+
end
|
120
|
+
true
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.create(args = {})
|
124
|
+
template = Template.new(args)
|
125
|
+
template.save
|
126
|
+
template
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.find(*args)
|
130
|
+
scope = args.slice!(0)
|
131
|
+
options = args.slice!(0) || {}
|
132
|
+
|
133
|
+
if scope == :all
|
134
|
+
array = options.map {|k, v| "#{k}=#{v}"}
|
135
|
+
arguments = array.join("&")
|
136
|
+
unless arguments.empty?
|
137
|
+
query = "/templates.json?#{arguments}"
|
138
|
+
else
|
139
|
+
query = "/templates.json"
|
140
|
+
end
|
141
|
+
response = RestClient.get("#{SilverlineAPI.url}#{query}")
|
142
|
+
hash = symbolize_keys(JSON.parse(response))
|
143
|
+
|
144
|
+
templates = []
|
145
|
+
hash[:templates].each {|template| templates.push(Template.new(template))}
|
146
|
+
SilverlineAPI.last_response = hash[:query]
|
147
|
+
templates
|
148
|
+
else # scope is ID => Template.find(5)
|
149
|
+
query = "/templates/#{scope}.json"
|
150
|
+
response = RestClient.get("#{SilverlineAPI.url}#{query}")
|
151
|
+
hash = symbolize_keys(JSON.parse(response))
|
152
|
+
Template.new(hash)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def self.find_by_name(template_name)
|
158
|
+
response = RestClient.get("#{SilverlineAPI.url}/templates.json?q=#{template_name}")
|
159
|
+
template = symbolize_keys(JSON.parse(response))
|
160
|
+
Template.new(template.first)
|
161
|
+
end
|
162
|
+
|
163
|
+
def container_by_name(container_name)
|
164
|
+
@containers.find {|c| c.name == container_name}
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
class Container
|
169
|
+
attr_accessor :name, :cpu, :mem, :network_rbw, :network_wbw, :storage_rbw, :storage_wbw
|
170
|
+
|
171
|
+
def initialize(args = {})
|
172
|
+
@name = args[:name]
|
173
|
+
@cpu = args[:cpu] ? Axis.new(args[:cpu]) : Axis.new
|
174
|
+
@mem = args[:mem] ? Axis.new(args[:mem]) : Axis.new
|
175
|
+
@network_rbw = args[:network_rbw] ? Axis.new(args[:network_rbw]) : Axis.new
|
176
|
+
@network_wbw = args[:network_wbw] ? Axis.new(args[:network_wbw]) : Axis.new
|
177
|
+
@storage_rbw = args[:storage_rbw] ? Axis.new(args[:storage_rbw]) : Axis.new
|
178
|
+
@storage_wbw = args[:storage_wbw] ? Axis.new(args[:storage_wbw]) : Axis.new
|
179
|
+
end
|
180
|
+
|
181
|
+
def to_json(x = nil)
|
182
|
+
{
|
183
|
+
:name => @name,
|
184
|
+
:cpu => @cpu,
|
185
|
+
:mem => @mem,
|
186
|
+
:network_rbw => @network_rbw,
|
187
|
+
:network_wbw => @network_wbw,
|
188
|
+
:storage_rbw => @storage_rbw,
|
189
|
+
:storage_wbw => @storage_wbw
|
190
|
+
}.to_json
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
class Axis
|
195
|
+
attr_accessor :allocation, :max
|
196
|
+
|
197
|
+
def initialize(args = {})
|
198
|
+
@allocation = args && args[:allocation] ? args[:allocation] : "unlimited"
|
199
|
+
@max = args && args[:max] ? args[:max] : nil
|
200
|
+
end
|
201
|
+
|
202
|
+
def to_json(x = nil)
|
203
|
+
{
|
204
|
+
:allocation => @allocation,
|
205
|
+
:max => @max
|
206
|
+
}.to_json
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/librato_silverline_api/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "librato_silverline_api"
|
6
|
+
s.version = SilverlineAPI::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = "Chris Blaettermann"
|
9
|
+
s.email = "chris@librato.com"
|
10
|
+
s.homepage = "http://rubygems.org/gems/librato_silverline_api"
|
11
|
+
s.summary = "Write a gem summary"
|
12
|
+
s.description = "Write a gem description"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "librato_silverline_api"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
18
|
+
|
19
|
+
s.add_dependency("rest-client", "1.6.1")
|
20
|
+
s.add_dependency("json", "1.4.6")
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
24
|
+
s.require_path = 'lib'
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "librato-silverline-api"
|
3
|
+
|
4
|
+
# Only for demonstration purposes
|
5
|
+
silverline_api_config = YAML::load_file(File.join(File.dirname(__FILE__), "..", "config", "librato-silverline-api.yml"))
|
6
|
+
|
7
|
+
# Configure API Access
|
8
|
+
SilverlineAPI.username = silverline_api_config["username"]
|
9
|
+
SilverlineAPI.key = silverline_api_config["key"]
|
10
|
+
|
11
|
+
# Retrieve Templates
|
12
|
+
templates = SilverlineAPI::Templates.find(:all) # returns a maximum of 100 templates
|
13
|
+
|
14
|
+
templates = SilverlineAPI::Templates.find(:all, :length => 10, :offset => 20) # returns the 3rd page and contains 10 templates
|
15
|
+
|
16
|
+
templates = SilverlineAPI::Templates.find(:all, :name => "foo") # returns a maximum of 100 templates which partially match the name
|
17
|
+
|
18
|
+
SilverlineAPI.last_response # holds the information of the last response, e.g. the amount of templates, pagination and search detail, etc.
|
19
|
+
|
20
|
+
# create a template with the default containers
|
21
|
+
template = SilverlineAPI::Template.new(:name => "foo", :min_cpu => 200, :min_mem => 128)
|
22
|
+
template.save # saves the newly created template
|
23
|
+
|
24
|
+
# add a special container
|
25
|
+
container = SilverlineAPI::Container.new(:name => "bar", :cpu => {:allocation => 40}, :mem => {:allocation => 64, :max => 64})
|
26
|
+
template.containers.push(container)
|
27
|
+
template.save
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "./lib/librato_silverline_api.rb"
|
3
|
+
|
4
|
+
module SilverlineAPI
|
5
|
+
class FunctionalTest < Test::Unit::TestCase
|
6
|
+
def configure
|
7
|
+
SilverlineAPI.site = ENV["SILVERLINE_API_SITE"]
|
8
|
+
SilverlineAPI.username = ENV["SILVERLINE_API_USERNAME"]
|
9
|
+
SilverlineAPI.key = ENV["SILVERLINE_API_KEY"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def has_error?(template, name)
|
13
|
+
template.errors["params"].find {|x| x.include?(name)} != nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_find_all_templates
|
17
|
+
configure
|
18
|
+
|
19
|
+
templates = Template.find(:all)
|
20
|
+
assert templates.count > 0
|
21
|
+
|
22
|
+
templates = Template.find(:all, :name => "oo")
|
23
|
+
assert templates.first.name == "foo"
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_new_template
|
27
|
+
configure
|
28
|
+
|
29
|
+
template = Template.new
|
30
|
+
assert template.save == false
|
31
|
+
assert has_error?(template, "name")
|
32
|
+
assert has_error?(template, "min_cpu")
|
33
|
+
assert has_error?(template, "min_mem")
|
34
|
+
|
35
|
+
template.name = "fwfewofiwe"
|
36
|
+
assert template.save == false
|
37
|
+
assert !has_error?(template, "name")
|
38
|
+
assert has_error?(template, "min_cpu")
|
39
|
+
assert has_error?(template, "min_mem")
|
40
|
+
|
41
|
+
template.min_cpu = 100
|
42
|
+
assert template.save == false
|
43
|
+
assert !has_error?(template, "name")
|
44
|
+
assert !has_error?(template, "min_cpu")
|
45
|
+
assert has_error?(template, "min_mem")
|
46
|
+
|
47
|
+
template = Template.new(:name => "bar")
|
48
|
+
assert template.name == "bar"
|
49
|
+
assert template.save == false
|
50
|
+
assert !has_error?(template, "name")
|
51
|
+
assert has_error?(template, "min_cpu")
|
52
|
+
assert has_error?(template, "min_mem")
|
53
|
+
|
54
|
+
template = Template.create
|
55
|
+
assert has_error?(template, "name")
|
56
|
+
assert has_error?(template, "min_cpu")
|
57
|
+
assert has_error?(template, "min_mem")
|
58
|
+
|
59
|
+
new_name = Time.now.to_i.to_s
|
60
|
+
|
61
|
+
template = Template.new
|
62
|
+
template.name = new_name
|
63
|
+
template.min_cpu = 100
|
64
|
+
template.min_mem = 100
|
65
|
+
assert template.save
|
66
|
+
|
67
|
+
id = template.id
|
68
|
+
template.min_cpu = 200
|
69
|
+
assert template.save
|
70
|
+
|
71
|
+
template = Template.find(id)
|
72
|
+
assert template != nil
|
73
|
+
assert template.min_cpu == 200
|
74
|
+
|
75
|
+
template.min_cpu = 50
|
76
|
+
assert template.save == false
|
77
|
+
|
78
|
+
template = Template.find_by_name(new_name)
|
79
|
+
assert template.name == new_name
|
80
|
+
|
81
|
+
container = template.container_by_name("system")
|
82
|
+
assert container.name == "system"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "./lib/librato_silverline_api.rb"
|
3
|
+
|
4
|
+
module SilverlineAPI
|
5
|
+
class AxisTest < Test::Unit::TestCase
|
6
|
+
def test_empty_axis
|
7
|
+
axis = Axis.new
|
8
|
+
assert axis.allocation == "unlimited"
|
9
|
+
assert axis.max == nil
|
10
|
+
end
|
11
|
+
|
12
|
+
# Validation does not happen in the gem for now. Therefore we only
|
13
|
+
# check whether values get handled correctly in the model.
|
14
|
+
|
15
|
+
def test_parameters
|
16
|
+
axis = Axis.new(:allocation => 20)
|
17
|
+
assert axis.allocation == 20
|
18
|
+
assert axis.max == nil
|
19
|
+
|
20
|
+
axis = Axis.new(:allocation => 20, :max => 20)
|
21
|
+
assert axis.allocation == 20
|
22
|
+
assert axis.max == 20
|
23
|
+
|
24
|
+
axis = Axis.new(:allocation => "unlimited")
|
25
|
+
assert axis.allocation == "unlimited"
|
26
|
+
assert axis.max == nil
|
27
|
+
|
28
|
+
axis = Axis.new({:allocation => "fair"})
|
29
|
+
assert axis.allocation == "fair"
|
30
|
+
assert axis.max == nil
|
31
|
+
|
32
|
+
axis = Axis.new({:allocation => "monitor"})
|
33
|
+
assert axis.allocation == "monitor"
|
34
|
+
assert axis.max == nil
|
35
|
+
|
36
|
+
axis = Axis.new({:allocation => 20, :max => nil})
|
37
|
+
assert axis.allocation == 20
|
38
|
+
assert axis.max == nil
|
39
|
+
|
40
|
+
axis = Axis.new({:allocation => "unlimited", :max => nil})
|
41
|
+
assert axis.allocation == "unlimited"
|
42
|
+
assert axis.max == nil
|
43
|
+
|
44
|
+
assert axis.to_json == '{"allocation":"unlimited","max":null}'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "./lib/librato_silverline_api.rb"
|
3
|
+
|
4
|
+
module SilverlineAPI
|
5
|
+
class ContainerTest < Test::Unit::TestCase
|
6
|
+
def test_empty_container
|
7
|
+
container = Container.new
|
8
|
+
assert container.name == nil
|
9
|
+
assert container.cpu.class == Axis
|
10
|
+
assert container.cpu.allocation == "unlimited"
|
11
|
+
assert container.cpu.max == nil
|
12
|
+
assert container.mem.class == Axis
|
13
|
+
assert container.mem.allocation == "unlimited"
|
14
|
+
assert container.mem.max == nil
|
15
|
+
assert container.network_rbw.class == Axis
|
16
|
+
assert container.network_rbw.allocation == "unlimited"
|
17
|
+
assert container.network_rbw.max == nil
|
18
|
+
assert container.network_wbw.class == Axis
|
19
|
+
assert container.network_wbw.allocation == "unlimited"
|
20
|
+
assert container.network_wbw.max == nil
|
21
|
+
assert container.storage_rbw.class == Axis
|
22
|
+
assert container.storage_rbw.allocation == "unlimited"
|
23
|
+
assert container.storage_rbw.max == nil
|
24
|
+
assert container.storage_wbw.class == Axis
|
25
|
+
assert container.storage_wbw.allocation == "unlimited"
|
26
|
+
assert container.storage_wbw.max == nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_container_with_hash
|
30
|
+
container = Container.new(:name => "foo", :cpu => {:allocation => 10})
|
31
|
+
assert container.name == "foo"
|
32
|
+
assert container.cpu.class == Axis
|
33
|
+
assert container.cpu.allocation == 10
|
34
|
+
assert container.cpu.max == nil
|
35
|
+
assert container.mem.class == Axis
|
36
|
+
assert container.mem.allocation == "unlimited"
|
37
|
+
assert container.mem.max == nil
|
38
|
+
assert container.network_rbw.class == Axis
|
39
|
+
assert container.network_rbw.allocation == "unlimited"
|
40
|
+
assert container.network_rbw.max == nil
|
41
|
+
assert container.network_wbw.class == Axis
|
42
|
+
assert container.network_wbw.allocation == "unlimited"
|
43
|
+
assert container.network_wbw.max == nil
|
44
|
+
assert container.storage_rbw.class == Axis
|
45
|
+
assert container.storage_rbw.allocation == "unlimited"
|
46
|
+
assert container.storage_rbw.max == nil
|
47
|
+
assert container.storage_wbw.class == Axis
|
48
|
+
assert container.storage_wbw.allocation == "unlimited"
|
49
|
+
assert container.storage_wbw.max == nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "./lib/librato_silverline_api.rb"
|
3
|
+
|
4
|
+
module SilverlineAPI
|
5
|
+
class TemplateTest < Test::Unit::TestCase
|
6
|
+
def test_empty_template
|
7
|
+
template = Template.new
|
8
|
+
assert template.new?
|
9
|
+
assert template.containers != nil
|
10
|
+
assert template.containers.class == Array
|
11
|
+
assert template.containers.count == 2 # System and Harvest container
|
12
|
+
template.containers.each do |container|
|
13
|
+
assert container.class == Container
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_template
|
18
|
+
# Because unit tests do not support the real deal, the following line goes into the functional tests
|
19
|
+
# template = SilverlineTemplate.new(:name => "foo")
|
20
|
+
|
21
|
+
# This test is no joke, since SilverlineTemplate is a wrapper around Template.
|
22
|
+
template = Template.new
|
23
|
+
template.name = "foo"
|
24
|
+
assert template.name == "foo"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: librato_silverline_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Chris Blaettermann
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-26 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bundler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 23
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
version: 1.0.0
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rest-client
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - "="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 13
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 6
|
49
|
+
- 1
|
50
|
+
version: 1.6.1
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: json
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - "="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 11
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 4
|
65
|
+
- 6
|
66
|
+
version: 1.4.6
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
|
+
description: Write a gem description
|
70
|
+
email: chris@librato.com
|
71
|
+
executables: []
|
72
|
+
|
73
|
+
extensions: []
|
74
|
+
|
75
|
+
extra_rdoc_files: []
|
76
|
+
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- config/librato_silverline_api.example.yml
|
85
|
+
- lib/librato_silverline_api.rb
|
86
|
+
- lib/librato_silverline_api/version.rb
|
87
|
+
- librato_silverline_api.gemspec
|
88
|
+
- samples/templates.rb
|
89
|
+
- test/functional_test.rb
|
90
|
+
- test/unit/axis-test.rb
|
91
|
+
- test/unit/container-test.rb
|
92
|
+
- test/unit/template-test.rb
|
93
|
+
has_rdoc: true
|
94
|
+
homepage: http://rubygems.org/gems/librato_silverline_api
|
95
|
+
licenses: []
|
96
|
+
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
version: "0"
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 23
|
117
|
+
segments:
|
118
|
+
- 1
|
119
|
+
- 3
|
120
|
+
- 6
|
121
|
+
version: 1.3.6
|
122
|
+
requirements: []
|
123
|
+
|
124
|
+
rubyforge_project: librato_silverline_api
|
125
|
+
rubygems_version: 1.4.2
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: Write a gem summary
|
129
|
+
test_files: []
|
130
|
+
|