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
@@ -0,0 +1,135 @@
1
+ module Squall
2
+ # OnApp HypervisorZone
3
+ class HypervisorZone < Base
4
+ # Returns a list of hypervisor zones
5
+ def list
6
+ response = request(:get, "/settings/hypervisor_zones.json")
7
+ response.collect { |i| i['hypervisor_group'] }
8
+ end
9
+
10
+ # Get the details for a hypervisor zone
11
+ #
12
+ # ==== Params
13
+ #
14
+ # * +id*+ - ID of the hypervisor zone
15
+ def show(id)
16
+ response = request(:get, "/settings/hypervisor_zones/#{id}.json")
17
+ response['hypervisor_group']
18
+ end
19
+
20
+ # Updates an existing hypervisor zone
21
+ #
22
+ # ==== Params
23
+ #
24
+ # * +id*+ - ID of the hypervisor zone
25
+ # * +options+ - Params for updating the hypervisor zone
26
+ #
27
+ # ==== Options
28
+ #
29
+ # See #create
30
+ def edit(id, options = {})
31
+ params.required(:label).validate!(options)
32
+ response = request(:put, "/settings/hypervisor_zones/#{id}.json", :query => {:pack => options})
33
+ end
34
+
35
+ # Creates a new hypervisor zone
36
+ #
37
+ # ==== Params
38
+ #
39
+ # * +options+ - Params for updating the hypervisor zone
40
+ #
41
+ # ==== Options
42
+ #
43
+ # * +label*+ - Label for the hypervisor zone
44
+ def create(options = {})
45
+ params.required(:label).validate!(options)
46
+ response = request(:post, "/settings/hypervisor_zones.json", :query => {:pack => options})
47
+ end
48
+
49
+ # Deletes an existing hypervisor zone
50
+ #
51
+ # ==== Params
52
+ #
53
+ # * +id*+ - ID of the hypervisor zone
54
+ def delete(id)
55
+ request(:delete, "/settings/hypervisor_zones/#{id}.json")
56
+ end
57
+
58
+ # Get the list of hypervisors attached to a zone
59
+ #
60
+ # ==== Params
61
+ #
62
+ # * +id*+ - ID of the hypervisor zone
63
+ def hypervisors(id)
64
+ response = request(:get, "/settings/hypervisor_zones/#{id}/hypervisors.json")
65
+ response.collect { |hv| hv['hypervisor'] }
66
+ end
67
+
68
+ # Get the list of data store joins attached to a hypervisor zone
69
+ #
70
+ # ==== Params
71
+ #
72
+ # * +id*+ - ID of the hypervisor zone
73
+ def data_store_joins(id)
74
+ response = request(:get, "/settings/hypervisor_zones/#{id}/data_store_joins.json")
75
+ response.collect { |i| i['data_store_join'] }
76
+ end
77
+
78
+ # Add a data store to a hypervisor zone
79
+ #
80
+ # ==== Params
81
+ #
82
+ # * +id*+ - ID of the hypervisor zone
83
+ # * +data_store_id*+ - ID of the data store
84
+ def add_data_store_join(id, data_store_id)
85
+ request(:post, "/settings/hypervisor_zones/#{id}/data_store_joins.json", :query => {:data_store_id => data_store_id})
86
+ end
87
+
88
+ # Remove a data store from a hypervisor zone
89
+ #
90
+ # ==== Params
91
+ #
92
+ # * +id*+ - ID of the hypervisor zone
93
+ # * +data_store_join_id*+ - ID of the join record
94
+ def remove_data_store_join(id, data_store_join_id)
95
+ request(:delete, "/settings/hypervisor_zones/#{id}/data_store_joins/#{data_store_join_id}.json")
96
+ end
97
+
98
+ # Get the list of networks attached to a hypervisor zone
99
+ #
100
+ # ==== Params
101
+ #
102
+ # * +id*+ - ID of the hypervisor zone
103
+ def network_joins(id)
104
+ response = request(:get, "/settings/hypervisor_zones/#{id}/network_joins.json")
105
+ response.collect { |i| i['network_join'] }
106
+ end
107
+
108
+ # Add a network to a hypervisor zone
109
+ #
110
+ # ==== Params
111
+ #
112
+ # * +id*+ - ID of the hypervisor zone
113
+ # * +options+ - Params for updating the hypervisor zone
114
+ #
115
+ # ==== Options
116
+ #
117
+ # * +network_id*+ - The ID of the network to add to the hypervisor zone
118
+ # * +interface*+ - The name of the appropriate network interface
119
+ def add_network_join(id, options={})
120
+ params.required(:network_id, :interface).validate!(options)
121
+ request(:post, "/settings/hypervisor_zones/#{id}/network_joins.json", :query => {:network_join => options})
122
+ end
123
+
124
+ # Remove a network from a hypervisor zone
125
+ #
126
+ # ==== Params
127
+ #
128
+ # * +id*+ - ID of the hypervisor zone
129
+ # * +network_join_id*+ - ID of the join record
130
+ def remove_network_join(id, network_join_id)
131
+ request(:delete, "/settings/hypervisor_zones/#{id}/network_joins/#{network_join_id}.json")
132
+ end
133
+
134
+ end
135
+ end
@@ -1,13 +1,60 @@
1
1
  module Squall
