fog 0.3.31 → 0.3.32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/.document +3 -0
  2. data/.gitignore +10 -0
  3. data/Gemfile.lock +1 -4
  4. data/README.rdoc +29 -37
  5. data/Rakefile +5 -25
  6. data/bin/fog +1 -3
  7. data/examples/dns_methods.rb +389 -0
  8. data/examples/storage.rb +103 -0
  9. data/fog.gemspec +4 -778
  10. data/lib/fog.rb +5 -66
  11. data/lib/fog/aws.rb +3 -0
  12. data/lib/fog/aws/bin.rb +7 -2
  13. data/lib/fog/aws/cdn.rb +2 -2
  14. data/lib/fog/aws/compute.rb +2 -2
  15. data/lib/fog/aws/dns.rb +101 -0
  16. data/lib/fog/aws/elb.rb +2 -2
  17. data/lib/fog/aws/iam.rb +2 -2
  18. data/lib/fog/aws/models/compute/image.rb +1 -0
  19. data/lib/fog/aws/models/compute/server.rb +1 -1
  20. data/lib/fog/aws/models/compute/servers.rb +1 -13
  21. data/lib/fog/aws/parsers/compute/describe_images.rb +36 -34
  22. data/lib/fog/aws/parsers/dns/change_resource_record_sets.rb +26 -0
  23. data/lib/fog/aws/parsers/dns/create_hosted_zone.rb +55 -0
  24. data/lib/fog/aws/parsers/dns/delete_hosted_zone.rb +25 -0
  25. data/lib/fog/aws/parsers/dns/get_change.rb +26 -0
  26. data/lib/fog/aws/parsers/dns/get_hosted_zone.rb +43 -0
  27. data/lib/fog/aws/parsers/dns/list_hosted_zones.rb +35 -0
  28. data/lib/fog/aws/parsers/dns/list_resource_record_sets.rb +46 -0
  29. data/lib/fog/aws/requests/compute/describe_images.rb +1 -0
  30. data/lib/fog/aws/requests/dns/change_resource_record_sets.rb +90 -0
  31. data/lib/fog/aws/requests/dns/create_hosted_zone.rb +68 -0
  32. data/lib/fog/aws/requests/dns/delete_hosted_zone.rb +48 -0
  33. data/lib/fog/aws/requests/dns/get_change.rb +47 -0
  34. data/lib/fog/aws/requests/dns/get_hosted_zone.rb +51 -0
  35. data/lib/fog/aws/requests/dns/list_hosted_zones.rb +63 -0
  36. data/lib/fog/aws/requests/dns/list_resource_record_sets.rb +68 -0
  37. data/lib/fog/aws/requests/storage/get_object_url.rb +2 -2
  38. data/lib/fog/aws/requests/storage/put_object_url.rb +2 -2
  39. data/lib/fog/aws/requests/storage/sync_clock.rb +28 -0
  40. data/lib/fog/aws/simpledb.rb +2 -2
  41. data/lib/fog/aws/storage.rb +5 -3
  42. data/lib/fog/bluebox.rb +2 -0
  43. data/lib/fog/bluebox/compute.rb +2 -2
  44. data/lib/fog/brightbox.rb +2 -0
  45. data/lib/fog/brightbox/compute.rb +2 -2
  46. data/lib/fog/core.rb +21 -1
  47. data/lib/fog/core/bin.rb +3 -1
  48. data/lib/fog/core/compute.rb +1 -0
  49. data/lib/fog/core/credentials.rb +72 -50
  50. data/lib/fog/core/deprecation.rb +11 -5
  51. data/lib/fog/core/mock.rb +34 -0
  52. data/lib/fog/core/model.rb +9 -1
  53. data/lib/fog/core/service.rb +40 -26
  54. data/lib/fog/core/storage.rb +1 -0
  55. data/lib/fog/core/time.rb +21 -0
  56. data/lib/fog/core/wait_for.rb +17 -0
  57. data/lib/fog/go_grid.rb +2 -0
  58. data/lib/fog/go_grid/compute.rb +2 -2
  59. data/lib/fog/google.rb +2 -0
  60. data/lib/fog/google/requests/storage/get_bucket.rb +6 -5
  61. data/lib/fog/google/requests/storage/get_object_url.rb +4 -4
  62. data/lib/fog/google/requests/storage/put_object_url.rb +4 -4
  63. data/lib/fog/google/storage.rb +4 -3
  64. data/lib/fog/linode.rb +3 -0
  65. data/lib/fog/linode/bin.rb +5 -3
  66. data/lib/fog/linode/compute.rb +6 -2
  67. data/lib/fog/linode/dns.rb +80 -0
  68. data/lib/fog/linode/requests/dns/domain_create.rb +52 -0
  69. data/lib/fog/linode/requests/dns/domain_delete.rb +35 -0
  70. data/lib/fog/linode/requests/dns/domain_list.rb +50 -0
  71. data/lib/fog/linode/requests/dns/domain_resource_create.rb +53 -0
  72. data/lib/fog/linode/requests/dns/domain_resource_delete.rb +36 -0
  73. data/lib/fog/linode/requests/dns/domain_resource_list.rb +48 -0
  74. data/lib/fog/linode/requests/dns/domain_resource_update.rb +54 -0
  75. data/lib/fog/linode/requests/dns/domain_update.rb +48 -0
  76. data/lib/fog/local.rb +2 -0
  77. data/lib/fog/local/storage.rb +3 -3
  78. data/lib/fog/new_servers.rb +2 -0
  79. data/lib/fog/new_servers/compute.rb +2 -2
  80. data/lib/fog/rackspace.rb +2 -0
  81. data/lib/fog/rackspace/cdn.rb +2 -2
  82. data/lib/fog/rackspace/compute.rb +2 -2
  83. data/lib/fog/rackspace/storage.rb +2 -2
  84. data/lib/fog/slicehost.rb +3 -0
  85. data/lib/fog/slicehost/bin.rb +2 -0
  86. data/lib/fog/slicehost/compute.rb +2 -2
  87. data/lib/fog/slicehost/dns.rb +84 -0
  88. data/lib/fog/slicehost/parsers/dns/create_record.rb +26 -0
  89. data/lib/fog/slicehost/parsers/dns/create_zone.rb +26 -0
  90. data/lib/fog/slicehost/parsers/dns/get_record.rb +26 -0
  91. data/lib/fog/slicehost/parsers/dns/get_records.rb +30 -0
  92. data/lib/fog/slicehost/parsers/dns/get_zone.rb +26 -0
  93. data/lib/fog/slicehost/parsers/dns/get_zones.rb +30 -0
  94. data/lib/fog/slicehost/requests/compute/create_slice.rb +2 -2
  95. data/lib/fog/slicehost/requests/compute/delete_slice.rb +3 -17
  96. data/lib/fog/slicehost/requests/dns/create_record.rb +61 -0
  97. data/lib/fog/slicehost/requests/dns/create_zone.rb +54 -0
  98. data/lib/fog/slicehost/requests/dns/delete_record.rb +31 -0
  99. data/lib/fog/slicehost/requests/dns/delete_zone.rb +31 -0
  100. data/lib/fog/slicehost/requests/dns/get_record.rb +40 -0
  101. data/lib/fog/slicehost/requests/dns/get_records.rb +41 -0
  102. data/lib/fog/slicehost/requests/dns/get_zone.rb +40 -0
  103. data/lib/fog/slicehost/requests/dns/get_zones.rb +38 -0
  104. data/lib/fog/terremark.rb +2 -0
  105. data/lib/fog/terremark/ecloud.rb +2 -4
  106. data/lib/fog/vcloud.rb +4 -2
  107. data/lib/fog/vcloud/bin.rb +3 -1
  108. data/lib/fog/vcloud/mock_data_classes.rb +77 -11
  109. data/lib/fog/vcloud/terremark/ecloud.rb +22 -7
  110. data/lib/fog/vcloud/terremark/ecloud/models/backup_internet_service.rb +60 -0
  111. data/lib/fog/vcloud/terremark/ecloud/models/backup_internet_services.rb +36 -0
  112. data/lib/fog/vcloud/terremark/ecloud/models/internet_service.rb +28 -13
  113. data/lib/fog/vcloud/terremark/ecloud/models/internet_services.rb +2 -2
  114. data/lib/fog/vcloud/terremark/ecloud/models/ip.rb +1 -1
  115. data/lib/fog/vcloud/terremark/ecloud/models/network.rb +4 -1
  116. data/lib/fog/vcloud/terremark/ecloud/models/server.rb +5 -5
  117. data/lib/fog/vcloud/terremark/ecloud/models/vdc.rb +6 -2
  118. data/lib/fog/vcloud/terremark/ecloud/requests/add_backup_internet_service.rb +111 -0
  119. data/lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb +2 -4
  120. data/lib/fog/vcloud/terremark/ecloud/requests/add_node.rb +1 -3
  121. data/lib/fog/vcloud/terremark/ecloud/requests/configure_internet_service.rb +39 -27
  122. data/lib/fog/vcloud/terremark/ecloud/requests/configure_network.rb +1 -2
  123. data/lib/fog/vcloud/terremark/ecloud/requests/configure_network_ip.rb +21 -6
  124. data/lib/fog/vcloud/terremark/ecloud/requests/delete_vapp.rb +2 -1
  125. data/lib/fog/vcloud/terremark/ecloud/requests/get_internet_services.rb +34 -17
  126. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_extensions.rb +12 -10
  127. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_ip.rb +15 -10
  128. data/lib/fog/vcloud/terremark/ecloud/requests/get_network_ips.rb +1 -12
  129. data/lib/fog/zerigo.rb +15 -0
  130. data/lib/fog/zerigo/bin.rb +25 -0
  131. data/lib/fog/zerigo/dns.rb +96 -0
  132. data/lib/fog/zerigo/parsers/dns/count_hosts.rb +24 -0
  133. data/lib/fog/zerigo/parsers/dns/count_zones.rb +24 -0
  134. data/lib/fog/zerigo/parsers/dns/create_host.rb +26 -0
  135. data/lib/fog/zerigo/parsers/dns/create_zone.rb +26 -0
  136. data/lib/fog/zerigo/parsers/dns/find_hosts.rb +30 -0
  137. data/lib/fog/zerigo/parsers/dns/get_host.rb +26 -0
  138. data/lib/fog/zerigo/parsers/dns/get_zone.rb +56 -0
  139. data/lib/fog/zerigo/parsers/dns/get_zone_stats.rb +26 -0
  140. data/lib/fog/zerigo/parsers/dns/list_hosts.rb +30 -0
  141. data/lib/fog/zerigo/parsers/dns/list_zones.rb +30 -0
  142. data/lib/fog/zerigo/requests/dns/count_hosts.rb +36 -0
  143. data/lib/fog/zerigo/requests/dns/count_zones.rb +36 -0
  144. data/lib/fog/zerigo/requests/dns/create_host.rb +70 -0
  145. data/lib/fog/zerigo/requests/dns/create_zone.rb +97 -0
  146. data/lib/fog/zerigo/requests/dns/delete_host.rb +32 -0
  147. data/lib/fog/zerigo/requests/dns/delete_zone.rb +33 -0
  148. data/lib/fog/zerigo/requests/dns/find_hosts.rb +63 -0
  149. data/lib/fog/zerigo/requests/dns/get_host.rb +47 -0
  150. data/lib/fog/zerigo/requests/dns/get_zone.rb +57 -0
  151. data/lib/fog/zerigo/requests/dns/get_zone_stats.rb +44 -0
  152. data/lib/fog/zerigo/requests/dns/list_hosts.rb +48 -0
  153. data/lib/fog/zerigo/requests/dns/list_zones.rb +53 -0
  154. data/lib/fog/zerigo/requests/dns/update_host.rb +60 -0
  155. data/lib/fog/zerigo/requests/dns/update_zone.rb +78 -0
  156. data/spec/spec_helper.rb +0 -5
  157. data/spec/vcloud/spec_helper.rb +3 -2
  158. data/spec/vcloud/terremark/ecloud/models/backup_internet_service_spec.rb +49 -0
  159. data/spec/vcloud/terremark/ecloud/models/backup_internet_services_spec.rb +29 -0
  160. data/spec/vcloud/terremark/ecloud/models/internet_service_spec.rb +32 -13
  161. data/spec/vcloud/terremark/ecloud/models/network_spec.rb +7 -4
  162. data/spec/vcloud/terremark/ecloud/models/server_spec.rb +20 -0
  163. data/spec/vcloud/terremark/ecloud/requests/add_backup_internet_service_spec.rb +60 -0
  164. data/spec/vcloud/terremark/ecloud/requests/configure_internet_service_spec.rb +3 -0
  165. data/spec/vcloud/terremark/ecloud/requests/configure_network_ip_spec.rb +55 -0
  166. data/spec/vcloud/terremark/ecloud/requests/delete_vapp_spec.rb +9 -0
  167. data/spec/vcloud/terremark/ecloud/requests/get_internet_services_spec.rb +60 -14
  168. data/spec/vcloud/terremark/ecloud/requests/get_network_ip_spec.rb +2 -0
  169. data/spec/vcloud/terremark/ecloud/requests/get_network_ips_spec.rb +3 -3
  170. data/tests/aws/requests/compute/image_tests.rb +15 -14
  171. data/tests/aws/requests/dns/dns_tests.rb +276 -0
  172. data/tests/brightbox/requests/compute/account_tests.rb +20 -9
  173. data/tests/brightbox/requests/compute/api_client_tests.rb +12 -4
  174. data/tests/brightbox/requests/compute/cloud_ip_tests.rb +20 -6
  175. data/tests/brightbox/requests/compute/image_tests.rb +9 -4
  176. data/tests/brightbox/requests/compute/interface_tests.rb +8 -2
  177. data/tests/brightbox/requests/compute/server_tests.rb +17 -5
  178. data/tests/brightbox/requests/compute/server_type_tests.rb +8 -4
  179. data/tests/brightbox/requests/compute/user_tests.rb +13 -5
  180. data/tests/brightbox/requests/compute/zone_tests.rb +8 -4
  181. data/tests/core/attribute_tests.rb +45 -0
  182. data/tests/helper.rb +0 -2
  183. data/tests/linode/requests/dns/dns_tests.rb +262 -0
  184. data/tests/rackspace/requests/compute/address_tests.rb +1 -1
  185. data/tests/rackspace/requests/compute/image_tests.rb +1 -1
  186. data/tests/slicehost/requests/dns_tests/dns_tests.rb +279 -0
  187. data/tests/zerigo/helper.rb +0 -0
  188. data/tests/zerigo/requests/dns/dns_tests.rb +374 -0
  189. metadata +280 -36
  190. data/spec/compact_progress_bar_formatter.rb +0 -195
  191. data/spec/core/attributes_spec.rb +0 -52
  192. data/spec/lorem.txt +0 -1
