fog 1.2.0 → 1.3.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 (93) hide show
  1. data/Rakefile +1 -0
  2. data/changelog.txt +91 -0
  3. data/fog.gemspec +3 -3
  4. data/lib/fog.rb +1 -1
  5. data/lib/fog/aws/compute.rb +5 -4
  6. data/lib/fog/aws/models/compute/security_group.rb +7 -1
  7. data/lib/fog/aws/models/compute/subnet.rb +0 -1
  8. data/lib/fog/aws/parsers/compute/create_security_group.rb +24 -0
  9. data/lib/fog/aws/requests/cloud_watch/get_metric_statistics.rb +1 -1
  10. data/lib/fog/aws/requests/compute/authorize_security_group_ingress.rb +19 -11
  11. data/lib/fog/aws/requests/compute/create_security_group.rb +5 -3
  12. data/lib/fog/aws/requests/compute/describe_security_groups.rb +1 -1
  13. data/lib/fog/aws/requests/storage/get_object_http_url.rb +2 -2
  14. data/lib/fog/aws/requests/storage/get_object_https_url.rb +2 -2
  15. data/lib/fog/aws/simpledb.rb +6 -1
  16. data/lib/fog/bin.rb +1 -0
  17. data/lib/fog/bin/ibm.rb +34 -0
  18. data/lib/fog/compute.rb +3 -0
  19. data/lib/fog/core/errors.rb +2 -0
  20. data/lib/fog/ibm.rb +176 -0
  21. data/lib/fog/ibm/compute.rb +233 -0
  22. data/lib/fog/ibm/models/compute/address.rb +62 -0
  23. data/lib/fog/ibm/models/compute/addresses.rb +28 -0
  24. data/lib/fog/ibm/models/compute/image.rb +61 -0
  25. data/lib/fog/ibm/models/compute/images.rb +27 -0
  26. data/lib/fog/ibm/models/compute/instance-type.rb +14 -0
  27. data/lib/fog/ibm/models/compute/instance-types.rb +15 -0
  28. data/lib/fog/ibm/models/compute/key.rb +35 -0
  29. data/lib/fog/ibm/models/compute/keys.rb +35 -0
  30. data/lib/fog/ibm/models/compute/location.rb +15 -0
  31. data/lib/fog/ibm/models/compute/locations.rb +27 -0
  32. data/lib/fog/ibm/models/compute/server.rb +193 -0
  33. data/lib/fog/ibm/models/compute/servers.rb +27 -0
  34. data/lib/fog/ibm/models/storage/offering.rb +18 -0
  35. data/lib/fog/ibm/models/storage/offerings.rb +19 -0
  36. data/lib/fog/ibm/models/storage/volume.rb +95 -0
  37. data/lib/fog/ibm/models/storage/volumes.rb +27 -0
  38. data/lib/fog/ibm/requests/compute/clone_image.rb +48 -0
  39. data/lib/fog/ibm/requests/compute/create_address.rb +50 -0
  40. data/lib/fog/ibm/requests/compute/create_image.rb +56 -0
  41. data/lib/fog/ibm/requests/compute/create_instance.rb +80 -0
  42. data/lib/fog/ibm/requests/compute/create_key.rb +61 -0
  43. data/lib/fog/ibm/requests/compute/delete_address.rb +46 -0
  44. data/lib/fog/ibm/requests/compute/delete_image.rb +43 -0
  45. data/lib/fog/ibm/requests/compute/delete_instance.rb +52 -0
  46. data/lib/fog/ibm/requests/compute/delete_key.rb +41 -0
  47. data/lib/fog/ibm/requests/compute/get_image.rb +67 -0
  48. data/lib/fog/ibm/requests/compute/get_image_agreement.rb +66 -0
  49. data/lib/fog/ibm/requests/compute/get_image_manifest.rb +39 -0
  50. data/lib/fog/ibm/requests/compute/get_instance.rb +76 -0
  51. data/lib/fog/ibm/requests/compute/get_instance_logs.rb +25 -0
  52. data/lib/fog/ibm/requests/compute/get_key.rb +49 -0
  53. data/lib/fog/ibm/requests/compute/get_location.rb +55 -0
  54. data/lib/fog/ibm/requests/compute/get_request.rb +78 -0
  55. data/lib/fog/ibm/requests/compute/list_address_offerings.rb +58 -0
  56. data/lib/fog/ibm/requests/compute/list_addresses.rb +53 -0
  57. data/lib/fog/ibm/requests/compute/list_images.rb +58 -0
  58. data/lib/fog/ibm/requests/compute/list_instances.rb +57 -0
  59. data/lib/fog/ibm/requests/compute/list_keys.rb +57 -0
  60. data/lib/fog/ibm/requests/compute/list_locations.rb +37 -0
  61. data/lib/fog/ibm/requests/compute/list_vlans.rb +52 -0
  62. data/lib/fog/ibm/requests/compute/modify_instance.rb +71 -0
  63. data/lib/fog/ibm/requests/compute/modify_key.rb +52 -0
  64. data/lib/fog/ibm/requests/storage/create_volume.rb +66 -0
  65. data/lib/fog/ibm/requests/storage/delete_volume.rb +42 -0
  66. data/lib/fog/ibm/requests/storage/get_volume.rb +72 -0
  67. data/lib/fog/ibm/requests/storage/list_offerings.rb +76 -0
  68. data/lib/fog/ibm/requests/storage/list_volumes.rb +47 -0
  69. data/lib/fog/ibm/storage.rb +82 -0
  70. data/lib/fog/ovirt/compute.rb +1 -0
  71. data/lib/fog/ovirt/models/compute/server.rb +5 -0
  72. data/lib/fog/ovirt/requests/compute/vm_ticket.rb +21 -0
  73. data/lib/fog/providers.rb +1 -0
  74. data/lib/fog/storage.rb +3 -0
  75. data/tests/aws/requests/compute/security_group_tests.rb +37 -39
  76. data/tests/compute/helper.rb +4 -0
  77. data/tests/compute/models/flavors_tests.rb +1 -1
  78. data/tests/helper.rb +1 -1
  79. data/tests/helpers/mock_helper.rb +2 -0
  80. data/tests/ibm/models/compute/image_tests.rb +10 -0
  81. data/tests/ibm/models/compute/key_tests.rb +23 -0
  82. data/tests/ibm/models/compute/keys_tests.rb +35 -0
  83. data/tests/ibm/models/compute/locations_tests.rb +18 -0
  84. data/tests/ibm/models/compute/server_tests.rb +88 -0
  85. data/tests/ibm/models/compute/servers_tests.rb +37 -0
  86. data/tests/ibm/models/storage/volume_tests.rb +60 -0
  87. data/tests/ibm/requests/compute/address_tests.rb +44 -0
  88. data/tests/ibm/requests/compute/image_tests.rb +110 -0
  89. data/tests/ibm/requests/compute/instance_tests.rb +102 -0
  90. data/tests/ibm/requests/compute/key_tests.rb +50 -0
  91. data/tests/ibm/requests/compute/location_tests.rb +28 -0
  92. data/tests/ibm/requests/storage/volume_tests.rb +100 -0
  93. metadata +122 -43
