fog 0.0.77 → 0.0.78

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/Gemfile.lock +2 -2
  2. data/fog.gemspec +59 -48
  3. data/lib/fog.rb +2 -1
  4. data/lib/fog/aws/models/ec2/snapshot.rb +3 -1
  5. data/lib/fog/aws/models/ec2/volume.rb +4 -2
  6. data/lib/fog/aws/s3.rb +1 -1
  7. data/lib/fog/deprecation.rb +14 -0
  8. data/lib/fog/terremark.rb +7 -220
  9. data/lib/fog/terremark/bin.rb +24 -14
  10. data/lib/fog/terremark/ecloud.rb +51 -0
  11. data/lib/fog/terremark/models/shared/address.rb +29 -0
  12. data/lib/fog/terremark/models/shared/addresses.rb +49 -0
  13. data/lib/fog/terremark/models/shared/network.rb +30 -0
  14. data/lib/fog/terremark/models/shared/networks.rb +52 -0
  15. data/lib/fog/terremark/models/shared/server.rb +57 -0
  16. data/lib/fog/terremark/models/shared/servers.rb +55 -0
  17. data/lib/fog/terremark/models/shared/task.rb +43 -0
  18. data/lib/fog/terremark/models/shared/tasks.rb +58 -0
  19. data/lib/fog/terremark/parser.rb +18 -0
  20. data/lib/fog/terremark/parsers/shared/get_catalog.rb +46 -0
  21. data/lib/fog/terremark/parsers/shared/get_catalog_item.rb +46 -0
  22. data/lib/fog/terremark/parsers/shared/get_internet_services.rb +60 -0
  23. data/lib/fog/terremark/parsers/{get_node_services.rb → shared/get_node_services.rb} +10 -11
  24. data/lib/fog/terremark/parsers/shared/get_organization.rb +47 -0
  25. data/lib/fog/terremark/parsers/shared/get_organizations.rb +27 -0
  26. data/lib/fog/terremark/parsers/shared/get_public_ips.rb +30 -0
  27. data/lib/fog/terremark/parsers/shared/get_tasks_list.rb +52 -0
  28. data/lib/fog/terremark/parsers/shared/get_vapp_template.rb +46 -0
  29. data/lib/fog/terremark/parsers/shared/get_vdc.rb +108 -0
  30. data/lib/fog/terremark/parsers/shared/instantiate_vapp_template.rb +41 -0
  31. data/lib/fog/terremark/parsers/shared/internet_service.rb +65 -0
  32. data/lib/fog/terremark/parsers/shared/network.rb +51 -0
  33. data/lib/fog/terremark/parsers/shared/node_service.rb +32 -0
  34. data/lib/fog/terremark/parsers/shared/public_ip.rb +26 -0
  35. data/lib/fog/terremark/parsers/shared/task.rb +40 -0
  36. data/lib/fog/terremark/parsers/shared/vapp.rb +47 -0
  37. data/lib/fog/terremark/requests/shared/add_internet_service.rb +63 -0
  38. data/lib/fog/terremark/requests/shared/add_node_service.rb +63 -0
  39. data/lib/fog/terremark/requests/shared/create_internet_service.rb +63 -0
  40. data/lib/fog/terremark/requests/shared/delete_internet_service.rb +42 -0
  41. data/lib/fog/terremark/requests/shared/delete_node_service.rb +42 -0
  42. data/lib/fog/terremark/requests/shared/delete_public_ip.rb +30 -0
  43. data/lib/fog/terremark/requests/shared/delete_vapp.rb +42 -0
  44. data/lib/fog/terremark/requests/shared/deploy_vapp.rb +43 -0
  45. data/lib/fog/terremark/requests/shared/get_catalog.rb +40 -0
  46. data/lib/fog/terremark/requests/shared/get_catalog_item.rb +43 -0
  47. data/lib/fog/terremark/requests/shared/get_internet_services.rb +43 -0
  48. data/lib/fog/terremark/requests/shared/get_network.rb +37 -0
  49. data/lib/fog/terremark/requests/shared/get_node_services.rb +38 -0
  50. data/lib/fog/terremark/requests/shared/get_organization.rb +42 -0
  51. data/lib/fog/terremark/requests/shared/get_organizations.rb +39 -0
  52. data/lib/fog/terremark/requests/shared/get_public_ip.rb +41 -0
  53. data/lib/fog/terremark/requests/shared/get_public_ips.rb +41 -0
  54. data/lib/fog/terremark/requests/shared/get_task.rb +47 -0
  55. data/lib/fog/terremark/requests/shared/get_tasks_list.rb +40 -0
  56. data/lib/fog/terremark/requests/shared/get_vapp.rb +50 -0
  57. data/lib/fog/terremark/requests/shared/get_vapp_template.rb +43 -0
  58. data/lib/fog/terremark/requests/shared/get_vdc.rb +43 -0
  59. data/lib/fog/terremark/requests/shared/instantiate_vapp_template.rb +79 -0
  60. data/lib/fog/terremark/requests/shared/power_off.rb +43 -0
  61. data/lib/fog/terremark/requests/shared/power_on.rb +43 -0
  62. data/lib/fog/terremark/requests/shared/reset.rb +43 -0
  63. data/lib/fog/terremark/requests/shared/shutdown.rb +43 -0
  64. data/lib/fog/terremark/shared.rb +139 -0
  65. data/lib/fog/terremark/vcloud.rb +98 -0
  66. metadata +60 -49
  67. data/lib/fog/terremark/models/server.rb +0 -56
  68. data/lib/fog/terremark/models/servers.rb +0 -53
  69. data/lib/fog/terremark/models/task.rb +0 -41
  70. data/lib/fog/terremark/models/tasks.rb +0 -56
  71. data/lib/fog/terremark/parsers/get_catalog.rb +0 -44
  72. data/lib/fog/terremark/parsers/get_catalog_item.rb +0 -44
  73. data/lib/fog/terremark/parsers/get_internet_services.rb +0 -58
  74. data/lib/fog/terremark/parsers/get_organization.rb +0 -45
  75. data/lib/fog/terremark/parsers/get_organizations.rb +0 -26
  76. data/lib/fog/terremark/parsers/get_public_ips.rb +0 -28
  77. data/lib/fog/terremark/parsers/get_tasks_list.rb +0 -50
  78. data/lib/fog/terremark/parsers/get_vapp_template.rb +0 -44
  79. data/lib/fog/terremark/parsers/get_vdc.rb +0 -106
  80. data/lib/fog/terremark/parsers/instantiate_vapp_template.rb +0 -39
  81. data/lib/fog/terremark/parsers/internet_service.rb +0 -63
  82. data/lib/fog/terremark/parsers/node_service.rb +0 -30
  83. data/lib/fog/terremark/parsers/public_ip.rb +0 -24
  84. data/lib/fog/terremark/parsers/task.rb +0 -38
  85. data/lib/fog/terremark/parsers/vapp.rb +0 -45
  86. data/lib/fog/terremark/requests/add_internet_service.rb +0 -61
  87. data/lib/fog/terremark/requests/add_node_service.rb +0 -61
  88. data/lib/fog/terremark/requests/create_internet_service.rb +0 -61
  89. data/lib/fog/terremark/requests/delete_internet_service.rb +0 -40
  90. data/lib/fog/terremark/requests/delete_node_service.rb +0 -40
  91. data/lib/fog/terremark/requests/delete_public_ip.rb +0 -28
  92. data/lib/fog/terremark/requests/delete_vapp.rb +0 -40
  93. data/lib/fog/terremark/requests/deploy_vapp.rb +0 -41
  94. data/lib/fog/terremark/requests/get_catalog.rb +0 -38
  95. data/lib/fog/terremark/requests/get_catalog_item.rb +0 -41
  96. data/lib/fog/terremark/requests/get_internet_services.rb +0 -41
  97. data/lib/fog/terremark/requests/get_node_services.rb +0 -36
  98. data/lib/fog/terremark/requests/get_organization.rb +0 -40
  99. data/lib/fog/terremark/requests/get_organizations.rb +0 -37
  100. data/lib/fog/terremark/requests/get_public_ip.rb +0 -35
  101. data/lib/fog/terremark/requests/get_public_ips.rb +0 -35
  102. data/lib/fog/terremark/requests/get_task.rb +0 -45
  103. data/lib/fog/terremark/requests/get_tasks_list.rb +0 -38
  104. data/lib/fog/terremark/requests/get_vapp.rb +0 -48
  105. data/lib/fog/terremark/requests/get_vapp_template.rb +0 -41
  106. data/lib/fog/terremark/requests/get_vdc.rb +0 -41
  107. data/lib/fog/terremark/requests/instantiate_vapp_template.rb +0 -77
  108. data/lib/fog/terremark/requests/power_off.rb +0 -41
  109. data/lib/fog/terremark/requests/power_on.rb +0 -41
  110. data/lib/fog/terremark/requests/reset.rb +0 -41
  111. data/lib/fog/terremark/requests/shutdown.rb +0 -41
