fog 1.0.0 → 1.1.0

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 (232) hide show
  1. data/README.rdoc +2 -9
  2. data/Rakefile +3 -2
  3. data/docs/_layouts/default.html +13 -13
  4. data/docs/about/contributing.markdown +1 -1
  5. data/docs/about/getting_started.markdown +28 -3
  6. data/docs/dns/index.markdown +4 -4
  7. data/docs/index.markdown +2 -10
  8. data/docs/public/css/fog.css +14 -1
  9. data/docs/storage/index.markdown +2 -2
  10. data/fog.gemspec +6 -5
  11. data/lib/fog.rb +1 -1
  12. data/lib/fog/aws.rb +26 -1
  13. data/lib/fog/aws/auto_scaling.rb +3 -1
  14. data/lib/fog/aws/cloud_formation.rb +3 -0
  15. data/lib/fog/aws/cloud_watch.rb +17 -1
  16. data/lib/fog/aws/compute.rb +50 -18
  17. data/lib/fog/aws/elb.rb +4 -2
  18. data/lib/fog/aws/emr.rb +133 -0
  19. data/lib/fog/aws/models/cloud_watch/alarm.rb +12 -0
  20. data/lib/fog/aws/models/cloud_watch/alarm_data.rb +39 -0
  21. data/lib/fog/aws/models/cloud_watch/alarm_datum.rb +66 -0
  22. data/lib/fog/aws/models/cloud_watch/alarm_histories.rb +18 -0
  23. data/lib/fog/aws/models/cloud_watch/alarm_history.rb +16 -0
  24. data/lib/fog/aws/models/cloud_watch/alarms.rb +30 -0
  25. data/lib/fog/aws/models/compute/addresses.rb +1 -1
  26. data/lib/fog/aws/models/compute/key_pairs.rb +1 -1
  27. data/lib/fog/aws/models/compute/security_groups.rb +1 -1
  28. data/lib/fog/aws/models/compute/server.rb +4 -2
  29. data/lib/fog/aws/models/compute/servers.rb +1 -1
  30. data/lib/fog/aws/models/compute/snapshots.rb +1 -1
  31. data/lib/fog/aws/models/compute/spot_request.rb +21 -4
  32. data/lib/fog/aws/models/compute/spot_requests.rb +45 -1
  33. data/lib/fog/aws/models/compute/volumes.rb +1 -1
  34. data/lib/fog/aws/models/elb/load_balancer.rb +2 -0
  35. data/lib/fog/aws/models/storage/file.rb +1 -1
  36. data/lib/fog/aws/parsers/cdn/get_invalidation_list.rb +0 -1
  37. data/lib/fog/aws/parsers/cloud_formation/update_stack.rb +19 -0
  38. data/lib/fog/aws/parsers/cloud_watch/delete_alarms.rb +26 -0
  39. data/lib/fog/aws/parsers/cloud_watch/describe_alarm_history.rb +40 -0
  40. data/lib/fog/aws/parsers/cloud_watch/describe_alarms.rb +73 -0
  41. data/lib/fog/aws/parsers/cloud_watch/describe_alarms_for_metric.rb +71 -0
  42. data/lib/fog/aws/parsers/cloud_watch/disable_alarm_actions.rb +26 -0
  43. data/lib/fog/aws/parsers/cloud_watch/enable_alarm_actions.rb +26 -0
  44. data/lib/fog/aws/parsers/cloud_watch/get_metric_statistics.rb +1 -0
  45. data/lib/fog/aws/parsers/cloud_watch/put_metric_alarm.rb +26 -0
  46. data/lib/fog/aws/parsers/cloud_watch/set_alarm_state.rb +26 -0
  47. data/lib/fog/aws/parsers/compute/spot_instance_requests.rb +2 -2
  48. data/lib/fog/aws/parsers/emr/add_instance_groups.rb +28 -0
  49. data/lib/fog/aws/parsers/emr/add_job_flow_steps.rb +17 -0
  50. data/lib/fog/aws/parsers/emr/describe_job_flows.rb +140 -0
  51. data/lib/fog/aws/parsers/emr/modify_instance_groups.rb +17 -0
  52. data/lib/fog/aws/parsers/emr/run_job_flow.rb +19 -0
  53. data/lib/fog/aws/parsers/emr/set_termination_protection.rb +17 -0
  54. data/lib/fog/aws/parsers/emr/terminate_job_flows.rb +17 -0
  55. data/lib/fog/aws/rds.rb +3 -1
  56. data/lib/fog/aws/requests/cloud_formation/create_stack.rb +6 -0
  57. data/lib/fog/aws/requests/cloud_formation/update_stack.rb +62 -0
  58. data/lib/fog/aws/requests/cloud_watch/delete_alarms.rb +30 -0
  59. data/lib/fog/aws/requests/cloud_watch/describe_alarm_history.rb +33 -0
  60. data/lib/fog/aws/requests/cloud_watch/describe_alarms.rb +38 -0
  61. data/lib/fog/aws/requests/cloud_watch/describe_alarms_for_metric.rb +39 -0
  62. data/lib/fog/aws/requests/cloud_watch/disable_alarm_actions.rb +30 -0
  63. data/lib/fog/aws/requests/cloud_watch/enable_alarm_actions.rb +30 -0
  64. data/lib/fog/aws/requests/cloud_watch/put_metric_alarm.rb +84 -0
  65. data/lib/fog/aws/requests/cloud_watch/set_alarm_state.rb +31 -0
  66. data/lib/fog/aws/requests/compute/authorize_security_group_ingress.rb +141 -36
  67. data/lib/fog/aws/requests/compute/create_snapshot.rb +2 -3
  68. data/lib/fog/aws/requests/compute/create_tags.rb +5 -3
  69. data/lib/fog/aws/requests/compute/create_volume.rb +0 -1
  70. data/lib/fog/aws/requests/compute/delete_security_group.rb +25 -0
  71. data/lib/fog/aws/requests/compute/delete_tags.rb +3 -4
  72. data/lib/fog/aws/requests/compute/describe_addresses.rb +2 -2
  73. data/lib/fog/aws/requests/compute/describe_availability_zones.rb +5 -2
  74. data/lib/fog/aws/requests/compute/describe_images.rb +6 -9
  75. data/lib/fog/aws/requests/compute/describe_instances.rb +17 -8
  76. data/lib/fog/aws/requests/compute/describe_key_pairs.rb +2 -2
  77. data/lib/fog/aws/requests/compute/describe_regions.rb +2 -2
  78. data/lib/fog/aws/requests/compute/describe_reserved_instances.rb +1 -1
  79. data/lib/fog/aws/requests/compute/describe_security_groups.rb +2 -2
  80. data/lib/fog/aws/requests/compute/describe_snapshots.rb +7 -5
  81. data/lib/fog/aws/requests/compute/describe_volumes.rb +5 -4
  82. data/lib/fog/aws/requests/compute/modify_image_attribute.rb +32 -0
  83. data/lib/fog/aws/requests/compute/modify_instance_attribute.rb +1 -1
  84. data/lib/fog/aws/requests/compute/purchase_reserved_instances_offering.rb +1 -1
  85. data/lib/fog/aws/requests/compute/register_image.rb +0 -1
  86. data/lib/fog/aws/requests/compute/revoke_security_group_ingress.rb +41 -29
  87. data/lib/fog/aws/requests/compute/run_instances.rb +1 -2
  88. data/lib/fog/aws/requests/elb/create_load_balancer.rb +1 -1
  89. data/lib/fog/aws/requests/elb/create_load_balancer_listeners.rb +1 -1
  90. data/lib/fog/aws/requests/elb/deregister_instances_from_load_balancer.rb +1 -1
  91. data/lib/fog/aws/requests/elb/describe_instance_health.rb +2 -2
  92. data/lib/fog/aws/requests/elb/describe_load_balancers.rb +3 -3
  93. data/lib/fog/aws/requests/elb/register_instances_with_load_balancer.rb +2 -2
  94. data/lib/fog/aws/requests/emr/add_instance_groups.rb +46 -0
  95. data/lib/fog/aws/requests/emr/add_job_flow_steps.rb +49 -0
  96. data/lib/fog/aws/requests/emr/describe_job_flows.rb +108 -0
  97. data/lib/fog/aws/requests/emr/modify_instance_groups.rb +40 -0
  98. data/lib/fog/aws/requests/emr/run_job_flow.rb +106 -0
  99. data/lib/fog/aws/requests/emr/set_termination_protection.rb +39 -0
  100. data/lib/fog/aws/requests/emr/terminate_job_flows.rb +37 -0
  101. data/lib/fog/aws/requests/iam/get_server_certificate.rb +5 -7
  102. data/lib/fog/aws/requests/iam/upload_server_certificate.rb +1 -0
  103. data/lib/fog/aws/requests/simpledb/get_attributes.rb +2 -2
  104. data/lib/fog/aws/requests/simpledb/select.rb +1 -1
  105. data/lib/fog/aws/requests/storage/copy_object.rb +1 -1
  106. data/lib/fog/aws/requests/storage/get_object_url.rb +2 -2
  107. data/lib/fog/aws/requests/storage/hash_to_acl.rb +35 -25
  108. data/lib/fog/aws/ses.rb +1 -1
  109. data/lib/fog/aws/simpledb.rb +2 -0
  110. data/lib/fog/aws/sns.rb +3 -1
  111. data/lib/fog/aws/sqs.rb +4 -2
  112. data/lib/fog/aws/storage.rb +12 -3
  113. data/lib/fog/bin.rb +1 -1
  114. data/lib/fog/bin/aws.rb +8 -4
  115. data/lib/fog/bin/bluebox.rb +2 -2
  116. data/lib/fog/bin/brightbox.rb +1 -1
  117. data/lib/fog/bin/dnsimple.rb +1 -1
  118. data/lib/fog/bin/dnsmadeeasy.rb +1 -1
  119. data/lib/fog/bin/ecloud.rb +1 -1
  120. data/lib/fog/bin/glesys.rb +1 -1
  121. data/lib/fog/bin/go_grid.rb +1 -1
  122. data/lib/fog/bin/google.rb +1 -1
  123. data/lib/fog/bin/libvirt.rb +1 -1
  124. data/lib/fog/bin/linode.rb +2 -2
  125. data/lib/fog/bin/local.rb +1 -1
  126. data/lib/fog/bin/new_servers.rb +1 -1
  127. data/lib/fog/bin/ninefold.rb +2 -2
  128. data/lib/fog/bin/openstack.rb +1 -1
  129. data/lib/fog/bin/rackspace.rb +3 -3
  130. data/lib/fog/bin/slicehost.rb +1 -1
  131. data/lib/fog/bin/stormondemand.rb +1 -1
  132. data/lib/fog/bin/virtual_box.rb +1 -1
  133. data/lib/fog/bin/vmfusion.rb +1 -1
  134. data/lib/fog/bin/voxel.rb +1 -1
  135. data/lib/fog/bin/zerigo.rb +1 -1
  136. data/lib/fog/brightbox/models/compute/account.rb +1 -1
  137. data/lib/fog/compute/models/server.rb +1 -2
  138. data/lib/fog/core/attributes.rb +5 -5
  139. data/lib/fog/core/connection.rb +1 -1
  140. data/lib/fog/core/deprecation.rb +2 -2
  141. data/lib/fog/core/logger.rb +8 -3
  142. data/lib/fog/core/mock.rb +4 -0
  143. data/lib/fog/core/provider.rb +7 -2
  144. data/lib/fog/core/service.rb +8 -2
  145. data/lib/fog/dnsmadeeasy/models/dns/record.rb +3 -2
  146. data/lib/fog/dynect/dns.rb +25 -3
  147. data/lib/fog/ecloud/compute.rb +2 -6
  148. data/lib/fog/go_grid/requests/compute/grid_server_power.rb +1 -1
  149. data/lib/fog/google/models/storage/file.rb +1 -1
  150. data/lib/fog/google/requests/storage/get_object_url.rb +2 -2
  151. data/lib/fog/google/storage.rb +1 -1
  152. data/lib/fog/libvirt/models/compute/uri.rb +7 -3
  153. data/lib/fog/linode/models/compute/server.rb +10 -0
  154. data/lib/fog/ninefold/models/storage/file.rb +8 -6
  155. data/lib/fog/ninefold/models/storage/files.rb +3 -2
  156. data/lib/fog/ninefold/requests/storage/head_namespace.rb +20 -0
  157. data/lib/fog/ninefold/storage.rb +4 -2
  158. data/lib/fog/openstack.rb +4 -3
  159. data/lib/fog/openstack/compute.rb +8 -5
  160. data/lib/fog/openstack/models/compute/server.rb +10 -1
  161. data/lib/fog/openstack/requests/compute/create_server.rb +6 -8
  162. data/lib/fog/rackspace/load_balancers.rb +1 -0
  163. data/lib/fog/rackspace/models/dns/callback.rb +1 -1
  164. data/lib/fog/rackspace/models/dns/record.rb +1 -1
  165. data/lib/fog/rackspace/models/dns/zone.rb +1 -1
  166. data/lib/fog/slicehost/dns.rb +1 -0
  167. data/lib/fog/slicehost/models/dns/record.rb +7 -3
  168. data/lib/fog/slicehost/models/dns/zone.rb +1 -1
  169. data/lib/fog/slicehost/parsers/dns/create_record.rb +8 -2
  170. data/lib/fog/slicehost/parsers/dns/get_record.rb +17 -5
  171. data/lib/fog/slicehost/parsers/dns/get_records.rb +10 -2
  172. data/lib/fog/slicehost/requests/dns/get_record.rb +1 -1
  173. data/lib/fog/slicehost/requests/dns/get_records.rb +7 -8
  174. data/lib/fog/slicehost/requests/dns/update_record.rb +43 -0
  175. data/lib/fog/storm_on_demand/models/compute/balancers.rb +1 -1
  176. data/lib/fog/storm_on_demand/models/compute/configs.rb +1 -1
  177. data/lib/fog/storm_on_demand/models/compute/images.rb +1 -1
  178. data/lib/fog/storm_on_demand/models/compute/servers.rb +1 -1
  179. data/lib/fog/storm_on_demand/models/compute/templates.rb +1 -1
  180. data/lib/fog/terremark/vcloud.rb +1 -1
  181. data/lib/fog/vsphere/compute.rb +40 -23
  182. data/lib/fog/vsphere/models/compute/server.rb +1 -0
  183. data/lib/fog/vsphere/requests/compute/list_virtual_machines.rb +36 -4
  184. data/lib/fog/zerigo/dns.rb +14 -3
  185. data/lib/fog/zerigo/models/dns/record.rb +1 -1
  186. data/lib/fog/zerigo/models/dns/records.rb +5 -0
  187. data/lib/fog/zerigo/models/dns/zones.rb +2 -2
  188. data/lib/fog/zerigo/requests/dns/count_hosts.rb +20 -1
  189. data/lib/fog/zerigo/requests/dns/count_zones.rb +12 -1
  190. data/lib/fog/zerigo/requests/dns/create_host.rb +67 -1
  191. data/lib/fog/zerigo/requests/dns/create_zone.rb +44 -1
  192. data/lib/fog/zerigo/requests/dns/delete_host.rb +19 -0
  193. data/lib/fog/zerigo/requests/dns/delete_zone.rb +17 -0
  194. data/lib/fog/zerigo/requests/dns/find_hosts.rb +22 -1
  195. data/lib/fog/zerigo/requests/dns/get_host.rb +18 -1
  196. data/lib/fog/zerigo/requests/dns/get_zone.rb +19 -2
  197. data/lib/fog/zerigo/requests/dns/get_zone_stats.rb +23 -0
  198. data/lib/fog/zerigo/requests/dns/list_hosts.rb +20 -1
  199. data/lib/fog/zerigo/requests/dns/list_zones.rb +15 -0
  200. data/lib/fog/zerigo/requests/dns/update_host.rb +20 -1
  201. data/lib/fog/zerigo/requests/dns/update_zone.rb +20 -1
  202. data/tests/aws/models/cloud_watch/alarm_data_tests.rb +42 -0
  203. data/tests/aws/models/cloud_watch/alarm_history_tests.rb +22 -0
  204. data/tests/aws/models/compute/security_group_tests.rb +15 -10
  205. data/tests/aws/models/elb/model_tests.rb +4 -4
  206. data/tests/aws/requests/cloud_formation/stack_tests.rb +14 -0
  207. data/tests/aws/requests/cloud_watch/list_metrics_test.rb +5 -5
  208. data/tests/aws/requests/compute/image_tests.rb +33 -2
  209. data/tests/aws/requests/compute/instance_tests.rb +16 -1
  210. data/tests/aws/requests/compute/security_group_tests.rb +251 -32
  211. data/tests/aws/requests/compute/tag_tests.rb +42 -2
  212. data/tests/aws/requests/emr/helper.rb +172 -0
  213. data/tests/aws/requests/emr/instance_group_tests.rb +106 -0
  214. data/tests/aws/requests/emr/job_flow_tests.rb +88 -0
  215. data/tests/aws/requests/iam/server_certificate_tests.rb +20 -7
  216. data/tests/aws/requests/storage/bucket_tests.rb +82 -54
  217. data/tests/aws/requests/storage/hash_to_acl_tests.rb +173 -0
  218. data/tests/aws/requests/storage/object_tests.rb +44 -24
  219. data/tests/brightbox/requests/compute/helper.rb +15 -6
  220. data/tests/core/attribute_tests.rb +29 -0
  221. data/tests/core/mocking_tests.rb +60 -0
  222. data/tests/dns/models/record_tests.rb +4 -2
  223. data/tests/dns/models/records_tests.rb +4 -2
  224. data/tests/dns/models/zone_tests.rb +3 -1
  225. data/tests/dns/models/zones_tests.rb +4 -2
  226. data/tests/helper.rb +4 -0
  227. data/tests/rackspace/requests/dns/dns_tests.rb +16 -12
  228. data/tests/rackspace/requests/dns/records_tests.rb +13 -11
  229. data/tests/slicehost/requests/dns/dns_tests.rb +58 -11
  230. data/tests/vsphere/compute_tests.rb +18 -10
  231. data/tests/vsphere/requests/compute/vm_clone_tests.rb +1 -1
  232. metadata +214 -221