@@ -0,0 +1,60 @@
1
+ module Fog
2
+ class Vcloud
3
+ module Terremark
4
+ class Ecloud
5
+ class BackupInternetService < Fog::Vcloud::Model
6
+
7
+ identity :href, :aliases => :Href
8
+
9
+ ignore_attributes :xmlns, :xmlns_i
10
+
11
+ attribute :name, :aliases => :Name
12
+ attribute :id, :aliases => :Id
13
+ attribute :protocol, :aliases => :Protocol
14
+ attribute :enabled, :aliases => :Enabled
15
+ attribute :description, :aliases => :Description
16
+ attribute :timeout, :aliases => :Timeout
17
+ attribute :redirect_url, :aliases => :RedirectURL
18
+ attribute :monitor, :aliases => :Monitor
19
+
20
+ def delete
21
+ requires :href
22
+
23
+ connection.delete_internet_service( href )
24
+ end
25
+
26
+ def monitor=(new_monitor = {})
27
+ if new_monitor.nil? || new_monitor.empty?
28
+ attributes[:monitor] = nil
29
+ end
30
+ end
31
+
32
+ def save
33
+ if new_record?
34
+ result = connection.add_backup_internet_service( collection.href, _compose_service_data )
35
+ merge_attributes(result.body)
36
+ else
37
+ connection.configure_backup_internet_service( href, _compose_service_data )
38
+ end
39
+ end
40
+
41
+ def nodes
42
+ @nodes ||= Fog::Vcloud::Terremark::Ecloud::Nodes.new( :connection => connection, :href => href + "/nodeServices" )
43
+ end
44
+
45
+ private
46
+
47
+ def _compose_service_data
48
+ #For some reason inject didn't work
49
+ service_data = {}
50
+ self.class.attributes.select{ |attribute| !send(attribute).nil? }.each { |attribute| service_data[attribute] = send(attribute) }
51
+ service_data
52
+ end
53
+
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+
@@ -0,0 +1,36 @@
1
+ require 'fog/vcloud/terremark/ecloud/models/backup_internet_service'
2
+
3
+ module Fog
4
+ class Vcloud
5
+ module Terremark
6
+ class Ecloud
7
+
8
+ class BackupInternetServices < Fog::Vcloud::Collection
9
+
10
+ model Fog::Vcloud::Terremark::Ecloud::BackupInternetService
11
+
12
+ attribute :href, :aliases => :Href
13
+
14
+ def all
15
+ check_href! :message => "the Internet Services for the Vdc you want to enumerate"
16
+ if data = connection.get_internet_services(href).body[:InternetService].find_all {|i| i[:IsBackupService] == "true" }
17
+ load(data)
18
+ end
19
+ end
20
+
21
+ # Optimize later, no need to get_internet_services again?
22
+ def get(uri)
23
+ internet_services = connection.get_internet_services(href).body[:InternetService]
24
+ internet_services = [ internet_services ] if internet_services.is_a?(Hash)
25
+ if data = internet_services.detect { |service| service[:Href] == uri }
26
+ new(data)
27
+ end
28
+ rescue Fog::Errors::NotFound
29
+ nil
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -18,6 +18,7 @@ module Fog
18
18
  attribute :timeout, :aliases => :Timeout
