Class: Bosh::Cli::Command::AWS

Inherits:
Base
  • Object
show all
Defined in:
lib/bosh/cli/commands/aws.rb

Constant Summary collapse

DEFAULT_CIDR =

KILL

'10.0.0.0/16'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner = []) ⇒ AWS

Returns a new instance of AWS.


15
16
17
18
# File 'lib/bosh/cli/commands/aws.rb', line 15

def initialize(runner = [])
  super(runner)
  @output_state = {}
end

Instance Attribute Details

#config_dirObject (readonly)

Returns the value of attribute config_dir.


12
13
14
# File 'lib/bosh/cli/commands/aws.rb', line 12

def config_dir
  @config_dir
end

#ec2Object (readonly)

Returns the value of attribute ec2.


12
13
14
# File 'lib/bosh/cli/commands/aws.rb', line 12

def ec2
  @ec2
end

#output_stateObject (readonly)

Returns the value of attribute output_state.


12
13
14
# File 'lib/bosh/cli/commands/aws.rb', line 12

def output_state
  @output_state
end

#vpcObject

Returns the value of attribute vpc.


13
14
15
# File 'lib/bosh/cli/commands/aws.rb', line 13

def vpc
  @vpc
end

Instance Method Details

#bootstrap_bosh(config_file = nil) ⇒ Object


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/bosh/cli/commands/aws.rb', line 55

def bootstrap_bosh(config_file = nil)
  target_required
  err "To bootstrap BOSH, first log in to '#{config.target}'" unless logged_in?

  options[:hm_director_user] ||= 'hm'
  options[:hm_director_password] = SecureRandom.base64

  bootstrap = Bosh::AwsCliPlugin::BoshBootstrap.new(director, s3(config_file), self.options)
  bootstrap.start

  say 'For security purposes, please provide a username and password for BOSH Director'
  username = ask('Enter username: ')
  password = ask('Enter password: ') { |q| q.echo = '*' }

  bootstrap.create_user(username, password)

  say "BOSH deployed successfully. You are logged in as #{username}."

  bootstrap.create_user(options[:hm_director_user], options[:hm_director_password])
rescue Bosh::AwsCliPlugin::BootstrapError => e
  err "Unable to bootstrap bosh: #{e.message}"
end

#bootstrap_microObject


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bosh/cli/commands/aws.rb', line 30

def bootstrap_micro
  options[:hm_director_password] = SecureRandom.base64
  options[:hm_director_user] ||= 'hm'

  bootstrap = Bosh::AwsCliPlugin::MicroBoshBootstrap.new(runner, options)
  bootstrap.start

  bootstrap.create_user(options[:hm_director_user], options[:hm_director_password])

  if interactive?
    username = ask('Enter username: ')
    password = ask('Enter password: ') { |q| q.echo = '*' }

    if username.blank? || password.blank?
      err('Please enter username and password')
    end

    bootstrap.create_user(username, password)
  else
    bootstrap.create_user('admin', SecureRandom.base64)
  end
end

#create(config_file = nil) ⇒ Object


124
125
126
127
128
129
130
131
# File 'lib/bosh/cli/commands/aws.rb', line 124

def create(config_file = nil)
  if !!options[:trace]
     require 'logger'
     ::AWS.config(:logger => Logger.new($stdout), :http_wire_trace => true)
  end

  Bosh::AwsCliPlugin::Migrator.new(load_config(config_file)).migrate
end

#create_bat_manifest(vpc_receipt_file, route53_receipt_file, stemcell_version, stemcell_name) ⇒ Object


110
111
112
113
114
115
116
117
118
119
# File 'lib/bosh/cli/commands/aws.rb', line 110

def create_bat_manifest(vpc_receipt_file, route53_receipt_file, stemcell_version, stemcell_name)
  target_required

  vpc_config = load_yaml_file(vpc_receipt_file)
  route53_config = load_yaml_file(route53_receipt_file)
  manifest = Bosh::AwsCliPlugin::BatManifest.new(
    vpc_config, route53_config, stemcell_version, director.uuid, stemcell_name)

  write_yaml(manifest, manifest.file_name)