2
2
  # OnApp IpAddress
3
3
  class IpAddress < Base
4
- # Returns a list of IpAddresses
4
+ # Returns a list of ip addresses for a network
5
5
  #
6
- # ==== Options
7
- # * +network_id+ - required
6
+ # ==== Params
7
+ #
8
+ # * +network_id+ - ID of the network
8
9
  def list(network_id)
9
10
  response = request(:get, "/settings/networks/#{network_id}/ip_addresses.json")
10
11
  response.collect { |ip| ip['ip_address'] }
11
12
  end
13
+
14
+ # Updates an existing ip address
15
+ #
16
+ # ==== Params
17
+ #
18
+ # * +network_id+ - ID of the network
19
+ # * +id+ - ID of the ip address
20
+ # * +options+ - Params for updating the ip address
21
+ #
22
+ # ==== Options
23
+ #
24
+ # See #create
25
+ def edit(network_id, id, options = {})
26
+ params.accepts(:address, :netmask, :broadcast, :network_address, :gateway, :disallowed_primary).validate!(options)
27
+ response = request(:put, "/settings/networks/#{network_id}/ip_addresses/#{id}.json", default_params(options))
28
+ end
29
+
30
+ # Creates a new IpAddress
31
+ #
32
+ # ==== Params
33
+ #
34
+ # * +network_id+ - ID of the network
35
+ # * +options+ - Params for the new ip address
36
+ #
37
+ # ==== Options
38
+ #
39
+ # * +address*+ - IP address
40
+ # * +netmask*+ - Network mask
41
+ # * +broadcast*+ - A logical address at which all devices connected to a multiple-access communications network are enabled to receive datagrams
42
+ # * +network_address*+ - IP address of network
43
+ # * +gateway*+ - Gateway address
44
+ # * +disallowed_primary+ - Set to '1' to prevent this address being used as primary
45
+ def create(network_id, options = {})
46
+ params.required(:address, :netmask, :broadcast, :network_address, :gateway).accepts(:disallowed_primary).validate!(options)
47
+ response = request(:post, "/settings/networks/#{network_id}/ip_addresses.json", default_params(options))
48
+ end
49
+
50
+ # Deletes an existing ip address
51
+ #
52
+ # ==== Params
53
+ #
54
+ # * +network_id+ - ID of the network
55
+ # * +id+ - ID of the ip address
56
+ def delete(network_id, id)
57
+ request(:delete, "/settings/networks/#{network_id}/ip_addresses/#{id}.json")
58
+ end
12
59
  end
13
60
  end
