squall 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +100 -0
- data/LICENSE +1 -1
- data/README.md +69 -0
- data/Rakefile +48 -42
- data/lib/squall/base.rb +96 -0
- data/lib/squall/config.rb +26 -0
- data/lib/squall/exception.rb +13 -0
- data/lib/squall/hypervisor.rb +46 -16
- data/lib/squall/ip_address.rb +13 -0
- data/lib/squall/network.rb +42 -0
- data/lib/squall/params.rb +50 -0
- data/lib/squall/role.rb +56 -0
- data/lib/squall/statistic.rb +10 -0
- data/lib/squall/template.rb +22 -0
- data/lib/squall/transaction.rb +16 -0
- data/lib/squall/user.rb +87 -0
- data/lib/squall/version.rb +3 -0
- data/lib/squall/virtual_machine.rb +169 -41
- data/lib/squall.rb +76 -20
- data/spec/params_spec.rb +195 -0
- data/spec/spec_helper.rb +47 -0
- data/spec/squall/base_spec.rb +135 -0
- data/spec/squall/config_spec.rb +44 -0
- data/spec/squall/hypervisor_spec.rb +143 -0
- data/spec/squall/ip_address_spec.rb +32 -0
- data/spec/squall/network_spec.rb +121 -0
- data/spec/squall/role_spec.rb +123 -0
- data/spec/squall/statistic_spec.rb +23 -0
- data/spec/squall/template_spec.rb +59 -0
- data/spec/squall/transaction_spec.rb +42 -0
- data/spec/squall/user_spec.rb +195 -0
- data/spec/squall/virtual_machine_spec.rb +471 -0
- data/spec/squall_spec.rb +67 -0
- data/spec/vcr_cassettes/hypervisor/create.yml +77 -0
- data/spec/vcr_cassettes/hypervisor/delete.yml +77 -0
- data/spec/vcr_cassettes/hypervisor/edit.yml +79 -0
- data/spec/vcr_cassettes/hypervisor/list.yml +40 -0
- data/spec/vcr_cassettes/hypervisor/reboot.yml +77 -0
- data/spec/vcr_cassettes/hypervisor/show.yml +77 -0
- data/spec/vcr_cassettes/ipaddress/list.yml +77 -0
- data/spec/vcr_cassettes/network/create.yml +196 -0
- data/spec/vcr_cassettes/network/delete.yml +77 -0
- data/spec/vcr_cassettes/network/edit.yml +233 -0
- data/spec/vcr_cassettes/network/list.yml +40 -0
- data/spec/vcr_cassettes/role/create.yml +77 -0
- data/spec/vcr_cassettes/role/delete.yml +77 -0
- data/spec/vcr_cassettes/role/edit.yml +139 -0
- data/spec/vcr_cassettes/role/list.yml +40 -0
- data/spec/vcr_cassettes/role/permissions.yml +40 -0
- data/spec/vcr_cassettes/role/show.yml +77 -0
- data/spec/vcr_cassettes/statistic/usage_statistics.yml +40 -0
- data/spec/vcr_cassettes/template/download.yml +40 -0
- data/spec/vcr_cassettes/template/list.yml +40 -0
- data/spec/vcr_cassettes/template/make_public.yml +77 -0
- data/spec/vcr_cassettes/transaction/list.yml +40 -0
- data/spec/vcr_cassettes/transaction/show.yml +77 -0
- data/spec/vcr_cassettes/user/activate.yml +40 -0
- data/spec/vcr_cassettes/user/create.yml +116 -0
- data/spec/vcr_cassettes/user/delete.yml +77 -0
- data/spec/vcr_cassettes/user/edit_role.yml +116 -0
- data/spec/vcr_cassettes/user/generate_api_key.yml +40 -0
- data/spec/vcr_cassettes/user/list.yml +40 -0
- data/spec/vcr_cassettes/user/show.yml +77 -0
- data/spec/vcr_cassettes/user/stats.yml +40 -0
- data/spec/vcr_cassettes/user/suspend.yml +40 -0
- data/spec/vcr_cassettes/user/virtual_machines.yml +79 -0
- data/spec/vcr_cassettes/virtual_machine/build.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/change_owner.yml +108 -0
- data/spec/vcr_cassettes/virtual_machine/change_password.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/create.yml +40 -0
- data/spec/vcr_cassettes/virtual_machine/delete.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/edit.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/list.yml +40 -0
- data/spec/vcr_cassettes/virtual_machine/migrate.yml +116 -0
- data/spec/vcr_cassettes/virtual_machine/reboot.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/resize.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/show.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/shutdown.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/startup.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/stop.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/suspend.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/unlock.yml +77 -0
- data/spec/vcr_cassettes/virtual_machine/unsuspend.yml +77 -0
- data/squall.gemspec +25 -62
- metadata +224 -42
- data/.document +0 -5
- data/README.rdoc +0 -17
- data/VERSION.yml +0 -5
- data/lib/squall/client.rb +0 -87
- data/test/fixtures/virtual_machines.json +0 -1
- data/test/fixtures/virtual_machines_1.json +0 -1
- data/test/helper.rb +0 -31
- data/test/test_client.rb +0 -152
- data/test/test_squall.rb +0 -12
- data/test/test_virtual_machine.rb +0 -98
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.8.7@squall
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
squall (1.0.0)
|
5
|
+
httparty (~> 0.7.4)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
Saikuro (1.1.0)
|
11
|
+
abstract (1.0.0)
|
12
|
+
activesupport (3.0.6)
|
13
|
+
arrayfields (4.7.4)
|
14
|
+
awesome_print (0.3.2)
|
15
|
+
chronic (0.3.0)
|
16
|
+
churn (0.0.13)
|
17
|
+
chronic (>= 0.2.3)
|
18
|
+
hirb
|
19
|
+
json_pure
|
20
|
+
main
|
21
|
+
ruby_parser (~> 2.0.4)
|
22
|
+
sexp_processor (~> 3.0.3)
|
23
|
+
colored (1.2)
|
24
|
+
crack (0.1.8)
|
25
|
+
diff-lcs (1.1.2)
|
26
|
+
erubis (2.6.6)
|
27
|
+
abstract (>= 1.0.0)
|
28
|
+
fakeweb (1.3.0)
|
29
|
+
fattr (2.2.0)
|
30
|
+
flay (1.4.2)
|
31
|
+
ruby_parser (~> 2.0)
|
32
|
+
sexp_processor (~> 3.0)
|
33
|
+
flog (2.5.1)
|
34
|
+
ruby_parser (~> 2.0)
|
35
|
+
sexp_processor (~> 3.0)
|
36
|
+
haml (3.0.25)
|
37
|
+
hirb (0.4.3)
|
38
|
+
httparty (0.7.7)
|
39
|
+
crack (= 0.1.8)
|
40
|
+
i18n (0.5.0)
|
41
|
+
json_pure (1.5.1)
|
42
|
+
main (4.4.0)
|
43
|
+
arrayfields (>= 4.7.4)
|
44
|
+
fattr (>= 2.1.0)
|
45
|
+
metric_fu (2.1.1)
|
46
|
+
Saikuro (>= 1.1.0)
|
47
|
+
activesupport (>= 2.0.0)
|
48
|
+
chronic (~> 0.3.0)
|
49
|
+
churn (>= 0.0.7)
|
50
|
+
flay (>= 1.2.1)
|
51
|
+
flog (>= 2.3.0)
|
52
|
+
rails_best_practices (>= 0.6.4)
|
53
|
+
rcov (>= 0.8.3.3)
|
54
|
+
reek (>= 1.2.6)
|
55
|
+
roodi (>= 2.1.0)
|
56
|
+
syntax
|
57
|
+
rails_best_practices (0.7.5)
|
58
|
+
activesupport
|
59
|
+
colored (~> 1.2)
|
60
|
+
erubis (~> 2.6.6)
|
61
|
+
haml (~> 3.0.18)
|
62
|
+
i18n
|
63
|
+
ruby-progressbar (~> 0.0.9)
|
64
|
+
ruby_parser (~> 2.0.4)
|
65
|
+
rcov (0.9.9)
|
66
|
+
reek (1.2.8)
|
67
|
+
ruby2ruby (~> 1.2)
|
68
|
+
ruby_parser (~> 2.0)
|
69
|
+
sexp_processor (~> 3.0)
|
70
|
+
roodi (2.1.0)
|
71
|
+
ruby_parser
|
72
|
+
rspec (2.5.0)
|
73
|
+
rspec-core (~> 2.5.0)
|
74
|
+
rspec-expectations (~> 2.5.0)
|
75
|
+
rspec-mocks (~> 2.5.0)
|
76
|
+
rspec-core (2.5.1)
|
77
|
+
rspec-expectations (2.5.0)
|
78
|
+
diff-lcs (~> 1.1.2)
|
79
|
+
rspec-mocks (2.5.0)
|
80
|
+
ruby-progressbar (0.0.9)
|
81
|
+
ruby2ruby (1.2.5)
|
82
|
+
ruby_parser (~> 2.0)
|
83
|
+
sexp_processor (~> 3.0)
|
84
|
+
ruby_parser (2.0.6)
|
85
|
+
sexp_processor (~> 3.0)
|
86
|
+
sexp_processor (3.0.5)
|
87
|
+
syntax (1.0.0)
|
88
|
+
vcr (1.8.0)
|
89
|
+
|
90
|
+
PLATFORMS
|
91
|
+
ruby
|
92
|
+
|
93
|
+
DEPENDENCIES
|
94
|
+
awesome_print
|
95
|
+
fakeweb (~> 1.3)
|
96
|
+
metric_fu (~> 2.1)
|
97
|
+
rcov (~> 0.9)
|
98
|
+
rspec (~> 2.5)
|
99
|
+
squall!
|
100
|
+
vcr (~> 1.8)
|
data/LICENSE
CHANGED
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
Squall
|
2
|
+
=======
|
3
|
+
[![Build Status](http://travis-ci.org/site5/squall.png)](http://travis-ci.org/site5/squall)
|
4
|
+
|
5
|
+
|
6
|
+
A Ruby library for working with the OnApp REST API
|
7
|
+
|
8
|
+
[RDoc](http://rdoc.info/github/site5/squall/master/frames)
|
9
|
+
|
10
|
+
Confirmed to work with ruby 1.8.7, 1.9.2, Rubinis, REE and JRuby 1.6.0 with OnApp 2.1
|
11
|
+
|
12
|
+
Install
|
13
|
+
-------
|
14
|
+
|
15
|
+
gem install squall
|
16
|
+
|
17
|
+
|
18
|
+
Usage
|
19
|
+
-----
|
20
|
+
|
21
|
+
Configure
|
22
|
+
|
23
|
+
require 'squall'
|
24
|
+
|
25
|
+
Squall.config do |c|
|
26
|
+
c.base_uri 'https://onappurl.com'
|
27
|
+
c.username 'username'
|
28
|
+
c.password 'topsecret'
|
29
|
+
end
|
30
|
+
|
31
|
+
Show the info for a VM
|
32
|
+
|
33
|
+
vm = Squall::VirtualMachine.new
|
34
|
+
vm.show 1
|
35
|
+
|
36
|
+
|
37
|
+
Create a new VM
|
38
|
+
|
39
|
+
vm = Squall::VirtualMachine.new
|
40
|
+
|
41
|
+
params = {
|
42
|
+
:label => 'testmachine',
|
43
|
+
:hypervisor_id => 5,
|
44
|
+
:hostname => 'testmachine',
|
45
|
+
:memory => 512,
|
46
|
+
:cpus => 1,
|
47
|
+
:cpu_shares => 10,
|
48
|
+
:primary_disk_size => 10
|
49
|
+
}
|
50
|
+
|
51
|
+
vm.create params
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
Note on Patches/Pull Requests
|
56
|
+
=======
|
57
|
+
|
58
|
+
* Fork the project.
|
59
|
+
* Make your feature addition or bug fix.
|
60
|
+
* Add tests for it. This is important so I don't break it in a
|
61
|
+
future version unintentionally.
|
62
|
+
* Commit, do not mess with rakefile, version, or history.
|
63
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
64
|
+
* Send me a pull request. Bonus points for topic branches.
|
65
|
+
|
66
|
+
Copyright
|
67
|
+
=======
|
68
|
+
|
69
|
+
Copyright (c) 2011 Site5 LLC. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,55 +1,61 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
|
1
|
+
require 'bundler'
|
2
|
+
require 'uri'
|
4
3
|
begin
|
5
|
-
require '
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "squall"
|
8
|
-
gem.summary = %Q{A Ruby library for working with the OnApp REST API}
|
9
|
-
gem.description = %Q{A Ruby library for working with the OnApp REST API}
|
10
|
-
gem.email = "jmazzi@site5.com"
|
11
|
-
gem.homepage = "http://www.site5.com"
|
12
|
-
gem.authors = ["Justin Mazzi"]
|
13
|
-
gem.add_dependency 'rest-client'
|
14
|
-
gem.add_dependency 'json'
|
15
|
-
gem.add_development_dependency 'fakeweb'
|
16
|
-
gem.add_development_dependency 'redgreen'
|
17
|
-
end
|
18
|
-
Jeweler::GemcutterTasks.new
|
4
|
+
require 'rspec/core/rake_task'
|
19
5
|
rescue LoadError
|
20
|
-
puts "
|
21
|
-
|
22
|
-
|
23
|
-
require 'rake/testtask'
|
24
|
-
Rake::TestTask.new(:test) do |test|
|
25
|
-
test.libs << 'lib' << 'test'
|
26
|
-
test.pattern = 'test/**/test_*.rb'
|
27
|
-
test.verbose = true
|
6
|
+
puts "Please install rspec (bundle install)"
|
7
|
+
exit
|
28
8
|
end
|
29
9
|
|
30
10
|
begin
|
31
|
-
require '
|
32
|
-
|
33
|
-
|
34
|
-
test.pattern = 'test/**/test_*.rb'
|
35
|
-
test.verbose = true
|
11
|
+
require 'metric_fu'
|
12
|
+
MetricFu::Configuration.run do |config|
|
13
|
+
config.rcov[:rcov_opts] << "-Ispec"
|
36
14
|
end
|
37
15
|
rescue LoadError
|
38
|
-
task :rcov do
|
39
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
-
end
|
41
16
|
end
|
42
17
|
|
43
|
-
|
18
|
+
RSpec::Core::RakeTask.new :spec
|
19
|
+
Bundler::GemHelper.install_tasks
|
44
20
|
|
45
|
-
|
21
|
+
desc "Sanitize sensitive info from cassettes"
|
22
|
+
task :sanitize_cassettes do
|
23
|
+
yaml = File.join(ENV['HOME'], '.squall.yml')
|
24
|
+
if File.exists?(yaml)
|
25
|
+
config = YAML::load_file(yaml)
|
26
|
+
uri = URI.parse(config['base_uri']).host
|
27
|
+
user = config['username']
|
28
|
+
pass = config['password']
|
46
29
|
|
47
|
-
|
48
|
-
|
49
|
-
|
30
|
+
path = File.join(File.dirname(__FILE__), 'spec', 'vcr_cassettes')
|
31
|
+
files = Dir.glob("#{path}/**/*.yml")
|
32
|
+
if files.any?
|
33
|
+
files.each do |file|
|
34
|
+
old = File.read(file)
|
35
|
+
# if old.match(/#{uri}|#{user}|#{pass}/)
|
36
|
+
puts "Sanitizing #{file}"
|
37
|
+
old.gsub!(user, 'user')
|
38
|
+
old.gsub!(pass, 'pass')
|
39
|
+
old.gsub!(uri, 'www.example.com')
|
40
|
+
old.gsub!(/_onapp_session=(.*?);/, "_onapp_session=WHAT;")
|
41
|
+
old.gsub!(/- Basic .*/, "- Basic WHAT")
|
42
|
+
File.open(file, 'w') do |f|
|
43
|
+
f.write old
|
44
|
+
end
|
45
|
+
# end
|
46
|
+
end
|
47
|
+
else
|
48
|
+
puts "Nothing to sanitize"
|
49
|
+
end
|
50
|
+
else
|
51
|
+
puts "I can't sanitize without setting up WHM_HASH and WHM_HOST"
|
52
|
+
end
|
53
|
+
end
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
desc "Run all specs with rcov"
|
56
|
+
RSpec::Core::RakeTask.new(:rcov) do |t|
|
57
|
+
t.rcov = true
|
58
|
+
t.rcov_opts = %w{--exclude osx\/objc,gems\/,spec\/,features\/}
|
55
59
|
end
|
60
|
+
|
61
|
+
task :default => [:spec]
|
data/lib/squall/base.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
module Squall
|
2
|
+
# All OnApp API classes subclass Base to get access to
|
3
|
+
# HTTParty methods and other convenience methods
|
4
|
+
class Base
|
5
|
+
# Params instance
|
6
|
+
attr_reader :params
|
7
|
+
|
8
|
+
# Returns true/false for successful/unsuccessful requests
|
9
|
+
attr_reader :success
|
10
|
+
|
11
|
+
# HTTParty class methods
|
12
|
+
include HTTParty
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
self.class.base_uri Squall::config[:base_uri]
|
16
|
+
self.class.basic_auth Squall::config[:username], Squall::config[:password]
|
17
|
+
self.class.format :json
|
18
|
+
self.class.headers 'Content-Type' => 'application/json'
|
19
|
+
# self.class.debug_output
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns a Params.new
|
23
|
+
def params
|
24
|
+
@params = Squall::Params.new
|
25
|
+
end
|
26
|
+
|
27
|
+
# Sets the default URL params for requests and merges +options+
|
28
|
+
#
|
29
|
+
# ==== Options
|
30
|
+
#
|
31
|
+
# * +options+
|
32
|
+
#
|
33
|
+
# ==== Example
|
34
|
+
#
|
35
|
+
# default_params(:something => 1)
|
36
|
+
def default_params(*options)
|
37
|
+
options.empty? ? {} : {:query => { key_for_class => options.first}}
|
38
|
+
end
|
39
|
+
|
40
|
+
# Returns an array of Request errors
|
41
|
+
def errors
|
42
|
+
return [] if @success
|
43
|
+
err = {}
|
44
|
+
@result.each do |k,v|
|
45
|
+
err[k] ||= []
|
46
|
+
err[k].push v.respond_to?(:first) ? v.first : v
|
47
|
+
end
|
48
|
+
err
|
49
|
+
end
|
50
|
+
|
51
|
+
# Peforms an HTTP Request
|
52
|
+
#
|
53
|
+
# ==== Options
|
54
|
+
# * +request_method+ - The HTTP verb for the #request. (:get/:post/:delete etc)
|
55
|
+
# * +path+ - URL path
|
56
|
+
# * +options+ - HTTP query params
|
57
|
+
#
|
58
|
+
# ==== Example
|
59
|
+
#
|
60
|
+
# request :get, '/something.json' # GET /seomthing.json
|
61
|
+
# request :put, '/something.json', :something => 1 # PUT /something.json?something=1
|
62
|
+
def request(request_method, path, options = {})
|
63
|
+
check_config
|
64
|
+
@result = self.class.send(request_method, path, options)
|
65
|
+
@success = (200..207).include?(@result.code)
|
66
|
+
case @result.code
|
67
|
+
when (200..207)
|
68
|
+
@result
|
69
|
+
when 404
|
70
|
+
raise NotFound, @result
|
71
|
+
when 422
|
72
|
+
raise RequestError, @result
|
73
|
+
else
|
74
|
+
raise ServerError, @result
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Raises an error if a request is made without first calling Squall.config
|
79
|
+
def check_config
|
80
|
+
raise NoConfig, "Squall.config must be specified" if Squall.config.empty?
|
81
|
+
end
|
82
|
+
|
83
|
+
# Sets the default param container for request. It is derived from the
|
84
|
+
# class name. Given the class name *Sandwich* and a param *bread* the
|
85
|
+
# resulting params would be 'bob[bread]=wheat'
|
86
|
+
def key_for_class
|
87
|
+
word = self.class.name.split("::").last.to_s.dup
|
88
|
+
word.gsub!(/::/, '/')
|
89
|
+
word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
|
90
|
+
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
91
|
+
word.tr!("-", "_")
|
92
|
+
word.downcase!
|
93
|
+
word.to_sym
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Squall
|
2
|
+
# Holds the configuration for Squall
|
3
|
+
class Config
|
4
|
+
attr_accessor :config
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@config = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](v)
|
11
|
+
@config[v]
|
12
|
+
end
|
13
|
+
|
14
|
+
def base_uri(value)
|
15
|
+
@config[:base_uri] = value
|
16
|
+
end
|
17
|
+
|
18
|
+
def username(value)
|
19
|
+
@config[:username] = value
|
20
|
+
end
|
21
|
+
|
22
|
+
def password(value)
|
23
|
+
@config[:password] = value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Squall
|
2
|
+
# HTTP 404 not found
|
3
|
+
class NotFound < StandardError;end
|
4
|
+
|
5
|
+
# HTTP 500 error
|
6
|
+
class RequestError < StandardError;end
|
7
|
+
|
8
|
+
# HTTP 422
|
9
|
+
class ServerError < StandardError;end
|
10
|
+
|
11
|
+
# Config missing
|
12
|
+
class NoConfig < StandardError;end
|
13
|
+
end
|
data/lib/squall/hypervisor.rb
CHANGED
@@ -1,30 +1,60 @@
|
|
1
1
|
module Squall
|
2
|
-
|
3
|
-
|
4
|
-
URI_PREFIX = 'settings/hypervisors'
|
2
|
+
# OnApp Hypervisor
|
3
|
+
class Hypervisor < Base
|
5
4
|
|
5
|
+
# Returns a list of all Hypervisors
|
6
6
|
def list
|
7
|
-
|
8
|
-
|
9
|
-
else
|
10
|
-
[]
|
11
|
-
end
|
7
|
+
req = request(:get, '/settings/hypervisors.json')
|
8
|
+
req.collect { |hv| hv['hypervisor'] }
|
12
9
|
end
|
13
10
|
|
11
|
+
# Returns the Hypervisor info as a Hash
|
12
|
+
#
|
13
|
+
# ==== Options
|
14
|
+
#
|
15
|
+
# * +id+ - The id of the Hypervisor
|
14
16
|
def show(id)
|
15
|
-
get
|
17
|
+
req = request(:get, "/settings/hypervisors/#{id}.json")
|
18
|
+
req.first[1]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Create a new Hypervisor
|
22
|
+
#
|
23
|
+
# ==== Options
|
24
|
+
#
|
25
|
+
# * +options+ - Params for creating the Hypervisor
|
26
|
+
#
|
27
|
+
# ==== Example
|
28
|
+
#
|
29
|
+
# create :label => 'myhv', :ip_address => '127.0.0.1', :hypervisor_type => 'xen'
|
30
|
+
def create(options = {})
|
31
|
+
params.required(:label, :ip_address, :hypervisor_type).validate!(options)
|
32
|
+
req = request(:post, '/settings/hypervisors.json', default_params(options))
|
33
|
+
req.first[1]
|
16
34
|
end
|
17
35
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
36
|
+
# Edit a Hypervisor
|
37
|
+
#
|
38
|
+
# ==== Options
|
39
|
+
#
|
40
|
+
# * +options+ - Params for editing the Hypervisor
|
41
|
+
# ==== Example
|
42
|
+
#
|
43
|
+
# edit :label => 'myhv', :ip_address => '127.0.0.1'
|
44
|
+
def edit(id, options ={})
|
45
|
+
params.accepts(:label, :ip_address).validate!(options)
|
46
|
+
request(:put, "/settings/hypervisors/#{id}.json", default_params(options))
|
23
47
|
end
|
24
48
|
|
25
|
-
|
26
|
-
|
49
|
+
# Reboot a Hypervisor
|
50
|
+
def reboot(id)
|
51
|
+
response = request(:get, "/settings/hypervisors/#{id}/rebooting.json")
|
52
|
+
response['hypervisor']
|
27
53
|
end
|
28
54
|
|
55
|
+
# Delete a Hypervisor
|
56
|
+
def delete(id)
|
57
|
+
req = request(:delete, "/settings/hypervisors/#{id}.json")
|
58
|
+
end
|
29
59
|
end
|
30
60
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Squall
|
2
|
+
# OnApp IpAddress
|
3
|
+
class IpAddress < Base
|
4
|
+
# Returns a list of IpAddresses
|
5
|
+
#
|
6
|
+
# ==== Options
|
7
|
+
# * +network_id+ - required
|
8
|
+
def list(network_id)
|
9
|
+
response = request(:get, "/settings/networks/#{network_id}/ip_addresses.json")
|
10
|
+
response.collect { |ip| ip['ip_address'] }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Squall
|
2
|
+
# OnApp Network
|
3
|
+
class Network < Base
|
4
|
+
# Returns a list of Networks
|
5
|
+
def list
|
6
|
+
response = request(:get, '/settings/networks.json')
|
7
|
+
response.collect { |network| network['network'] }
|
8
|
+
end
|
9
|
+
|
10
|
+
# Edit a Network
|
11
|
+
#
|
12
|
+
# ==== Options
|
13
|
+
#
|
14
|
+
# * +options+ - Params for editing the Network
|
15
|
+
# ==== Example
|
16
|
+
#
|
17
|
+
# edit :label => 'mynetwork', :network_group_id => 1, :vlan => 2, :identifier => 'something'
|
18
|
+
def edit(id, options = {})
|
19
|
+
params.accepts(:label, :network_group_id, :vlan, :identifier).validate!(options)
|
20
|
+
response = request(:put, "/settings/networks/#{id}.json", default_params(options))
|
21
|
+
end
|
22
|
+
|
23
|
+
# Create a Network
|
24
|
+
#
|
25
|
+
# ==== Options
|
26
|
+
#
|
27
|
+
# * +options+ - Params for creating the Network
|
28
|
+
# ==== Example
|
29
|
+
#
|
30
|
+
# create :label => 'mynetwork', :network_group_id => 1, :vlan => 2, :identifier => 'something'
|
31
|
+
def create(options = {})
|
32
|
+
params.accepts(:label, :vlan, :identifier).required(:label).validate!(options)
|
33
|
+
response = request(:post, '/settings/networks.json', default_params(options))
|
34
|
+
response.first[1]
|
35
|
+
end
|
36
|
+
|
37
|
+
# Delete a network
|
38
|
+
def delete(id)
|
39
|
+
request(:delete, "/settings/networks/#{id}.json")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Squall
|
2
|
+
class Params
|
3
|
+
# Required
|
4
|
+
attr_accessor :valid
|
5
|
+
|
6
|
+
# Optional
|
7
|
+
attr_accessor :optional
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@valid = []
|
11
|
+
@optional = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def required(*options)
|
15
|
+
@valid = options.flatten.map { |o| o.to_sym}
|
16
|
+
@valid.uniq!
|
17
|
+
@optional.concat @valid
|
18
|
+
@optional.uniq!
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def accepts(*options)
|
23
|
+
@optional.concat options.flatten.map { |o| o.to_sym}
|
24
|
+
@optional.uniq!
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def validate!(*options)
|
29
|
+
validate_required!(*options) unless @valid.empty?
|
30
|
+
validate_optionals!(*options) unless @optional.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
def validate_required!(*options)
|
34
|
+
options = options.first.keys if options.first.respond_to?(:keys)
|
35
|
+
options.map! { |o| o.respond_to?(:to_sym) ? o.to_sym : o }
|
36
|
+
delta = (@valid - options)
|
37
|
+
raise ArgumentError, "Missing required params: #{delta.join(',')}" if delta.any?
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate_optionals!(*options)
|
42
|
+
options = options.first.keys if options.first.respond_to?(:keys)
|
43
|
+
options.map! { |o| o.respond_to?(:to_sym) ? o.to_sym : o }
|
44
|
+
options.each do |key|
|
45
|
+
raise ArgumentError, "Unknown params: #{key}" unless @optional.include?(key)
|
46
|
+
end
|
47
|
+
true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/squall/role.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Squall
|
2
|
+
# OnApp Role
|
3
|
+
class Role < Base
|
4
|
+
# Return a list of Roles
|
5
|
+
def list
|
6
|
+
response = request(:get, '/roles.json')
|
7
|
+
response.collect { |role| role['role']}
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns a Hash of the given Role
|
11
|
+
def show(id)
|
12
|
+
response = request(:get, "/roles/#{id}.json")
|
13
|
+
response.first[1]
|
14
|
+
end
|
15
|
+
|
16
|
+
# Edit a Role
|
17
|
+
#
|
18
|
+
# ==== Options
|
19
|
+
#
|
20
|
+
# * +options+ - Params for editing the Role
|
21
|
+
# ==== Example
|
22
|
+
#
|
23
|
+
# edit :label => 'myrole', :permission => [1,3]
|
24
|
+
# edit :label => 'myrole', :permission => 1
|
25
|
+
def edit(id, options = {})
|
26
|
+
params.accepts(:label, :permission).validate!(options)
|
27
|
+
response = request(:put, "/roles/#{id}.json", default_params(options))
|
28
|
+
end
|
29
|
+
|
30
|
+
# Delete a Role
|
31
|
+
def delete(id)
|
32
|
+
request(:delete, "/roles/#{id}.json")
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns a list of permissions available
|
36
|
+
def permissions
|
37
|
+
response = request(:get, '/permissions.json')
|
38
|
+
response.collect { |perm| perm['permission'] }
|
39
|
+
end
|
40
|
+
|
41
|
+
# Create a new Role
|
42
|
+
#
|
43
|
+
# ==== Options
|
44
|
+
#
|
45
|
+
# * +options+ - Params for creating the Role
|
46
|
+
#
|
47
|
+
# ==== Example
|
48
|
+
#
|
49
|
+
# create :label => 'mypriv', :identifier => 'magic'
|
50
|
+
def create(options = {})
|
51
|
+
params.required(:label, :identifier).validate!(options)
|
52
|
+
response = request(:post, '/roles.json', default_params(options))
|
53
|
+
response.first[1]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|