fog 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. data/Rakefile +106 -17
  2. data/bin/fog +1 -1
  3. data/changelog.txt +17 -0
  4. data/docs/_layouts/default.html +2 -1
  5. data/docs/about/contributing.markdown +1 -1
  6. data/docs/compute/index.markdown +104 -0
  7. data/docs/index.markdown +1 -0
  8. data/docs/storage/index.markdown +17 -0
  9. data/fog.gemspec +3 -2
  10. data/lib/fog.rb +1 -1
  11. data/lib/fog/aws/elb.rb +1 -0
  12. data/lib/fog/aws/iam.rb +1 -0
  13. data/lib/fog/aws/rds.rb +1 -0
  14. data/lib/fog/aws/requests/simpledb/batch_put_attributes.rb +5 -5
  15. data/lib/fog/aws/requests/simpledb/create_domain.rb +1 -1
  16. data/lib/fog/aws/requests/simpledb/delete_attributes.rb +3 -3
  17. data/lib/fog/aws/requests/simpledb/delete_domain.rb +1 -1
  18. data/lib/fog/aws/requests/simpledb/domain_metadata.rb +1 -1
  19. data/lib/fog/aws/requests/simpledb/get_attributes.rb +5 -5
  20. data/lib/fog/aws/requests/simpledb/list_domains.rb +2 -2
  21. data/lib/fog/aws/requests/simpledb/put_attributes.rb +6 -6
  22. data/lib/fog/aws/ses.rb +1 -0
  23. data/lib/fog/aws/simpledb.rb +8 -2
  24. data/lib/fog/bin.rb +2 -2
  25. data/lib/fog/cdn/aws.rb +8 -2
  26. data/lib/fog/cdn/rackspace.rb +8 -2
  27. data/lib/fog/compute/aws.rb +12 -3
  28. data/lib/fog/compute/bluebox.rb +8 -2
  29. data/lib/fog/compute/ecloud.rb +9 -4
  30. data/lib/fog/compute/go_grid.rb +8 -2
  31. data/lib/fog/compute/linode.rb +38 -6
  32. data/lib/fog/compute/models/aws/volumes.rb +4 -4
  33. data/lib/fog/compute/models/bluebox/server.rb +3 -3
  34. data/lib/fog/compute/models/brightbox/server.rb +9 -9
  35. data/lib/fog/compute/models/linode/data_center.rb +12 -0
  36. data/lib/fog/compute/models/linode/data_centers.rb +26 -0
  37. data/lib/fog/compute/models/linode/disk.rb +62 -0
  38. data/lib/fog/compute/models/linode/disks.rb +40 -0
  39. data/lib/fog/compute/models/linode/flavor.rb +23 -0
  40. data/lib/fog/compute/models/linode/flavors.rb +32 -0
  41. data/lib/fog/compute/models/linode/image.rb +14 -0
  42. data/lib/fog/compute/models/linode/images.rb +33 -0
  43. data/lib/fog/compute/models/linode/ip.rb +30 -0
  44. data/lib/fog/compute/models/linode/ips.rb +40 -0
  45. data/lib/fog/compute/models/linode/kernel.rb +12 -0
  46. data/lib/fog/compute/models/linode/kernels.rb +32 -0
  47. data/lib/fog/compute/models/linode/server.rb +88 -0
  48. data/lib/fog/compute/models/linode/servers.rb +32 -0
  49. data/lib/fog/compute/models/linode/stack_script.rb +13 -0
  50. data/lib/fog/compute/models/linode/stack_scripts.rb +32 -0
  51. data/lib/fog/compute/models/rackspace/server.rb +2 -2
  52. data/lib/fog/compute/models/slicehost/server.rb +2 -2
  53. data/lib/fog/compute/models/voxel/server.rb +3 -3
  54. data/lib/fog/compute/new_servers.rb +8 -2
  55. data/lib/fog/compute/rackspace.rb +8 -2
  56. data/lib/fog/compute/requests/aws/allocate_address.rb +4 -2
  57. data/lib/fog/compute/requests/aws/associate_address.rb +4 -2
  58. data/lib/fog/compute/requests/aws/attach_volume.rb +4 -2
  59. data/lib/fog/compute/requests/aws/authorize_security_group_ingress.rb +5 -3
  60. data/lib/fog/compute/requests/aws/create_image.rb +2 -1
  61. data/lib/fog/compute/requests/aws/create_key_pair.rb +4 -2
  62. data/lib/fog/compute/requests/aws/create_security_group.rb +5 -3
  63. data/lib/fog/compute/requests/aws/create_snapshot.rb +6 -4
  64. data/lib/fog/compute/requests/aws/create_tags.rb +7 -5
  65. data/lib/fog/compute/requests/aws/create_volume.rb +4 -2
  66. data/lib/fog/compute/requests/aws/delete_key_pair.rb +3 -1
  67. data/lib/fog/compute/requests/aws/delete_security_group.rb +4 -2
  68. data/lib/fog/compute/requests/aws/delete_snapshot.rb +3 -1
  69. data/lib/fog/compute/requests/aws/delete_tags.rb +5 -3
  70. data/lib/fog/compute/requests/aws/delete_volume.rb +4 -2
  71. data/lib/fog/compute/requests/aws/deregister_image.rb +2 -0
  72. data/lib/fog/compute/requests/aws/describe_addresses.rb +3 -1
  73. data/lib/fog/compute/requests/aws/describe_availability_zones.rb +2 -0
  74. data/lib/fog/compute/requests/aws/describe_images.rb +3 -1
  75. data/lib/fog/compute/requests/aws/describe_instances.rb +12 -10
  76. data/lib/fog/compute/requests/aws/describe_key_pairs.rb +3 -1
  77. data/lib/fog/compute/requests/aws/describe_regions.rb +2 -0
  78. data/lib/fog/compute/requests/aws/describe_reserved_instances.rb +2 -0
  79. data/lib/fog/compute/requests/aws/describe_reserved_instances_offerings.rb +2 -0
  80. data/lib/fog/compute/requests/aws/describe_security_groups.rb +3 -1
  81. data/lib/fog/compute/requests/aws/describe_snapshots.rb +5 -3
  82. data/lib/fog/compute/requests/aws/describe_tags.rb +2 -0
  83. data/lib/fog/compute/requests/aws/describe_volumes.rb +9 -7
  84. data/lib/fog/compute/requests/aws/detach_volume.rb +3 -1
  85. data/lib/fog/compute/requests/aws/disassociate_address.rb +4 -2
  86. data/lib/fog/compute/requests/aws/get_console_output.rb +3 -1
  87. data/lib/fog/compute/requests/aws/get_password_data.rb +15 -1
  88. data/lib/fog/compute/requests/aws/import_key_pair.rb +4 -2
  89. data/lib/fog/compute/requests/aws/modify_image_attributes.rb +4 -0
  90. data/lib/fog/compute/requests/aws/modify_snapshot_attribute.rb +4 -0
  91. data/lib/fog/compute/requests/aws/monitor_instances.rb +3 -1
  92. data/lib/fog/compute/requests/aws/reboot_instances.rb +4 -2
  93. data/lib/fog/compute/requests/aws/register_image.rb +4 -0
  94. data/lib/fog/compute/requests/aws/release_address.rb +3 -1
  95. data/lib/fog/compute/requests/aws/revoke_security_group_ingress.rb +3 -1
  96. data/lib/fog/compute/requests/aws/run_instances.rb +12 -6
  97. data/lib/fog/compute/requests/aws/start_instances.rb +2 -0
  98. data/lib/fog/compute/requests/aws/stop_instances.rb +2 -0
  99. data/lib/fog/compute/requests/aws/terminate_instances.rb +5 -3
  100. data/lib/fog/compute/requests/aws/unmonitor_instances.rb +3 -1
  101. data/lib/fog/compute/requests/go_grid/grid_image_get.rb +1 -1
  102. data/lib/fog/compute/requests/go_grid/grid_image_list.rb +1 -1
  103. data/lib/fog/compute/requests/linode/avail_datacenters.rb +1 -2
  104. data/lib/fog/compute/requests/linode/avail_distributions.rb +1 -2
  105. data/lib/fog/compute/requests/linode/avail_kernels.rb +6 -5
  106. data/lib/fog/compute/requests/linode/avail_linodeplans.rb +9 -3
  107. data/lib/fog/compute/requests/linode/avail_stackscripts.rb +3 -15
  108. data/lib/fog/compute/requests/linode/linode_boot.rb +15 -0
  109. data/lib/fog/compute/requests/linode/linode_config_create.rb +21 -0
  110. data/lib/fog/compute/requests/linode/linode_config_list.rb +18 -0
  111. data/lib/fog/compute/requests/linode/linode_create.rb +3 -4
  112. data/lib/fog/compute/requests/linode/linode_delete.rb +0 -1
  113. data/lib/fog/compute/requests/linode/linode_disk_create.rb +21 -0
  114. data/lib/fog/compute/requests/linode/linode_disk_createfromdistribution.rb +22 -0
  115. data/lib/fog/compute/requests/linode/linode_disk_createfromstackscript.rb +24 -0
  116. data/lib/fog/compute/requests/linode/linode_disk_delete.rb +19 -0
  117. data/lib/fog/compute/requests/linode/linode_disk_list.rb +19 -0
  118. data/lib/fog/compute/requests/linode/linode_ip_addprivate.rb +15 -0
  119. data/lib/fog/compute/requests/linode/linode_ip_list.rb +19 -0
  120. data/lib/fog/compute/requests/linode/linode_list.rb +0 -1
  121. data/lib/fog/compute/requests/linode/linode_reboot.rb +1 -2
  122. data/lib/fog/compute/requests/linode/linode_shutdown.rb +15 -0
  123. data/lib/fog/compute/requests/linode/linode_update.rb +15 -0
  124. data/lib/fog/compute/requests/linode/stackscript_list.rb +31 -0
  125. data/lib/fog/compute/requests/rackspace/confirm_resized_server.rb +3 -3
  126. data/lib/fog/compute/requests/rackspace/create_image.rb +2 -2
  127. data/lib/fog/compute/requests/rackspace/create_server.rb +2 -2
  128. data/lib/fog/compute/requests/rackspace/delete_image.rb +2 -2
  129. data/lib/fog/compute/requests/rackspace/delete_server.rb +2 -2
  130. data/lib/fog/compute/requests/rackspace/list_images_detail.rb +2 -2
  131. data/lib/fog/compute/requests/rackspace/list_servers_detail.rb +2 -2
  132. data/lib/fog/compute/requests/rackspace/resize_server.rb +4 -4
  133. data/lib/fog/compute/requests/rackspace/revert_resized_server.rb +4 -4
  134. data/lib/fog/compute/slicehost.rb +8 -2
  135. data/lib/fog/compute/storm_on_demand.rb +12 -1
  136. data/lib/fog/compute/voxel.rb +8 -2
  137. data/lib/fog/core/mock.rb +14 -1
  138. data/lib/fog/dns/aws.rb +8 -2
  139. data/lib/fog/dns/bluebox.rb +8 -2
  140. data/lib/fog/dns/dnsimple.rb +15 -3
  141. data/lib/fog/dns/linode.rb +8 -2
  142. data/lib/fog/dns/slicehost.rb +8 -2
  143. data/lib/fog/dns/zerigo.rb +8 -2
  144. data/lib/fog/providers/aws.rb +5 -10
  145. data/lib/fog/providers/linode.rb +0 -3
  146. data/lib/fog/storage.rb +6 -4
  147. data/lib/fog/storage/aws.rb +8 -2
  148. data/lib/fog/storage/google.rb +8 -2
  149. data/lib/fog/storage/local.rb +8 -2
  150. data/lib/fog/storage/models/aws/file.rb +0 -1
  151. data/lib/fog/storage/models/google/file.rb +1 -5
  152. data/lib/fog/storage/models/local/file.rb +1 -1
  153. data/lib/fog/storage/models/rackspace/file.rb +1 -5
  154. data/lib/fog/storage/rackspace.rb +8 -2
  155. data/lib/fog/storage/requests/aws/copy_object.rb +2 -2
  156. data/lib/fog/storage/requests/aws/delete_bucket.rb +3 -3
  157. data/lib/fog/storage/requests/aws/delete_object.rb +1 -1
  158. data/lib/fog/storage/requests/aws/get_bucket.rb +1 -1
  159. data/lib/fog/storage/requests/aws/get_bucket_acl.rb +1 -1
  160. data/lib/fog/storage/requests/aws/get_bucket_location.rb +1 -1
  161. data/lib/fog/storage/requests/aws/get_object.rb +1 -1
  162. data/lib/fog/storage/requests/aws/get_object_acl.rb +1 -1
  163. data/lib/fog/storage/requests/aws/get_request_payment.rb +1 -1
  164. data/lib/fog/storage/requests/aws/get_service.rb +1 -1
  165. data/lib/fog/storage/requests/aws/put_bucket.rb +3 -3
  166. data/lib/fog/storage/requests/aws/put_object.rb +3 -3
  167. data/lib/fog/storage/requests/aws/put_request_payment.rb +1 -1
  168. data/lib/fog/storage/requests/google/copy_object.rb +2 -2
  169. data/lib/fog/storage/requests/google/delete_bucket.rb +3 -3
  170. data/lib/fog/storage/requests/google/delete_object.rb +1 -1
  171. data/lib/fog/storage/requests/google/get_bucket.rb +1 -1
  172. data/lib/fog/storage/requests/google/get_bucket_acl.rb +1 -1
  173. data/lib/fog/storage/requests/google/get_object.rb +1 -1
  174. data/lib/fog/storage/requests/google/get_object_acl.rb +1 -1
  175. data/lib/fog/storage/requests/google/get_service.rb +2 -2
  176. data/lib/fog/storage/requests/google/put_bucket.rb +3 -3
  177. data/lib/fog/storage/requests/google/put_object.rb +3 -3
  178. data/lib/fog/terremark/requests/shared/get_network.rb +1 -1
  179. data/lib/fog/terremark/requests/shared/get_organization.rb +1 -1
  180. data/lib/fog/terremark/requests/shared/get_organizations.rb +1 -1
  181. data/lib/fog/terremark/requests/shared/get_public_ips.rb +1 -1
  182. data/lib/fog/terremark/requests/shared/get_vdc.rb +1 -1
  183. data/lib/fog/terremark/shared.rb +4 -0
  184. data/lib/fog/terremark/vcloud.rb +11 -1
  185. data/spec/ecloud/bin_spec.rb +8 -2
  186. data/spec/ecloud/spec_helper.rb +3 -3
  187. data/tests/compute/helper.rb +1 -3
  188. data/tests/compute/models/aws/server_tests.rb +3 -2
  189. data/tests/compute/requests/aws/instance_tests.rb +12 -9
  190. data/tests/compute/requests/aws/key_pair_tests.rb +1 -1
  191. data/tests/compute/requests/aws/volume_tests.rb +2 -2
  192. data/tests/compute/requests/brightbox/helper.rb +3 -0
  193. data/tests/compute/requests/linode/kernel_tests.rb +27 -0
  194. data/tests/compute/requests/linode/linode_tests.rb +62 -4
  195. data/tests/compute/requests/linode/stackscripts_tests.rb +35 -0
  196. data/tests/compute/requests/rackspace/resize_tests.rb +2 -2
  197. data/tests/compute/requests/voxel/server_tests.rb +1 -0
  198. data/tests/core/credential_tests.rb +7 -2
  199. data/tests/core/parser_tests.rb +1 -1
  200. data/tests/helper.rb +1 -1
  201. data/tests/helpers/compute/server_helper.rb +6 -0
  202. data/tests/helpers/formats_helper.rb +2 -0
  203. data/tests/helpers/mock_helper.rb +8 -1
  204. data/tests/helpers/model_helper.rb +1 -3
  205. data/tests/helpers/responds_to_helper.rb +2 -2
  206. data/tests/storage/helper.rb +1 -1
  207. data/tests/storage/models/directories_tests.rb +8 -4
  208. data/tests/storage/models/directory_test.rb +15 -11
  209. data/tests/storage/models/file_tests.rb +6 -6
  210. data/tests/storage/models/files_tests.rb +5 -5
  211. metadata +105 -55