19
19
  attribute :redirect_url, :aliases => :RedirectURL
20
20
  attribute :monitor, :aliases => :Monitor
21
+ attribute :backup_service_data, :aliases => :BackupService
21
22
 
22
23
  def delete
23
24
  requires :href
@@ -36,19 +37,19 @@ module Fog
36
37
 
37
38
  def monitor=(new_monitor = {})
38
39
  if new_monitor.nil? || new_monitor.empty?
39
- @monitor = nil
40
+ attributes[:monitor] = nil
40
41
  elsif new_monitor.is_a?(Hash)
41
- @monitor = {}
42
- @monitor[:type] = new_monitor[:MonitorType] || new_monitor[:type]
43
- @monitor[:url_send_string] = new_monitor[:UrlSendString] || new_monitor[:url_send_string]
44
- @monitor[:http_headers] = new_monitor[:HttpHeader] || new_monitor[:http_headers]
45
- @monitor[:http_headers] = @monitor[:http_headers].split("\n") unless @monitor[:http_headers].is_a?(Array)
46
- @monitor[:receive_string] = new_monitor[:ReceiveString] || new_monitor[:receive_string]
47
- @monitor[:interval] = new_monitor[:Interval] || new_monitor[:interval]
48
- @monitor[:response_timeout] = new_monitor[:ResponseTimeOut] || new_monitor[:response_timeout]
49
- @monitor[:downtime] = new_monitor[:DownTime] || new_monitor[:downtime]
50
- @monitor[:retries] = new_monitor[:Retries] || new_monitor[:retries]
51
- @monitor[:is_enabled] = new_monitor[:IsEnabled] || new_monitor[:is_enabled]
42
+ attributes[:monitor] = {}
43
+ attributes[:monitor][:type] = new_monitor[:MonitorType] || new_monitor[:type]
44
+ attributes[:monitor][:url_send_string] = new_monitor[:UrlSendString] || new_monitor[:url_send_string]
45
+ attributes[:monitor][:http_headers] = new_monitor[:HttpHeader] || new_monitor[:http_headers]
46
+ attributes[:monitor][:http_headers] = attributes[:monitor][:http_headers].split("\n") unless attributes[:monitor][:http_headers].is_a?(Array)
47
+ attributes[:monitor][:receive_string] = new_monitor[:ReceiveString] || new_monitor[:receive_string]
48
+ attributes[:monitor][:interval] = new_monitor[:Interval] || new_monitor[:interval]
49
+ attributes[:monitor][:response_timeout] = new_monitor[:ResponseTimeOut] || new_monitor[:response_timeout]
50
+ attributes[:monitor][:downtime] = new_monitor[:DownTime] || new_monitor[:downtime]
51
+ attributes[:monitor][:retries] = new_monitor[:Retries] || new_monitor[:retries]
52
+ attributes[:monitor][:is_enabled] = new_monitor[:IsEnabled] || new_monitor[:is_enabled]
52
53
  else
