Class: Bosh::Deployer::InstanceManager::Aws

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/deployer/instance_manager/aws.rb

Instance Method Summary collapse

Constructor Details

#initialize(instance_manager, logger) ⇒ Aws

Returns a new instance of Aws.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bosh/deployer/instance_manager/aws.rb', line 8

def initialize(instance_manager, logger)
  @instance_manager = instance_manager
  @logger = logger
  properties = Config.cloud_options['properties']

  @registry = Registry.new(
    properties['registry']['endpoint'],
    'aws',
    properties['aws'],
    instance_manager,
    logger,
  )

  ssh_key, ssh_port, ssh_user, ssh_wait = ssh_properties(properties)

  ssh_server = SshServer.new(ssh_user, ssh_key, ssh_port, logger)
  @remote_tunnel = RemoteTunnel.new(ssh_server, ssh_wait, logger)
end

Instance Method Details

#check_dependenciesObject



52
53
54
# File 'lib/bosh/deployer/instance_manager/aws.rb', line 52

def check_dependencies
  # nothing to check, move on...
end

#discover_bosh_ipObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/bosh/deployer/instance_manager/aws.rb', line 65

def discover_bosh_ip
  if instance_manager.state.vm_cid
    # choose elastic IP over public, as any agent connecting to the
    # deployed micro bosh will be cut off from the public IP when
    # we re-deploy micro bosh
    instance = instance_manager.cloud.ec2.instances[instance_manager.state.vm_cid]
    if instance.has_elastic_ip?
      ip = instance.elastic_ip.public_ip
    else
      ip = instance.public_ip_address
    end

    if ip && ip != instance_manager.bosh_ip
      instance_manager.bosh_ip = ip
      logger.info("discovered bosh ip=#{instance_manager.bosh_ip}")
    end
  end

  instance_manager.bosh_ip
end

#disk_modelObject



31
32
33
# File 'lib/bosh/deployer/instance_manager/aws.rb', line 31

def disk_model
  nil
end

#disk_size(cid) ⇒ Integer

Returns size in MiB.

Returns:

  • (Integer)

    size in MiB



91
92
93
94
# File 'lib/bosh/deployer/instance_manager/aws.rb', line 91

def disk_size(cid)
  # AWS stores disk size in GiB but the CPI uses MiB
  instance_manager.cloud.ec2.volumes[cid].size * 1024
end

#persistent_disk_changed?Boolean

Returns:

  • (Boolean)


96
97
98
99
100
101
102
103
# File 'lib/bosh/deployer/instance_manager/aws.rb', line 96

def persistent_disk_changed?
  # since AWS stores disk size in GiB and the CPI uses MiB there
  # is a risk of conversion errors which lead to an unnecessary
  # disk migration, so we need to do a double conversion
  # here to avoid that
  requested = (Config.resources['persistent_disk'] / 1024.0).ceil * 1024
  requested != disk_size(instance_manager.state.disk_cid)
end

#remote_tunnelObject



27
28
29
# File 'lib/bosh/deployer/instance_manager/aws.rb', line 27

def remote_tunnel
  @remote_tunnel.create(instance_manager.bosh_ip, registry.port)
end

#service_ipObject



86
87
88
# File 'lib/bosh/deployer/instance_manager/aws.rb', line 86

def service_ip
  instance_manager.cloud.ec2.instances[instance_manager.state.vm_cid].private_ip_address
end

#startObject



56
57
58
# File 'lib/bosh/deployer/instance_manager/aws.rb', line 56

def start
  registry.start
end

#stopObject



60
61
62
63
# File 'lib/bosh/deployer/instance_manager/aws.rb', line 60

def stop
  registry.stop
  instance_manager.save_state
end

#update_spec(spec) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bosh/deployer/instance_manager/aws.rb', line 35

def update_spec(spec)
  properties = spec.properties

  # pick from micro_bosh.yml the aws settings in
  # `apply_spec` section (apply_spec.properties.aws),
  # and if it doesn't exist, use the bosh deployer
  # aws properties (cloud.properties.aws)
  properties['aws'] =
    Config.spec_properties['aws'] ||
    Config.cloud_options['properties']['aws'].dup

  properties['aws']['registry'] = Config.cloud_options['properties']['registry']
  properties['aws']['stemcell'] = Config.cloud_options['properties']['stemcell']

  spec.delete('networks')
end