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, fog_compute) ⇒ Base

Returns a new instance of Base.



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

def initialize(manifest_path, settings, fog_compute)
  @manifest_path = manifest_path
  @fog_compute = fog_compute
  @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

#fog_computeObject (readonly)

Returns the value of attribute fog_compute.



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

def fog_compute
  @fog_compute
end

#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



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

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

#default_apply_specObject



108
109
110
111
112
113
114
115
116
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 108

def default_apply_spec
  return {} unless  settings.exists?("recursor")
  {"apply_spec"=>
    {"properties"=>
     {"dns"=>{
       "recursor"=>settings.recursor} }
    }
  }
end

#discover_if_stemcell_image_already_uploadedObject

override if infrastructure has enough information to discover if stemcell already uploaded and can be used via its image ID/AMI



89
90
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 89

def discover_if_stemcell_image_already_uploaded
end

#download_stemcellObject

downloads latest stemcell & returns path



93
94
95
96
97
98
99
100
101
102
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 93

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

#jenkins_bucketObject



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

def jenkins_bucket
  "bosh-jenkins-artifacts"
end

#microbosh_nameObject



37
38
39
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 37

def microbosh_name
  settings.bosh.name
end

#private_key_pathObject



54
55
56
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 54

def private_key_path
  settings.key_pair.path
end

#proxyObject



58
59
60
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 58

def proxy
  settings.proxy.to_hash
end

#proxy?Boolean

Returns:

  • (Boolean)


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

def proxy?
  settings.exists?("proxy")
end

#public_ipObject



46
47
48
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 46

def public_ip
  settings.address.ip
end

#public_ip?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 50

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

#recent_stemcellsObject



79
80
81
82
83
84
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 79

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

#salted_passwordObject



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

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

#stemcell_dirObject



104
105
106
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 104

def stemcell_dir
  File.dirname(manifest_path)
end

#stemcell_pathObject



70
71
72
73
74
75
76
77
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 70

def stemcell_path
  settings.exists?("bosh.stemcell_path") || begin
    if image = discover_if_stemcell_image_already_uploaded
      return image
    end
    download_stemcell
  end
end

#to_hashObject



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

def to_hash
  {"name"=>microbosh_name,
   "logging"=>{"level"=>"DEBUG"},
  }.merge(default_apply_spec)
end