53
54
  raise RuntimeError.new("monitor needs to either be nil or a Hash")
54
55
  end
@@ -58,12 +59,26 @@ module Fog
58
59
  @nodes ||= Fog::Vcloud::Terremark::Ecloud::Nodes.new( :connection => connection, :href => href + "/nodeServices" )
59
60
  end
60
61
 
62
+ def backup_service_uri
63
+ if backup_service_data
64
+ backup_service_data[:Href]
65
+ end
66
+ end
67
+
68
+ def backup_service_uri=(new_value)
69
+ self.backup_service_data = {
70
+ :Href => new_value
71
+ }
72
+ end
73
+
61
74
  private
62
75
 
63
76
  def _compose_service_data
64
77
  #For some reason inject didn't work
65
78
  service_data = {}
66
- self.class.attributes.select{ |attribute| !send(attribute).nil? }.each { |attribute| service_data[attribute] = send(attribute) }
79
+ self.class.attributes.select{ |attribute| attribute != :backup_service_data }.each { |attribute| service_data[attribute] = send(attribute) }
80
+ service_data[:backup_service_uri] = backup_service_uri
81
+ service_data.reject! {|k, v| v.nil? }
67
82
  service_data
68
83
  end
69
84
 
@@ -13,8 +13,8 @@ module Fog
13
13
 
