squall 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. data/.gitignore +3 -0
  2. data/.rbenv-version +1 -0
  3. data/.rspec +1 -1
  4. data/.rvmrc +41 -1
  5. data/.travis.yml +13 -3
  6. data/README.md +122 -27
  7. data/Rakefile +5 -34
  8. data/lib/squall/data_store_zone.rb +58 -0
  9. data/lib/squall/firewall_rule.rb +66 -0
  10. data/lib/squall/hypervisor.rb +63 -11
  11. data/lib/squall/hypervisor_zone.rb +135 -0
  12. data/lib/squall/ip_address.rb +50 -3
  13. data/lib/squall/ip_address_join.rb +46 -0
  14. data/lib/squall/network.rb +21 -4
  15. data/lib/squall/network_zone.rb +73 -0
  16. data/lib/squall/payment.rb +59 -0
  17. data/lib/squall/role.rb +28 -11
  18. data/lib/squall/statistic.rb +3 -3
  19. data/lib/squall/{base.rb → support/base.rb} +8 -4
  20. data/lib/squall/{config.rb → support/config.rb} +4 -0
  21. data/lib/squall/{exception.rb → support/exception.rb} +0 -0
  22. data/lib/squall/{params.rb → support/params.rb} +0 -0
  23. data/lib/squall/support/version.rb +3 -0
  24. data/lib/squall/support/yaml.rb +5 -0
  25. data/lib/squall/template.rb +4 -0
  26. data/lib/squall/transaction.rb +4 -0
  27. data/lib/squall/user.rb +126 -30
  28. data/lib/squall/user_group.rb +56 -0
  29. data/lib/squall/virtual_machine.rb +176 -52
  30. data/lib/squall/whitelist.rb +74 -0
  31. data/lib/squall.rb +21 -12
  32. data/spec/spec_helper.rb +21 -16
  33. data/spec/squall/data_store_zone_spec.rb +97 -0
  34. data/spec/squall/firewall_rule_spec.rb +112 -0
  35. data/spec/squall/hypervisor_spec.rb +101 -48
  36. data/spec/squall/hypervisor_zone_spec.rb +190 -0
  37. data/spec/squall/ip_address_join_spec.rb +67 -0
  38. data/spec/squall/ip_address_spec.rb +68 -6
  39. data/spec/squall/network_spec.rb +0 -1
  40. data/spec/squall/network_zone_spec.rb +147 -0
  41. data/spec/squall/payment_spec.rb +98 -0
  42. data/spec/squall/role_spec.rb +31 -46
  43. data/spec/squall/statistic_spec.rb +7 -9
  44. data/spec/squall/{base_spec.rb → support/base_spec.rb} +5 -7
  45. data/spec/squall/{config_spec.rb → support/config_spec.rb} +0 -0
  46. data/spec/{params_spec.rb → squall/support/params_spec.rb} +0 -0
  47. data/spec/squall/template_spec.rb +0 -1
  48. data/spec/squall/transaction_spec.rb +0 -1
  49. data/spec/squall/user_group_spec.rb +74 -0
  50. data/spec/squall/user_spec.rb +142 -59
  51. data/spec/squall/virtual_machine_spec.rb +179 -67
  52. data/spec/squall/whitelist_spec.rb +113 -0
  53. data/spec/squall_spec.rb +4 -8
  54. data/spec/vcr_cassettes/data_store_zone/create.yml +40 -0
  55. data/spec/vcr_cassettes/data_store_zone/delete.yml +77 -0
  56. data/spec/vcr_cassettes/data_store_zone/edit.yml +77 -0
  57. data/spec/vcr_cassettes/data_store_zone/list.yml +40 -0
  58. data/spec/vcr_cassettes/data_store_zone/show.yml +77 -0
  59. data/spec/vcr_cassettes/firewall_rule/create.yml +75 -0
  60. data/spec/vcr_cassettes/firewall_rule/delete.yml +75 -0
  61. data/spec/vcr_cassettes/firewall_rule/edit.yml +75 -0
  62. data/spec/vcr_cassettes/firewall_rule/list.yml +40 -0
  63. data/spec/vcr_cassettes/hypervisor/add_data_store_join.yml +40 -0
  64. data/spec/vcr_cassettes/hypervisor/add_network_join.yml +40 -0
  65. data/spec/vcr_cassettes/hypervisor/create.yml +7 -44
  66. data/spec/vcr_cassettes/hypervisor/data_store_joins.yml +40 -0
  67. data/spec/vcr_cassettes/hypervisor/delete.yml +11 -11
  68. data/spec/vcr_cassettes/hypervisor/edit.yml +7 -46
  69. data/spec/vcr_cassettes/hypervisor/list.yml +7 -7
  70. data/spec/vcr_cassettes/hypervisor/network_joins.yml +40 -0
  71. data/spec/vcr_cassettes/hypervisor/reboot.yml +13 -13
  72. data/spec/vcr_cassettes/hypervisor/remove_data_store_join.yml +40 -0
  73. data/spec/vcr_cassettes/hypervisor/remove_network_join.yml +40 -0
  74. data/spec/vcr_cassettes/hypervisor/show.yml +13 -13
  75. data/spec/vcr_cassettes/hypervisor_zones/add_data_store_join.yml +40 -0
  76. data/spec/vcr_cassettes/hypervisor_zones/add_network_join.yml +40 -0
  77. data/spec/vcr_cassettes/hypervisor_zones/create.yml +40 -0
  78. data/spec/vcr_cassettes/hypervisor_zones/data_store_joins.yml +40 -0
  79. data/spec/vcr_cassettes/hypervisor_zones/delete.yml +77 -0
  80. data/spec/vcr_cassettes/hypervisor_zones/edit.yml +77 -0
  81. data/spec/vcr_cassettes/hypervisor_zones/hypervisors.yml +40 -0
  82. data/spec/vcr_cassettes/hypervisor_zones/list.yml +40 -0
  83. data/spec/vcr_cassettes/hypervisor_zones/network_joins.yml +40 -0
  84. data/spec/vcr_cassettes/hypervisor_zones/remove_data_store_join.yml +40 -0
  85. data/spec/vcr_cassettes/hypervisor_zones/remove_network_join.yml +40 -0
  86. data/spec/vcr_cassettes/hypervisor_zones/show.yml +77 -0
  87. data/spec/vcr_cassettes/ipaddress/create.yml +40 -0
  88. data/spec/vcr_cassettes/ipaddress/delete.yml +40 -0
  89. data/spec/vcr_cassettes/ipaddress/edit.yml +40 -0
  90. data/spec/vcr_cassettes/ipaddress/list.yml +17 -17
  91. data/spec/vcr_cassettes/ipaddress_join/assign.yml +77 -0
  92. data/spec/vcr_cassettes/ipaddress_join/delete.yml +77 -0
  93. data/spec/vcr_cassettes/ipaddress_join/list.yml +77 -0
  94. data/spec/vcr_cassettes/network/create.yml +15 -15
  95. data/spec/vcr_cassettes/network/delete.yml +6 -6
  96. data/spec/vcr_cassettes/network/edit.yml +18 -18
  97. data/spec/vcr_cassettes/network/list.yml +3 -3
  98. data/spec/vcr_cassettes/network_zones/attach.yml +114 -0
  99. data/spec/vcr_cassettes/network_zones/create.yml +40 -0
  100. data/spec/vcr_cassettes/network_zones/delete.yml +77 -0
  101. data/spec/vcr_cassettes/network_zones/detach.yml +114 -0
  102. data/spec/vcr_cassettes/network_zones/edit.yml +77 -0
  103. data/spec/vcr_cassettes/network_zones/list.yml +40 -0
  104. data/spec/vcr_cassettes/network_zones/show.yml +77 -0
  105. data/spec/vcr_cassettes/payment/create.yml +78 -0
  106. data/spec/vcr_cassettes/payment/delete.yml +77 -0
  107. data/spec/vcr_cassettes/payment/edit.yml +77 -0
  108. data/spec/vcr_cassettes/payment/list.yml +41 -0
  109. data/spec/vcr_cassettes/role/create.yml +7 -44
  110. data/spec/vcr_cassettes/role/delete.yml +6 -6
  111. data/spec/vcr_cassettes/role/edit.yml +13 -75
  112. data/spec/vcr_cassettes/role/list.yml +7 -7
  113. data/spec/vcr_cassettes/role/permissions.yml +7 -7
  114. data/spec/vcr_cassettes/role/show.yml +13 -13
  115. data/spec/vcr_cassettes/statistic/usage_statistics.yml +7 -7
  116. data/spec/vcr_cassettes/template/list.yml +3 -3
  117. data/spec/vcr_cassettes/template/make_public.yml +6 -6
  118. data/spec/vcr_cassettes/transaction/list.yml +3 -3
  119. data/spec/vcr_cassettes/transaction/show.yml +6 -6
  120. data/spec/vcr_cassettes/user/activate.yml +7 -7
  121. data/spec/vcr_cassettes/user/create.yml +7 -83
  122. data/spec/vcr_cassettes/user/data_store_zones.yml +79 -0
  123. data/spec/vcr_cassettes/user/delete.yml +11 -11
  124. data/spec/vcr_cassettes/user/edit.yml +40 -0
  125. data/spec/vcr_cassettes/user/edit_role.yml +9 -9
  126. data/spec/vcr_cassettes/user/generate_api_key.yml +7 -7
  127. data/spec/vcr_cassettes/user/hypervisors.yml +77 -0
  128. data/spec/vcr_cassettes/user/limits.yml +77 -0
  129. data/spec/vcr_cassettes/user/list.yml +8 -8
  130. data/spec/vcr_cassettes/user/monthly_bills.yml +40 -0
  131. data/spec/vcr_cassettes/user/network_zones.yml +79 -0
  132. data/spec/vcr_cassettes/user/show.yml +29 -29
  133. data/spec/vcr_cassettes/user/stats.yml +6 -6
  134. data/spec/vcr_cassettes/user/suspend.yml +7 -7
  135. data/spec/vcr_cassettes/user/virtual_machines.yml +18 -20
  136. data/spec/vcr_cassettes/user_group/create.yml +40 -0
  137. data/spec/vcr_cassettes/user_group/delete.yml +77 -0
  138. data/spec/vcr_cassettes/user_group/edit.yml +77 -0
  139. data/spec/vcr_cassettes/user_group/list.yml +40 -0
  140. data/spec/vcr_cassettes/virtual_machine/build.yml +7 -7
  141. data/spec/vcr_cassettes/virtual_machine/change_owner.yml +8 -8
  142. data/spec/vcr_cassettes/virtual_machine/change_password.yml +13 -13
  143. data/spec/vcr_cassettes/virtual_machine/console.yml +63 -0
  144. data/spec/vcr_cassettes/virtual_machine/create.yml +9 -11
  145. data/spec/vcr_cassettes/virtual_machine/delete.yml +11 -11
  146. data/spec/vcr_cassettes/virtual_machine/edit.yml +16 -18
  147. data/spec/vcr_cassettes/virtual_machine/list.yml +3 -3
  148. data/spec/vcr_cassettes/virtual_machine/migrate.yml +22 -24
  149. data/spec/vcr_cassettes/virtual_machine/reboot.yml +22 -22
  150. data/spec/vcr_cassettes/virtual_machine/resize.yml +13 -13
  151. data/spec/vcr_cassettes/virtual_machine/segregate.yml +114 -0
  152. data/spec/vcr_cassettes/virtual_machine/set_ssh_keys.yml +77 -0
  153. data/spec/vcr_cassettes/virtual_machine/set_vip.yml +77 -0
  154. data/spec/vcr_cassettes/virtual_machine/show.yml +6 -6
  155. data/spec/vcr_cassettes/virtual_machine/shutdown.yml +6 -6
  156. data/spec/vcr_cassettes/virtual_machine/startup.yml +6 -6
  157. data/spec/vcr_cassettes/virtual_machine/stats.yml +63 -0
  158. data/spec/vcr_cassettes/virtual_machine/stop.yml +22 -22
  159. data/spec/vcr_cassettes/virtual_machine/suspend.yml +13 -13
  160. data/spec/vcr_cassettes/virtual_machine/unlock.yml +13 -13
  161. data/spec/vcr_cassettes/virtual_machine/unsuspend.yml +6 -6
  162. data/spec/vcr_cassettes/whitelist/create.yml +77 -0
  163. data/spec/vcr_cassettes/whitelist/delete.yml +77 -0
  164. data/spec/vcr_cassettes/whitelist/edit.yml +77 -0
  165. data/spec/vcr_cassettes/whitelist/list.yml +40 -0
  166. data/spec/vcr_cassettes/whitelist/show.yml +77 -0
  167. data/squall.gemspec +3 -2
  168. metadata +247 -131
  169. data/Gemfile.lock +0 -100
  170. data/lib/squall/version.rb +0 -3
