bosh_aws_cpi 0.5.0 → 0.6.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.
@@ -11,12 +11,6 @@ module Bosh::AwsCloud
11
11
  METADATA_TIMEOUT = 5 # seconds
12
12
  DEVICE_POLL_TIMEOUT = 60 # seconds
13
13
 
14
- DEFAULT_AKI = "aki-b4aa75dd"
15
- DEFAULT_ROOT_DEVICE_NAME = "/dev/sda1"
16
-
17
- # UBUNTU_10_04_32_BIT_US_EAST_EBS = "ami-3e9b4957"
18
- # UBUNTU_10_04_32_BIT_US_EAST = "ami-809a48e9"
19
-
20
14
  attr_reader :ec2
21
15
  attr_reader :registry
22
16
  attr_accessor :logger
@@ -101,7 +95,11 @@ module Bosh::AwsCloud
101
95
  @logger.debug("using security groups: #{security_groups.join(', ')}")
102
96
 
103
97
  response = @ec2.client.describe_images(:image_ids => [stemcell_id])
104
- root_device_name = response.images_set.first.root_device_name
98
+ images_set = response.images_set
99
+ if images_set.empty?
100
+ cloud_error("no stemcell info for #{stemcell_id}")
101
+ end
102
+ root_device_name = images_set.first.root_device_name
105
103
 