@@ -1,35 +1,45 @@
1
1
  module Terremark
2
2
  class << self
3
- if Fog.credentials[:terremark_password] && Fog.credentials[:terremark_username]
3
+ if (Fog::Terremark::ECLOUD_OPTIONS.all? { |option| Fog.credentials.has_key?(option) } ) ||
4
+ (Fog::Terremark::VCLOUD_OPTIONS.all? { |option| Fog.credentials.has_key?(option) } )
4
5
 
5
6
  def initialized?
6
7
  true
7
8
  end
8
9
 
9
- def terremark_service
10
- @terremark_service ||= begin
11
- Fog.credentials[:terremark_service] || :vcloud
10
+ def terremark_service(service)
11
+ case service
12
+ when :ecloud
13
+ Fog::Terremark::Ecloud
14
+ when :vcloud
15
+ Fog::Terremark::Vcloud
16
+ else
17
+ raise "Unsupported Terremark Service"
12
18
  end
13
19
  end
14
20
 
15
21
  def [](service)
16
22
  @@connections ||= Hash.new do |hash, key|
17
23
  credentials = Fog.credentials.reject do |k,v|
18
- ![:terremark_username, :terremark_password].include?(k)
24
+ case key
25
+ when :ecloud
26
+ !Fog::Terremark::ECLOUD_OPTIONS.include?(k)
27
+ when :vcloud
28
+ !Fog::Terremark::VCLOUD_OPTIONS.include?(k)
29
+ end
30
+ end
31
+ case key
32
+ when :ecloud
33
+ hash[key] = Fog::Terremark::Ecloud.new(credentials)
34
+ when :vcloud
35
+ hash[key] = Fog::Terremark::Vcloud.new(credentials)
36
+ else
37
+ raise "Unsupported Terremark Service"
19
38
  end