data/lib/squall.rb CHANGED
@@ -1,40 +1,51 @@
1
1
  require 'httparty'
2
2
 
3
- require 'squall/version'
4
- require 'squall/exception'
3
+ require 'squall/support/version'
4
+ require 'squall/support/exception'
5
+ require 'squall/support/yaml'
5
6
 
6
7
  module Squall
7
- autoload :Params, 'squall/params'
8
+ # Support
9
+ autoload :Params, 'squall/support/params'
10
+ autoload :Config, 'squall/support/config'
11
+ autoload :Base, 'squall/support/base'
12
+ # Api
8
13
  autoload :Hypervisor, 'squall/hypervisor'
9
- autoload :Config, 'squall/config'
10
- autoload :Base, 'squall/base'
11
14
  autoload :User, 'squall/user'
12
15
  autoload :Role, 'squall/role'
13
16
  autoload :Network, 'squall/network'
14
17
  autoload :IpAddress, 'squall/ip_address'
18
+ autoload :IpAddressJoin, 'squall/ip_address_join'
15
19
  autoload :Template, 'squall/template'
16
20
  autoload :VirtualMachine, 'squall/virtual_machine'
17
21
  autoload :Statistic, 'squall/statistic'
18
22
  autoload :Transaction, 'squall/transaction'