end

#create_bosh_manifest(vpc_receipt_file, route53_receipt_file, bosh_rds_receipt_file) ⇒ Object


94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/bosh/cli/commands/aws.rb', line 94

def create_bosh_manifest(vpc_receipt_file, route53_receipt_file, bosh_rds_receipt_file)
  target_required

  options[:hm_director_user] ||= 'hm'
  options[:hm_director_password] = SecureRandom.base64

  vpc_config = load_yaml_file(vpc_receipt_file)
  route53_config = load_yaml_file(route53_receipt_file)
  bosh_rds_config = load_yaml_file(bosh_rds_receipt_file)
  bosh_manifest = Bosh::AwsCliPlugin::BoshManifest.new(vpc_config, route53_config, director.uuid, bosh_rds_config, options)

  write_yaml(bosh_manifest, bosh_manifest.file_name)
end

#create_key_pairs(config_file = nil) ⇒ Object


141
142
143
# File 'lib/bosh/cli/commands/aws.rb', line 141

def create_key_pairs(config_file = nil)
  Bosh::AwsCliPlugin::Migrator.new(load_config(config_file)).migrate_version('20130412000811')
end

#create_micro_bosh_manifest(vpc_receipt_file, route53_receipt_file) ⇒ Object


80
81
82
83
84
85
86
87
88
89
90
# File 'lib/bosh/cli/commands/aws.rb', line 80

def create_micro_bosh_manifest(vpc_receipt_file, route53_receipt_file)
  vpc_config = load_yaml_file(vpc_receipt_file)
  route53_config = load_yaml_file(route53_receipt_file)

  options[:hm_director_user] ||= 'hm'
  options[:hm_director_password] = SecureRandom.base64

  manifest = Bosh::AwsCliPlugin::MicroboshManifest.new(vpc_config, route53_config, options)

  write_yaml(manifest, manifest.file_name)
end

#create_route53_records(config_file = nil) ⇒ Object


147
148
149
# File 'lib/bosh/cli/commands/aws.rb', line 147

def create_route53_records(config_file = nil)
  Bosh::AwsCliPlugin::Migrator.new(load_config(config_file)).migrate_version('20130412181302')
end

#create_s3(config_file = nil) ⇒ Object


135
136
137
# File 'lib/bosh/cli/commands/aws.rb', line 135

def create_s3(config_file = nil)
  Bosh::AwsCliPlugin::Migrator.new(load_config(config_file)).migrate_version('20130412192351')
end

#create_vpc(config_file = nil) ⇒ Object


153
154
155
# File 'lib/bosh/cli/commands/aws.rb', line 153

def create_vpc(config_file = nil)
  Bosh::AwsCliPlugin::Migrator.new(load_config(config_file)).migrate_version('20130412004642')
end

#destroy(config_file = nil) ⇒ Object


159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/bosh/cli/commands/aws.rb', line 159

def destroy(config_file = nil)
  config = load_config(config_file)

  rds_destroyer = Bosh::AwsCliPlugin::RdsDestroyer.new(self, config)
  vpc_destroyer = Bosh::AwsCliPlugin::VpcDestroyer.new(self, config)
  destroyer = Bosh::AwsCliPlugin::Destroyer.new(self, config, rds_destroyer, vpc_destroyer)

  destroyer.ensure_not_production!
  destroyer.delete_all_elbs
  destroyer.delete_all_ec2
  destroyer.delete_all_ebs
  destroyer.delete_all_rds
  destroyer.delete_all_s3
  destroyer.delete_all_vpcs
  destroyer.delete_all_key_pairs
  destroyer.delete_all_elastic_ips
  destroyer.delete_all_security_groups
  destroyer.delete_all_route53_records
end

#helpObject


22
23
24
25
26
# File 'lib/bosh/cli/commands/aws.rb', line 22

def help
  say "bosh aws sub-commands:\n"
  commands = Bosh::Cli::Config.commands.values.find_all { |command| command.usage =~ /^aws/ }
  Bosh::Cli::Command::Help.list_commands(commands)
end