Class: Pantry::PantryLookup

Inherits:
Chef::Knife
  • Object
show all
Defined in:
lib/chef/knife/lookup.rb

Instance Method Summary collapse

Instance Method Details

#get_cbk_versions(env, cbk) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/chef/knife/lookup.rb', line 30

def get_cbk_versions(env, cbk)
  cookbooks = rest.get_rest("environments/#{env}/cookbooks")
  if !(cookbooks.has_key?(cbk))
    puts "#{cbk} not found in #{env}"
  else
    puts "[Cookbook found!]    Checking current version..."
    version = cookbooks[cbk]['versions'][0]['version']
    puts "[Version found!]    Finding latest releases..."
  end
  return version
end

#get_env(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/chef/knife/lookup.rb', line 18

def get_env(env)
  environments = []
  for key in rest.get_rest('environments')
    environments.push(key[0])
  end
  if !(environments.include?(env))
    puts "Specified environment does not exist"
  else
    puts "[Environment found!]   Looking for cookbook..."
  end
end

#get_past_versions(cbk, version) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/chef/knife/lookup.rb', line 42

def get_past_versions(cbk, version)
  available_versions= rest.get_rest("cookbooks/#{cbk}")
  puts "[Releases found!]"
  available_versions[cbk]['versions'][0..4].each { |release|
    if release['version'] == version
      puts release['version'] + "  <== Current version"
    else
      puts release['version']
    end
  }
end

#runObject



9
10
11
12
13
14
15
16
# File 'lib/chef/knife/lookup.rb', line 9

def run
  cbk = name_args.first
  env = name_args.last

  get_env(env)
  version = get_cbk_versions(env, cbk)
  get_past_versions(cbk, version)
end