23
+ autoload :Payment, 'squall/payment'
24
+ autoload :UserGroup, 'squall/user_group'
25
+ autoload :Whitelist, 'squall/whitelist'
26
+ autoload :FirewallRule, 'squall/firewall_rule'
27
+ autoload :DataStoreZone, 'squall/data_store_zone'
28
+ autoload :NetworkZone, 'squall/network_zone'
29
+ autoload :HypervisorZone, 'squall/hypervisor_zone'
19
30
 
20
31
  extend self
21
32
 
22
33
  # Config
23
34
  attr_accessor :configuration
24
35
 
25
- # Config
36
+ # Config
26
37
  attr_accessor :configuration_file
27
38
 
28
- # The path to your squall.yml
29
39
  self.configuration ||= Squall::Config.new
30
40
 
31
41
  # Specificy the config via block
32
- #
42
+ #
33
43
  # ==== Attributes
34
44
  #
35
45
  # * +base_uri+ - URL of your OnApp instance
36
46
  # * +username+ - API username
37
47
  # * +password+ - API Password
48
+ # * +debug+ - Toggle debug mode to log HTTParty
38
49
  #
39
50
  # ==== Example
40
51
  #
@@ -67,11 +78,9 @@ module Squall
67
78
  else
68
79
  raise ArgumentError, "Config file doesn't exist '#{file}'"
