Class: Bosh::Deployer::DeploymentsState

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

Constant Summary collapse

DEPLOYMENTS_FILE =
'bosh-deployments.yml'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deployments, file) ⇒ DeploymentsState

Returns a new instance of DeploymentsState.



22
23
24
25
# File 'lib/bosh/deployer/deployments_state.rb', line 22

def initialize(deployments, file)
  @deployments = deployments
  @file = file
end

Instance Attribute Details

#deploymentsObject (readonly)

Returns the value of attribute deployments.



8
9
10
# File 'lib/bosh/deployer/deployments_state.rb', line 8

def deployments
  @deployments
end

#fileObject (readonly)

Returns the value of attribute file.



8
9
10
# File 'lib/bosh/deployer/deployments_state.rb', line 8

def file
  @file
end

#stateObject (readonly)

Returns the value of attribute state.



8
9
10
# File 'lib/bosh/deployer/deployments_state.rb', line 8

def state
  @state
end

Class Method Details

.load_from_dir(dir, logger) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bosh/deployer/deployments_state.rb', line 10

def self.load_from_dir(dir, logger)
  file = File.join(dir, DEPLOYMENTS_FILE)
  if File.exists?(file)
    logger.info("Loading existing deployment data from: #{file}")
    deployments = Psych.load_file(file)
  else
    logger.info("No existing deployments found (will save to #{file})")
    deployments = { 'instances' => [], 'disks' => [] }
  end
  new(deployments, file)
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


49
50
51
52
# File 'lib/bosh/deployer/deployments_state.rb', line 49

def exists?
  return false unless state
  [state.vm_cid, state.stemcell_cid, state.disk_cid].any?
end

#load_deployment(name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bosh/deployer/deployments_state.rb', line 27

def load_deployment(name)
  models_instance.multi_insert(deployments['instances'])

  @state = models_instance.find(name: name)
  if state.nil?
    @state = models_instance.new
    state.uuid = "bm-#{SecureRandom.uuid}"
    state.name = name
    state.stemcell_sha1 = nil
    state.save
  end
end

#save(infrastructure) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/bosh/deployer/deployments_state.rb', line 40

def save(infrastructure)
  state.save
  deployments['instances'] = models_instance.map { |instance| instance.values }

  File.open(file, 'w') do |file|
    file.write(Psych.dump(deployments))
  end
end