bosh_aws_cpi 0.7.0 → 1.5.0.pre.1113

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/README.md +22 -19
  2. data/bin/bosh_aws_console +1 -13
  3. data/lib/bosh_aws_cpi.rb +1 -1
  4. data/lib/cloud/aws/aki_picker.rb +7 -7
  5. data/lib/cloud/aws/availability_zone_selector.rb +40 -0
  6. data/lib/cloud/aws/cloud.rb +359 -476
  7. data/lib/cloud/aws/dynamic_network.rb +0 -6
  8. data/lib/cloud/aws/helpers.rb +10 -68
  9. data/lib/cloud/aws/instance_manager.rb +171 -0
  10. data/lib/cloud/aws/manual_network.rb +26 -0
  11. data/lib/cloud/aws/network_configurator.rb +33 -62
  12. data/lib/cloud/aws/resource_wait.rb +189 -0
  13. data/lib/cloud/aws/stemcell.rb +68 -0
  14. data/lib/cloud/aws/stemcell_creator.rb +114 -0
  15. data/lib/cloud/aws/tag_manager.rb +30 -0
  16. data/lib/cloud/aws/version.rb +1 -1
  17. data/lib/cloud/aws/vip_network.rb +9 -7
  18. data/lib/cloud/aws.rb +11 -2
  19. data/scripts/stemcell-copy.sh +37 -0
  20. metadata +45 -81
  21. data/Rakefile +0 -50
  22. data/lib/cloud/aws/registry_client.rb +0 -109
  23. data/spec/assets/stemcell-copy +0 -31
  24. data/spec/integration/cpi_test.rb +0 -78
  25. data/spec/spec_helper.rb +0 -121
  26. data/spec/unit/aki_picker_spec.rb +0 -29
  27. data/spec/unit/attach_disk_spec.rb +0 -143
  28. data/spec/unit/cloud_spec.rb +0 -32
  29. data/spec/unit/configure_networks_spec.rb +0 -113
  30. data/spec/unit/create_disk_spec.rb +0 -73
  31. data/spec/unit/create_stemcell_spec.rb +0 -113
  32. data/spec/unit/create_vm_spec.rb +0 -249
  33. data/spec/unit/delete_disk_spec.rb +0 -34
  34. data/spec/unit/delete_stemcell_spec.rb +0 -29
  35. data/spec/unit/delete_vm_spec.rb +0 -25
  36. data/spec/unit/detach_disk_spec.rb +0 -63
  37. data/spec/unit/helpers_spec.rb +0 -64
  38. data/spec/unit/network_configurator_spec.rb +0 -57
  39. data/spec/unit/reboot_vm_spec.rb +0 -38
  40. data/spec/unit/set_vm_metadata_spec.rb +0 -30
  41. data/spec/unit/validate_deployment_spec.rb +0 -16
data/README.md CHANGED
@@ -9,22 +9,25 @@ These options are passed to the AWS CPI when it is instantiated.
9
9
 
10
10
  ### AWS options
11
11
 
12
- * `access_key_id` (required)
12
+ * `access_key_id` (required)
13
13
  AWS IAM user access key
14
- * `secret_access_key` (required)
14
+ * `secret_access_key` (required)
15
15
  AWS IAM secret access key
16
- * `default_key_name` (required)
16
+ * `default_key_name` (required)
17
17
  default AWS ssh key name to assign to created virtual machines
18
- * `default_security_group` (required)
19
- default AWS security group to assign to created virtual machines
20
- * `ec2_private_key` (required)
18
+ * `default_security_groups` (required)
19
+ list of AWS security group to assign to created virtual machines
20
+ * `ec2_private_key` (required)
21
21
  local path to the ssh private key, must match `default_key_name`
22
- * `region` (optional)
23
- EC2 region, defaults to `us-east-1`
24
- * `ec2_endpoint` (optional)
22
+ * `region` (required)
23
+ EC2 region
24
+ * `ec2_endpoint` (optional)
25
25
  URL of the EC2 endpoint to connect to, defaults to the endpoint corresponding to the selected region,
26
- or `DEFAULT_EC2_ENDPOINT` if no region has been selected
27
- * `max_retries` (optional)
26
+ or `default_ec2_endpoint` if no region has been selected
27
+ * `elb_endpoint` (optional)
28
+ URL of the ELB endpoint to connect to, default to the endpoint corresponding to the selected region,
29
+ or `default_elb_endpoint` if no region has been selected
30
+ * `max_retries` (optional)
28
31
  maximum number of time to retry an AWS API call, defaults to `DEFAULT_MAX_RETRIES`
29
32
 
30
33
  ### Registry options
@@ -32,11 +35,11 @@ These options are passed to the AWS CPI when it is instantiated.
32
35
  The registry options are passed to the AWS CPI by the BOSH director based on the settings in `director.yml`, but can be
33
36
  overridden if needed.
34
37
 
35
- * `endpoint` (required)
38
+ * `endpoint` (required)
36
39
  registry URL
37
- * `user` (required)
40
+ * `user` (required)
38
41
  registry user
39
- * `password` (required)
42
+ * `password` (required)
40
43
  registry password
41
44
 
42
45
  ### Agent options
@@ -48,16 +51,16 @@ overridden if needed.
48
51
 