@@ -13,7 +13,7 @@ module Fog
13
13
  # * body<~Hash>
14
14
  # * 'count'<~Integer>
15
15
  # * 'status'<~Integer> - 200 indicates success
16
- def count_hosts( zone_id)
16
+ def count_hosts(zone_id)
17
17
  request(
18
18
  :expects => 200,
19
19
  :method => 'GET',
@@ -23,6 +23,25 @@ module Fog
23
23
  end
24
24
 
25
25
  end
26
+
27
+ class Mock # :nodoc:all
28
+ def count_hosts(zone_id)
29
+ zone = find_by_zone_id(zone_id)
30
+
31
+ response = Excon::Response.new
32
+
33
+ if zone
34
+ response.status = 200
35
+ response.body = {
36
+ 'count' => zone['hosts'].size
37
+ }
38
+ else
39
+ response.status = 404
40
+ end
41
+
42
+ response
43
+ end
44
+ end
26
45
  end
27
46
  end
28
47
  end
@@ -13,7 +13,7 @@ module Fog
13
13
  # * body<~Hash>
14
14
  # * 'count'<~Integer>
15
15
  # * 'status'<~Integer> - 200 indicates success
16
- def count_zones()
16
+ def count_zones
17
17
  request(
18
18
  :expects => 200,
19
19
  :method => 'GET',
@@ -23,6 +23,17 @@ module Fog
23
23
  end
24
24
 
25
25
  end
26
+
27
+ class Mock # :nodoc:all
28
+ def count_zones
29
+ response = Excon::Response.new
30
+
31
+ response.status = 200
32
+ response.body = { 'count' => self.data[:zones].size }
33
+
34
+ response
35
+ end
36
+ end
26
37
  end
27
38
  end
28
39
  end
@@ -11,7 +11,7 @@ module Fog
11
11
  # * zone_id<~Integer>
12
12
  # * host_type<~String>
13
13
  # * data<~String>
14
- # * options<~Hash> - optional paramaters
14
+ # * options<~Hash> - optional parameters
15
15
  # * hostname<~String> - Note: normally this is set/required!!
16
16
  # * notes<~String>
17
17
  # * priority<~Integer> - Note: required for MX or SRV records
@@ -57,6 +57,72 @@ module Fog
57
57
  end
58
58
 
59
59
  end
60
+
61
+ class Mock # :nodoc:all
62
+ def valid_host_types
63
+ %w[A AAAA CNAME GEO MX NS SPF SRV TXT URL PTR CNAME NS]
64
+ end
65
+
66
+ def create_host(zone_id, host_type, data, options = {})
67
+ zone = find_by_zone_id(zone_id)
68
+
69
+ response = Excon::Response.new
70
+
71
+ # Handle error cases.
72
+
73
+ # Zone doesn't exist.
74
+ unless zone
75
+ response.status = 404
76
+ return response
77
+ end
78
+
79
+ # Bad host type.
80
+ unless valid_host_types.include?(host_type)
81
+ response.status = 422
82
+ response.body = {
83
+ 'errors' => [
84
+ 'error' => 'Host type is not included in the list'
85
+ ]
86
+ }
87
+
88
+ return response
89
+ end
90
+
91
+ # Missing or bad priority value for MX or SRV records.
92
+ if %w[MX SRV].include?(host_type) && options['priority'].to_s !~ /\d+/
93
+ response.status = 422
94
+ response.body = {
95
+ 'errors' => [
96
+ 'error' => 'Priority is not a number'
97
+ ]
98
+ }
99
+
100
+ return response
101
+ end
102
+
103
+ # Successful case.
104
+ now = Time.now
105
+ host = {
106
+ 'id' => rand(10000000),
107
+ 'fqdn' => options[:hostname] ? "#{options[:hostname]}.#{zone['domain']}" : zone['domain'],
108
+ 'data' => data,
109
+ 'hostname' => options[:hostname],
110
+ 'ttl' => options[:ttl].to_i,
111
+ 'host-type' => host_type,
112
+ 'created-at' => now,
113
+ 'updated-at' => now,
114
+ 'notes' => options[:notes],
115
+ 'priority' => options[:priority].to_i,
116
+ 'zone-id' => zone_id
117
+ }
118
+
119
+ zone['hosts'] << host
120
+ response.status = 201
121
+ response.body = host
122
+
123
+ response
124
+ end
125
+ end
60
126
  end
61
127
  end
62
128
  end
@@ -46,7 +46,7 @@ module Fog
46
46
  # * 'restrict-axfr'<~String>
47
47
  # * 'status'<~Integer> - 201 if successful
48
48
 
49
- def create_zone( domain, default_ttl, ns_type, options = {})
49
+ def create_zone(domain, default_ttl, ns_type, options = {})
50
50
 
51
51
  optional_tags= ''
52
52
  options.each { |option, value|
@@ -84,6 +84,49 @@ module Fog
84
84
  end
85
85
 
86
86
  end
87
+
88
+ class Mock # :nodoc:all
89
+ def create_zone(domain, default_ttl, ns_type, options = {})
90
+ now = Time.now
91
+ zone = {
92
+ 'id' => rand(10000000),
93
+ 'domain' => domain,
94
+ 'created-at' => now,
95
+ 'updated-at' => now,
96
+ 'ns1' => options[:ns1],
97
+ 'nx-ttl' => options[:nx_ttl].to_i,
98
+ 'default-ttl' => default_ttl.to_i,
99
+ 'ns-type' => ns_type,
100
+ 'hosts' => options[:hosts] || [],
101
+ 'hosts-count' => (options[:hosts] || []).size,
102
+ 'notes' => options[:notes],
103
+ 'slave-nameservers' => options[:slave_nameservers],
104
+ 'tag-list' => options[:tag_list]
105
+ }
106
+
107
+ response = Excon::Response.new
108
+
109
+ if self.data[:zones].any? {|z| z['domain'] == zone['domain'] }
110
+ response.status = 422
111
+ response.body = {
112
+ 'errors' => [
113
+ 'error' => 'Domain is already associated to another account',
114
+ 'error' => 'Domain already exists. If it was just deleted, wait a minute and try again'
115
+ ]
116
+ }
117
+
118
+ else
119
+ self.data[:zones] << zone
120
+
121
+ response.status = 201
122
+ response.headers = { 'Location' => "http://ns.zerigo.com/api/1.1/zones/#{zone['id']}" }
123
+ response.body = zone['hosts'].empty? ? zone.merge(:hosts => nil) : zone # Zerigo returns nil, not an empty list only on the create command.
124
+ end
125
+
126
+ response
127
+ end
128
+ end
129
+
87
130
  end
88
131
  end
89
132
  end
@@ -19,6 +19,25 @@ module Fog
19
19
  end
20
20
 
21
21
  end
22
+
23
+ class Mock # :nodoc:all
24
+ def delete_host(host_id)
25
+ host = find_host(host_id)
26
+
27
+ response = Excon::Response.new
28
+
29
+ if host
30
+ zone = find_by_zone_id(host['zone-id'])
31
+ zone['hosts'].delete(host)
32
+
33
+ response.status = 200
34
+ else
35
+ response.status = 404
36
+ end
37
+
38
+ response
39
+ end
40
+ end
22
41
  end
23
42
  end
24
43
  end
@@ -20,6 +20,23 @@ module Fog
20
20
  end
21
21
 
22
22
  end
23
+
24
+ class Mock # :nodoc:all
25
+ def delete_zone(zone_id)
26
+ zone = find_by_zone_id(zone_id)
27
+
28
+ response = Excon::Response.new
29
+
30
+ if zone
31
+ self.data[:zones].delete(zone)
32
+ response.status = 200
33
+ else
34
+ response.status = 404
35
+ end
36
+
37
+ response
38
+ end
39
+ end
23
40
  end
24
41
  end
25
42
  end
@@ -29,7 +29,7 @@ module Fog
29
29
  # * 'zone-id'<~String>
30
30
  # * 'status'<~Integer> - 200 indicated success
31
31
  #
32
- def find_hosts( fqdn, zone_id = nil)
32
+ def find_hosts(fqdn, zone_id = nil)
33
33
  if zone_id.nil?
34
34
  #look for matching host across all zones
35
35
  request(
@@ -50,6 +50,27 @@ module Fog
50
50
  end
51
51
 
52
52
  end
53
+
54
+ class Mock # :nodoc:all
55
+ def find_hosts(fqdn, zone_id = nil)
56
+ response = Excon::Response.new
57
+
58
+ zone = find_by_zone_id(zone_id)
59
+ if zone_id && !zone
60
+ response.status = 404
61
+ else
62
+ hosts = zone ? zone['hosts'].select { |z| z['fqdn'] == fqdn } :
63
+ self.data[:zones].collect { |z| z['hosts'].find { |h| h['fqdn'] == fqdn } }.compact
64
+
65
+ response.status = 200
66
+ response.body = {
67
+ 'hosts' => hosts
68
+ }
69
+ end
70
+
71
+ response
72
+ end
73
+ end
53
74
  end
54
75
  end
55
76
  end
@@ -24,7 +24,7 @@ module Fog
24
24
  # * 'updated-at'<~String>
25
25
  # * 'zone-id'<~String>
26
26
  # * 'status'<~Integer> - 200 indicates success
27
- def get_host( host_id)
27
+ def get_host(host_id)
28
28
  request(
29
29
  :expects => 200,
30
30
  :method => 'GET',
@@ -34,6 +34,23 @@ module Fog
34
34
  end
35
35
 
36
36
  end
37
+
38
+ class Mock # :nodoc:all
39
+ def get_host(host_id)
40
+ host = find_host(host_id)
41
+
42
+ response = Excon::Response.new
43
+
44
+ if host
45
+ response.status = 200
46
+ response.body = host
47
+ else
48
+ response.status = 404
49
+ end
50
+
51
+ response
52
+ end
53
+ end
37
54
  end
38
55
  end
39
56
  end
@@ -34,16 +34,33 @@ module Fog
34
34
  # * 'restrict-axfr'<~String>
35
35
  # * 'status'<~Integer> - 200 indicates success
36
36
 
37
- def get_zone(zone)
37
+ def get_zone(zone_id_or_domain)
38
38
  request(
39
39
  :expects => 200,
40
40
  :method => 'GET',
41
41
  :parser => Fog::Parsers::DNS::Zerigo::GetZone.new,
42
- :path => "/api/1.1/zones/#{zone}.xml"
42
+ :path => "/api/1.1/zones/#{zone_id_or_domain}.xml"
43
43
  )
44
44
  end
45
45
 
46
46
  end
47
+
48
+ class Mock # :nodoc:all
49
+ def get_zone(zone_id_or_domain)
50
+ zone = find_by_zone_id(zone_id_or_domain) || find_by_domain(zone_id_or_domain)
51
+
52
+ response = Excon::Response.new
53
+
54
+ if zone
55
+ response.status = 200
56
+ response.body = zone
57
+ else
58
+ response.status = 404
59
+ end
60
+
61
+ response
62
+ end
63
+ end
47
64
  end
48
65
  end
49
66
  end
@@ -31,6 +31,29 @@ module Fog
31
31
  end
32
32
 
33
33
  end
34
+
35
+ class Mock # :nodoc:all
36
+ def get_zone_stats(zone_id)
37
+ zone = find_by_zone_id(zone_id)
38
+
39
+ response = Excon::Response.new
40
+
41
+ if zone
42
+ response.status = 200
43
+ response.body = {
44
+ 'id' => zone,
45
+ 'domain' => zone['domain'],
46
+ 'period-begin' => zone['created-at'].strftime("%F"),
47
+ 'period-end' => Date.today.to_s,
48
+ 'queries' => 0
49
+ }
50
+ else
51
+ response.status = 404
52
+ end
53
+
54
+ response
55
+ end
56
+ end
34
57
  end
35
58
  end
36
59
  end
@@ -25,7 +25,7 @@ module Fog
25
25
  # * 'updated-at'<~String>
26
26
  # * 'zone-id'<~String>
27
27
  # * 'status'<~Integer> - 200 indicates success
28
- def list_hosts( zone_id)
28
+ def list_hosts(zone_id)
29
29
  request(
30
30
  :expects => 200,
31
31
  :method => 'GET',
@@ -35,6 +35,25 @@ module Fog
35
35
  end
36
36
 
37
37
  end
38
+
39
+ class Mock # :nodoc:all
40
+ def list_hosts(zone_id)
41
+ zone = find_by_zone_id(zone_id)
42
+
43
+ response = Excon::Response.new
44
+
45
+ if zone
46
+ response.status = 200
47
+ response.body = {
48
+ 'hosts' => zone['hosts']
49
+ }
50
+ else
51
+ response.status = 404
52
+ end
53
+
54
+ response
55
+ end
56
+ end
38
57
  end
39
58
  end
40
59
  end
@@ -40,6 +40,21 @@ module Fog
40
40
  end
41
41
 
42
42
  end
43
+
44
+ class Mock # :nodoc:all
45
+
46
+ def list_zones
47
+ response = Excon::Response.new
48
+
49
+ response.status = 200
50
+ response.body = {
51
+ 'zones' => self.data[:zones]
52
+ }
53
+
54
+ response
55
+ end
56
+
57
+ end
43
58
  end
44
59
  end
45
60
  end