fog 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
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,176 @@
1
+ require(File.expand_path(File.join(File.dirname(__FILE__), 'core')))
2
+
3
+ module Fog
4
+ module IBM
5
+
6
+ extend Fog::Provider
7
+
8
+ service(:compute, 'ibm/compute', 'Compute')
9
+ service(:storage, 'ibm/storage', 'Storage')
10
+
11
+ # Provisioning is very slow. We'll pass this arg explicitly until there's a way
12
+ # to set the default timeout on a per-provider basis.
13
+ TIMEOUT = 1800
14
+
15
+ class Connection < Fog::Connection
16
+
17
+ ENDPOINT = 'https://www-147.ibm.com/computecloud/enterprise/api/rest/20100331'
18
+
19
+ def initialize(user, password)
20
+ require 'multi_json'
21
+ @user = user
22
+ @password = password
23
+ @endpoint = URI.parse(ENDPOINT)
24
+ @base_path = @endpoint.path
25
+ super("#{@endpoint.scheme}://#{@endpoint.host}:#{@endpoint.port}")
26
+ end
27
+
28
+ def request(options)
29
+ options[:path] = @base_path + options[:path]
30
+ options[:headers] ||= {}
31
+ options[:headers]['Authorization'] = auth_header
32
+ options[:headers]['Accept'] = 'application/json'
33
+ options[:headers]['Accept-Encoding'] = 'gzip'
34
+ unless options[:body].nil?
35
+ options[:headers]['Content-Type'] = 'application/x-www-form-urlencoded'
36
+ options[:body] = form_encode(options[:body])
37
+ end
38
+ response = super(options)
39
+ unless response.body.empty?
40
+ response.body = MultiJson.decode(response.body)
41
+ end
42
+ response
43
+ end
44
+
45
+ def auth_header
46
+ @auth_header ||= 'Basic ' + Base64.encode64("#{@user}:#{@password}").gsub("\n",'')
47
+ end
48
+
49
+ def form_encode(params)
50
+ params.reject {|k, v| v.nil? }.map {|pair| pair.map {|x| URI.escape(x.to_s) }.join('=') }.join('&')
51
+ end
52
+ end
53
+
54
+ class Mock
55
+ class << self
56
+
57
+ def id
58
+ Fog::Mock.random_numbers(7).to_i.to_s
59
+ end
60
+ alias :instance_id :id
61
+ alias :request_id :id
62
+
63
+ def primary_ip
64
+ { "type" => 0, "ip" => Fog::IBM::Mock.ip_address, "hostname" => Fog::IBM::Mock.hostname }
65
+ end
66
+
67
+ def ip_address
68
+ ip = []
69
+ 4.times do
70
+ ip << Fog::Mock.random_numbers(rand(3) + 1).to_i.to_s # remove leading 0
71
+ end
72
+ ip.join('.')
73
+ end
74
+
75
+ def hostname
76
+ "vhost" + Fog::Mock.random_numbers(3).to_i.to_s + ".fake.compute.ihost.com"
77
+ end
78
+
79
+ # Miliseconds since epoch
80
+ def launch_time
81
+ (Time.now.tv_sec * 1000).to_i
82
+ end
83
+
84
+ # 1 year from now, in miliseconds since epoch
85
+ def expiry_time
86
+ ((Time.now.tv_sec + 31556926) * 1000).to_i
87
+ end
88
+
89
+ def owner
90
+ "user" + Fog::Mock.random_numbers(3).to_i.to_s + "@company.com"
91
+ end
92
+
93
+ def key_material
94
+ OpenSSL::PKey::RSA.generate(1024)
95
+ end
96
+
97
+ def private_image(name, description)
98
+ {
99
+ "name" => name,
100
+ "createdTime" => Fog::IBM::Mock.launch_time,
101
+ "productCodes"=> [],
102
+ "id" => Fog::IBM::Mock.instance_id,
103
+ "description" => description,
104
+ "visibility" => "PRIVATE",
105
+ "state" => 0
106
+ }
107
+ end
108
+
109
+ def create_instance(name, image_id, instance_type, location, options)
110
+ {
111
+ "name" => name,
112
+ "location" => location,
113
+ "keyName" => options[:key_name],
114
+ "primaryIP" => Fog::IBM::Mock.primary_ip,
115
+ "productCodes" => [],
116
+ "requestId" => Fog::IBM::Mock.request_id,
117
+ "imageId" => image_id,
118
+ "launchTime" => Fog::IBM::Mock.launch_time,
119
+ "id" => Fog::IBM::Mock.instance_id,
120
+ "volumes" => [],
121
+ "isMiniEphemeral" => "false",
122
+ "instanceType" => instance_type,
123
+ "diskSize" => "60",
124
+ "requestName" => "",
125
+ "secondaryIP" => [],
126
+ "status" => 1,
127
+ "software" => [
128
+ { "name"=>"SUSE Linux Enterprise Server",
129
+ "type"=>"OS",
130
+ "version"=>"11 SP1" }
131
+ ],
132
+ "expirationTime"=> Fog::IBM::Mock.expiry_time,
133
+ "owner" => Fog::IBM::Mock.owner
134
+ }
135
+ end
136
+
137
+ def create_volume(name, format, location_id, size, offering_id)
138
+ {
139
+ "instanceId" => "0",
140
+ "state" => 1,
141
+ "size" => size,
142
+ "offeringId" => offering_id,
143
+ "ioPrice" => {
144
+ "rate" => 0.11,
145
+ "unitOfMeasure" => "CNT",
146
+ "countryCode" => "897",
147
+ "effectiveDate" => Fog::IBM::Mock.launch_time,
148
+ "currencyCode" => "USD",
149
+ "pricePerQuantity" => 1
150
+ },
151
+ "owner" => Fog::IBM::Mock.owner,
152
+ "createdTime" => Fog::IBM::Mock.launch_time,
153
+ "location" => location_id,
154
+ "productCodes"=> [],
155
+ "format" => format,
156
+ "name" => name,
157
+ "id" => Fog::IBM::Mock.id,
158
+ }
159
+ end
160
+
161
+ def create_address(location_id, offering_id, vlan_id)
162
+ # TODO: Figure out vlan handling
163
+ {
164
+ "id" => Fog::IBM::Mock.id,
165
+ "location" => location_id,
166
+ "offeringId"=> offering_id,
167
+ "ip" => "",
168
+ "state" => 0
169
+ }
170
+ end
171
+
172
+ end
173
+ end
174
+
175
+ end
176
+ end
@@ -0,0 +1,233 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'ibm'))
2
+ require 'fog/compute'
3
+
4
+ module Fog
5
+ module Compute
6
+ class IBM < Fog::Service
7
+
8
+ requires :ibm_username, :ibm_password
9
+ recognizes :location
10
+
11
+ model_path 'fog/ibm/models/compute'
12
+
13
+ model :image
14
+ collection :images
15
+ model :server
16
+ collection :servers
17
+ model :address
18
+ collection :addresses
19
+ model :key
20
+ collection :keys
21
+ model :location
22
+ collection :locations
23
+
24
+ request_path 'fog/ibm/requests/compute'
25
+
26
+ request :list_images
27
+ request :create_image
28
+ request :clone_image
29
+ request :delete_image
30
+ request :get_image
31
+ request :get_image_agreement
32
+ request :get_image_manifest
33
+ # request :get_image_swbundles
34
+ # request :get_image_swbundle
35
+
36
+ request :list_instances
37
+ request :create_instance
38
+ request :delete_instance
39
+ request :modify_instance
40
+ request :get_instance
41
+ request :get_instance_logs
42
+ # request :get_instance_swbundle
43
+
44
+ request :get_request
45
+
46
+ request :list_addresses
47
+ request :list_address_offerings
48
+ request :list_vlans
49
+ request :create_address
50
+ request :delete_address
51
+
52
+ request :list_keys
53
+ request :create_key
54
+ request :delete_key
55
+ request :modify_key
56
+ request :get_key
57
+
58
+ request :list_locations
59
+ request :get_location
60
+
61
+ class Real
62
+ def initialize(options={})
63
+ @connection = Fog::IBM::Connection.new(options[:ibm_username], options[:ibm_password])
64
+ end
65
+
66
+ private
67
+
68
+ def request(options)
69
+ begin
70
+ @connection.request(options)
71
+ rescue Excon::Errors::HTTPStatusError => error
72
+ raise case error
73
+ when Excon::Errors::NotFound
74
+ Fog::Compute::IBM::NotFound.slurp(error)
75
+ else
76
+ error
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ class Mock
83
+
84
+ def self.data
85
+ @data ||= Hash.new do |hash, key|
86
+ hash[key] = {
87
+ :instances => {},
88
+ :images => populate_images,
89
+ :keys => {},
90
+ :locations => populate_locations,
91
+ :private_keys => {},
92
+ :addresses => {}
93
+ }
94
+ end
95
+ end
96
+
97
+ def self.reset
98
+ @data = nil
99
+ end
100
+
101
+ def data
102
+ self.class.data[@ibm_username]
103
+ end
104
+
105
+ def reset_data
106
+ self.class.data.delete(@ibm_username)
107
+ @data = self.class.data[@ibm_username]
108
+ end
109
+
110
+ def initialize(options={})
111
+ @ibm_username = options[:ibm_username]
112
+ @ibm_password = options[:ibm_password]
113
+ @data = self.class.data[@ibm_username]
114
+ end
115
+
116
+ def self.populate_images
117
+ images = {}
118
+ images["20010001"] = {
119
+ "name"=>"SUSE Linux Enterprise Server 11 SP1 for x86",
120
+ "manifest"=>"https://www-147.ibm.com/cloud/enterprise/ram.ws/RAMSecure/artifact/{6CD09CE4-E99B-D72F-6C29-233C9B2A1676}/1.0/parameters.xml",
121
+ "state"=>1,
122
+ "visibility"=>"PUBLIC",
123
+ "owner"=>"SYSTEM",
124
+ "platform"=>"SUSE Linux Enterprise Server/11 SP1",
125
+ "location"=>"41",
126
+ "createdTime"=>1282466781000,
127
+ "supportedInstanceTypes"=>
128
+ [{"detail"=>"Copper - 32 bit (vCPU: 1, RAM: 2 GiB, Disk: 60 GiB)",
129
+ "label"=>"Copper 32 bit",
130
+ "price"=>{"rate"=>0.095, "unitOfMeasure"=>"UHR ", "countryCode"=>"897", "effectiveDate"=>-1, "currencyCode"=>"USD", "pricePerQuantity"=>1},
131
+ "id"=>"COP32.1/2048/60"},
132
+ {"detail"=>"Bronze - 32 bit (vCPU: 1, RAM: 2 GiB, Disk: 235 GiB)",
133
+ "label"=>"Bronze 32 bit",
134
+ "price"=>{"rate"=>0.115, "unitOfMeasure"=>"UHR ", "countryCode"=>"897", "effectiveDate"=>-1, "currencyCode"=>"USD", "pricePerQuantity"=>1},
135
+ "id"=>"BRZ32.1/2048/60*175"},
136
+ {"detail"=>"Silver - 32 bit (vCPU: 2, RAM: 4 GiB, Disk: 410 GiB)",
137
+ "label"=>"Silver 32 bit",
138
+ "price"=>{"rate"=>0.2, "unitOfMeasure"=>"UHR ", "countryCode"=>"897", "effectiveDate"=>-1, "currencyCode"=>"USD", "pricePerQuantity"=>1},
139
+ "id"=>"SLV32.2/4096/60*350"},
140
+ {"detail"=>"Gold - 32 bit (vCPU: 4, RAM: 4 GiB, Disk: 410 GiB)",
141
+ "label"=>"Gold 32 bit",
142
+ "price"=>{"rate"=>0.33, "unitOfMeasure"=>"UHR ", "countryCode"=>"897", "effectiveDate"=>-1, "currencyCode"=>"USD", "pricePerQuantity"=>1},
143
+ "id"=>"GLD32.4/4096/60*350"}],
144
+ "productCodes"=>["rtpSr7dKs9ARDmuPy6WPgV"],
145
+ "documentation"=>"https://www-147.ibm.com/cloud/enterprise/ram.ws/RAMSecure/artifact/{6CD09CE4-E99B-D72F-6C29-233C9B2A1676}/1.0/GettingStarted.html",
146
+ "id"=>"20010001",
147
+ "description"=>"Suse Linux 32 bit"
148
+ }
149
+ images
150
+ end
151
+
152
+ def self.populate_locations
153
+ locations = {}
154
+ locations["41"] = {
155
+ "state"=>1,
156
+ "location"=>"RTP",
157
+ "capabilities"=>[
158
+ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"},
159
+ {"entries"=>{}, "id"=>"oss.instance.spec.i386"},
160
+ {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"},
161
+ {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}],
162
+ "name"=>"Raleigh, U.S.A",
163
+ "id"=>"41",
164
+ "description"=>"This data center is located in Raleigh, North Carolina, U.S.A. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN."
165
+ }
166
+ locations["61"] = {
167
+ "state"=>1,
168
+ "location"=>"EHN",
169
+ "capabilities"=>[
170
+ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"},
171
+ {"entries"=>{}, "id"=>"oss.instance.spec.i386"},
172
+ {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"},
173
+ {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}],
174
+ "name"=>"Ehningen, Germany",
175
+ "id"=>"61",
176
+ "description"=>"This data center is located in Ehningen(near Baden-Wurttemberg), Germany. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN."
177
+ }
178
+ locations["82"] = {
179
+ "state"=>1,
180
+ "location"=>"us-co-dc1",
181
+ "capabilities"=>[
182
+ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"},
183
+ {"entries"=>{}, "id"=>"oss.instance.spec.i386"},
184
+ {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"},
185
+ {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}],
186
+ "name"=>"Boulder1, U.S.A",
187
+ "id"=>"82",
188
+ "description"=>"This data center is located in Boulder(near Denver), Colorado, U.S.A. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN."
189
+ }
190
+ locations["101"] = {
191
+ "state"=>1,
192
+ "location"=>"ca-on-dc1",
193
+ "capabilities"=>[
194
+ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"},
195
+ {"entries"=>{}, "id"=>"oss.instance.spec.i386"},
196
+ {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"},
197
+ {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}],
198
+ "name"=>"Markham, Canada",
199
+ "id"=>"101",
200
+ "description"=>"This data center is located in Markham(near Toronto), Ontario, Canada. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN."
201
+ }
202
+ locations["121"] = {
203
+ "state"=>1,
204
+ "location"=>"ap-jp-dc1",
205
+ "capabilities"=>[
206
+ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"},
207
+ {"entries"=>{}, "id"=>"oss.instance.spec.i386"},
208
+ {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"},
209
+ {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}],
210
+ "name"=>"Makuhari, Japan",
211
+ "id"=>"121",
212
+ "description"=>"This data center is located in Makuhari(near Tokoyo), Japan. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN."
213
+ }
214
+ locations["141"] = {
215
+ "state"=>1,
216
+ "location"=>"ap-sg-dc1",
217
+ "capabilities"=>[
218
+ {"entries"=>{"EXT3"=>["ext3"], "RAW"=>["raw"]}, "id"=>"oss.storage.format"},
219
+ {"entries"=>{}, "id"=>"oss.instance.spec.i386"},
220
+ {"entries"=>{}, "id"=>"oss.instance.spec.x86_64"},
221
+ {"entries"=>{}, "id"=>"oss.storage.availabilityarea"}],
222
+ "name"=>"Singapore, Singapore",
223
+ "id"=>"141",
224
+ "description"=>"This data center is located in Singapore. The services provided are: Guest Instances, Image Capture, Persistent Storage, Reserved IP, Private VLAN/VPN."
225
+ }
226
+ locations
227
+ end
228
+
229
+ end
230
+
231
+ end
232
+ end
233
+ end
@@ -0,0 +1,62 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class IBM
6
+ class Address < Fog::Model
7
+
8
+ STATES = {
9
+ 0 => 'New',
10
+ 1 => 'Allocating',
11
+ 2 => 'Free',
12
+ 3 => 'Attached',
13
+ 4 => 'Releasing',
14
+ 5 => 'Released',
15
+ 6 => 'Failed',
16
+ 7 => 'Release pending',
17
+ }
18
+
19
+ identity :id
20
+
21
+ attribute :type
22
+ attribute :location
23
+ attribute :ip
24
+ attribute :state
25
+ attribute :instance_id, :aliases => 'instanceId'
26
+ attribute :offering_id, :aliases => 'offeringId'
27
+ attribute :vlan_id, :aliases => 'vlanId'
28
+ attribute :hostname
29
+ attribute :mode
30
+ attribute :owner
31
+
32
+ def initialize(new_attributes={})
33
+ super(new_attributes)
34
+ self.offering_id ||= '20001223'
35
+ self.location ||= '82'
36
+ end
37
+
38
+ def save
39
+ requires :offering_id, :location
40
+ data = connection.create_address(location, offering_id,
41
+ :vlan_id => vlan_id,
42
+ :ip => ip)
43
+ merge_attributes(data.body)
44
+ true
45
+ end
46
+
47
+ def state
48
+ STATES[attributes[:state]]
49
+ end
50
+
51
+ def ready?
52
+ state == 'Free' || state == 'Released'
53
+ end
54
+
55
+ def destroy
56
+ requires :id
57
+ connection.delete_address(id).body['success']
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end