20
- hash[key] = Fog::Terremark.new(credentials.merge(:terremark_service => terremark_service))
21
39
  end
22
40
  @@connections[service]
23
41
  end
24
42
 
25
- def servers
26
- self[terremark_service].servers
27
- end
28
-
29
- def tasks
30
- self[terremark_service].tasks
31
- end
32
-
33
43
  else
34
44
 
35
45
  def initialized?
@@ -0,0 +1,51 @@
1
+ module Fog
2
+ module Terremark
3
+ module Ecloud
4
+
5
+ module Bin
6
+ end
7
+
8
+ extend Fog::Terremark::Shared
9
+
10
+ def self.new(options={})
11
+
12
+ unless @required
13
+ shared_requires
14
+ @required = true
15
+ end
16
+
17
+ check_shared_options(options)
18
+
19
+ if Fog.mocking?
20
+ Fog::Terremark::Ecloud::Mock.new(options)
21
+ else
22
+ Fog::Terremark::Ecloud::Real.new(options)
23
+ end
24
+ end
25
+
26
+ class Real
27
+
28
+ include Fog::Terremark::Shared::Real
29
+ include Fog::Terremark::Shared::Parser
30
+
31
+ def initialize(options={})
32
+ @terremark_password = options[:terremark_ecloud_password]
33
+ @terremark_username = options[:terremark_ecloud_username]
34
+ @host = options[:host] || "services.enterprisecloud.terremark.com"
35
+ @path = options[:path] || "/api/v0.8a-ext2.0"
36
+ @port = options[:port] || 443
37
+ @scheme = options[:scheme] || 'https'
38
+ @cookie = get_organizations.headers['Set-Cookie']
39
+ end
40
+
41
+ end
42
+
43
+ class Mock
44
+ include Fog::Terremark::Shared::Mock
45
+ include Fog::Terremark::Shared::Parser
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,29 @@
1
+ require 'fog/model'
2
+
3
+ module Fog
4
+ module Terremark
5
+ module Shared
6
+
7
+ class Address < Fog::Model
8
+
9
+ identity :id
10
+
11
+ attribute :ip, 'name'
12
+
13
+ def destroy
14
+ requires :id
15
+ connection.delete_public_ip(@id)
16
+ true
17
+ end
18
+
19
+ private
20
+
21
+ def href=(new_href)
22
+ @id = new_href.split('/').last.to_i
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,49 @@
1
+ module Fog
2
+ module Terremark
3
+ module Shared
4
+
5
+ module Mock
6
+ def addresses(options = {})
7
+ Fog::Terremark::Shared::Addresses.new(options.merge(:connection => self))
8
+ end
9
+ end
10
+
11
+ module Real
12
+ def addresses(options = {})
13
+ Fog::Terremark::Shared::Addresses.new(options.merge(:connection => self))
14
+ end
15
+ end
16
+
17
+ class Addresses < Fog::Collection
18
+
19
+ model Fog::Terremark::Shared::Address
20
+
21
+ def all
22
+ load(connection.get_public_ips(vdc_id).body['PublicIpAddresses'])
23
+ end
24
+
25
+ def get(ip_id)
26
+ if ip_id && ip = connection.get_public_ip(ip_id).body
27
+ new(ip)
28
+ elsif !ip_id
29
+ nil
30
+ end
31
+ rescue Excon::Errors::Forbidden
32
+ nil
33
+ end
34
+
35
+ def vdc_id
36
+ @vdc_id ||= connection.default_vdc_id
37
+ end
38
+
39
+ private
40
+
41
+ def vdc_id=(new_vdc_id)
42
+ @vdc_id = new_vdc_id
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,30 @@
1
+ require 'fog/model'
2
+
3
+ module Fog
4
+ module Terremark
5
+ module Shared
6
+
7
+ class Network < Fog::Model
8
+
9
+ identity :id
10
+
11
+ attribute :name
12
+ attribute :subnet
13
+ attribute :gateway
14
+ attribute :netmask
15
+ attribute :fencemode
16
+ attribute :links
17
+
18
+ private
19
+
20
+ def href=(new_href)
21
+ @id = new_href.split('/').last.to_i
22
+ end
23
+
24
+ def type=(new_type); end
25
+
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,52 @@
1
+ module Fog
2
+ module Terremark
3
+ module Shared
4
+
5
+ module Mock
6
+ def networks(options = {})
7
+ Fog::Terremark::Shared::Networks.new(options.merge(:connection => self))
8
+ end
9
+ end
10
+
11
+ module Real
12
+ def networks(options = {})
13
+ Fog::Terremark::Shared::Networks.new(options.merge(:connection => self))
14
+ end
15
+ end
16
+
17
+ class Networks < Fog::Collection
18
+
19
+ model Fog::Terremark::Shared::Network
20
+
21
+ def all
22
+ data = connection.get_vdc(vdc_id).body['AvailableNetworks'].map do |network|
23
+ connection.get_network(network["href"].split("/").last).body
24
+ end
25
+ load(data)
26
+ end
27
+
28
+ def get(network_id)
29
+ if network_id && network = connection.get_network(network_id).body
30
+ new(network)
31
+ elsif !network_id
32
+ nil
33
+ end
34
+ rescue Excon::Errors::Forbidden
35
+ nil
36
+ end
37
+
38
+ def vdc_id
39
+ @vdc_id ||= connection.default_vdc_id
40
+ end
41
+
42
+ private
43
+
44
+ def vdc_id=(new_vdc_id)
45
+ @vdc_id = new_vdc_id
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,57 @@
1
+ require 'fog/model'
2
+
3
+ module Fog
4
+ module Terremark
5
+ module Shared
6
+
7
+ class Server < Fog::Model
8
+
9
+ identity :id
10
+
11
+ attribute :name
12
+ attribute :status
13
+
14
+ def destroy
15
+ requires :id
16
+ data = connection.power_off(@id).body
17
+ task = connection.tasks.new(data)
18
+ task.wait_for { ready? }
19
+ connection.delete_vapp(@id)
20
+ true
21
+ end
22
+
23
+ # { '0' => 'Being created', '2' => 'Powered Off', '4' => 'Powered On'}
24
+ def ready?
25
+ @status == '2'
26
+ end
27
+
28
+ def reboot
29
+ requires :id
30
+ connection.reset(@id)
31
+ true
32
+ end
33
+
34
+ def save
35
+ requires :name
36
+ data = connection.instantiate_vapp(@name)
37
+ merge_attributes(data.body)
38
+ task = connection.deploy_vapp(@id)
39
+ task.wait_for { ready? }
40
+ task = connection.power_on(@id)
41
+ task.wait_for { ready? }
42
+ true
43
+ end
44
+
45
+ private
46
+
47
+ def href=(new_href)
48
+ @id = new_href.split('/').last.to_i
49
+ end
50
+
51
+ def type=(new_type); end
52
+
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,55 @@
1
+ require 'fog/collection'
2
+ require 'fog/terremark/models/shared/server'
3
+
4
+ module Fog
5
+ module Terremark
6
+ module Shared
7
+
8
+ module Mock
9
+ def servers(options = {})
10
+ Fog::Terremark::Shared::Servers.new(options.merge(:connection => self))
11
+ end
12
+ end
13
+
14
+ module Real
15
+ def servers(options = {})
16
+ Fog::Terremark::Shared::Servers.new(options.merge(:connection => self))
17
+ end
18
+ end
19
+
20
+ class Servers < Fog::Collection
21
+
22
+ model Fog::Terremark::Shared::Server
23
+
24
+ def all
25
+ data = connection.get_vdc(vdc_id).body['ResourceEntities'].select do |entity|
26
+ entity['type'] == 'application/vnd.vmware.vcloud.vApp+xml'
27
+ end
28
+ load(data)
29
+ end
30
+
31
+ def get(server_id)
32
+ if server_id && server = connection.get_vapp(server_id).body
33
+ new(server)
34
+ elsif !server_id
35
+ nil
36
+ end
37
+ rescue Excon::Errors::Forbidden
38
+ nil
39
+ end
40
+
41
+ def vdc_id
42
+ @vdc_id ||= connection.default_vdc_id
43
+ end
44
+
45
+ private
46
+
47
+ def vdc_id=(new_vdc_id)
48
+ @vdc_id = new_vdc_id
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,43 @@
1
+ require 'fog/model'
2
+
3
+ module Fog
4
+ module Terremark
5
+ module Shared
6
+
7
+ class Task < Fog::Model
8
+
9
+ identity :id
10
+
11
+ attribute :end_time, 'endTime'
12
+ attribute :owner, 'Owner'
13
+ attribute :result, 'Result'
14
+ attribute :start_time, 'startTime'
15
+ attribute :status
16
+
17
+ def initialize(attributes = {})
18
+ new_owner = attributes.delete('Owner')
19
+ new_result = attributes.delete('Result')
20
+ super
21
+ @owner = connection.parse(new_owner)
22
+ if new_result
23
+ @result = connection.parse(new_result)
24
+ end
25
+ end
26
+
27
+ def ready?
28
+ @status == 'success'
29
+ end
30
+
31
+ private
32
+
33
+ def href=(new_href)
34
+ @id = new_href.split('/').last.to_i
35
+ end
36
+
37
+ def type=(new_type); end
38
+
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,58 @@
1
+ require 'fog/collection'
2
+ require 'fog/terremark/models/shared/server'
3
+
4
+ module Fog
5
+ module Terremark
6
+ module Shared
7
+
8
+ module Mock
9
+ def tasks
10
+ Fog::Terremark::Shared::Tasks.new(:connection => self)
11
+ end
12
+ end
13
+
14
+ module Real
15
+ def tasks
16
+ Fog::Terremark::Shared::Tasks.new(:connection => self)
17
+ end
18
+ end
19
+
20
+ class Tasks < Fog::Collection
21
+
22
+ model Fog::Terremark::Shared::Task
23
+
24
+ def all
25
+ data = connection.get_tasks_list(task_list_id).body['Tasks']
26
+ load(data)
27
+ end
28
+
29
+ def get(task_id)
30
+ if task_id && task = connection.get_task(task_id).body
31
+ new(task)
32
+ elsif !task_id
33
+ nil
34
+ end
35
+ rescue Excon::Errors::Forbidden
36
+ nil
37
+ end
38
+
39
+ def task_list_id
40
+ @task_list_id ||=
41
+ if connection.default_organization_id && organization = connection.get_organization(connection.default_organization_id).body
42
+ organization['Links'].detect {|link| link['type'] == 'application/vnd.vmware.vcloud.tasksList+xml'}['href'].split('/').last.to_i
43
+ else
44
+ nil
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def task_list_id=(new_task_list_id)
51
+ @task_list_id = new_task_list_id
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
58
+ end