69
80
  end
81
+ settings = YAML::load_file(file)
70
82
  config do |c|
71
- conf = YAML::load_file(file)
72
- c.base_uri conf['base_uri']
73
- c.username conf['username']
74
- c.password conf['password']
83
+ settings.each { |k, v| c.send(k, v) }
75
84
  end
76
85
  end
77
86
 
data/spec/spec_helper.rb CHANGED
@@ -6,32 +6,37 @@ require 'squall'
6
6
  VCR.config do |c|
7
7
  c.cassette_library_dir = 'spec/vcr_cassettes'
8
8
  c.stub_with :fakeweb
9
- c.default_cassette_options = {:record => :new_episodes}
9
+ if ENV['RERECORD']
10
+ c.default_cassette_options = {:record => :all}
11
+ else
12
+ c.default_cassette_options = {:record => :none}
13
+ end
14
+ c.filter_sensitive_data("Basic <REDACTED>") { |i| [i.request.headers['authorization']].flatten.first }
15
+ c.filter_sensitive_data("<REDACTED>") { |i| [i.response.headers['set-cookie']].flatten.first }
16
+ c.filter_sensitive_data("<URL>") { URI.parse(Squall.config[:base_uri]).host }
17
+ c.filter_sensitive_data("<USER>") { Squall.config[:username] }
18
+ c.filter_sensitive_data("<PASS>") { Squall.config[:password] }
10
19
  end
11
20
 
12
21
  RSpec.configure do |c|
13
22
  c.extend VCR::RSpec::Macros
23
+ c.before(:each) do
24
+ configure_for_tests
25
+ end
14
26
  c.after(:each) do
15
27
  Squall.reset_config
