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

Constant Summary collapse

DEFAULT_NTP_SERVERS =
%w[0.pool.ntp.org 1.pool.ntp.org]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest_path, settings, fog_compute) ⇒ Base

Returns a new instance of Base.



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

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.



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

def fog_compute
  @fog_compute
end

#manifest_pathObject (readonly)

Returns the value of attribute manifest_path.



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

def manifest_path
  @manifest_path
end

#settingsObject (readonly)

Returns the value of attribute settings.



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

def settings
  @settings
end

Instance Method Details

#create_microbosh_yml(settings) ⇒ Object



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

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_specObject



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 117

def default_spec
  spec = {
    "cloud" => { "properties" => { "agent" => { "ntp" => ntp_servers } } },
    "apply_spec" => { "properties" => { "ntp" => ntp_servers } }
  }

  if settings.exists?("recursor")
    spec["apply_spec"]["properties"]["dns"] = {
      "recursor" => settings.recursor
    }
  end
  spec
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



98
99
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 98

def discover_if_stemcell_image_already_uploaded
end

#download_stemcellObject

downloads latest stemcell & returns path



102
103
104
105
106
107
108
109
110
111
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 102

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



75
76
77
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 75

def jenkins_bucket
  "bosh-jenkins-artifacts"
end

#microbosh_nameObject



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

def microbosh_name
  settings.bosh.name
end

#ntp_serversObject



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

def ntp_servers
  servers = DEFAULT_NTP_SERVERS
  servers = settings.provider.ntps if settings.exists?("provider.ntps")
  servers = settings.ntp if settings.exists?("ntp")
  return servers.is_a?(String) ? servers.split(",") : servers
end

#private_key_pathObject



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

def private_key_path
  settings.key_pair.path
end

#proxyObject



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

def proxy
  settings.proxy.to_hash
end

#proxy?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 64

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

#public_ipObject



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

def public_ip
  settings.address.ip
end

#public_ip?Boolean

Returns:

  • (Boolean)


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

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

#recent_stemcellsObject



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

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

#salted_passwordObject



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

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

#stemcell_dirObject



113
114
115
# File 'lib/bosh-bootstrap/microbosh_providers/base.rb', line 113

def stemcell_dir
  File.dirname(manifest_path)
end

#stemcell_pathObject



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

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



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

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