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.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -1
  3. data/README.md +64 -41
  4. data/Rakefile +3 -9
  5. data/lib/squall/data_store_zone.rb +20 -26
  6. data/lib/squall/disk.rb +174 -0
  7. data/lib/squall/firewall_rule.rb +34 -41
  8. data/lib/squall/hypervisor.rb +40 -38
  9. data/lib/squall/hypervisor_zone.rb +51 -63
  10. data/lib/squall/ip_address.rb +32 -37
  11. data/lib/squall/ip_address_join.rb +13 -22
  12. data/lib/squall/network.rb +36 -33
  13. data/lib/squall/network_zone.rb +27 -29
  14. data/lib/squall/payment.rb +22 -32
  15. data/lib/squall/role.rb +30 -37
  16. data/lib/squall/statistic.rb +3 -1
  17. data/lib/squall/support/base.rb +35 -31
  18. data/lib/squall/support/config.rb +25 -1
  19. data/lib/squall/support/version.rb +1 -1
  20. data/lib/squall/template.rb +7 -5
  21. data/lib/squall/transaction.rb +6 -4
  22. data/lib/squall/user.rb +84 -83
  23. data/lib/squall/user_group.rb +17 -30
  24. data/lib/squall/virtual_machine.rb +154 -178
  25. data/lib/squall/whitelist.rb +29 -40
  26. data/lib/squall.rb +27 -25
  27. data/spec/spec_helper.rb +6 -11
  28. data/spec/squall/data_store_zone_spec.rb +2 -20
  29. data/spec/squall/disk_spec.rb +189 -0
  30. data/spec/squall/firewall_rule_spec.rb +2 -32
  31. data/spec/squall/hypervisor_spec.rb +3 -47
  32. data/spec/squall/hypervisor_zone_spec.rb +3 -28
  33. data/spec/squall/ip_address_join_spec.rb +1 -15
  34. data/spec/squall/ip_address_spec.rb +10 -35
  35. data/spec/squall/network_spec.rb +20 -31
  36. data/spec/squall/network_zone_spec.rb +2 -36
  37. data/spec/squall/payment_spec.rb +2 -21
  38. data/spec/squall/role_spec.rb +4 -16
  39. data/spec/squall/support/base_spec.rb +10 -16
  40. data/spec/squall/template_spec.rb +0 -4
  41. data/spec/squall/transaction_spec.rb +1 -3
  42. data/spec/squall/user_group_spec.rb +1 -17
  43. data/spec/squall/user_spec.rb +4 -92
  44. data/spec/squall/virtual_machine_spec.rb +8 -242
  45. data/spec/squall/whitelist_spec.rb +2 -40
  46. data/spec/squall_spec.rb +2 -2
  47. data/spec/vcr_cassettes/disk/add_schedule.yml +40 -0
  48. data/spec/vcr_cassettes/disk/auto_backup_off.yml +40 -0
  49. data/spec/vcr_cassettes/disk/auto_backup_on.yml +40 -0
  50. data/spec/vcr_cassettes/disk/backups.yml +40 -0
  51. data/spec/vcr_cassettes/disk/build.yml +40 -0
  52. data/spec/vcr_cassettes/disk/create.yml +40 -0
  53. data/spec/vcr_cassettes/disk/delete.yml +38 -0
  54. data/spec/vcr_cassettes/disk/edit.yml +40 -0
  55. data/spec/vcr_cassettes/disk/iops_usage.yml +40 -0
  56. data/spec/vcr_cassettes/disk/list.yml +40 -0
  57. data/spec/vcr_cassettes/disk/migrate.yml +38 -0
  58. data/spec/vcr_cassettes/disk/schedules.yml +40 -0
  59. data/spec/vcr_cassettes/disk/unlock.yml +40 -0
  60. data/spec/vcr_cassettes/disk/vm_disk_list.yml +40 -0
  61. data/spec/vcr_cassettes/network/rebuild.yml +41 -0
  62. metadata +217 -66
  63. data/.gitignore +0 -13
  64. data/.rspec +0 -2
  65. data/.rvmrc +0 -41
  66. data/.travis.yml +0 -17
  67. data/lib/squall/support/params.rb +0 -50
  68. data/lib/squall/support/yaml.rb +0 -5
  69. data/spec/squall/support/params_spec.rb +0 -195
  70. data/squall.gemspec +0 -32
@@ -1,71 +1,69 @@
1
1
  module Squall
2
2
  # OnApp NetworkZone
3
3
  class NetworkZone < Base
4
- # Returns a list of network zones
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
- # ==== Params
14
+ # id - ID of the network zone
13
15
  #
14
- # * +id*+ - ID of the network zone
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
- # ==== Options
24
+ # id - ID of the network zone
25
+ # options - Options to update the network zone, see `#create`
27
26
  #
28
- # See #create
27
+ # Returns a Hash.
29
28
  def edit(id, options = {})
30
- params.required(:label).validate!(options)
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
- # ==== Options
34
+ # options - Options for creating the new network zone:
35
+ # :label - Label for the network zone
37
36
  #
38
- # * +label*+ - Label for the network zone
37
+ # Returns a Hash.
39
38
  def create(options = {})
40
- params.required(:label).validate!(options)
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
- # ==== Params
44
+ # id - ID of the network zone
47
45
  #