16
28
  end
17
29
  end
18
30
 
19
- def default_config
20
- yaml = File.join(ENV['HOME'], '.squall.yml')
21
- if ENV['SQUALL_LIVE'] && File.exists?(yaml)
22
- config = YAML::load_file(yaml)
23
- uri = config['base_uri']
24
- user = config['username']
25
- pass = config['password']
31
+ def configure_for_tests
32
+ if ENV['RERECORD']
33
+ Squall.config_file
26
34
  else
27
- uri = 'http://www.example.com'
28
- user = 'user'
29
- pass = 'pass'
30
- end
31
- Squall.config do |c|
32
- c.base_uri uri
33
- c.username user
34
- c.password pass
35
+ Squall.config do |c|
36
+ c.username "test"
37
+ c.password "test"
38
+ c.base_uri "http://example.com"
39
+ end
35
40
  end
36
41
  end
37
42
 
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ describe Squall::DataStoreZone do
4
+ before(:each) do
5
+ @data_store_zone = Squall::DataStoreZone.new
6
+ @valid = {:label => "My zone"}
7
+ end
8
+
9
+ describe "#list" do
10
+ use_vcr_cassette "data_store_zone/list"
11
+
12
+ it "returns all data store zones" do
13
+ data_store_zones = @data_store_zone.list
14
+ data_store_zones.should be_an(Array)
15
+ end
16
+
17
+ it "contains the data store zone data" do
18
+ data_store_zones = @data_store_zone.list
19
+ data_store_zones.all? {|w| w.is_a?(Hash) }.should be_true
20
+ end
21
+ end
22
+
23
+ describe "#show" do
24
+ use_vcr_cassette "data_store_zone/show"
25
+ it "requires an id" do
26
+ expect { @data_store_zone.show }.to raise_error(ArgumentError)
27
+ end
28
+
29
+ it "returns not found for invalid data store zone id" do
30
+ expect { @data_store_zone.show(404) }.to raise_error(Squall::NotFound)
31
+ end
32
+
33
+ it "returns a data store zone" do
34
+ data_store_zone = @data_store_zone.show(1)
35
+ data_store_zone.should be_a(Hash)
36
+ end
37
+ end
38
+
39
+ describe "#create" do
40
+ use_vcr_cassette "data_store_zone/create"
41
+ it "requires label" do
42
+ invalid = @valid.reject{|k,v| k == :label }
43
+ requires_attr(:label) { @data_store_zone.create(invalid) }
44
+ end
45
+
46
+ it "raises error on unknown params" do
47
+ expect { @data_store_zone.create(@valid.merge(:what => 'what')) }.to raise_error(ArgumentError, 'Unknown params: what')
48
+ end
49
+
50
+ it "creates a data store zone" do
51
+ @data_store_zone.create(@valid)
52
+ @data_store_zone.success.should be_true
53
+ end
54
+ end
55
+
56
+ describe "#edit" do
57
+ use_vcr_cassette "data_store_zone/edit"
58
+
59
+ it "allows select params" do
60
+ optional = [:label]
61
+ @data_store_zone.should_receive(:request).exactly(optional.size).times.and_return Hash.new()
62
+ optional.each do |param|
63
+ @data_store_zone.edit(1, param => "test")
64
+ end
65
+ end
66
+
67
+ it "raises error on unknown params" do
68
+ expect { @data_store_zone.edit(1, @valid.merge(:what => 'what')) }.to raise_error(ArgumentError, 'Unknown params: what')
69
+ end
70
+
71
+ it "edits a data store zone" do
72
+ @data_store_zone.edit(1, :label => "Updated zone")
73
+ @data_store_zone.success.should be_true
74
+ end
75
+
76
+ it "raises an error for an invalid data store zone id" do
77
+ expect { @data_store_zone.edit(404, @valid) }.to raise_error(Squall::NotFound)
78
+ end
79
+ end
80
+
81
+ describe "#delete" do
82
+ use_vcr_cassette "data_store_zone/delete"
83
+ it "requires an id" do
84
+ expect { @data_store_zone.delete }.to raise_error(ArgumentError)
85
+ end
86
+
87
+ it "deletes a data store zone" do
88
+ @data_store_zone.delete(1)
89
+ @data_store_zone.success.should be_true
90
+ end
91
+
92
+ it "returns NotFound for invalid data store zone id" do
93
+ expect { @data_store_zone.delete(404) }.to raise_error(Squall::NotFound)
94
+ end
95
+ end
96
+
97
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ describe Squall::FirewallRule do
4
+ before(:each) do
5
+ @firewall_rule = Squall::FirewallRule.new
6
+ @valid = {:command => "DROP", :protocol => "TCP", :network_interface_id => 1}
7
+ end
8
+
9
+ describe "#list" do
10
+ use_vcr_cassette "firewall_rule/list"
11
+
12
+ it "requires vm id" do
13
+ expect { @firewall_rule.list }.to raise_error(ArgumentError)
14
+ end
15
+
16
+ it "returns a list of firewall rules for a vm" do
17
+ firewall_rules = @firewall_rule.list(1)
18
+ firewall_rules.should be_an(Array)
19
+ end
20
+
21
+ it "contains first firewall_rule's data" do
22
+ firewall_rules = @firewall_rule.list(1)
23
+ firewall_rules.all?.should be_true
24
+ end
25
+ end
26
+
27
+ describe "#create" do
28
+ use_vcr_cassette "firewall_rule/create"
29
+ it "requires command" do
30
+ invalid = @valid.reject{|k,v| k == :command }
31
+ requires_attr(:command) { @firewall_rule.create(1, invalid) }
32
+ end
33
+
34
+ it "requires protocol" do
35
+ invalid = @valid.reject{|k,v| k == :protocol }
36
+ requires_attr(:protocol) { @firewall_rule.create(1, invalid) }
37
+ end
38
+
39
+ it "requires network_interface_id" do
40
+ invalid = @valid.reject{|k,v| k == :network_interface_id }
41
+ requires_attr(:network_interface_id) { @firewall_rule.create(1, invalid) }
42
+ end
43
+
44
+ it "allows all optional params" do
45
+ optional = [:network_interface_id, :address, :port]
46
+ @firewall_rule.should_receive(:request).exactly(optional.size).times.and_return Hash.new("firewall_rule" => {})
47
+ optional.each do |param|
48
+ @firewall_rule.create(1, @valid.merge(param => "test"))
49
+ end
50
+ end
51
+
52
+ it "raises error on unknown params" do
53
+ expect { @firewall_rule.create(1, @valid.merge(:what => 'what')) }.to raise_error(ArgumentError, 'Unknown params: what')
54
+ end
55
+
56
+ it "raises an error for an invalid vm id" do
57
+ expect { @firewall_rule.create(404, @valid) }.to raise_error(Squall::NotFound)
58
+ end
59
+
60
+ it "creates a firewall rule for a virtual machine" do
61
+ @firewall_rule.create(1, @valid)
62
+ @firewall_rule.success.should be_true
63
+ end
64
+ end
65
+
66
+ describe "#edit" do
67
+ use_vcr_cassette "firewall_rule/edit"
68
+
69
+ it "allows select params" do
70
+ optional = [:command, :protocol, :network_interface_id, :address, :port]
71
+ @firewall_rule.should_receive(:request).exactly(optional.size).times.and_return Hash.new()
72
+ optional.each do |param|
73
+ @firewall_rule.edit(1, 1, param => "test")
74
+ end
75
+ end
76
+
77
+ it "raises error on unknown params" do
78
+ expect { @firewall_rule.edit(1, 1, :what => 'what') }.to raise_error(ArgumentError, 'Unknown params: what')
79
+ end
80
+
81
+ it "edits a firewall rule" do
82
+ pending "broken in OnApp: returning invalid JSON" do
83
+ @firewall_rule.edit(1, 1, :port => 1000)
84
+ @firewall_rule.success.should be_true
85
+ end
86
+ end
87
+
88
+ it "raises an error for an invalid firewall rule id" do
89
+ expect { @firewall_rule.edit(1, 404, @valid) }.to raise_error(Squall::NotFound)
90
+ end
91
+ end
92
+
93
+ describe "#delete" do
94
+ use_vcr_cassette "firewall_rule/delete"
95
+
96
+ it "requires an id" do
97
+ expect { @firewall_rule.delete }.to raise_error(ArgumentError)
98
+ end
99
+
100
+ it "deletes a firewall rule" do
101
+ pending "broken in OnApp: returning invalid JSON" do
102
+ @firewall_rule.delete(1, 1)
103
+ @firewall_rule.success.should be_true
104
+ end
105
+ end
106
+
107
+ it "returns NotFound for missing virtual machine" do
108
+ expect { @firewall_rule.delete(1, 404) }.to raise_error(Squall::NotFound)
109
+ end
110
+ end
111
+
112
+ end
@@ -2,24 +2,23 @@ require 'spec_helper'
2
2
 