14
14
  def all
15
15
  check_href! :message => "the Internet Services for the Vdc you want to enumerate"
16
- if data = connection.get_internet_services(href).body[:InternetService]
17
- load(data)
16
+ if internet_service_data = connection.get_internet_services(href).body[:InternetService]
17
+ load(Array[internet_service_data].flatten.find_all {|i| i[:IsBackupService] == "false" })
18
18
  end
19
19
  end
20
20
 
@@ -15,7 +15,7 @@ module Fog
15
15
  attribute :id, :aliases => :Id, :type => :integer
16
16
 
17
17
  def rnat=(new_rnat)
18
- @rnat = new_rnat
18
+ attributes[:rnat] = new_rnat
19
19
  @changed = true
20
20
  end
21
21
 
@@ -18,6 +18,9 @@ module Fog
18
18
  attribute :address, :aliases => :Address
19
19
  attribute :rnat, :aliases => :RnatAddress
20
20
  attribute :extension_href, :aliases => :Href
21
+ attribute :network_type, :aliases => :NetworkType
22
+ attribute :vlan, :aliases => :Vlan
23
+ attribute :friendly_name, :aliases => :FriendlyName
21
24
 
22
25
  def ips
23
26
  load_unless_loaded!
@@ -27,7 +30,7 @@ module Fog
27
30
  end