@@ -0,0 +1,46 @@
1
+ module Squall
2
+ # Handles IP assignments for virtual machines
3
+ class IpAddressJoin < Base
4
+
5
+ # Get the list of IP address assignments for a particular virtual machine
6
+ #
7
+ # ==== Params
8
+ #
9
+ # * +virtual_machine_id*+ - Virtual machine ID to lookup
10
+ def list(virtual_machine_id)
11
+ response = request(:get, "/virtual_machines/#{virtual_machine_id}/ip_addresses.json")
12
+ response.collect { |ip| ip['ip_address_join'] }
13
+ end
14
+
15
+ # Assigns an IP address to a VM
16
+ #
17
+ # ==== Params
18
+ #
19
+ # * +virtual_machine_id*+ - Virtual machine ID to assign IP to
20
+ # * +options+ - Params for IP assignment
21
+ #
22
+ # ==== Options
23
+ #
24
+ # * +ip_address_id*+ - ID of the IP address
25
+ # * +network_interface_id*+ - ID of the network interface id
26
+ def assign(virtual_machine_id, options = {})
27
+ params.required(:ip_address_id, :network_interface_id).validate!(options)
28
+ response = request(:post, "/virtual_machines/#{virtual_machine_id}/ip_addresses.json", default_params(options))
29
+ response['ip_address_join']
30
+ end
31
+
32
+ # Deletes an IP address assignment from a VM
33
+ #
34
+ # ==== Params
35
+ #
36
+ # * +virtual_machine_id+ - Virtual machine ID to remove IP join from
37
+ # * +ip_address_id+ - IP Address ID to remove
38
+ #
39
+ # ==== Options
40
+ #
41
+ # See #assign
42
+ def delete(virtual_machine_id, ip_address_id)
43
+ request(:delete, "/virtual_machines/#{virtual_machine_id}/ip_addresses/#{ip_address_id}.json")
44
+ end
45
+ end
46
+ end
@@ -9,12 +9,18 @@ module Squall
9
9
 
10
10
  # Edit a Network
11
11
  #
12
- # ==== Options
12
+ # ==== Params
13
13
  #
14
+ # * +id*+ - ID of the network
14
15
  # * +options+ - Params for editing the Network
16
+ #
17
+ # ==== Options
18
+ #
19
+ # See #create
20
+ #
15
21
  # ==== Example
16
22
  #
17
- # edit :label => 'mynetwork', :network_group_id => 1, :vlan => 2, :identifier => 'something'
23
+ # edit 1, :label => 'mynetwork', :network_group_id => 1, :vlan => 2, :identifier => 'something'
18
24
  def edit(id, options = {})
19
25
  params.accepts(:label, :network_group_id, :vlan, :identifier).validate!(options)
20
26
  response = request(:put, "/settings/networks/#{id}.json", default_params(options))
@@ -22,19 +28,30 @@ module Squall
22
28
 
23
29
  # Create a Network
24
30
  #
25
- # ==== Options
31
+ # ==== Params
26
32
  #
27
33
  # * +options+ - Params for creating the Network
34
+ #
35
+ # ==== Options
36
+ #
37
+ # * +label*+
38
+ # * +vlan+
39
+ # * +identifier+
40
+ #
28
41
  # ==== Example
29
42
  #
30
43
  # create :label => 'mynetwork', :network_group_id => 1, :vlan => 2, :identifier => 'something'
31
44
  def create(options = {})
32
- params.accepts(:label, :vlan, :identifier).required(:label).validate!(options)
45
+ params.accepts(:vlan, :identifier).required(:label).validate!(options)
33
46
  response = request(:post, '/settings/networks.json', default_params(options))
34
47
  response.first[1]
35
48
  end
36
49
 
37
50
  # Delete a network
51
+ #
52
+ # ==== Params
53
+ #
54
+ # * +id*+ - ID of the network
38
55
  def delete(id)
39
56
  request(:delete, "/settings/networks/#{id}.json")
40
57
  end