3
3
  describe Squall::Hypervisor do
4
4
  before(:each) do
5
- default_config
6
5
  @hv = Squall::Hypervisor.new
6
+ @valid = {:label => 'A new hypervisor', :ip_address => '127.126.126.126', :hypervisor_type => 'xen'}
7
7
  end
8
8
 
9
9
  describe "#list" do
10
10
  use_vcr_cassette 'hypervisor/list'
11
+
11
12
  it "returns hypervisors" do
12
13
  hvs = @hv.list
13
- hvs.size.should be(2)
14
-
15
- keys = ["label", "called_in_at", "spare", "created_at", "hypervisor_type",
16
- "updated_at", "xen_info", "id", "hypervisor_group_id", "enabled", "health",
17
- "failure_count", "memory_overhead", "online", "locked", "ip_address"]
18
- first = hvs.first
19
- first.keys.should include(*keys)
20
- first['label'].should == 'Testing'
21
- first['hypervisor_type'].should == 'xen'
14
+ hvs.should be_an(Array)
15
+ end
16
+
17
+ it "contains hypervisor data" do
18
+ hvs = @hv.list
19
+ hvs.all?.should be_true
22
20
  end
21
+
23
22
  end
24
23
 
25
24
  describe "#show" do
@@ -29,55 +28,38 @@ describe Squall::Hypervisor do
29
28
  end