28
31
 
29
32
  def rnat=(new_rnat)
30
- @rnat = new_rnat
33
+ attributes[:rnat] = new_rnat
31
34
  @changed = true
32
35
  end
33
36
 
@@ -33,17 +33,17 @@ module Fog
33
33
 
34
34
  def ready?
35
35
  load_unless_loaded!
36
- @status == '2'
36
+ status == '2'
37
37
  end
38
38
 
39
39
  def on?
40
40
  load_unless_loaded!
41
- @status == '4'
41
+ status == '4'
42
42
  end
43
43
 
44
44
  def off?
45
45
  load_unless_loaded!
46
- @status == '2'
46
+ status == '2'
47
47
  end
48
48
 
49
49
  def power_on
@@ -75,7 +75,7 @@ module Fog
75
75
  end
76
76
 
77
77
  def name=(new_name)
78
- @name = new_name
78
+ attributes[:name] = new_name
79
79
  @changed = true
80
80
  end
81
81
 
@@ -199,7 +199,7 @@ module Fog
199
199
  connection.send(op.keys.first, href + "/power/action/#{op.values.first}" )
200
200
  rescue Excon::Errors::InternalServerError => e
201
201
  #Frankly we shouldn't get here ...
202
- raise e unless e.to_s =~ /because it is already powered on/
202
+ raise e unless e.to_s =~ /because it is already powered o(n|ff)/
203
203
  end
204
204
  true
205
205
  end
@@ -27,6 +27,10 @@ module Fog
27
27
  @internet_services ||= collection_based_on_type("application/vnd.tmrk.ecloud.internetServicesList+xml")
28
28
  end
29
29
 
30
+ def backup_internet_services
31
+ @backup_internet_services ||= collection_based_on_type("application/vnd.tmrk.ecloud.internetServicesList+xml", BackupInternetServices)
32
+ end
33
+
30
34
  def networks
31
35
  @networks ||= Fog::Vcloud::Terremark::Ecloud::Networks.