49
52
  These options are specified under `cloud_options` in the `resource_pools` section of a BOSH deployment manifest.
50
53
 
51
- * `availability_zone` (optional)
54
+ * `availability_zone` (optional)
52
55
  the EC2 availability zone the VMs should be created in
53
- * `instance_type` (required)
56
+ * `instance_type` (required)
54
57
  which [type of instance](http://aws.amazon.com/ec2/instance-types/) the VMs should belong to
55
58
 
56
59
  ### Network options
57
60
 
58
61
  These options are specified under `cloud_options` in the `networks` section of a BOSH deployment manifest.
59
62
 
60
- * `type` (required)
63
+ * `type` (required)
61
64
  can be either `dynamic` for a DHCP assigned IP by AWS, or `vip` to use an Elastic IP (which needs to be already
62
65
  allocated)
63
66
 
@@ -88,8 +91,8 @@ This is a sample of how AWS specific properties are used in a BOSH deployment ma
88
91
  network: default
89
92
  size: 3
90
93
  stemcell:
91
- name: bosh-stemcell
92
- version: 0.6.7
94
+ name: bosh-aws-xen-ubuntu
95
+ version: latest
93
96
  cloud_properties:
94
97
  instance_type: m1.small
95
98
 
data/bin/bosh_aws_console CHANGED
@@ -6,15 +6,6 @@
6
6
  # irb(main):001:0> cpi.create_vm("test", "ami-809a48e9",
7
7
  # {"instance_type" => "m1.small"}, {}, [], {"foo" =>"bar"})
8
8
 
9
- gemfile = File.expand_path("../../Gemfile", __FILE__)
10
-
11
- if File.exists?(gemfile)
12
- ENV["BUNDLE_GEMFILE"] = gemfile
13
- require "rubygems"
14
- require "bundler/setup"
15
- end
16
-
17
- $:.unshift(File.expand_path("../../lib", __FILE__))
18
9
  require "bosh_aws_cpi"
19
10
  require "irb"
20
11
  require "irb/completion"
@@ -34,7 +25,7 @@ unless config_file
34
25
  exit(1)
35
26
  end
36
27
 
37
- @config = YAML.load_file(config_file)
28
+ @config = Psych.load_file(config_file)
38
29
 
39
30
  module ConsoleHelpers
40
31
  def cpi
@@ -67,6 +58,3 @@ puts "=> Welcome to BOSH AWS CPI console"
67
58
  puts "You can use 'cpi' to access CPI methods"
68
59
 
69
60
  IRB.start
70
-
71
-
72
-
data/lib/bosh_aws_cpi.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # Copyright (c) 2009-2012 VMware, Inc.
2
2
 
3
- require "cloud/aws"
3
+ require "cloud/aws"
@@ -1,9 +1,9 @@
1
1
  module Bosh::AwsCloud
2
2
  class AKIPicker
3
3
 
4
- # @param [AWS::Core::ServiceInterface] ec2
5
- def initialize(ec2)
6
- @ec2 = ec2
4
+ # @param [AWS::Core::ServiceInterface] region
5
+ def initialize(region)
6
+ @region = region
7
7
  end
8
8
 
9
9
  # finds the correct aki for the current region
@@ -22,15 +22,15 @@ module Bosh::AwsCloud
22
22
 
23
23
  def fetch_akis(architecture)
24
24
  filter = aki_filter(architecture)
25
- @ec2.client.describe_images(:filters => filter).images_set
25
+ @region.client.describe_images(filters: filter).images_set
26
26
  end
27
27
 
28
28
  # @return [Hash] search filter
29
29
  def aki_filter(architecture)
30
30
  [
31
- {:name => "architecture", :values => [architecture]},
32
- {:name => "image-type", :values => %w[kernel]},
33
- {:name => "owner-alias", :values => %w[amazon]}
31
+ {name: "architecture", values: [architecture]},
32
+ {name: "image-type", values: %w[kernel]},
33
+ {name: "owner-alias", values: %w[amazon]}
34
34
  ]
35
35
  end
36
36
 
@@ -0,0 +1,40 @@
1
+ module Bosh::AwsCloud
2
+ class AvailabilityZoneSelector
3
+ attr_accessor :region
4
+
5
+ def initialize(region, default_name)
6
+ @region = region
7
+ @default = default_name
8
+ end
9
+
10
+ def common_availability_zone(volume_az_names, resource_pool_az_name, vpc_subnet_az_name)
11
+ zone_names = (volume_az_names + [resource_pool_az_name, vpc_subnet_az_name]).compact.uniq
12
+ ensure_same_availability_zone(zone_names)
13
+
14
+ zone_names.first || @default
15
+ end
16
+
17
+ def select_availability_zone(instance_id)
18
+ if instance_id
19
+ region.instances[instance_id].availability_zone
20
+ elsif @default
21
+ @default
22
+ else
23
+ random_availability_zone
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def random_availability_zone
30
+ zones = []
31
+ region.availability_zones.each { |zone| zones << zone.name }
32
+ zones[Random.rand(zones.size)]
33
+ end
34
+
35
+ def ensure_same_availability_zone(zone_names)
36
+ raise Bosh::Clouds::CloudError,
37
+ "can't use multiple availability zones: #{zone_names.join(', ')}" if zone_names.size > 1
38
+ end
39
+ end
40
+ end