30
29
 
31
30
  it "returns not found for invalid hvs" do
32
- expect { @hv.show(5) }.to raise_error(Squall::NotFound)
31
+ expect { @hv.show(404) }.to raise_error(Squall::NotFound)
33
32
  end
34
33
 
35
34
  it "returns a hv" do
36
- hv = @hv.show(1)
37
- hv['label'].should == 'Testing'
35
+ @hv.show(1)
36
+ @hv.success.should be_true
38
37
  end
39
38
  end
40
39
 
41
40
  describe "#create" do
42
41
  use_vcr_cassette "hypervisor/create"
43
42
  it "requires label" do
44
- requires_attr(:label) { @hv.create }
43
+ invalid = @valid.reject{|k,v| k == :label }
44
+ requires_attr(:label) { @hv.create(invalid) }
45
45
  @hv.success.should be_false
46
46
  end
47
47
 
48
48
  it "requires ip_address" do
49
- requires_attr(:ip_address) { @hv.create(:label => 'Brand New') }
49
+ invalid = @valid.reject{|k,v| k == :ip_address }
50
+ requires_attr(:ip_address) { @hv.create(invalid) }
50
51
  @hv.success.should be_false
51
52
  end
52
53
 
53
54
  it "requires hypervisor_type" do
54
- requires_attr(:hypervisor_type) { @hv.create(:label => 'Brand New', :ip_address => '222.222.222.222') }
55
- @hv.success.should be_false
56
- end
57
-
58
- # The API allows you to commit this value but subsequent
59
- # saves do not work because of this missing value.
60
- it "requires memory_overhead" do
61
- pending "Broken in OnApp"
62
- requires_attr(:memory_overhead) { @hv.create(:label => 'Brand New', :ip_address => '222.222.222.222', :hypervisor_type => 'xen') }
63
- end
64
-
65
- it "raises error on duplicate account" do
66
- expect {
67
- @hv.create(:label => 'Testing', :ip_address => '123.123.123.123', :hypervisor_type => 'xen')
68
- }.to raise_error(Squall::RequestError)
69
- @hv.errors['label'].should include("has already been taken")
70
- @hv.errors['ip_address'].should include("has already been taken")
55
+ invalid = @valid.reject{|k,v| k == :hypervisor_type }
56
+ requires_attr(:hypervisor_type) { @hv.create(invalid) }
71
57
  @hv.success.should be_false
72
58
  end
73
59
 
74
60
  it "creates a hypervisor" do
75
- create = @hv.create(:label => 'Brand new', :ip_address => '126.126.126.126', :hypervisor_type => 'xen')
61
+ @hv.create(@valid)
76
62
  @hv.success.should be_true