@@ -17,7 +17,7 @@ module Fog
17
17
  attribute :image_id
18
18
  attribute :ips
19
19
  attribute :memory
20
- attribute :status
20
+ attribute :state, :aliases => :status
21
21
  attribute :storage
22
22
  attribute :template
23
23
 
@@ -73,7 +73,7 @@ module Fog
73
73
  end
74
74
 
75
75
  def ready?
76
- status == 'running'
76
+ self.state == 'running'
77
77
  end
78
78
 
79
79
  def reboot(type = 'SOFT')
@@ -89,7 +89,7 @@ module Fog
89
89
 
90
90
  if identity.nil? # new record
91
91
  raise(ArgumentError, "password or public_key is required for this operation") if !password && !public_key
92
- options['ssh_public_key'] = public_key if @public_key
92
+ options['ssh_public_key'] = public_key if public_key
93
93
  options['password'] = password if @password
94
94
  end
95
95
 
@@ -10,19 +10,19 @@ module Fog
10
10
 
11
11
  attribute :url
12
12
  attribute :name
13
- attribute :status
13
+ attribute :state, :aliases => 'status'
14
14
  attribute :hostname
15
- attribute :created_at, :type => :time
16
- attribute :deleted_at, :type => :time
17
- attribute :started_at, :type => :time
15
+ attribute :created_at, :type => :time
16
+ attribute :deleted_at, :type => :time
17
+ attribute :started_at, :type => :time
18
18
  attribute :user_data