@@ -0,0 +1,73 @@
1
+ module Squall
2
+ # OnApp NetworkZone
3
+ class NetworkZone < Base
4
+ # Returns a list of network zones
5
+ def list
6
+ response = request(:get, "/network_zones.json")
7
+ response.collect { |i| i['network_group'] }
8
+ end
9
+
10
+ # Get the details for a network zone
11
+ #
12
+ # ==== Params
13
+ #
14
+ # * +id*+ - ID of the network zone
15
+ def show(id)
16
+ response = request(:get, "/network_zones/#{id}.json")
17
+ response['network_group']
18
+ end
19
+
20
+ # Updates an existing network zone
21
+ #
22
+ # ==== Params
23
+ #
24
+ # * +id*+ - ID of the network zone
25
+ #
26
+ # ==== Options
27
+ #
28
+ # See #create
29
+ def edit(id, options = {})
30
+ params.required(:label).validate!(options)
31
+ response = request(:put, "/network_zones/#{id}.json", :query => {:pack => options})
32
+ end
33
+
34
+ # Creates a new network zone
35
+ #
36
+ # ==== Options
37
+ #
38
+ # * +label*+ - Label for the network zone
39
+ def create(options = {})
40
+ params.required(:label).validate!(options)
41
+ response = request(:post, "/network_zones.json", :query => {:pack => options})
42
+ end
43
+
44
+ # Deletes an existing network zone
45
+ #
46
+ # ==== Params
47
+ #
48
+ # * +id*+ - ID of the network zone
49
+ def delete(id)
50
+ request(:delete, "/network_zones/#{id}.json")
51
+ end
52
+
53
+ # Attach a network to a network zone
54
+ #
55
+ # ==== Params
56
+ #
57
+ # * +id*+ - ID of the network zone
58
+ # * +network_id+ - ID of the network
59
+ def attach(id, network_id)
60
+ request(:post, "/network_zones/#{id}/networks/#{network_id}/attach.json")
61
+ end
62
+
63
+ # Detach a network from a network zone
64
+ #
65
+ # ==== Params
66
+ #
67
+ # * +id*+ - ID of the network zone
68
+ # * +network_id+ - ID of the network
69
+ def detach(id, network_id)
70
+ request(:post, "/network_zones/#{id}/networks/#{network_id}/detach.json")
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,59 @@
1
+ module Squall
2
+ # OnApp Payment
3
+ class Payment < Base
4
+
5
+ # Return a list of all payments
6
+ def list(user_id)
7
+ response = request(:get, "/users/#{user_id}/payments.json")
8
+ response.collect { |user| user['payment'] }
9
+ end
10
+
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
17
+ #
18
+ # ==== Options
19
+ #
20
+ # * +amount*+ - Amount of the payment
21
+ # * +invoice_number+ - Number of the invoice
22
+ #
23
+ # ==== Example
24
+ #
25
+ # create :amount => 500,
26
+ # :invoice_number => "01234",
27
+ def create(user_id, options={})
28
+ params.required(:amount).accepts(:invoice_number).validate!(options)
29
+ request(:post, "/users/#{user_id}/payments.json", default_params(options))
30
+ end
31
+
32
+ # Edit a payment
33
+ #
34
+ # ==== Params
35
+ #
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)
45
+ request(:put, "/users/#{user_id}/payments/#{id}.json", default_params(options))
46
+ end
47
+
48
+ # Delete a payment
49
+ #
50
+ # ==== Params
51
+ #
52
+ # * +user_id*+ - ID of the user
53
+ # * +id*+ - ID of the payment
54
+ def delete(user_id, id)
55
+ request(:delete, "/users/#{user_id}/payments/#{id}.json")
56
+ end
57
+
58
+ end
59
+ end
data/lib/squall/role.rb CHANGED
@@ -1,33 +1,46 @@
1
1
  module Squall
2
2
  # OnApp Role
3
3
  class Role < Base
4
- # Return a list of Roles
4
+ # Return a list of roles
5
5
  def list
6
6
  response = request(:get, '/roles.json')
7
7
  response.collect { |role| role['role']}
8
8
  end
9
9
 
10
- # Returns a Hash of the given Role
10
+ # Returns a Hash of the given roles
11
+ #
12
+ # ==== Params
13
+ #
14
+ # * +id*+ - ID of the role
11
15
  def show(id)
12
16
  response = request(:get, "/roles/#{id}.json")
13
- response.first[1]
17
+ response["role"]
14
18
  end
15
19
 
16
20
  # Edit a Role
17
21
  #
22
+ # ==== Params
23
+ #
24
+ # * +id*+ - ID of the role
25
+ # * +options+ - Params for editing the roles
26
+ #
18
27
  # ==== Options
19
28
  #
20
- # * +options+ - Params for editing the Role
29
+ # See #create
30
+ #
21
31
  # ==== Example
22
32
  #
23
- # edit :label => 'myrole', :permission => [1,3]
24
- # edit :label => 'myrole', :permission => 1
33
+ # edit 1, :label => 'myrole', :permission_ids => [1,3]
25
34
  def edit(id, options = {})
26
- params.accepts(:label, :permission).validate!(options)
35
+ params.accepts(:label, :permission_ids).validate!(options)
27
36
  response = request(:put, "/roles/#{id}.json", default_params(options))