77
-
78
- create['label'].should == 'Brand new'
79
- create['ip_address'].should == '126.126.126.126'
80
- create['hypervisor_type'].should == 'xen'
81
63
  end
82
64
  end
83
65
 
@@ -89,17 +71,12 @@ describe Squall::Hypervisor do
89
71
  end
90
72
 
91
73
  it "raises an error with unknown param " do
92
- expect { @hv.edit(3, :blah => 1)}.to raise_error(ArgumentError)
74
+ expect { @hv.edit(1, :blah => 1)}.to raise_error(ArgumentError)
93
75
  @hv.success.should be_false
94
76
  end
95
77
 
96
- it "edits the label" do
97
- edit = @hv.edit(3, :label => 'Old Gregg')
98
- @hv.success.should be_true
99
- end
100
-
101
- it "edits the ip_address" do
102
- edit = @hv.edit(3, :ip_address => '120.120.120.120')
78
+ it "edits the hypervisor" do
79
+ edit = @hv.edit(1, :label => 'A new label')
103
80
  @hv.success.should be_true
104
81
  end
105
82
  end
@@ -119,8 +96,6 @@ describe Squall::Hypervisor do
119
96
  it "reboots the hypervisor" do
120
97
  reboot = @hv.reboot(1)
121
98
  @hv.success.should be_true
122
-
123
- reboot['label'].should == 'Testing'
124
99
  end
125
100
  end
126
101
 
@@ -136,8 +111,86 @@ describe Squall::Hypervisor do
136
111
  end
137
112
 
138
113
  it "returns a hv" do
139
- @hv.delete(3)
114
+ @hv.delete(1)
115
+ @hv.success.should be_true
116
+ end
117
+ end
118
+
119
+ describe "#data_store_joins" do
120
+ use_vcr_cassette "hypervisor/data_store_joins"
121
+
122
+ it "returns a list of data store joins" do
123
+ joins = @hv.data_store_joins(1)
124
+ joins.should be_an(Array)
125
+ end
126
+
127
+ it "contains the data store join data" do
128
+ joins = @hv.data_store_joins(1)
129
+ joins.all? {|w| w.is_a?(Hash) }.should be_true
130
+ end
131
+
132
+ end
133
+
134
+ describe "#add_data_store_join" do
135
+ use_vcr_cassette "hypervisor/add_data_store_join"
136
+
137
+ it "adds the data store to the hypervisor zone" do
138
+ @hv.add_data_store_join(1, 1)
139
+ @hv.success.should be_true
140
+ end
141
+
142
+ end
143
+
144
+ describe "#remove_data_store_join" do
145
+ use_vcr_cassette "hypervisor/remove_data_store_join"
146
+
147
+ it "removes the data store from the hypervisor zone" do
148
+ @hv.remove_data_store_join(1, 1)
149
+ @hv.success.should be_true
150
+ end
151
+
152
+ end
153
+
154
+ describe "#network_joins" do
155
+ use_vcr_cassette "hypervisor/network_joins"
156
+
157
+ it "returns a list of network joins" do
158
+ joins = @hv.network_joins(1)
159
+ joins.should be_an(Array)
160
+ end
161
+
162
+ it "contains the network join data" do
163
+ joins = @hv.network_joins(1)
164
+ joins.all? {|w| w.is_a?(Hash) }.should be_true
165
+ end
166
+
167
+ end
168
+
169
+ describe "#add_network_join" do
170
+ use_vcr_cassette "hypervisor/add_network_join"
171
+
172
+ it "requires network id" do
173
+ requires_attr(:network_id) { @hv.add_network_join(1, :interface => "interface") }
174
+ end
175
+
176
+ it "requires interface" do
177
+ requires_attr(:interface) { @hv.add_network_join(1, :network_id => 1) }
178
+ end
179
+
180
+ it "adds the network to the hypervisor zone" do
181
+ @hv.add_network_join(1, :network_id => 1, :interface => "interface")
182
+ @hv.success.should be_true
183
+ end
184
+
185
+ end
186
+
187
+ describe "#remove_network_join" do
188
+ use_vcr_cassette "hypervisor/remove_network_join"
189
+
190
+ it "removes the network from the hypervisor zone" do
191
+ @hv.remove_network_join(1, 1)
140
192
  @hv.success.should be_true
141
193
  end
194
+
142
195
  end
143
196
  end