32
36
  new( :connection => connection,
@@ -55,14 +59,14 @@ module Fog
55
59
 
56
60
  private
57
61
 
58
- def collection_based_on_type(type)
62
+ def collection_based_on_type(type, klass = nil)
59
63
  load_unless_loaded!
60
64
  if link = other_links.detect { |link| link[:type] == type }
61
65
  case type
62
66
  when "application/vnd.tmrk.ecloud.publicIpsList+xml"
63
67
  Fog::Vcloud::Terremark::Ecloud::PublicIps
64
68
  when "application/vnd.tmrk.ecloud.internetServicesList+xml"
65
- Fog::Vcloud::Terremark::Ecloud::InternetServices
69
+ klass || Fog::Vcloud::Terremark::Ecloud::InternetServices
66
70
  when "application/vnd.vmware.vcloud.catalog+xml"
67
71
  Fog::Vcloud::Terremark::Ecloud::Catalog
68
72
  when "application/vnd.tmrk.ecloud.firewallAclsList+xml"
@@ -0,0 +1,111 @@
1
+ module Fog
2
+ class Vcloud
3
+ module Terremark
4
+ class Ecloud
5
+ module Shared
6
+ def validate_backup_internet_service_data(service_data, configure=false)
7
+ required_opts = [:name, :protocol, :description, :enabled]
8
+ if configure
9
+ required_opts + [ :id, :href, :timeout ]
10
+ end
11
+ unless required_opts.all? { |opt| service_data.keys.include?(opt) }
12
+ raise ArgumentError.new("Required Backup Internet Service data missing: #{(required_opts - service_data.keys).map(&:inspect).join(", ")}")
13
+ end
14
+ end
15
+ end
16
+
17
+ class Real
18
+ include Shared
19
+
20
+ def add_backup_internet_service(internet_services_uri, service_data)
21
+ validate_backup_internet_service_data(service_data)
22
+ if monitor = service_data[:monitor]
23
+ validate_internet_service_monitor(monitor)
24
+ ensure_monitor_defaults!(monitor)
25
+ end
26
+
27
+ request(
28
+ :body => generate_backup_internet_service_request(service_data),
29
+ :expects => 200,
30
+ :headers => {'Content-Type' => 'application/xml'},
31
+ :method => 'POST',
32
+ :uri => internet_services_uri,
33
+ :parse => true
34
+ )
35
+ end
36
+
37
+ private
38
+
39
+ def generate_backup_internet_service_request(service_data)
40
+ builder = Builder::XmlMarkup.new
41
+ builder.CreateBackupInternetServiceRequest("xmlns" => "urn:tmrk:eCloudExtensions-2.5") {
42
+ builder.Name(service_data[:name])
43
+ builder.Protocol(service_data[:protocol])
44
+ builder.Enabled(service_data[:enabled])
45
+ builder.Description(service_data[:description])
46
+ builder.RedirectURL(service_data[:redirect_url])
47
+ if monitor = service_data[:monitor]
48
+ generate_monitor_section(builder,monitor)
49
+ end
50
+ }
51
+ end
52
+ end
53
+
54
+ class Mock
55
+ include Shared
56
+
57
+ #
58
+ # Based on
59
+ # http://support.theenterprisecloud.com/kb/default.asp?id=729&Lang=1&SID=
60
+ # and many tears shed.
61
+ #
62
+
63
+ def add_backup_internet_service(internet_services_uri, service_data)
64
+ validate_backup_internet_service_data(service_data)
65
+
66
+ internet_services_uri = ensure_unparsed(internet_services_uri)
67
+
68
+ if vdc_internet_service_collection = mock_data.vdc_internet_service_collection_from_href(internet_services_uri)
69
+ new_backup_internet_service = MockBackupInternetService.new(service_data, vdc_internet_service_collection.backup_internet_services)
70
+ vdc_internet_service_collection.backup_internet_services << new_backup_internet_service
71
+ xml = generate_backup_internet_service_added_response(new_backup_internet_service)
72
+
73
+ mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}
74
+ else
75
+ mock_error 200, "401 Unauthorized"
76
+ end
77
+ end
78
+
79
+ private
80
+
81
+ def generate_backup_internet_service_added_response(new_backup_internet_service)
82
+ builder = Builder::XmlMarkup.new
83
+ builder.InternetService("xmlns" => "urn:tmrk:eCloudExtensions-2.5", "xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance") {
84
+ builder.Id new_backup_internet_service.object_id
85
+ builder.Href new_backup_internet_service.href
86
+ builder.Name new_backup_internet_service.name
87
+ # so broken
88
+ builder.PublicIpAddress do
89
+ builder.Id -2147483648
90
+ builder.Id "http://totally.invalid/1234"
91
+ builder.Name
92
+ end
93
+ builder.Port new_backup_internet_service.port
94
+ builder.Protocol new_backup_internet_service.protocol
95
+ builder.Enabled new_backup_internet_service.enabled
96
+ builder.Timeout new_backup_internet_service.timeout
97
+ builder.Description new_backup_internet_service.description
98
+ builder.RedirectURL new_backup_internet_service.redirect_url
99
+ builder.Monitor "i:nil" => true
100
+ # so broken
101
+ builder.IsBackupService false
102
+ builder.BackupService "i:nil" => true
103
+ builder.BackupOf "i:nil" => true
104
+ }
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+
@@ -59,9 +59,7 @@ module Fog
59
59
 
60
60
  def generate_internet_service_request(service_data)
61
61
  builder = Builder::XmlMarkup.new
