Class: Chef::Knife::PinningsPromote

Inherits:
Chef::Knife show all
Defined in:
lib/chef/knife/pinnings_promote.rb

Overview

This class copies cookbook pinnings between environments

Instance Method Summary collapse

Instance Method Details

#copy_pinnings(source_env, target_env, cookbook_regex) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chef/knife/pinnings_promote.rb', line 34

def copy_pinnings(source_env, target_env, cookbook_regex)
  ui.msg('')
  ui.confirm("Do you want to write to #{target_env.name}")
  ui.msg('')

  source_env.cookbook_versions.each do |name, version|
    target_env.cookbook_versions[name] = version if name =~ /#{cookbook_regex}/
  end

  target_env.save
  ui.msg('Done!')
end

#runObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chef/knife/pinnings_promote.rb', line 22

def run
  unless name_args.length > 1
    ui.fatal('You must specify a source and target environment.')
    exit 255
  end
  source_env = Environment.load(name_args[0])
  target_env = Environment.load(name_args[1])
  cookbook_regex = name_args[2] || '.*'
  display_pinnings_table([source_env, target_env], cookbook_regex)
  copy_pinnings(source_env, target_env, cookbook_regex)
end