squall 1.3.0 → 1.3.1
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.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.md +64 -41
- data/Rakefile +3 -9
- data/lib/squall/data_store_zone.rb +20 -26
- data/lib/squall/disk.rb +174 -0
- data/lib/squall/firewall_rule.rb +34 -41
- data/lib/squall/hypervisor.rb +40 -38
- data/lib/squall/hypervisor_zone.rb +51 -63
- data/lib/squall/ip_address.rb +32 -37
- data/lib/squall/ip_address_join.rb +13 -22
- data/lib/squall/network.rb +36 -33
- data/lib/squall/network_zone.rb +27 -29
- data/lib/squall/payment.rb +22 -32
- data/lib/squall/role.rb +30 -37
- data/lib/squall/statistic.rb +3 -1
- data/lib/squall/support/base.rb +35 -31
- data/lib/squall/support/config.rb +25 -1
- data/lib/squall/support/version.rb +1 -1
- data/lib/squall/template.rb +7 -5
- data/lib/squall/transaction.rb +6 -4
- data/lib/squall/user.rb +84 -83
- data/lib/squall/user_group.rb +17 -30
- data/lib/squall/virtual_machine.rb +154 -178
- data/lib/squall/whitelist.rb +29 -40
- data/lib/squall.rb +27 -25
- data/spec/spec_helper.rb +6 -11
- data/spec/squall/data_store_zone_spec.rb +2 -20
- data/spec/squall/disk_spec.rb +189 -0
- data/spec/squall/firewall_rule_spec.rb +2 -32
- data/spec/squall/hypervisor_spec.rb +3 -47
- data/spec/squall/hypervisor_zone_spec.rb +3 -28
- data/spec/squall/ip_address_join_spec.rb +1 -15
- data/spec/squall/ip_address_spec.rb +10 -35
- data/spec/squall/network_spec.rb +20 -31
- data/spec/squall/network_zone_spec.rb +2 -36
- data/spec/squall/payment_spec.rb +2 -21
- data/spec/squall/role_spec.rb +4 -16
- data/spec/squall/support/base_spec.rb +10 -16
- data/spec/squall/template_spec.rb +0 -4
- data/spec/squall/transaction_spec.rb +1 -3
- data/spec/squall/user_group_spec.rb +1 -17
- data/spec/squall/user_spec.rb +4 -92
- data/spec/squall/virtual_machine_spec.rb +8 -242
- data/spec/squall/whitelist_spec.rb +2 -40
- data/spec/squall_spec.rb +2 -2
- data/spec/vcr_cassettes/disk/add_schedule.yml +40 -0
- data/spec/vcr_cassettes/disk/auto_backup_off.yml +40 -0
- data/spec/vcr_cassettes/disk/auto_backup_on.yml +40 -0
- data/spec/vcr_cassettes/disk/backups.yml +40 -0
- data/spec/vcr_cassettes/disk/build.yml +40 -0
- data/spec/vcr_cassettes/disk/create.yml +40 -0
- data/spec/vcr_cassettes/disk/delete.yml +38 -0
- data/spec/vcr_cassettes/disk/edit.yml +40 -0
- data/spec/vcr_cassettes/disk/iops_usage.yml +40 -0
- data/spec/vcr_cassettes/disk/list.yml +40 -0
- data/spec/vcr_cassettes/disk/migrate.yml +38 -0
- data/spec/vcr_cassettes/disk/schedules.yml +40 -0
- data/spec/vcr_cassettes/disk/unlock.yml +40 -0
- data/spec/vcr_cassettes/disk/vm_disk_list.yml +40 -0
- data/spec/vcr_cassettes/network/rebuild.yml +41 -0
- metadata +217 -66
- data/.gitignore +0 -13
- data/.rspec +0 -2
- data/.rvmrc +0 -41
- data/.travis.yml +0 -17
- data/lib/squall/support/params.rb +0 -50
- data/lib/squall/support/yaml.rb +0 -5
- data/spec/squall/support/params_spec.rb +0 -195
- data/squall.gemspec +0 -32
data/lib/squall/network_zone.rb
CHANGED
@@ -1,71 +1,69 @@
|
|
1
1
|
module Squall
|
2
2
|
# OnApp NetworkZone
|
3
3
|
class NetworkZone < Base
|
4
|
-
#
|
4
|
+
# Public: Lists all network zones.
|
5
|
+
#
|
6
|
+
# Returns an Array.
|
5
7
|
def list
|
6
8
|
response = request(:get, "/network_zones.json")
|
7
9
|
response.collect { |i| i['network_group'] }
|
8
10
|
end
|
9
11
|
|
10
|
-
# Get the details for a network zone
|
12
|
+
# Public: Get the details for a network zone.
|
11
13
|
#
|
12
|
-
#
|
14
|
+
# id - ID of the network zone
|
13
15
|
#
|
14
|
-
#
|
16
|
+
# Returns a Hash.
|
15
17
|
def show(id)
|
16
18
|
response = request(:get, "/network_zones/#{id}.json")
|
17
19
|
response['network_group']
|
18
20
|
end
|
19
21
|
|
20
|
-
# Updates an existing network zone
|
21
|
-
#
|
22
|
-
# ==== Params
|
23
|
-
#
|
24
|
-
# * +id*+ - ID of the network zone
|
22
|
+
# Public: Updates an existing network zone.
|
25
23
|
#
|
26
|
-
#
|
24
|
+
# id - ID of the network zone
|
25
|
+
# options - Options to update the network zone, see `#create`
|
27
26
|
#
|
28
|
-
#
|
27
|
+
# Returns a Hash.
|
29
28
|
def edit(id, options = {})
|
30
|
-
|
31
|
-
response = request(:put, "/network_zones/#{id}.json", :query => {:pack => options})
|
29
|
+
request(:put, "/network_zones/#{id}.json", query: { pack: options })
|
32
30
|
end
|
33
31
|
|
34
|
-
# Creates a new network zone
|
32
|
+
# Public: Creates a new network zone.
|
35
33
|
#
|
36
|
-
#
|
34
|
+
# options - Options for creating the new network zone:
|
35
|
+
# :label - Label for the network zone
|
37
36
|
#
|
38
|
-
#
|
37
|
+
# Returns a Hash.
|
39
38
|
def create(options = {})
|
40
|
-
|
41
|
-
response = request(:post, "/network_zones.json", :query => {:pack => options})
|
39
|
+
request(:post, "/network_zones.json", query: { pack: options })
|
42
40
|
end
|
43
41
|
|
44
|
-
# Deletes an existing network zone
|
42
|
+
# Public: Deletes an existing network zone.
|
45
43
|
#
|
46
|
-
#
|
44
|
+
# id - ID of the network zone
|
47
45
|
#
|
48
|
-
#
|
46
|
+
# Returns a Hash.
|
49
47
|
def delete(id)
|
50
48
|
request(:delete, "/network_zones/#{id}.json")
|
51
49
|
end
|
52
50
|
|
53
|
-
# Attach a network to a network zone
|
51
|
+
# Public: Attach a network to a network zone.
|
54
52
|
#
|
55
|
-
#
|
53
|
+
# id - ID of the network zone
|
54
|
+
# network_id - ID of the network
|
56
55
|
#
|
57
|
-
#
|
58
|
-
# * +network_id+ - ID of the network
|
56
|
+
# Returns a Hash.
|
59
57
|
def attach(id, network_id)
|
60
58
|
request(:post, "/network_zones/#{id}/networks/#{network_id}/attach.json")
|
61
59
|
end
|
62
60
|
|
63
|
-
# Detach a network from a network zone
|
61
|
+
# Public: Detach a network from a network zone.
|
64
62
|
#
|
65
|
-
#
|
63
|
+
# id - ID of the network zone
|
64
|
+
# network_id - ID of the network
|
66
65
|
#
|
67
|
-
#
|
68
|
-
# * +network_id+ - ID of the network
|
66
|
+
# Returns a Hash.
|
69
67
|
def detach(id, network_id)
|
70
68
|
request(:post, "/network_zones/#{id}/networks/#{network_id}/detach.json")
|
71
69
|
end
|
data/lib/squall/payment.rb
CHANGED
@@ -1,59 +1,49 @@
|
|
1
1
|
module Squall
|
2
2
|
# OnApp Payment
|
3
3
|
class Payment < Base
|
4
|
-
|
5
|
-
#
|
4
|
+
# Public: Lists all payments.
|
5
|
+
#
|
6
|
+
# Returns an Array.
|
6
7
|
def list(user_id)
|
7
8
|
response = request(:get, "/users/#{user_id}/payments.json")
|
8
9
|
response.collect { |user| user['payment'] }
|
9
10
|
end
|
10
11
|
|
11
|
-
# Create a payment for a user
|
12
|
-
#
|
13
|
-
# ==== Params
|
14
|
-
#
|
15
|
-
# * +user_id*+ - ID of the user
|
16
|
-
# * +options+ - Params for creating the User
|
12
|
+
# Public: Create a payment for a user.
|
17
13
|
#
|
18
|
-
#
|
14
|
+
# user_id - ID of the user
|
15
|
+
# options - Params for creating the User:
|
16
|
+
# :amount - Amount of the payment
|
17
|
+
# :invoice_number - Number of the invoice
|
19
18
|
#
|
20
|
-
#
|
21
|
-
# * +invoice_number+ - Number of the invoice
|
19
|
+
# Example
|
22
20
|
#
|
23
|
-
#
|
21
|
+
# create amount: 500, invoice_number: "01234"
|
24
22
|
#
|
25
|
-
#
|
26
|
-
|
27
|
-
def create(user_id, options={})
|
28
|
-
params.required(:amount).accepts(:invoice_number).validate!(options)
|
23
|
+
# Returns a Hash.
|
24
|
+
def create(user_id, options = {})
|
29
25
|
request(:post, "/users/#{user_id}/payments.json", default_params(options))
|
30
26
|
end
|
31
27
|
|
32
|
-
# Edit a payment
|
28
|
+
# Public: Edit a payment
|
33
29
|
#
|
34
|
-
#
|
30
|
+
# user_id - ID of the user
|
31
|
+
# id - ID of the payment
|
32
|
+
# options - Params for editing the payment, see `#create`
|
35
33
|
#
|
36
|
-
#
|
37
|
-
|
38
|
-
# * +options+ - Params for editing the payment
|
39
|
-
#
|
40
|
-
# ==== Options
|
41
|
-
#
|
42
|
-
# See #create
|
43
|
-
def edit(user_id, id, options={})
|
44
|
-
params.accepts(:amount, :invoice_number).validate!(options)
|
34
|
+
# Returns a Hash.
|
35
|
+
def edit(user_id, id, options = {})
|
45
36
|
request(:put, "/users/#{user_id}/payments/#{id}.json", default_params(options))
|
46
37
|
end
|
47
38
|
|
48
|
-
# Delete a payment
|
39
|
+
# Public: Delete a payment
|
49
40
|
#
|
50
|
-
#
|
41
|
+
# user_id - ID of the user
|
42
|
+
# id - ID of the payment
|
51
43
|
#
|
52
|
-
#
|
53
|
-
# * +id*+ - ID of the payment
|
44
|
+
# Returns a Hash.
|
54
45
|
def delete(user_id, id)
|
55
46
|
request(:delete, "/users/#{user_id}/payments/#{id}.json")
|
56
47
|
end
|
57
|
-
|
58
48
|
end
|
59
49
|
end
|
data/lib/squall/role.rb
CHANGED
@@ -1,73 +1,66 @@
|
|
1
1
|
module Squall
|
2
2
|
# OnApp Role
|
3
3
|
class Role < Base
|
4
|
-
#
|
4
|
+
# Public: Lists all roles.
|
5
|
+
#
|
6
|
+
# Returns an Array.
|
5
7
|
def list
|
6
8
|
response = request(:get, '/roles.json')
|
7
9
|
response.collect { |role| role['role']}
|
8
10
|
end
|
9
11
|
|
10
|
-
#
|
12
|
+
# Public: Show info for the given role.
|
11
13
|
#
|
12
|
-
#
|
14
|
+
# id - ID of the role
|
13
15
|
#
|
14
|
-
#
|
16
|
+
# Returns a Hash.
|
15
17
|
def show(id)
|
16
18
|
response = request(:get, "/roles/#{id}.json")
|
17
19
|
response["role"]
|
18
20
|
end
|
19
21
|
|
20
|
-
#
|
22
|
+
# Public: Create a new Role
|
23
|
+
#
|
24
|
+
# options - Params for creating the roles:
|
25
|
+
# :label - Label for the role
|
26
|
+
# :permission_ids - An array of permission ids granted to the role.
|
21
27
|
#
|
22
|
-
#
|
28
|
+
# Example
|
23
29
|
#
|
24
|
-
#
|
25
|
-
|
30
|
+
# create label: 'Admin'
|
31
|
+
def create(options = {})
|
32
|
+
request(:post, '/roles.json', default_params(options))
|
33
|
+
end
|
34
|
+
|
35
|
+
# Public: Edit a Role.
|
26
36
|
#
|
27
|
-
#
|
37
|
+
# id - ID of the role
|
38
|
+
# options - Params for editing the roles, see `#create`
|
28
39
|
#
|
29
|
-
#
|
40
|
+
# Example
|
30
41
|
#
|
31
|
-
#
|
42
|
+
# edit 1, label: 'myrole', permission_ids: [1, 3]
|
32
43
|
#
|
33
|
-
#
|
44
|
+
# Returns a Hash.
|
34
45
|
def edit(id, options = {})
|
35
|
-
|
36
|
-
response = request(:put, "/roles/#{id}.json", default_params(options))
|
46
|
+
request(:put, "/roles/#{id}.json", default_params(options))
|
37
47
|
end
|
38
48
|
|
39
|
-
# Delete a Role
|
49
|
+
# Public: Delete a Role.
|
40
50
|
#
|
41
|
-
#
|
51
|
+
# id - ID of the role
|
42
52
|
#
|
43
|
-
#
|
53
|
+
# Returns a Hash.
|
44
54
|
def delete(id)
|
45
55
|
request(:delete, "/roles/#{id}.json")
|
46
56
|
end
|
47
57
|
|
48
|
-
#
|
58
|
+
# Public: Lists all permissions available.
|
59
|
+
#
|
60
|
+
# Returns an Array.
|
49
61
|
def permissions
|
50
62
|
response = request(:get, '/permissions.json')
|
51
63
|
response.collect { |perm| perm['permission'] }
|
52
64
|
end
|
53
|
-
|
54
|
-
# Create a new Role
|
55
|
-
#
|
56
|
-
# ==== Params
|
57
|
-
#
|
58
|
-
# * +options+ - Params for creating the roles
|
59
|
-
#
|
60
|
-
# ==== Options
|
61
|
-
#
|
62
|
-
# * +label*+ - Label for the role
|
63
|
-
# * +permission_ids+ - An array of permission ids granted to the role.
|
64
|
-
#
|
65
|
-
# ==== Example
|
66
|
-
#
|
67
|
-
# create :label => 'Admin'
|
68
|
-
def create(options = {})
|
69
|
-
params.required(:label).accepts(:permission_ids).validate!(options)
|
70
|
-
response = request(:post, '/roles.json', default_params(options))
|
71
|
-
end
|
72
65
|
end
|
73
66
|
end
|
data/lib/squall/statistic.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
module Squall
|
2
2
|
# OnApp Statistic
|
3
3
|
class Statistic < Base
|
4
|
-
#
|
4
|
+
# Public: Get usage statistics for virtual machines.
|
5
|
+
#
|
6
|
+
# Returns an Array.
|
5
7
|
def daily_stats
|
6
8
|
response = request(:get, "/usage_statistics.json")
|
7
9
|
response.collect {|s| s["vm_stat"]}
|
data/lib/squall/support/base.rb
CHANGED
@@ -1,49 +1,46 @@
|
|
1
1
|
module Squall
|
2
|
-
# All OnApp API classes subclass Base to get access to
|
3
|
-
#
|
2
|
+
# All OnApp API classes subclass Base to get access to HTTP methods and
|
3
|
+
# other convenience methods.
|
4
4
|
class Base
|
5
|
-
#
|
6
|
-
attr_reader :params
|
7
|
-
|
8
|
-
# Returns true/false for successful/unsuccessful requests
|
5
|
+
# Public: Returns true/false for successful/unsuccessful requests
|
9
6
|
attr_reader :success
|
10
7
|
|
11
|
-
#
|
8
|
+
# Public: Faraday response body
|
12
9
|
attr_reader :result
|
13
10
|
|
14
|
-
#
|
15
|
-
def params
|
16
|
-
@params = Squall::Params.new
|
17
|
-
end
|
18
|
-
|
19
|
-
# Sets the default URL params for requests and merges +options+
|
11
|
+
# Public: Sets the default URL params for requests and merges `options`
|
20
12
|
#
|
21
|
-
#
|
13
|
+
# *options - One or more options
|
22
14
|
#
|
23
|
-
#
|
15
|
+
# Example
|
24
16
|
#
|
25
|
-
#
|
17
|
+
# default_params(something: 1)
|
26
18
|
#
|
27
|
-
#
|
19
|
+
# Returns a Hash.
|
28
20
|
def default_params(*options)
|
29
|
-
options.empty? ? {} : {:
|
21
|
+
options.empty? ? {} : { query: { key_for_class => options.first } }
|
30
22
|
end
|
31
23
|
|
32
|
-
#
|
24
|
+
# Public: Performs an HTTP Request
|
25
|
+
#
|
26
|
+
# request_method - The HTTP verb for the request, one of
|
27
|
+
# :get/:post/:delete/:put, etc
|
28
|
+
# path - URL path
|
29
|
+
# options - HTTP query params
|
33
30
|
#
|
34
|
-
#
|
35
|
-
# * +request_method+ - The HTTP verb for the #request. (:get/:post/:delete etc)
|
36
|
-
# * +path+ - URL path
|
37
|
-
# * +options+ - HTTP query params
|
31
|
+
# Example
|
38
32
|
#
|
39
|
-
#
|
33
|
+
# # GET /something.json
|
34
|
+
# request :get, '/something.json'
|
40
35
|
#
|
41
|
-
#
|
42
|
-
# request :put, '/something.json', :
|
36
|
+
# # PUT /something.json?something=1
|
37
|
+
# request :put, '/something.json', something: 1
|
38
|
+
#
|
39
|
+
# Returns the JSON response.
|
43
40
|
def request(request_method, path, options = {})
|
44
41
|
check_config
|
45
42
|
|
46
|
-
conn = Faraday.new(:
|
43
|
+
conn = Faraday.new(url: Squall.config[:base_uri]) do |c|
|
47
44
|
c.basic_auth Squall.config[:username], Squall.config[:password]
|
48
45
|
c.params = (options[:query] || {})
|
49
46
|
c.request :url_encoded
|
@@ -60,14 +57,21 @@ module Squall
|
|
60
57
|
@result = response.body
|
61
58
|
end
|
62
59
|
|
63
|
-
#
|
60
|
+
# Public: Ensures `Squall.config` is set.
|
61
|
+
#
|
62
|
+
# Raises Squall::NoConfig if a request is made without first calling
|
63
|
+
# Squall.config.
|
64
|
+
#
|
65
|
+
# Returns nothing.
|
64
66
|
def check_config
|
65
67
|
raise NoConfig, "Squall.config must be specified" if Squall.config.empty?
|
66
68
|
end
|
67
69
|
|
68
|
-
# Sets the default param container for request. It is derived from
|
69
|
-
# class name. Given the class name
|
70
|
-
# resulting params would be
|
70
|
+
# Public: Sets the default param container for request. It is derived from
|
71
|
+
# the class name. Given the class name `Sandwich` and a param `bread` the
|
72
|
+
# resulting params would be `bob[bread]=wheat`.
|
73
|
+
#
|
74
|
+
# Returns a String
|
71
75
|
def key_for_class
|
72
76
|
word = self.class.name.split("::").last.to_s.dup
|
73
77
|
word.gsub!(/::/, '/')
|
@@ -1,28 +1,52 @@
|
|
1
1
|
module Squall
|
2
2
|
# Holds the configuration for Squall
|
3
3
|
class Config
|
4
|
+
# Public: A Hash that stores configuration info.
|
4
5
|
attr_accessor :config
|
5
6
|
|
6
7
|
def initialize
|
7
8
|
@config = {}
|
8
9
|
end
|
9
10
|
|
11
|
+
# Public: Hash accessor, delegates to `@config`.
|
12
|
+
#
|
13
|
+
# Returns the value from `@config`.
|
10
14
|
def [](v)
|
11
15
|
@config[v]
|
12
16
|
end
|
13
17
|
|
18
|
+
# Public: Sets the URL of your OnApp instance.
|
19
|
+
#
|
20
|
+
# value - The String URL
|
21
|
+
#
|
22
|
+
# Returns value.
|
14
23
|
def base_uri(value)
|
15
|
-
@config[:base_uri]
|
24
|
+
@config[:base_uri] = value
|
16
25
|
end
|
17
26
|
|
27
|
+
# Public: Sets the API username.
|
28
|
+
#
|
29
|
+
# value - The String username
|
30
|
+
#
|
31
|
+
# Returns value.
|
18
32
|
def username(value)
|
19
33
|
@config[:username] = value
|
20
34
|
end
|
21
35
|
|
36
|
+
# Public: Sets the API Password>
|
37
|
+
#
|
38
|
+
# value - The String password
|
39
|
+
#
|
40
|
+
# Returns value.
|
22
41
|
def password(value)
|
23
42
|
@config[:password] = value
|
24
43
|
end
|
25
44
|
|
45
|
+
# Public: Set to true to enable HTTP logging.
|
46
|
+
#
|
47
|
+
# value - A Boolean
|
48
|
+
#
|
49
|
+
# Returns value.
|
26
50
|
def debug(value)
|
27
51
|
@config[:debug] = value
|
28
52
|
end
|
data/lib/squall/template.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
module Squall
|
2
2
|
# OnApp Template
|
3
3
|
class Template < Base
|
4
|
-
#
|
4
|
+
# Public: Lists available templates.
|
5
|
+
#
|
6
|
+
# Returns an Array.
|
5
7
|
def list
|
6
8
|
response = request(:get, '/templates.json')
|
7
9
|
response.collect { |temp| temp['image_template'] }
|
8
10
|
end
|
9
11
|
|
10
|
-
# Make a Template public so that it can be downloaded
|
11
|
-
#
|
12
|
+
# Public: Make a Template public so that it can be downloaded via a HTTP
|
13
|
+
# URL.
|
12
14
|
#
|
13
|
-
#
|
15
|
+
# id - ID of template
|
14
16
|
#
|
15
|
-
#
|
17
|
+
# Returns a Hash.
|
16
18
|
def make_public(id)
|
17
19
|
response = request(:post, "/templates/#{id}/make_public.json")
|
18
20
|
response.first[1]
|
data/lib/squall/transaction.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
module Squall
|
2
2
|
# OnApp Transaction
|
3
3
|
class Transaction < Base
|
4
|
-
#
|
4
|
+
# Public: Lists all transactions.
|
5
|
+
#
|
6
|
+
# Returns an Array.
|
5
7
|
def list
|
6
8
|
response = request :get, '/transactions.json'
|
7
9
|
response.collect { |t| t['transaction'] }
|
8
10
|
end
|
9
11
|
|
10
|
-
#
|
12
|
+
# Public: Get info for the given transaction.
|
11
13
|
#
|
12
|
-
#
|
14
|
+
# id - ID of transaction
|
13
15
|
#
|
14
|
-
#
|
16
|
+
# Returns a Hash.
|
15
17
|
def show(id)
|
16
18
|
response = request :get, "/transactions/#{id}.json"
|
17
19
|
response['transaction']
|