62
- builder.CreateInternetServiceRequest(:"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
63
- :"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
64
- :xmlns => "urn:tmrk:eCloudExtensions-2.3") {
62
+ builder.CreateInternetServiceRequest(ecloud_xmlns) {
65
63
  builder.Name(service_data[:name])
66
64
  builder.Protocol(service_data[:protocol])
67
65
  builder.Port(service_data[:port])
@@ -127,7 +125,7 @@ module Fog
127
125
  if public_ip_internet_service_collection = mock_data.public_ip_internet_service_collection_from_href(internet_services_uri)
128
126
  new_public_ip_internet_service = MockPublicIpInternetService.new(service_data, public_ip_internet_service_collection)
129
127
  public_ip_internet_service_collection.items << new_public_ip_internet_service
130
- xml = generate_internet_service_response(new_public_ip_internet_service)
128
+ xml = generate_internet_service(Builder::XmlMarkup.new, new_public_ip_internet_service, true)
131
129
 
132
130
  mock_it 200, xml, {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'}
133
131
  else
@@ -7,9 +7,7 @@ module Fog
7
7
 
8
8
  def generate_node_request(node_data)
9
9
  builder = Builder::XmlMarkup.new
10
- builder.CreateNodeServiceRequest(:"xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
11
- :"xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
12
- :xmlns => "urn:tmrk:eCloudExtensions-2.3") {
10
+ builder.CreateNodeServiceRequest(ecloud_xmlns) {
13
11
  builder.IpAddress(node_data[:ip_address])
14
12
  builder.Name(node_data[:name])
15
13
  builder.Port(node_data[:port])
@@ -5,30 +5,6 @@ module Fog
5
5
  module Shared
6
6
  private
7
7
 
8
- def generate_internet_service_response(public_ip_internet_service)
9
- builder = Builder::XmlMarkup.new
10
- builder.InternetService(:"xmlns:i" => "http://www.w3.org/2001/XMLSchema-instance",
11
- :xmlns => "urn:tmrk:eCloudExtensions-2.3") {
12
- builder.Id(public_ip_internet_service.object_id)
13
- builder.Href(public_ip_internet_service.href)
14
- builder.Name(public_ip_internet_service.name)
15
- builder.Protocol(public_ip_internet_service.protocol)
16
- builder.Port(public_ip_internet_service.port)
17
- builder.Enabled(public_ip_internet_service.enabled)
18
- builder.Description(public_ip_internet_service.description)
19
- builder.Timeout(public_ip_internet_service.timeout)
20
- builder.RedirectURL(public_ip_internet_service.redirect_url)
21
- builder.PublicIpAddress {
22
- builder.Id(public_ip_internet_service._parent._parent.object_id)
23
- builder.Href(public_ip_internet_service._parent._parent.href)
24
- builder.Name(public_ip_internet_service._parent._parent.name)
25
- }
26
- if monitor = public_ip_internet_service.monitor
27
- generate_monitor_section(builder, public_ip_internet_service.monitor)
28
- end
29
- }
30
- end
31
-
32
8
  def validate_public_ip_address_data(ip_address_data)
33
9
  valid_opts = [:name, :href, :id]
34
10
  unless valid_opts.all? { |opt| ip_address_data.keys.include?(opt) }
@@ -51,7 +27,7 @@ module Fog
51
27
  end
52
28
 
53
29
  request(
54
- :body => generate_internet_service_response(service_data, ip_address_data),
30
+ :body => generate_configure_internet_service_request(service_data, ip_address_data),
55
31
  :expects => 200,
56
32
  :headers => {'Content-Type' => 'application/vnd.tmrk.ecloud.internetService+xml'},
57
33
  :method => 'PUT',
@@ -60,6 +36,35 @@ module Fog
60
36
  )
61
37
  end
62
38
 
39
+ private
40
+
41
+ def generate_configure_internet_service_request(service_data, ip_address_data)
42
+ builder = Builder::XmlMarkup.new
43
+ builder.InternetService(ecloud_xmlns) {
44
+ builder.Id(service_data[:id])
45
+ builder.Href(service_data[:href])
46
+ builder.Name(service_data[:name])
47
+ builder.Protocol(service_data[:protocol])
48
+ builder.Port(service_data[:port])
49
+ builder.Enabled(service_data[:enabled])
50
+ builder.Description(service_data[:description])
51
+ builder.Timeout(service_data[:timeout])
52
+ builder.RedirectURL(service_data[:redirect_url])
53
+ builder.PublicIpAddress {
54
+ builder.Id(ip_address_data[:id])
55
+ builder.Href(ip_address_data[:href])
56
+ builder.Name(ip_address_data[:name])
57
+ }
58
+ if monitor = service_data[:monitor]
59
+ generate_monitor_section(builder, monitor)
60
+ end
61
+ if service_data[:backup_service_uri]
62
+ builder.BackupService do
63
+ builder.Href(service_data[:backup_service_uri])
64
+ end
65
+ end
66
+ }
67
+ end
63
68
  end
64
69
 
65
70
  class Mock
@@ -71,17 +76,24 @@ module Fog
71
76
  #
72
77
 
73
78
  def configure_internet_service(internet_service_uri, service_data, ip_address_data)
79
+ service_data = service_data.dup
80
+
74
81
  validate_internet_service_data(service_data, true)
75
82
 
76
83
  validate_public_ip_address_data(ip_address_data)
77
84
 
78
85
  internet_service_uri = ensure_unparsed(internet_service_uri)
79
86
 
87
+ backup_service_uri = service_data.delete(:backup_service_uri)
88
+ backup_service = backup_service_uri && mock_data.backup_internet_service_from_href(backup_service_uri)
89
+
80
90
  xml = nil
81
91
 
82
- if public_ip_internet_service = mock_data.public_ip_internet_service_from_href(internet_service_uri)
92
+ if (public_ip_internet_service = mock_data.public_ip_internet_service_from_href(internet_service_uri)) &&
93
+ (backup_service_uri.nil? || backup_service)
83
94
  public_ip_internet_service.update(service_data.reject {|k, v| [:id, :href].include?(k) })
84
- xml = generate_internet_service_response(public_ip_internet_service)
95
+ public_ip_internet_service[:backup_service] = backup_service
96
+ xml = generate_internet_service(Builder::XmlMarkup.new, public_ip_internet_service, true)
85
97
  end
86
98
 
87
99
  if xml