|
17 | 17 |
|
18 | 18 | module ChefIngredientCookbook
|
19 | 19 | module Helpers
|
20 |
| - # FIXME: (jtimberman) make this data we can change / use without |
21 |
| - # having to update the library code (e.g., if we create new |
22 |
| - # add-ons, or change any of these in the future). |
23 |
| - def chef_ctl_command(pkg) |
24 |
| - ctl_cmds = { |
25 |
| - 'chef-server-core' => 'chef-server-ctl', |
26 |
| - 'opscode-manage' => 'opscode-manage-ctl', |
27 |
| - 'opscode-push-jobs-server' => 'opscode-push-jobs-server-ctl', |
28 |
| - 'opscode-reporting' => 'opscode-reporting-ctl', |
29 |
| - 'opscode-analytics' => 'opscode-analytics-ctl', |
30 |
| - 'chef-sync' => 'chef-sync-ctl', |
31 |
| - 'supermarket' => 'supermarket-ctl' |
32 |
| - } |
33 |
| - ctl_cmds[pkg] |
| 20 | + def chef_ctl_command(product) |
| 21 | + if new_resource.respond_to?(:version) |
| 22 | + product_lookup(product, new_resource.version)['ctl-command'] |
| 23 | + else |
| 24 | + product_lookup(product)['ctl-command'] |
| 25 | + end |
34 | 26 | end
|
35 | 27 |
|
36 | 28 | def local_package_resource
|
@@ -86,6 +78,67 @@ def reconfigure
|
86 | 78 | command "#{ctl_cmd} reconfigure"
|
87 | 79 | end
|
88 | 80 | end
|
| 81 | + |
| 82 | + # When updating this, also update PRODUCT_MATRIX.md |
| 83 | + def product_matrix |
| 84 | + { |
| 85 | + 'analytics' => {'package-name' => 'opscode-analytics', 'ctl-command' => 'opscode-analytics-ctl' }, |
| 86 | + 'chef' => {'package-name' => 'chef', 'ctl-command' => nil }, |
| 87 | + 'chef-ha' => {'package-name' => 'chef-ha', 'ctl-command' => nil }, |
| 88 | + 'chef-server' => {'package-name' => 'chef-server-core', 'ctl-command' => 'chef-server-ctl' }, |
| 89 | + 'chef-sync' => {'package-name' => 'chef-sync', 'ctl-command' => 'chef-sync-ctl' }, |
| 90 | + 'chefdk' => {'package-name' => 'chefdk', 'ctl-command' => nil }, |
| 91 | + 'delivery' => {'package-name' => 'delivery', 'ctl-command' => 'delivery-ctl' }, |
| 92 | + 'delivery-cli' => {'package-name' => 'delivery-cli', 'ctl-command' => nil }, |
| 93 | + 'manage' => {'package-name' => 'chef-manage', 'ctl-command' => 'chef-manage-ctl' }, |
| 94 | + 'private-chef' => {'package-name' => 'private-chef', 'ctl-command' => 'private-chef-ctl' }, |
| 95 | + 'push-client' => {'package-name' => 'chef-push-client', 'ctl-command' => nil }, |
| 96 | + 'push-server' => {'package-name' => 'chef-push-server', 'ctl-command' => 'chef-push-ctl' }, |
| 97 | + 'reporting' => {'package-name' => 'opscode-reporting', 'ctl-command' => 'opscode-reporting-ctl' }, |
| 98 | + 'supermarket' => {'package-name' => 'supermarket', 'ctl-command' => 'supermarket-ctl' }, |
| 99 | + } |
| 100 | + end |
| 101 | + |
| 102 | + # Version has a default value of 0.0.0 so that it is a valid |
| 103 | + # string for the Mixlib::Versioning.parse method. This implies |
| 104 | + # "latest", but "latest" is not a value that is valid for |
| 105 | + # mixlib/versioning. |
| 106 | + def product_lookup(product, version = '0.0.0') |
| 107 | + unless product_matrix.has_key?(product) |
| 108 | + Chef::Log.fatal("We don't have a product, '#{product}'. Please specify a valid product name:") |
| 109 | + Chef::Log.fatal(product_matrix.keys.join(' ')) |
| 110 | + fail |
| 111 | + end |
| 112 | + |
| 113 | + require 'mixlib/versioning' |
| 114 | + v = Mixlib::Versioning.parse(version) |
| 115 | + |
| 116 | + data = product_matrix[product] |
| 117 | + |
| 118 | + # We want to validate that we're getting a version that is valid |
| 119 | + # for the Chef Server. However, since the default is 0.0.0, |
| 120 | + # implying latest, we need to additionally ensure that the |
| 121 | + # bottom version is something valid. If we don't have the check |
| 122 | + # in the elsif, it will say that 0.0.0 is not a valid version. |
| 123 | + if (product == 'chef-server') |
| 124 | + if (v < Mixlib::Versioning.parse('12.0.0') && v > Mixlib::Versioning.parse('11.0.0')) |
| 125 | + data['package-name'] = 'chef-server' |
| 126 | + elsif (v < Mixlib::Versioning.parse('11.0.0')) && (v > Mixlib::Versioning.parse('1.0.0')) |
| 127 | + Chef::Log.fatal("Invalid version specified, '#{version}' for #{product}!") |
| 128 | + fail |
| 129 | + end |
| 130 | + elsif (product == 'manage') && (v < Mixlib::Versioning.parse('2.0.0')) |
| 131 | + data['package-name'] = 'opscode-manage' |
| 132 | + data['ctl-command'] = 'opscode-manage-ctl' |
| 133 | + elsif (product == 'push-server') && (v < Mixlib::Versioning.parse('2.0.0')) |
| 134 | + data['package-name'] = 'chef-push-server' |
| 135 | + data['ctl-command'] = 'chef-push-ctl' |
| 136 | + elsif (product == 'push-client') && (v < Mixlib::Versioning.parse('2.0.0')) |
| 137 | + data['package-name'] = 'chef-push-client' |
| 138 | + end |
| 139 | + |
| 140 | + data |
| 141 | + end |
89 | 142 | end
|
90 | 143 | end
|
91 | 144 |
|
|
0 commit comments