28
37
  end
29
38
 
30
39
  # Delete a Role
40
+ #
41
+ # ==== Params
42
+ #
43
+ # * +id*+ - ID of the role
31
44
  def delete(id)
32
45
  request(:delete, "/roles/#{id}.json")
33
46
  end
@@ -40,17 +53,21 @@ module Squall
40
53
 
41
54
  # Create a new Role
42
55
  #
56
+ # ==== Params
57
+ #
58
+ # * +options+ - Params for creating the roles
59
+ #
43
60
  # ==== Options
44
61
  #
45
- # * +options+ - Params for creating the Role
62
+ # * +label*+ - Label for the role
63
+ # * +permission_ids+ - An array of permission ids granted to the role.
46
64
  #
47
65
  # ==== Example
48
66
  #
49
- # create :label => 'mypriv', :identifier => 'magic'
67
+ # create :label => 'Admin'
50
68
  def create(options = {})
51
- params.required(:label, :identifier).validate!(options)
69
+ params.required(:label).accepts(:permission_ids).validate!(options)
52
70
  response = request(:post, '/roles.json', default_params(options))
53
- response.first[1]
54
71
  end
55
72
  end
56
73
  end
@@ -1,10 +1,10 @@
1
1
  module Squall
2
2
  # OnApp Statistic
3
3
  class Statistic < Base
4
- # Returns statitics for a given VirtualMachine
5
- def daily_stats(id)
4
+ # Returns statitics for virtual machines
5
+ def daily_stats
6
6
  response = request(:get, "/usage_statistics.json")
7
- response.first['vm_hourly_stat']
7
+ response.collect {|s| s["vm_stat"]}
8
8
  end
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  module Squall
2
- # All OnApp API classes subclass Base to get access to
2
+ # All OnApp API classes subclass Base to get access to
3
3
  # HTTParty methods and other convenience methods
4
4
  class Base
5
5
  # Params instance
@@ -19,7 +19,11 @@ module Squall
19
19
  self.class.basic_auth Squall::config[:username], Squall::config[:password]
20
20
  self.class.format :json
21
21
  self.class.headers 'Content-Type' => 'application/json'
22
- # self.class.debug_output
22
+ if Squall::config[:debug]
23
+ self.class.debug_output
24
+ else
25
+ self.class.debug_output(nil)
26
+ end
23
27
  end
24
28
 
25
29
  # Returns a Params.new
@@ -83,8 +87,8 @@ module Squall
83
87
  raise NoConfig, "Squall.config must be specified" if Squall.config.empty?
84
88
  end
85
89
 
86
- # Sets the default param container for request. It is derived from the
87
- # class name. Given the class name *Sandwich* and a param *bread* the
90
+ # Sets the default param container for request. It is derived from the
91
+ # class name. Given the class name *Sandwich* and a param *bread* the
88
92
  # resulting params would be 'bob[bread]=wheat'
89
93
  def key_for_class
90
94
  word = self.class.name.split("::").last.to_s.dup
@@ -22,5 +22,9 @@ module Squall
22
22
  def password(value)
23
23
  @config[:password] = value
24
24
  end
25
+
26
+ def debug(value)
27
+ @config[:debug] = value
28
+ end
25
29
  end
26
30
  end
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ module Squall
2
+ VERSION = '1.1.0'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'yaml'
2
+
3
+ if ::YAML.const_defined?(:ENGINE)
4
+ ::YAML::ENGINE.yamler = 'syck'
5
+ end
@@ -9,6 +9,10 @@ module Squall
9
9
 
10
10
  # Make a Template public so that it can be downloaded
11
11
  # via a HTTP url
12
+ #
13
+ # ==== Params
14
+ #
15
+ # * +id*+ - ID of template
12
16
  def make_public(id)
13
17
  response = request(:post, "/templates/#{id}/make_public.json")
14
18
  response.first[1]
@@ -8,6 +8,10 @@ module Squall
8
8
  end
9
9
 
10
10
  # Return a Hash for the given Transaction
11
+ #
12
+ # ==== Params
13
+ #
14
+ # * +id*+ - ID of transaction
11
15
  def show(id)
12
16
  response = request :get, "/transactions/#{id}.json"
13
17
  response['transaction']