@@ -0,0 +1,28 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/ibm/models/compute/address'
3
+
4
+ module Fog
5
+ module Compute
6
+ class IBM
7
+
8
+ class Addresses < Fog::Collection
9
+
10
+ model Fog::Compute::IBM::Address
11
+
12
+ def all
13
+ load(connection.list_addresses.body['addresses'])
14
+ end
15
+
16
+ def get(address_id)
17
+ begin
18
+ address = connection.list_addresses.body
19
+ new(address['addresses'].find{|address| address['id'] == address_id.to_s })
20
+ rescue Fog::Compute::IBM::NotFound
21
+ nil
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,61 @@
1
+ require 'fog/core/model'
2
+ require 'fog/ibm/models/compute/instance-types'
3
+
4
+ module Fog
5
+ module Compute
6
+ class IBM
7
+ class Image < Fog::Model
8
+
9
+ STATES = {
10
+ 0 => 'New',
11
+ 1 => 'Available',
12
+ 2 => 'Unavailable',
13
+ 3 => 'Deleted',
14
+ 4 => 'Capturing',
15
+ 5 => 'Importing',
16
+ 6 => 'Copying',
17
+ 7 => 'Failed',
18
+ }
19
+
20
+ identity :id
21
+
22
+ attribute :architecture
23
+ attribute :created_at, :aliases => 'createdTime'
24
+ attribute :description
25
+ attribute :documentation
26
+ attribute :location
27
+ attribute :manifest
28
+ attribute :name
29
+ attribute :owner
30
+ attribute :platform
31
+ attribute :product_codes, :aliases => 'productCodes'
32
+ attribute :state
33
+ attribute :supported_instance_types, :aliases => 'supportedInstanceTypes'
34
+ attribute :visibility
35
+
36
+ attribute :volume_id
37
+
38
+ def initialize(new_attributes = {})
39
+ super(new_attributes)
40
+ attributes[:supported_instance_types] = Fog::Compute::IBM::InstanceTypes.new.load(attributes[:supported_instance_types]) if attributes[:supported_instance_types]
41
+ end
42
+
43
+ def save
44
+ requires :id, :volume_id
45
+ data = connection.create_image(id, volume_id)
46
+ merge_attributes(data.body)
47
+ data.body['success']
48
+ end
49
+
50
+ def state
51
+ STATES[attributes[:state]]
52
+ end
53
+
54
+ def ready?
55
+ state == 'Available'
56
+ end
57
+
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,27 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/ibm/models/compute/image'
3
+
4
+ module Fog
5
+ module Compute
6
+ class IBM
7
+
8
+ class Images < Fog::Collection
9
+
10
+ model Fog::Compute::IBM::Image
11
+
12
+ def all
13
+ load(connection.list_images.body['images'])
14
+ end
15
+
16
+ def get(image_id)
17
+ begin
18
+ new(connection.get_image(image_id).body)
19
+ rescue Fog::Compute::IBM::NotFound
20
+ nil
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class IBM
6
+ class InstanceType < Fog::Model
7
+ identity :id
8
+ attribute :detail
9
+ attribute :label
10
+ attribute :price
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/ibm/models/compute/instance-type'
3
+
4
+ module Fog
5
+ module Compute
6
+ class IBM
7
+
8
+ class InstanceTypes < Fog::Collection
9
+
10
+ model Fog::Compute::IBM::InstanceType
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class IBM
6
+ class Key < Fog::Model
7
+ identity :name, :aliases => 'keyName'
8
+ attribute :default
9
+ attribute :public_key, :aliases => 'keyMaterial'
10
+ attribute :instance_ids, :aliases => 'instanceIds'
11
+ attribute :modified_at, :aliases => 'lastModifiedTime'
12
+
13
+ def save
14
+ requires :name
15
+ data = connection.create_key(name, public_key)
16
+ merge_attributes(data.body)
17
+ data.body['keyName'] == name
18
+ end
19
+
20
+ def destroy
21
+ data = connection.delete_key(identity)
22
+ data.body['success']
23
+ end
24
+
25
+ def default?
26
+ default
27
+ end
28
+
29
+ def instances
30
+ instance_ids.map { Fog::Compute[:ibm].servers.get(instance_id) }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/ibm/models/compute/key'
3
+
4
+ module Fog
5
+ module Compute
6
+ class IBM
7
+
8
+ class Keys < Fog::Collection
9
+
10
+ model Fog::Compute::IBM::Key
11
+
12
+ def all
13
+ load(connection.list_keys.body['keys'])
14
+ end
15
+
16
+ def get(key_id)
17
+ begin
18
+ new(connection.get_key(key_id).body)
19
+ rescue Fog::Compute::IBM::NotFound
20
+ nil
21
+ end
22
+ end
23
+
24
+ def default
25
+ find {|key| key.default? }
26
+ end
27
+
28
+ def default=(key_name)
29
+ connection.modify_key(key_name, 'default' => true)
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class IBM
6
+ class Location < Fog::Model
7
+ identity :id
8
+ attribute :name
9
+ attribute :location
10
+ attribute :capabilities
11
+ attribute :description
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/ibm/models/compute/location'
3
+
4
+ module Fog
5
+ module Compute
6
+ class IBM
7
+
8
+ class Locations < Fog::Collection
9
+
10
+ model Fog::Compute::IBM::Location
11
+
12
+ def all
13
+ load(connection.list_locations.body['locations'])
14
+ end
15
+
16
+ def get(location_id)
17
+ begin
18
+ new(connection.get_location(location_id).body)
19
+ rescue Fog::Compute::IBM::NotFound
20
+ nil
21
+ end
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,193 @@
1
+ require 'fog/compute/models/server'
2
+
3
+ module Fog
4
+ module Compute
5
+ class IBM
6
+
7
+ class Server < Fog::Compute::Server
8
+
9
+ STATES = [
10
+ "New", # => 0
11
+ "Provisioning", # => 1
12
+ "Failed", # => 2
13
+ "Removed", # => 3
14
+ "Rejected", # => 4
15
+ "Active", # => 5
16
+ "Unknown", # => 6
17
+ "Deprovisioning", # => 7
18
+ "Restarting", # => 8
19
+ "Starting", # => 9
20
+ "Stopping", # => 10
21
+ "Stopped", # => 11
22
+ "Deprovisioning pending", # => 12
23
+ "Restart pending",# => 13
24
+ "Attaching", # => 14
25
+ "Detaching" # => 15
26
+ ]
27
+
28
+ identity :id
29
+
30
+ attribute :disk_size, :aliases => 'diskSize'
31
+ attribute :expires_at, :aliases => 'expirationTime'
32
+ attribute :image_id, :aliases => 'imageId'
33
+ attribute :instance_type, :aliases => 'instanceType'
34
+ attribute :ip
35
+ attribute :key_name, :aliases => 'keyName'
36
+ attribute :launched_at, :aliases => 'launchTime'
37
+ attribute :location_id, :aliases => 'location'
38
+ attribute :name
39
+ attribute :owner
40
+ attribute :primary_ip, :aliases => 'primaryIP'
41
+ attribute :product_codes, :aliases => 'productCodes'
42
+ attribute :request_id, :aliases => 'requestId'
43
+ attribute :request_name, :aliases => 'requestName'
44
+ attribute :is_mini_ephemeral, :aliases => 'isMiniEphemeral'
45
+ attribute :secondary_ip, :aliases => 'secondaryIP'
46
+ attribute :software
47
+ attribute :state, :aliases => 'status'
48
+ attribute :volume_ids, :aliases => 'volumes'
49
+ attribute :vlan_id, :aliases => 'vlanID'
50
+
51
+ def initialize(new_attributes={})
52
+ super(new_attributes)
53
+ self.name ||= 'fog-instance'
54
+ self.image_id ||= '20010001'
55
+ self.location_id ||= '41'
56
+ self.instance_type ||= 'COP32.1/2048/60'
57
+ self.key_name ||= 'fog'
58
+ end
59
+
60
+ def save
61
+ requires :name, :image_id, :instance_type, :location_id
62
+ data = connection.create_instance(name, image_id, instance_type, location_id,
63
+ :key_name => key_name,
64
+ :vlan_id => vlan_id,
65
+ :secondary_ip => secondary_ip)
66
+ data.body['instances'].each do |iattrs|
67
+ if iattrs['name'] == name
68
+ merge_attributes(iattrs)
69
+ return true
70
+ end
71
+ end
72
+ false
73
+ end
74
+
75
+ def state
76
+ STATES[attributes[:state].to_i]
77
+ end
78
+
79
+ def ready?
80
+ state == "Active"
81
+ end
82
+
83
+ def reboot
84
+ requires :id
85
+ connection.modify_instance(id, 'state' => 'restart').body['success']
86
+ end
87
+
88
+ def destroy
89
+ requires :id
90
+ connection.delete_instance(id).body['success']
91
+ end
92
+
93
+ def rename(name)
94
+ requires :id
95
+ if connection.modify_instance(id, 'name' => name).body["success"]
96
+ attributes[:name] = name
97
+ else
98
+ return false
99
+ end
100
+ true
101
+ end
102
+
103
+ def allocate_ip(wait_for_ready=true)
104
+ requires :location_id
105
+ new_ip = connection.addresses.new(:location => location_id)
106
+ new_ip.save
107
+ new_ip.wait_for(Fog::IBM::TIMEOUT) { ready? } if wait_for_ready
108
+ secondary_ip << new_ip
109
+ new_ip
110
+ end
111
+
112
+ def addresses
113
+ addys = secondary_ip.map {|ip| Fog::Compute[:ibm].addresses.new(ip) }
114
+ # Set an ID, in case someone tries to save
115
+ addys << connection.addresses.new(attributes[:primary_ip].merge(
116
+ :id => "0",
117
+ :location => location_id,
118
+ :state => 3
119
+ ))
120
+ addys
121
+ end
122
+
123
+ def attach(volume_id)
124
+ requires :id
125
+ data = connection.modify_instance(id, {'type' => 'attach', 'storageId' => volume_id})
126
+ data.body
127
+ end
128
+
129
+ def detach(volume_id)
130
+ requires :id
131
+ data = connection.modify_instance(id, {'type' => 'detach', 'storageId' => volume_id})
132
+ data.body
133
+ end
134
+
135
+ def launched_at
136
+ Time.at(attributes[:launched_at].to_f / 1000)
137
+ end
138
+
139
+ def expires_at
140
+ Time.at(attributes[:expires_at].to_f / 1000)
141
+ end
142
+
143
+ # Sets expiration time - Pass an instance of Time.
144
+ def expire_at(time)
145
+ expiry_time = (time.tv_sec * 1000).to_i
146
+ data = connection.modify_instance(id, 'expirationTime' => expiry_time)
147
+ if data.body['expirationTime'] == expiry_time
148
+ attributes[:expires_at] = expiry_time
149
+ true
150
+ else
151
+ false
152
+ end
153
+ end
154
+
155
+ # Expires the instance immediately
156
+ def expire!
157
+ expire_at(Time.now + 5)
158
+ end
159
+
160
+ def image
161
+ requires :image_id
162
+ connection.images.get(image_id)
163
+ end
164
+
165
+ def location
166
+ requires :location_id
167
+ connection.locations.get(location_id)
168
+ end
169
+
170
+ def public_hostname
171
+ primary_ip ? primary_ip['hostname'] : nil
172
+ end
173
+
174
+ def public_ip_address
175
+ primary_ip ? primary_ip['ip'] : nil
176
+ end
177
+
178
+ # Creates an image from the current instance
179
+ # if name isn't passed then we'll take the current name and timestamp it
180
+ def to_image(opts={})
181
+ options = {
182
+ :name => name + " as of " + Time.now.strftime("%Y-%m-%d %H:%M"),
183
+ :description => ""
184
+ }.merge(opts)
185
+ connection.create_image(id, options[:name], options[:description]).body
186
+ end
187
+ alias :create_image :to_image
188
+ end
189
+
190
+ end
191
+ end
192
+
193
+ end