Class: Bosh::AwsCloud::InstanceManager

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/cloud/aws/instance_manager.rb

Defined Under Namespace

Classes: DiskInfo

Constant Summary collapse

InstanceStorageMap =
{
  # previous generation
  'm1.small' => DiskInfo.new(160, 1),
  'm1.medium' => DiskInfo.new(410, 1),
  'm1.large' => DiskInfo.new(420, 2),
  'm1.xlarge' => DiskInfo.new(420, 4),

  'c1.medium' => DiskInfo.new(350, 1),
  'c1.xlarge' => DiskInfo.new(420, 4),

  'cc2.8xlarge' => DiskInfo.new(840, 4),

  'cg1.4xlarge' => DiskInfo.new(840, 2),

  'm2.xlarge' => DiskInfo.new(420, 1),
  'm2.2xlarge' => DiskInfo.new(850, 1),
  'm2.4xlarge' => DiskInfo.new(840, 2),

  'cr1.8xlarge' => DiskInfo.new(120, 2),

  'hi1.4xlarge' => DiskInfo.new(1024, 2),

  'hs1.8xlarge' => DiskInfo.new(2000, 24),

  # current generation
  'm3.medium' => DiskInfo.new(4, 1),
  'm3.large' => DiskInfo.new(32, 1),
  'm3.xlarge' => DiskInfo.new(40, 2),
  'm3.2xlarge' => DiskInfo.new(80, 2),

  'c3.large' => DiskInfo.new(16, 2),
  'c3.xlarge' => DiskInfo.new(40, 2),
  'c3.2xlarge' => DiskInfo.new(80, 2),
  'c3.4xlarge' => DiskInfo.new(160, 2),
  'c3.8xlarge' => DiskInfo.new(320, 2),

  'r3.large' => DiskInfo.new(32, 1),
  'r3.xlarge' => DiskInfo.new(80, 1),
  'r3.2xlarge' => DiskInfo.new(160, 1),
  'r3.4xlarge' => DiskInfo.new(320, 1),
  'r3.8xlarge' => DiskInfo.new(320, 2),

  'g2.2xlarge' => DiskInfo.new(60, 1),
  'g2.8xlarge' => DiskInfo.new(120, 2),

  'i2.xlarge' => DiskInfo.new(800, 1),
  'i2.2xlarge' => DiskInfo.new(800, 2),
  'i2.4xlarge' => DiskInfo.new(800, 4),
  'i2.8xlarge' => DiskInfo.new(800, 8),

  'd2.xlarge' => DiskInfo.new(2000, 3),
  'd2.2xlarge' => DiskInfo.new(2000, 6),
  'd2.4xlarge' => DiskInfo.new(2000, 12),
  'd2.8xlarge' => DiskInfo.new(2000, 24)
}

Instance Method Summary collapse

Methods included from Helpers

#cloud_error, #default_ephemeral_disk_mapping, #ebs_ephemeral_disk_mapping, #extract_security_groups

Constructor Details

#initialize(region, registry, elb, az_selector, logger) ⇒ InstanceManager

Returns a new instance of InstanceManager.



73
74
75
76
77
78
79
# File 'lib/cloud/aws/instance_manager.rb', line 73

def initialize(region, registry, elb, az_selector, logger)
  @region = region
  @registry = registry
  @elb = elb
  @az_selector = az_selector
  @logger = logger
end

Instance Method Details

#create(agent_id, stemcell_id, resource_pool, networks_spec, disk_locality, environment, options) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/cloud/aws/instance_manager.rb', line 81

def create(agent_id, stemcell_id, resource_pool, networks_spec, disk_locality, environment, options)
  instance_params, block_device_info = build_instance_params(stemcell_id, resource_pool, networks_spec, disk_locality, options)

  @logger.info("Creating new instance with: #{instance_params.inspect}")

  aws_instance = create_aws_instance(instance_params, resource_pool)

  instance = Instance.new(aws_instance, @registry, @elb, @logger)

  begin
    # We need to wait here for the instance to be running, as if we are going to
    # attach to a load balancer, the instance must be running.
    instance.wait_for_running
    instance.attach_to_load_balancers(resource_pool['elbs'] || [])
  rescue => e
    @logger.warn("Failed to configure instance '#{instance.id}': #{e.inspect}")
    begin
      instance.terminate
    rescue => e
      @logger.error("Failed to terminate mis-configured instance '#{instance.id}': #{e.inspect}")
    end
    raise
  end

  block_device_agent_info = block_device_info
                              .group_by { |v| v[:bosh_type] }
                              .map { |type, devices| {type => devices.map { |device| {"path" => device[:device_name]} }} }
                              .inject({}) { |a, b| a.merge(b) }

  return instance, block_device_agent_info
end

#find(instance_id) ⇒ Object

Parameters:

  • instance_id (String)

    EC2 instance id



114
115
116
# File 'lib/cloud/aws/instance_manager.rb', line 114

def find(instance_id)
  Instance.new(@region.instances[instance_id], @registry, @elb, @logger)
end