Class: Chef::Knife::PinningsSetAuto
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::PinningsSetAuto
- Defined in:
- lib/chef/knife/pinnings_set_auto.rb
Overview
This class implements knife pinnings set auto <environment> [cookbook]
Defined Under Namespace
Classes: FakeChefEnvironmentStruct
Instance Method Summary collapse
Instance Method Details
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/chef/knife/pinnings_set_auto.rb', line 23 def run case name_args.length when 1 # Just environment was specified @environment_name = name_args[0] @cookbook_regex = '.*' when 2 # Environment, cookbook version constraints specified @environment_name = name_args[0] @cookbook_version_constraints_string = name_args[1] @cookbook_version_constraints = @cookbook_version_constraints_string.split(",") @cookbook_regex = '.*' else ui.fatal('You must specify ENVIRONMENT or ENVIRONMENT COOKBOOK_CONSTRAINTS (constraints example: "foo","bar","[email protected]")') exit 255 end @environment = Environment.load(@environment_name) nodes = nodes_in(rest, @environment) ui.info("#{nodes.length} nodes have been found in environment #{@environment_name}: #{nodes.to_s}") cookbooks = cookbooks_used_by(rest, @environment_name) ui.info("#{cookbooks.length} recipes have been found for the nodes: #{cookbooks.to_s}") if @cookbook_version_constraints != nil cookbooks_with_contraints = cookbooks_merged_with_version_constraints(cookbooks, @cookbook_version_constraints) ui.info("the cookbook version constraints are as follow: #{cookbooks_with_contraints.to_s}") else ui.info("No version constraint have been specified as input") cookbooks_with_contraints = cookbooks end ui.info("knife-pinnings will attempt resolving the dependencies with chef resolver...") solution_cookbook_versions = solve_recipes(rest, @environment, cookbooks_with_contraints) ui.msg('') environments = [] environments.push(@environment) environments.push(FakeChefEnvironmentStruct.new('chef_resolver_solution',solution_cookbook_versions)) display_pinnings_table(environments, @cookbook_regex) ui.msg('') ui.confirm("Do you want to set these cookbook versions on chef environment:#{@environment_name} ") ui.msg('') set_environnment_pinnings(@environment, solution_cookbook_versions) ui.info("version pinnings have been set on #{@environment_name}") end |