48
- # * +id*+ - ID of the network zone
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
- # ==== Params
53
+ # id - ID of the network zone
54
+ # network_id - ID of the network
56
55
  #
57
- # * +id*+ - ID of the network zone
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
- # ==== Params
63
+ # id - ID of the network zone
64
+ # network_id - ID of the network
66
65
  #
67
- # * +id*+ - ID of the network zone
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
@@ -1,59 +1,49 @@
1
1
  module Squall
2
2
  # OnApp Payment
3
3
  class Payment < Base
4
-
5
- # Return a list of all payments
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
- # ==== Options
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
- # * +amount*+ - Amount of the payment
21
- # * +invoice_number+ - Number of the invoice
19
+ # Example
22
20
  #
23
- # ==== Example
21
+ # create amount: 500, invoice_number: "01234"
24
22
  #
25
- # create :amount => 500,
26
- # :invoice_number => "01234",
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
- # ==== Params
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
- # * +user_id*+ - ID of the user
37
- # * +id*+ - ID of the payment
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
- # ==== Params
41
+ # user_id - ID of the user
42
+ # id - ID of the payment
51
43
  #
52
- # * +user_id*+ - ID of the user
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
- # Return a list of roles
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
- # Returns a Hash of the given roles
12
+ # Public: Show info for the given role.
11
13
  #
12
- # ==== Params
14
+ # id - ID of the role
13
15
  #
14
- # * +id*+ - ID of the role
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
- # Edit a Role
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
- # ==== Params
28
+ # Example
23
29
  #
24
- # * +id*+ - ID of the role
25
- # * +options+ - Params for editing the roles
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
- # ==== Options
37
+ # id - ID of the role
38
+ # options - Params for editing the roles, see `#create`
28
39
  #
29
- # See #create
40
+ # Example
30
41
  #
31
- # ==== Example
42
+ # edit 1, label: 'myrole', permission_ids: [1, 3]
32
43
  #
33
- # edit 1, :label => 'myrole', :permission_ids => [1,3]
44
+ # Returns a Hash.
34
45
  def edit(id, options = {})
35
- params.accepts(:label, :permission_ids).validate!(options)
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
- # ==== Params
51
+ # id - ID of the role
42
52
  #
43
- # * +id*+ - ID of the role
53
+ # Returns a Hash.
44
54
  def delete(id)
45
55
  request(:delete, "/roles/#{id}.json")
46
56
  end
47
57
 
48
- # Returns a list of permissions available
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
@@ -1,7 +1,9 @@
1
1
  module Squall
2
2
  # OnApp Statistic
3
3
  class Statistic < Base
4
- # Returns statitics for virtual machines
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"]}
@@ -1,49 +1,46 @@
1
1
  module Squall
2
- # All OnApp API classes subclass Base to get access to
3
- # HTTParty methods and other convenience methods
2
+ # All OnApp API classes subclass Base to get access to HTTP methods and
3
+ # other convenience methods.
4
4
  class Base
5
- # Params instance
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
- # HTTPart request result
8
+ # Public: Faraday response body
12
9
  attr_reader :result
13
10
 
14
- # Returns a Params.new
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
- # ==== Options
13
+ # *options - One or more options
22
14
  #
23
- # * +options+
15
+ # Example
24
16
  #
25
- # ==== Example
17
+ # default_params(something: 1)
26
18
  #
27
- # default_params(:something => 1)
19
+ # Returns a Hash.
28
20
  def default_params(*options)
29
- options.empty? ? {} : {:query => { key_for_class => options.first}}
21
+ options.empty? ? {} : { query: { key_for_class => options.first } }
30
22
  end
31
23
 
32
- # Peforms an HTTP Request
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
- # ==== Options
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
- # ==== Example
33
+ # # GET /something.json
34
+ # request :get, '/something.json'
40
35
  #
41
- # request :get, '/something.json' # GET /seomthing.json
42
- # request :put, '/something.json', :something => 1 # PUT /something.json?something=1
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(:url => Squall.config[:base_uri]) do |c|
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
- # Raises an error if a request is made without first calling Squall.config
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 the
69
- # class name. Given the class name *Sandwich* and a param *bread* the
70
- # resulting params would be 'bob[bread]=wheat'
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] = value
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
@@ -1,3 +1,3 @@
1
1
  module Squall
2
- VERSION = '1.3.0'
2
+ VERSION = '1.3.1'
3
3
  end
@@ -1,18 +1,20 @@
1
1
  module Squall
2
2
  # OnApp Template
3
3
  class Template < Base
4
- # Return a list of available Templates
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
- # via a HTTP url
12
+ # Public: Make a Template public so that it can be downloaded via a HTTP
13
+ # URL.
12
14
  #
13
- # ==== Params
15
+ # id - ID of template
14
16
  #
15
- # * +id*+ - ID of template
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]
@@ -1,17 +1,19 @@
1
1
  module Squall
2
2
  # OnApp Transaction
3
3
  class Transaction < Base
4
- # Returns a list of all Transactions.
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
- # Return a Hash for the given Transaction
12
+ # Public: Get info for the given transaction.
11
13
  #
12
- # ==== Params
14
+ # id - ID of transaction
13
15
  #
14
- # * +id*+ - ID of transaction
16
+ # Returns a Hash.
15
17
  def show(id)
16
18
  response = request :get, "/transactions/#{id}.json"
17
19
  response['transaction']