19
19
 
20
20
  attribute :resource_type
21
21
 
22
- attribute :account_id, :aliases => "account", :squash => "id"
23
- attribute :image_id, :aliases => "image", :squash => "id"
24
- attribute :flavor_id, :aliases => "server_type", :squash => "id"
25
- attribute :zone_id, :aliases => "zone", :squash => "id"
22
+ attribute :account_id, :aliases => "account", :squash => "id"
23
+ attribute :image_id, :aliases => "image", :squash => "id"
24
+ attribute :flavor_id, :aliases => "server_type", :squash => "id"
25
+ attribute :zone_id, :aliases => "zone", :squash => "id"
26
26
 
27
27
  attribute :snapshots
28
28
  attribute :cloud_ips
@@ -86,7 +86,7 @@ module Fog
86
86
  end
87
87
 
88
88
  def ready?
89
- status == 'active'
89
+ self.state == 'active'
90
90
  end
91
91
 
92
92
  def activate_console
@@ -0,0 +1,12 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Linode
5
+ class Compute
6
+ class DataCenter < Fog::Model
7
+ identity :id
8
+ attribute :location
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/compute/models/linode/data_center'
3
+
4
+ module Fog
5
+ module Linode
6
+ class Compute
7
+ class DataCenters < Fog::Collection
8
+ model Fog::Linode::Compute::DataCenter
9
+
10
+ def all
11
+ load datacenters
12
+ end
13
+
14
+ private
15
+ def datacenters(id=nil)
16
+ connection.avail_datacenters.body['DATA'].map { |datacenter| map_datacenter datacenter }
17
+ end
18
+
19
+ def map_datacenter(datacenter)
20
+ datacenter = datacenter.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
21
+ datacenter.merge! :id => datacenter[:datacenterid], :name => datacenter[:location]
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,62 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Linode
5
+ class Compute
6
+ class Disk < Fog::Model
7
+ identity :id
8
+ attribute :name
9
+ attribute :type
10
+
11
+ def save
12
+ requires :server
13
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
14
+ @type, @image, @stack_script, @name, @password, @size =
15
+ attributes.values_at :type, :image, :stack_script, :name, :password, :size
16
+ create_disk
17
+ end
18
+
19
+ def destroy
20
+ requires :identity, :server
21
+ connection.linode_disk_delete server.id, id
22
+ end
23
+
24
+ def server
25
+ @server
26
+ end
27
+
28
+ private
29
+ def server=(server)
30
+ @server = server
31
+ end
32
+
33
+ def create_disk
34
+ case
35
+ when @image && @stack_script then create_disk_from_stack_script
36
+ when @image then create_disk_from_image
37
+ when @type then create_disk_type
38
+ else raise 'disk cannot be created'
39
+ end
40
+ end
41
+
42
+ def create_disk_type
43
+ self.id = connection.linode_disk_create(server.id, "#{@name}_#{@type}", @type, @size).body['DATA']['DiskID']
44
+ reload
45
+ end
46
+
47
+ def create_disk_from_image
48
+ disk = connection.linode_disk_createfromdistribution server.id, @image.id, "#{@name}_main", @size, @password
49
+ self.id = disk.body['DATA']['DiskID']
50
+ reload
51
+ end
52
+
53
+ def create_disk_from_stack_script
54
+ disk = connection.linode_disk_createfromstackscript(server.id, @stack_script.id, @image.id,
55
+ "#{@name}_main", @size, @password, @stack_script.options)
56
+ self.id = disk.body['DATA']['DiskID']
57
+ reload
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,40 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/compute/models/linode/disk'
3
+
4
+ module Fog
5
+ module Linode
6
+ class Compute
7
+ class Disks < Fog::Collection
8
+ model Fog::Linode::Compute::Disk
9
+ attribute :server
10
+
11
+ def all
12
+ requires :server
13
+ load disks(server.id)
14
+ end
15
+
16
+ def get(id)
17
+ requires :server
18
+ new disks(server.id, id).first
19
+ rescue Fog::Linode::Compute::NotFound
20
+ nil
21
+ end
22
+
23
+ def new(attributes = {})
24
+ requires :server
25
+ super({ :server => server }.merge!(attributes))
26
+ end
27
+
28
+ private
29
+ def disks(linode_id, id=nil)
30
+ connection.linode_disk_list(linode_id, id).body['DATA'].map { |disk| map_disk disk }
31
+ end
32
+
33
+ def map_disk(disk)
34
+ disk = disk.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
35
+ disk.merge! :id => disk[:diskid], :name => disk[:label], :server_id => disk[:linodeid]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Linode
5
+ class Compute
6
+ class Flavor < Fog::Model
7
+ identity :id
8
+ attribute :disk
9
+ attribute :name
10
+ attribute :ram
11
+ attribute :price
12
+
13
+ def cores
14
+ 4 # linode always has 4 cores
15
+ end
16
+
17
+ def bits
18
+ 0 # these are determined by images you select not the hardware
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,32 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/compute/models/linode/flavor'
3
+
4
+ module Fog
5
+ module Linode
6
+ class Compute
7
+ class Flavors < Fog::Collection
8
+ model Fog::Linode::Compute::Flavor
9
+
10
+ def all
11
+ load flavors
12
+ end
13
+
14
+ def get(id)
15
+ new flavors(id).first
16
+ rescue Fog::Linode::Compute::NotFound
17
+ nil
18
+ end
19
+
20
+ private
21
+ def flavors(id=nil)
22
+ connection.avail_linodeplans(id).body['DATA'].map { |flavor| map_flavor flavor }
23
+ end
24
+
25
+ def map_flavor(flavor)
26
+ flavor = flavor.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
27
+ flavor.merge! :id => flavor[:planid], :name => flavor[:label]
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Linode
5
+ class Compute
6
+ class Image < Fog::Model
7
+ identity :id
8
+ attribute :name
9
+ attribute :bits
10
+ attribute :image_size
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/compute/models/linode/image'
3
+
4
+ module Fog
5
+ module Linode
6
+ class Compute
7
+ class Images < Fog::Collection
8
+ model Fog::Linode::Compute::Image
9
+
10
+ def all
11
+ load images
12
+ end
13
+
14
+ def get(id)
15
+ new images(id).first
16
+ rescue Fog::Linode::Compute::NotFound
17
+ nil
18
+ end
19
+
20
+ private
21
+ def images(id=nil)
22
+ connection.avail_distributions(id).body['DATA'].map { |image| map_image image }
23
+ end
24
+
25
+ def map_image(image)
26
+ image = image.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
27
+ image.merge!(:id => image[:distributionid], :name => image[:label], :image_size => image[:minimagesize],
28
+ :kernel_id => image[:requirespvopskernel], :bits => ((image[:is64bit] == 1) ? 64 : 32 ))
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,30 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Linode
5
+ class Compute
6
+ class Ip < Fog::Model
7
+ identity :id
8
+ attribute :ip
9
+ attribute :public
10
+
11
+ def save
12
+ requires :server
13
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
14
+
15
+ connection.linode_ip_addprivate server.id
16
+ server.ips.all.find { |ip| !ip.public }
17
+ end
18
+
19
+ def server
20
+ @server
21
+ end
22
+
23
+ private
24
+ def server=(server)
25
+ @server = server
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,40 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/compute/models/linode/ip'
3
+
4
+ module Fog
5
+ module Linode
6
+ class Compute
7
+ class Ips < Fog::Collection
8
+ model Fog::Linode::Compute::Ip
9
+ attribute :server
10
+
11
+ def all
12
+ requires :server
13
+ load ips(server.id)
14
+ end
15
+
16
+ def get(id)
17
+ requires :server
18
+ new ips(server.id, id).first
19
+ rescue Fog::Linode::Compute::NotFound
20
+ nil
21
+ end
22
+
23
+ def new(attributes = {})
24
+ requires :server
25
+ super({ :server => server }.merge!(attributes))
26
+ end
27
+
28
+ private
29
+ def ips(linode_id, id=nil)
30
+ connection.linode_ip_list(linode_id, id).body['DATA'].map { |ip| map_ip ip }
31
+ end
32
+
33
+ def map_ip(ip)
34
+ ip = ip.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
35
+ ip.merge! :id => ip[:ipaddressid], :ip => ip[:ipaddress], :public => ip[:ispublic]==1
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,12 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Linode
5
+ class Compute
6
+ class Kernel < Fog::Model
7
+ identity :id
8
+ attribute :name
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,32 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/compute/models/linode/kernel'
3
+
4
+ module Fog
5
+ module Linode
6
+ class Compute
7
+ class Kernels < Fog::Collection
8
+ model Fog::Linode::Compute::Kernel
9
+
10
+ def all
11
+ load kernels
12
+ end
13
+
14
+ def get(id)
15
+ new kernels(id).first
16
+ rescue Fog::Linode::Compute::NotFound
17
+ nil
18
+ end
19
+
20
+ private
21
+ def kernels(id=nil)
22
+ connection.avail_kernels(id).body['DATA'].map { |kernel| map_kernel kernel }
23
+ end
24
+
25
+ def map_kernel(kernel)
26
+ kernel = kernel.each_with_object({}) { |(k, v), h| h[k.downcase.to_sym] = v }
27
+ kernel.merge! :id => kernel[:kernelid], :name => kernel[:label]
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,88 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Linode
5
+ class Compute
6
+ class Server < Fog::Model
7
+ attr_reader :stack_script
8
+ identity :id
9
+ attribute :name
10
+ attribute :status
11
+
12
+ def ips
13
+ Fog::Linode::Compute::Ips.new :server => self, :connection => connection
14
+ end
15
+
16
+ def disks
17
+ Fog::Linode::Compute::Disks.new :server => self, :connection => connection
18
+ end
19
+
20
+ def disks?
21
+ not disks.empty?
22
+ end
23
+
24
+ def reboot
25
+ connection.linode_reboot id
26
+ end
27
+
28
+ def shutdown
29
+ connection.linode_shutdown id
30
+ end
31
+
32
+ def boot
33
+ connection.linode_boot id, config
34
+ end
35
+
36
+ def save
37
+ raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if identity
38
+ @data_center, @flavor, @image, @kernel, @type, @payment_terms, @stack_script, @name, @password, @callback =
39
+ attributes.values_at :data_center, :flavor, :image, :kernel, :type, :payment_terms, :stack_script, :name, :password, :callback
40
+
41
+ create_linode
42
+ @callback.call self if @callback
43
+ create_disks
44
+ create_config
45
+ boot_linode
46
+ self
47
+ rescue Exception => ex
48
+ destroy if id
49
+ raise ex
50
+ end
51
+
52
+ def destroy
53
+ requires :identity
54
+ connection.linode_shutdown id
55
+ disks.each { |disk| disk.destroy }
56
+ wait_for { not disks? }
57
+ connection.linode_delete id
58
+ end
59
+
60
+ private
61
+ def config
62
+ connection.linode_config_list(id).body['DATA'].first['ConfigID']
63
+ end
64
+
65
+ def create_linode
66
+ self.id = connection.linode_create(@data_center.id, @flavor.id, @payment_terms).body['DATA']['LinodeID']
67
+ connection.linode_update id, :label => @name
68
+ ips.create
69
+ reload
70
+ end
71
+
72
+ def create_disks
73
+ @swap = disks.create :type => :swap, :name => @name, :size => @flavor.ram
74
+ @disk = disks.create(:type => @type, :image => @image, :stack_script => @stack_script,
75
+ :password => @password, :name => @name, :size => (@flavor.disk*1024)-@flavor.ram)
76
+ end
77
+
78
+ def create_config
79
+ @config = connection.linode_config_create(id, @kernel.id, @name, "#{@disk.id},#{@swap.id},,,,,,,").body['DATA']['ConfigID']
80
+ end
81
+
82
+ def boot_linode
83
+ connection.linode_boot id, @config
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end