Class: Bosh::Bootstrap::MicroboshProviders::Base

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/bosh-bootstrap/microbosh_providers/base.rb

Direct Known Subclasses

AWS, OpenStack, VSphere

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest_path, settings) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 14

def initialize(manifest_path, settings)
  @manifest_path = manifest_path
  @settings = settings.is_a?(Hash) ? ReadWriteSettings.new(settings) : settings
  raise "@settings must be ReadWriteSettings (or Hash)" unless @settings.is_a?(ReadWriteSettings)
end

Instance Attribute Details

#manifest_pathObject (readonly)

Returns the value of attribute manifest_path.



11
12
13
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 11

def manifest_path
  @manifest_path
end

#settingsObject (readonly)

Returns the value of attribute settings.



12
13
14
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 12

def settings
  @settings
end

Instance Method Details

#create_microbosh_yml(settings) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 20

def create_microbosh_yml(settings)
  @settings = settings.is_a?(Hash) ? ReadWriteSettings.new(settings) : settings
  raise "@settings must be ReadWriteSettings (or Hash)" unless @settings.is_a?(ReadWriteSettings)
  mkdir_p(File.dirname(manifest_path))
  File.open(manifest_path, "w") do |f|
    f << self.to_hash.to_yaml
  end
end

#download_stemcellObject

downloads latest stemcell & returns path



74
75
76
77
78
79
80
81
82
83
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 74

def download_stemcell
  mkdir_p(stemcell_dir)
  chdir(stemcell_dir) do
    stemcell_path = File.expand_path(latest_stemcell.name)
    unless File.exists?(stemcell_path)
      sh "curl -O '#{latest_stemcell.url}'"
    end
    return stemcell_path
  end
end

#jenkins_bucketObject



56
57
58
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 56

def jenkins_bucket
  "bosh-jenkins-artifacts"
end

#microbosh_nameObject



35
36
37
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 35

def microbosh_name
  settings.bosh.name
end

#private_key_pathObject



52
53
54
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 52

def private_key_path
  settings.key_pair.path
end

#public_ipObject



44
45
46
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 44

def public_ip
  settings.address.ip
end

#public_ip?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 48

def public_ip?
  settings.exists?("address.ip")
end

#recent_stemcellsObject



66
67
68
69
70
71
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 66

def recent_stemcells
  @recent_stemcells ||= begin
    public_stemcells = Bosh::Bootstrap::PublicStemcells.new
    public_stemcells.recent
  end
end

#salted_passwordObject



39
40
41
42
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 39

def salted_password
  # BCrypt::Password.create(settings.bosh.password).to_s.force_encoding("UTF-8")
  settings.bosh.salted_password
end

#stemcell_dirObject



85
86
87
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 85

def stemcell_dir
  File.dirname(manifest_path)
end

#stemcell_pathObject



60
61
62
63
64
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 60

def stemcell_path
  unless settings.exists?("bosh.stemcell_path")
    download_stemcell
  end
end

#to_hashObject



29
30
31
32
33
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 29

def to_hash
  {"name"=>microbosh_name,
   "logging"=>{"level"=>"DEBUG"}
  }
end