106
104
  instance_params = {
107
105
  :image_id => stemcell_id,
@@ -285,6 +283,14 @@ module Bosh::AwsCloud
285
283
  # involves creating and mounting new EBS volume as local block device.
286
284
  # @param [String] image_path local filesystem path to a stemcell image
287
285
  # @param [Hash] cloud_properties CPI-specific properties
286
+ # @option cloud_properties [String] kernel_id
287
+ # AKI, auto-selected based on the region
288
+ # @option cloud_properties [String] root_device_name
289
+ # provided by the stemcell manifest
290
+ # @option cloud_properties [String] architecture
291
+ # provided by the stemcell manifest
292
+ # @option cloud_properties [String] disk (2048)
293
+ # root disk size
288
294
  def create_stemcell(image_path, cloud_properties)
289
295
  # TODO: refactor into several smaller methods
290
296
  with_thread_name("create_stemcell(#{image_path}...)") do
@@ -309,13 +315,18 @@ module Bosh::AwsCloud
309
315
  snapshot = volume.create_snapshot
310
316
  wait_resource(snapshot, :completed)
311
317
 
312
- root_device_name = cloud_properties["root_device_name"] ||
313
- DEFAULT_ROOT_DEVICE_NAME
318
+ root_device_name = cloud_properties["root_device_name"]
319
+ architecture = cloud_properties["architecture"]
320
+
321
+ aki = find_aki(architecture, root_device_name)
314
322
 
323
+ # we could set :description here, but since we don't have a
324
+ # handle to the stemcell name and version, we can't set it
325
+ # to something useful :(
315
326
  image_params = {
316
327
  :name => "BOSH-#{generate_unique_name}",
317
- :architecture => "x86_64", # TODO should this be configurable?
318
- :kernel_id => cloud_properties["kernel_id"] || DEFAULT_AKI,
328
+ :architecture => architecture,
329
+ :kernel_id => aki,
319
330
  :root_device_name => root_device_name,
320
331
  :block_device_mappings => {
321
332
  "/dev/sda" => { :snapshot_id => snapshot.id },
@@ -340,6 +351,42 @@ module Bosh::AwsCloud
340
351
  end
341
352
  end
342
353
 
354
+ # finds the correct aki for the current region
355
+ def find_aki(arch, root_device_name)
356
+
357
+ filters = []
358
+ filters << {:name => "architecture", :values => [arch]}
359
+ filters << {:name => "image-type", :values => %w[kernel]}
360
+ filters << {:name => "owner-alias", :values => %w[amazon]}
361
+
362
+ response = @ec2.client.describe_images(:filters => filters)
363
+
364
+ # do nasty hackery to select boot device and version from
365
+ # the image_location string e.g. pv-grub-hd00_1.03-x86_64.gz
366
+ if root_device_name == "/dev/sda1"
367
+ regexp = /-hd00[-_](\d+)\.(\d+)/
368
+ else
369
+ regexp = /-hd0[-_](\d+)\.(\d+)/
370
+ end
371
+
372
+ candidate = nil
373
+ major = 0
374
+ minor = 0
375
+ response.images_set.each do |image|
376
+ match = image.image_location.match(regexp)
377
+ if match && match[1].to_i > major && match[2].to_i > minor
378
+ candidate = image
379
+ major = match[1].to_i
380
+ minor = match[2].to_i
381
+ end
382
+ end
383
+
384
+ cloud_error("unable to find AKI") unless candidate
385
+ @logger.info("auto-selected AKI: #{candidate.image_id}")
386
+
387
+ candidate.image_id
388
+ end
389
+
343
390
  def delete_stemcell(stemcell_id)
344
391
  with_thread_name("delete_stemcell(#{stemcell_id})") do
345
392
  image = @ec2.images[stemcell_id]
@@ -393,6 +440,7 @@ module Bosh::AwsCloud
393
440
  # assume its identity
394
441
  # @param [Hash] network_spec Agent network spec
395
442
  # @param [Hash] environment
443
+ # @param [String] root_device_name root device, e.g. /dev/sda1
396
444
  # @return [Hash]
397
445
  def initial_agent_settings(agent_id, network_spec, environment,
398
446
  root_device_name)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bosh
4
4
  module AwsCloud
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
@@ -39,6 +39,17 @@ describe Bosh::AwsCloud::Cloud do
39
39
  ec2.volumes.stub(:[]).with("v-foo").and_return(volume)
40
40
  ec2.instances.stub(:[]).with("i-current").and_return(current_instance)
41
41
  ec2.images.should_receive(:create).with(image_params).and_return(image)
42
+
43
+ i1 = double("image-1", :root_device_name => "/dev/sda1",
44
+ :image_location => "pv-grub-hd00_1.03-x86_64.gz",
45
+ :image_id => "aki-b4aa75dd")
46
+ i2 = double("image-2", :root_device_name => "/dev/sda1",
47
+ :image_location => "pv-grub-hd00_1.02-x86_64.gz",
48
+ :image_id => "aki-b4aa75d0")
49
+
50
+ result = double("images_set", :images_set => [i1, i2])
51
+ client = double("client", :describe_images => result)
52
+ ec2.should_receive(:client).and_return(client)
42
53
  end
43
54
 
44
55
  cloud.stub(:generate_unique_name).and_return(unique_name)
@@ -89,7 +100,11 @@ describe Bosh::AwsCloud::Cloud do
89
100
 
90
101
  cloud.should_receive(:delete_disk).with("v-foo")
91
102
 
92
- cloud.create_stemcell("/tmp/foo", {}).should == "i-bar"
103
+ cloud_properties = {
104
+ "root_device_name" => "/dev/sda1",
105
+ "architecture" => "x86_64"
106
+ }
107
+ cloud.create_stemcell("/tmp/foo", cloud_properties).should == "i-bar"
93
108
  end
94
109
 
95
110
  end
@@ -127,6 +127,16 @@ describe Bosh::AwsCloud::Cloud, "create_vm" do
127
127
 
128
128
  cloud = mock_cloud do |ec2|
129
129
  ec2.instances.should_receive(:create).and_return(instance)
130
+ image = double("image")
131
+ image.should_receive(:root_device_name).and_return("/dev/sda1")
132
+
133
+ result = double("result")
134
+ result.should_receive(:images_set).and_return([image])
135
+
136
+ client = double("client")
137
+ client.should_receive(:describe_images).with({:image_ids=>["sc-id"]}).
138
+ and_return(result)
139
+
130
140
  ec2.should_receive(:client).and_return(client)
131
141
  end
132
142
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bosh_aws_cpi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-10 00:00:00.000000000 Z
12
+ date: 2012-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -158,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  segments:
160
160
  - 0
161
- hash: -2403392629027305829
161
+ hash: 3392403251669276232
162
162
  required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  none: false
164
164
  requirements:
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  segments:
169
169
  - 0
170
- hash: -2403392629027305829
170
+ hash: 3392403251669276232
171
171
  requirements: []
172
172
  rubyforge_project:
173
173
  rubygems_version: 1.8.24