fog-terremark 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rubocop.yml +20 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +17 -0
  7. data/CONTRIBUTING.md +18 -0
  8. data/CONTRIBUTORS.md +10 -0
  9. data/Gemfile +4 -0
  10. data/LICENSE.md +20 -0
  11. data/README.md +36 -0
  12. data/Rakefile +11 -0
  13. data/fog-terremark.gemspec +34 -0
  14. data/gemfiles/Gemfile.1.9.2- +8 -0
  15. data/gemfiles/Gemfile.1.9.3+ +7 -0
  16. data/lib/fog/compute/terremark.rb +62 -0
  17. data/lib/fog/compute/terremark/common.rb +18 -0
  18. data/lib/fog/compute/terremark/mock.rb +144 -0
  19. data/lib/fog/compute/terremark/models/address.rb +23 -0
  20. data/lib/fog/compute/terremark/models/addresses.rb +33 -0
  21. data/lib/fog/compute/terremark/models/image.rb +17 -0
  22. data/lib/fog/compute/terremark/models/images.rb +26 -0
  23. data/lib/fog/compute/terremark/models/internetservice.rb +60 -0
  24. data/lib/fog/compute/terremark/models/internetservices.rb +24 -0
  25. data/lib/fog/compute/terremark/models/network.rb +29 -0
  26. data/lib/fog/compute/terremark/models/networks.rb +37 -0
  27. data/lib/fog/compute/terremark/models/nodeservice.rb +44 -0
  28. data/lib/fog/compute/terremark/models/nodeservices.rb +14 -0
  29. data/lib/fog/compute/terremark/models/server.rb +201 -0
  30. data/lib/fog/compute/terremark/models/servers.rb +35 -0
  31. data/lib/fog/compute/terremark/models/task.rb +44 -0
  32. data/lib/fog/compute/terremark/models/tasks.rb +41 -0
  33. data/lib/fog/compute/terremark/models/vdc.rb +39 -0
  34. data/lib/fog/compute/terremark/models/vdcs.rb +36 -0
  35. data/lib/fog/compute/terremark/parser.rb +16 -0
  36. data/lib/fog/compute/terremark/real.rb +67 -0
  37. data/lib/fog/compute/terremark/requests/add_internet_service.rb +54 -0
  38. data/lib/fog/compute/terremark/requests/add_node_service.rb +51 -0
  39. data/lib/fog/compute/terremark/requests/configure_vapp.rb +58 -0
  40. data/lib/fog/compute/terremark/requests/create_internet_service.rb +57 -0
  41. data/lib/fog/compute/terremark/requests/delete_internet_service.rb +21 -0
  42. data/lib/fog/compute/terremark/requests/delete_node_service.rb +21 -0
  43. data/lib/fog/compute/terremark/requests/delete_public_ip.rb +21 -0
  44. data/lib/fog/compute/terremark/requests/delete_vapp.rb +20 -0
  45. data/lib/fog/compute/terremark/requests/deploy_vapp.rb +33 -0
  46. data/lib/fog/compute/terremark/requests/get_catalog.rb +30 -0
  47. data/lib/fog/compute/terremark/requests/get_catalog_item.rb +33 -0
  48. data/lib/fog/compute/terremark/requests/get_internet_services.rb +32 -0
  49. data/lib/fog/compute/terremark/requests/get_keys_list.rb +32 -0
  50. data/lib/fog/compute/terremark/requests/get_network.rb +70 -0
  51. data/lib/fog/compute/terremark/requests/get_network_ips.rb +29 -0
  52. data/lib/fog/compute/terremark/requests/get_node_services.rb +29 -0
  53. data/lib/fog/compute/terremark/requests/get_organization.rb +89 -0
  54. data/lib/fog/compute/terremark/requests/get_organizations.rb +45 -0
  55. data/lib/fog/compute/terremark/requests/get_public_ip.rb +31 -0
  56. data/lib/fog/compute/terremark/requests/get_public_ips.rb +69 -0
  57. data/lib/fog/compute/terremark/requests/get_task.rb +37 -0
  58. data/lib/fog/compute/terremark/requests/get_tasks_list.rb +30 -0
  59. data/lib/fog/compute/terremark/requests/get_vapp.rb +40 -0
  60. data/lib/fog/compute/terremark/requests/get_vapp_template.rb +33 -0
  61. data/lib/fog/compute/terremark/requests/get_vdc.rb +153 -0
  62. data/lib/fog/compute/terremark/requests/instantiate_vapp_template.rb +75 -0
  63. data/lib/fog/compute/terremark/requests/power_off.rb +33 -0
  64. data/lib/fog/compute/terremark/requests/power_on.rb +33 -0
  65. data/lib/fog/compute/terremark/requests/power_reset.rb +33 -0
  66. data/lib/fog/compute/terremark/requests/power_shutdown.rb +22 -0
  67. data/lib/fog/parsers/terremark.rb +26 -0
  68. data/lib/fog/parsers/terremark/base.rb +23 -0
  69. data/lib/fog/parsers/terremark/get_catalog.rb +31 -0
  70. data/lib/fog/parsers/terremark/get_catalog_item.rb +30 -0
  71. data/lib/fog/parsers/terremark/get_internet_services.rb +55 -0
  72. data/lib/fog/parsers/terremark/get_keys_list.rb +36 -0
  73. data/lib/fog/parsers/terremark/get_network_ips.rb +22 -0
  74. data/lib/fog/parsers/terremark/get_node_services.rb +30 -0
  75. data/lib/fog/parsers/terremark/get_organization.rb +46 -0
  76. data/lib/fog/parsers/terremark/get_organizations.rb +27 -0
  77. data/lib/fog/parsers/terremark/get_public_ips.rb +24 -0
  78. data/lib/fog/parsers/terremark/get_tasks_list.rb +33 -0
  79. data/lib/fog/parsers/terremark/get_vapp_template.rb +29 -0
  80. data/lib/fog/parsers/terremark/get_vdc.rb +85 -0
  81. data/lib/fog/parsers/terremark/instantiate_vapp_template.rb +24 -0
  82. data/lib/fog/parsers/terremark/internet_service.rb +56 -0
  83. data/lib/fog/parsers/terremark/network.rb +37 -0
  84. data/lib/fog/parsers/terremark/node_service.rb +26 -0
  85. data/lib/fog/parsers/terremark/public_ip.rb +20 -0
  86. data/lib/fog/parsers/terremark/task.rb +23 -0
  87. data/lib/fog/parsers/terremark/vapp.rb +59 -0
  88. data/lib/fog/terremark.rb +17 -0
  89. data/lib/fog/terremark/vcloud.rb +27 -0
  90. data/lib/fog/terremark/vcloud/mock.rb +24 -0
  91. data/lib/fog/terremark/vcloud/real.rb +66 -0
  92. data/lib/fog/terremark/version.rb +5 -0
  93. data/spec/minitest_helper.rb +31 -0
  94. metadata +251 -0
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Address < Fog::Model
5
+ identity :id
6
+
7
+ attribute :ip, :aliases => 'name'
8
+
9
+ def destroy
10
+ requires :id
11
+ service.delete_public_ip(id)
12
+ true
13
+ end
14
+
15
+ private
16
+
17
+ def href=(new_href)
18
+ self.id = new_href.split('/').last.to_i
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Addresses < Fog::Collection
5
+ model Fog::Compute::Terremark::Address
6
+
7
+ def all
8
+ load(service.get_public_ips(vdc_id).body['PublicIpAddresses'])
9
+ end
10
+
11
+ def get(ip_id)
12
+ if ip_id && ip = service.get_public_ip(ip_id).body
13
+ new(ip)
14
+ elsif !ip_id
15
+ nil
16
+ end
17
+ rescue Excon::Errors::Forbidden
18
+ nil
19
+ end
20
+
21
+ def vdc_id
22
+ @vdc_id ||= service.default_vdc_id
23
+ end
24
+
25
+ private
26
+
27
+ def vdc_id=(new_vdc_id)
28
+ @vdc_id = new_vdc_id
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Image < Fog::Model
5
+ identity :id
6
+
7
+ attribute :name
8
+ end
9
+
10
+ private
11
+
12
+ def href=(new_href)
13
+ self.id = new_href.split('/').last.to_i
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Images < Fog::Collection
5
+ model Fog::Compute::Terremark::Image
6
+
7
+ def all
8
+ data = service.get_catalog(vdc_id).body['CatalogItems'].select do |entity|
9
+ entity['type'] == "application/vnd.vmware.vcloud.catalogItem+xml"
10
+ end
11
+ load(data)
12
+ end
13
+
14
+ def vdc_id
15
+ @vdc_id ||= service.default_vdc_id
16
+ end
17
+
18
+ private
19
+
20
+ def vdc_id=(new_vdc_id)
21
+ @vdc_id = new_vdc_id
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,60 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class InternetService < Fog::Model
5
+ identity :Id
6
+
7
+ attribute :Name
8
+ attribute :Port
9
+ attribute :Protocol
10
+ attribute :Description
11
+ attribute :PublicIpAddress
12
+ attribute :public_ip_address_id
13
+
14
+ def destroy(delete_public_ip = true)
15
+ service.delete_internet_service(self.Id)
16
+ service.delete_public_ip(self.PublicIpAddress["Id"]) if delete_public_ip
17
+ true
18
+ end
19
+
20
+ def save
21
+ requires :Name, :Protocol, :Port
22
+ if !public_ip_address_id
23
+ #Create the first internet service and allocate public IP
24
+ data = service.create_internet_service(
25
+ vdc = service.default_vdc_id,
26
+ name = self.Name,
27
+ protocol = self.Protocol,
28
+ port = self.Port,
29
+ options = {
30
+ 'Enabled' => 'true',
31
+ "Description" => self.Name
32
+ }
33
+ )
34
+ else
35
+ #create additional services to existing Public IP
36
+ data = service.add_internet_service(
37
+ ip_id = public_ip_address_id,
38
+ name = self.Name,
39
+ protocol = self.Protocol,
40
+ port = self.Port,
41
+ options = {
42
+ 'Enabled' => 'true',
43
+ "Description" => self.Name
44
+ }
45
+ )
46
+ end
47
+ merge_attributes(data.body)
48
+ true
49
+ end
50
+ private
51
+
52
+ attr_writer :type, :size, :Links
53
+
54
+ def href=(new_href)
55
+ self.id = new_href.split('/').last.to_i
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class InternetServices < Fog::Collection
5
+ model Fog::Compute::Terremark::InternetService
6
+
7
+ def all
8
+ data = service.get_internet_services(vdc_id).body["InternetServices"]
9
+ load(data)
10
+ end
11
+
12
+ def get(service_id)
13
+ service.get_internet_services(vdc_id)
14
+ internet_service = services.body["InternetServices"].select {|item| item["Id"] == service_id}
15
+ new(internet_service)
16
+ end
17
+
18
+ def vdc_id
19
+ @vdc_id ||= service.default_vdc_id
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Network < Fog::Model
5
+ identity :id
6
+
7
+ attribute :name
8
+ attribute :subnet
9
+ attribute :gateway
10
+ attribute :netmask
11
+ attribute :fencemode
12
+ attribute :links
13
+
14
+ def ips
15
+ #Until there is a real models for these ?
16
+ service.get_network_ips(id).body['IpAddresses']
17
+ end
18
+
19
+ private
20
+
21
+ def href=(new_href)
22
+ self.id = new_href.split('/').last.to_i
23
+ end
24
+
25
+ def type=(_new_type); end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Networks < Fog::Collection
5
+ model Fog::Compute::Terremark::Network
6
+
7
+ def all
8
+ data = service.get_vdc(vdc_id).body['AvailableNetworks'].map do |network|
9
+ service.get_network(network["href"].split("/").last).body
10
+ end
11
+ load(data)
12
+ end
13
+
14
+ def get(network_id)
15
+ network = service.get_network(network_id).body
16
+ if network_id && network
17
+ new(network)
18
+ elsif !network_id
19
+ nil
20
+ end
21
+ rescue Excon::Errors::Forbidden
22
+ nil
23
+ end
24
+
25
+ def vdc_id
26
+ @vdc_id ||= service.default_vdc_id
27
+ end
28
+
29
+ private
30
+
31
+ def vdc_id=(new_vdc_id)
32
+ @vdc_id = new_vdc_id
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,44 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class NodeService < Fog::Model
5
+ identity :Id
6
+ attribute :Name
7
+ attribute :Href
8
+ attribute :Port
9
+ attribute :Description
10
+ attribute :IpAddress
11
+ attribute :Enabled
12
+ attribute :InternetServiceId
13
+
14
+ def destroy
15
+ service.delete_node_service(self.Id)
16
+ end
17
+
18
+ def save
19
+ requires :Name, :Port, :InternetServiceId
20
+ data = service.add_node_service(
21
+ service_id = self.InternetServiceId,
22
+ ip = self.IpAddress,
23
+ name = self.Name,
24
+ port = self.Port,
25
+ options = {"Enabled" => 'true',
26
+ "Description" => self.Name,
27
+ }
28
+
29
+ )
30
+ merge_attributes(data.body)
31
+ true
32
+ end
33
+
34
+ private
35
+
36
+ attr_writer :type, :size, :Links
37
+
38
+ def href=(new_href)
39
+ self.id = new_href.split('/').last.to_i
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,14 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class NodeServices < Fog::Collection
5
+ model Fog::Compute::Terremark::NodeService
6
+
7
+ def all(internet_service_id)
8
+ data = service.get_node_services(internet_service_id).body["NodeServices"]
9
+ load(data)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,201 @@
1
+ module Fog
2
+ module Compute
3
+ module Terremark
4
+ class Server < Fog::Model
5
+ module VAppStatus
6
+ BEING_CREATED = "0"
7
+ BEING_DEPLOYED = "1"
8
+ POWERED_OFF = "2"
9
+ POWERED_ON = "4"
10
+ end
11
+
12
+ identity :id
13
+
14
+ attribute :name
15
+ attribute :image
16
+ attribute :vcpus
17
+ attribute :memory
18
+ attribute :sshkeyFingerPrint
19
+ attribute :powerOn
20
+ attribute :status
21
+ attribute :OperatingSystem
22
+ attribute :VirtualHardware
23
+ attribute :IpAddress
24
+
25
+ def reload
26
+ merge_attributes(service.get_vapp(id).body)
27
+ end
28
+
29
+ def destroy
30
+ case self.status
31
+ when VAppStatus::BEING_CREATED, VAppStatus::BEING_DEPLOYED
32
+ return false
33
+ when VAppStatus::POWERED_ON
34
+ service.power_off(self.id).body
35
+ wait_for { off? }
36
+ end
37
+ #Failsafe .. Always check if we are ready
38
+ wait_for { ready? }
39
+ service.delete_vapp(self.id)
40
+ true
41
+ end
42
+
43
+ def PublicIpAddress
44
+ @PublicIpAddress ||=
45
+ if internet_services.size > 0
46
+ internet_services[0].PublicIpAddress["Name"]
47
+ end
48
+ @PublicIpAddress
49
+ end
50
+
51
+ def internet_services
52
+ @internet_services ||= service.internetservices.all.select { |item| item.Name == self.name }
53
+ end
54
+
55
+ def delete_internet_services
56
+ #Find the internet service
57
+
58
+ while (inet_service = internet_services.pop) do
59
+
60
+ nodes = service.nodeservices.all(inet_service.Id)
61
+ #Delete all the associated nodes
62
+ nodes.select { |item| item.destroy }
63
+ #Clear out the services
64
+ inet_service.destroy(delete_public_ip = !(internet_services.size > 0))
65
+ end
66
+ true
67
+ end
68
+
69
+ # { '0' => 'Being created', '2' => 'Powered Off', '4' => 'Powered On'}
70
+ def ready?
71
+ status == VAppStatus::POWERED_OFF
72
+ end
73
+
74
+ def on?
75
+ status == VAppStatus::POWERED_ON
76
+ end
77
+
78
+ def off?
79
+ status == VAppStatus::POWERED_OFF
80
+ end
81
+
82
+ def power_on(_options = {})
83
+ requires :id
84
+ begin
85
+ service.power_on(id)
86
+ rescue Excon::Errors::InternalServerError => e
87
+ #Frankly we shouldn't get here ...
88
+ raise e unless e.to_s =~ /because it is already powered on/
89
+ end
90
+ true
91
+ end
92
+
93
+ def power_off
94
+ requires :id
95
+ begin
96
+ service.power_off(id)
97
+ rescue Excon::Errors::InternalServerError => e
98
+ #Frankly we shouldn't get here ...
99
+ raise e unless e.to_s =~ /because it is already powered off/
100
+ end
101
+ true
102
+ end
103
+
104
+ def shutdown
105
+ requires :id
106
+ begin
107
+ service.power_shutdown(id)
108
+ rescue Excon::Errors::InternalServerError => e
109
+ #Frankly we shouldn't get here ...
110
+ raise e unless e.to_s =~ /because it is already powered off/
111
+ end
112
+ true
113
+ end
114
+
115
+ def power_reset
116
+ requires :id
117
+ service.power_reset(id)
118
+ true
119
+ end
120
+
121
+ def graceful_restart
122
+ requires :id
123
+ shutdown
124
+ wait_for { off? }
125
+ power_on
126
+ end
127
+
128
+ def create_internet_services(internet_spec)
129
+ public_ip_info = nil
130
+ internet_service_id = nil
131
+ internet_spec.each do |proto, ports|
132
+ for port in ports
133
+ if not public_ip_info
134
+ #Create the first internet service and allocate public IP
135
+ inet_services = service.internetservices.create({
136
+ "Name" => self.name,
137
+ "Protocol" => proto,
138
+ "Port" => port,
139
+ })
140
+ internet_service_id = inet_services.Id
141
+ public_ip_info = inet_services.PublicIpAddress
142
+
143
+ else
144
+ #create additional services to existing Public IP
145
+ inet_services = service.internetservices.create({
146
+ "public_ip_address_id" => public_ip_info["Id"],
147
+ "Name" => self.name,
148
+ "Protocol" => proto,
149
+ "Port" => port,
150
+ }
151
+ )
152
+ internet_service_id = inet_services.Id
153
+ end
154
+
155
+ #Create the associate node service to the server
156
+ service.nodeservices.create({"Name" => self.name,
157
+ "IpAddress" => self.IpAddress,
158
+ "Port" => port,
159
+ "InternetServiceId" => internet_service_id
160
+ })
161
+ end
162
+ end
163
+ true
164
+ end
165
+
166
+ def save
167
+ requires :name
168
+ if powerOn
169
+ end
170
+ data = service.instantiate_vapp_template(
171
+ server_name=name,
172
+ vapp_template=image,
173
+ options={
174
+ 'ssh_key_fingerprint' => sshkeyFingerPrint,
175
+ 'cpus' => vcpus,
176
+ 'memory' => memory
177
+ })
178
+
179
+ merge_attributes(data.body)
180
+ wait_for { ready? }
181
+
182
+ #Optional, incase further configuration required.
183
+ if powerOn
184
+ power_on
185
+ wait_for { ready? }
186
+ end
187
+
188
+ true
189
+ end
190
+
191
+ private
192
+
193
+ attr_writer :type, :size, :Links
194
+
195
+ def href=(new_href)
196
+ self.id = new_href.split('/').last.to_i
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end