~ubuntu-branches/ubuntu/saucy/cloud-init/saucy

« back to all changes in this revision

Viewing changes to debian/patches/catchup-446-447.patch

  • Committer: Package Import Robot
  • Author(s): Scott Moser, Mike Moulton, Avishai Ish-Shalom
  • Date: 2011-09-13 17:02:48 UTC
  • mto: (174.2.1 precise)
  • mto: This revision was merged to the branch mainline in revision 136.
  • Revision ID: package-import@ubuntu.com-20110913170248-4ty3t0epmq8cg9wz
* minor documentation improvement.

[Mike Moulton, Avishai Ish-Shalom]
* Chef support fixes. support for environment and initial attr (LP: #845208)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
------------------------------------------------------------
 
2
revno: 447
 
3
committer: Scott Moser <smoser@ubuntu.com>
 
4
branch nick: trunk
 
5
timestamp: Tue 2011-09-13 11:48:08 -0400
 
6
message:
 
7
  [doc] add 'preseed' string to cloud-config for debconf-set-selections
 
8
------------------------------------------------------------
 
9
revno: 446 [merge]
 
10
fixes bug(s): https://launchpad.net/bugs/845208
 
11
committer: Scott Moser <smoser@ubuntu.com>
 
12
branch nick: trunk
 
13
timestamp: Tue 2011-09-13 08:02:37 -0400
 
14
message:
 
15
  Chef support fixes, and support for environment and initial attr (LP: #845208)
 
16
  
 
17
  Thanks to Mike Mouulton and Avishai Ish-Shalom.
 
18
------------------------------------------------------------
 
19
Use --include-merges or -n0 to see merged revisions.
 
20
=== modified file 'cloudinit/CloudConfig/cc_chef.py'
 
21
--- old/cloudinit/CloudConfig/cc_chef.py        2011-09-08 23:10:17 +0000
 
22
+++ new/cloudinit/CloudConfig/cc_chef.py        2011-09-13 00:38:37 +0000
 
23
@@ -1,6 +1,7 @@
 
24
 # vi: ts=4 expandtab
 
25
 #
 
26
 #    Author: Avishai Ish-Shalom <avishai@fewbytes.com>
 
27
+#    Author: Mike Moulton <mike@meltmedia.com>
 
28
 #
 
29
 #    This program is free software: you can redistribute it and/or modify
 
30
 #    it under the terms of the GNU General Public License version 3, as
 
31
@@ -17,6 +18,7 @@
 
32
 import pwd
 
33
 import socket
 
34
 import subprocess
 
35
+import json
 
36
 import StringIO
 
37
 import ConfigParser
 
38
 import cloudinit.CloudConfig as cc
 
39
@@ -31,60 +33,73 @@
 
40
     if not cfg.has_key('chef'): return
 
41
     chef_cfg = cfg['chef']
 
42
 
 
43
-    # Install chef packages from selected source
 
44
-    install_type = util.get_cfg_option_str(chef_cfg, "install_type", "packages")
 
45
-    if not os.path.isfile('/usr/bin/chef-client'):
 
46
-        if install_type == "gems":
 
47
-            if chef_cfg.has_key('version'):
 
48
-                chef_version = chef_cfg['version']
 
49
-            else:
 
50
-                chef_version = None
 
51
-            install_chef_from_gems(
 
52
-                    util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8'),
 
53
-                    chef_version)
 
54
-        else:
 
55
-            cc.install_packages(('chef',))
 
56
+    # ensure the chef directories we use exist
 
57
+    mkdirs(['/etc/chef', '/var/log/chef', '/var/lib/chef',
 
58
+            '/var/cache/chef', '/var/backups/chef', '/var/run/chef'])
 
59
 
 
60
-    # set the validation cert
 
61
-    if chef_cfg.has_key('validation_cert'):
 
62
-        with open('/etc/chef/validation.pem', 'w') as validation_cert_fh:
 
63
-            validation_cert_fh.write(chef_cfg['validation_cert'])
 
64
+    # set the validation key based on the presence of either 'validation_key'
 
65
+    # or 'validation_cert'. In the case where both exist, 'validation_key'
 
66
+    # takes precedence
 
67
+    if chef_cfg.has_key('validation_key') or chef_cfg.has_key('validation_cert'):
 
68
+        validation_key = util.get_cfg_option_str(chef_cfg, 'validation_key',
 
69
+                                                 chef_cfg['validation_cert'])
 
70
+        with open('/etc/chef/validation.pem', 'w') as validation_key_fh:
 
71
+            validation_key_fh.write(validation_key)
 
72
 
 
73
     validation_name = chef_cfg.get('validation_name','chef-validator')
 
74
     # create the chef config from template
 
75
     util.render_to_file('chef_client.rb', '/etc/chef/client.rb',
 
76
             {'server_url': chef_cfg['server_url'], 
 
77
+             'node_name': util.get_cfg_option_str(chef_cfg, 'node_name', 
 
78
+                                                  cloud.datasource.get_instance_id()),
 
79
+             'environment': util.get_cfg_option_str(chef_cfg, 'environment',
 
80
+                                                    '_default'),
 
81
              'validation_name': chef_cfg['validation_name']})
 
82
 
 
83
-    chef_args = ['-d']
 
84
     # set the firstboot json
 
85
-    if chef_cfg.has_key('run_list'):
 
86
-        with open('/etc/chef/firstboot.json', 'w') as firstboot_json_fh:
 
87
-            firstboot_json_fh.write("{\n\"run_list\":\n[\n")
 
88
-            firstboot_json_fh.write(
 
89
-                    ",\n".join(["\"%s\"" % runlist_item for runlist_item in chef_cfg['run_list']])
 
90
-                    )
 
91
-            firstboot_json_fh.write("]\n\}")
 
92
-        chef_args.append('-j /etc/chef/firstboot.json')
 
93
+    with open('/etc/chef/firstboot.json', 'w') as firstboot_json_fh:
 
94
+        initial_json = {}
 
95
+        if chef_cfg.has_key('run_list'):
 
96
+            initial_json['run_list'] = chef_cfg['run_list']
 
97
+        if chef_cfg.has_key('initial_attributes'):
 
98
+            initial_attributes = chef_cfg['initial_attributes']
 
99
+            for k in initial_attributes.keys(): initial_json[k] = initial_attributes[k]
 
100
+        firstboot_json_fh.write(json.dumps(initial_json))
 
101
 
 
102
-    # and finally, run chef
 
103
-    log.debug("running chef-client %s" % chef_args)
 
104
-    subprocess.check_call(['/usr/bin/chef-client'] + chef_args)
 
105
+    # If chef is not installed, we install chef based on 'install_type'
 
106
+    if not os.path.isfile('/usr/bin/chef-client'):
 
107
+        install_type = util.get_cfg_option_str(chef_cfg, 'install_type', 'packages')
 
108
+        if install_type == "gems":
 
109
+            # this will install and run the chef-client from gems
 
110
+            chef_version = util.get_cfg_option_str(chef_cfg, 'version', None)
 
111
+            ruby_version = util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8')
 
112
+            install_chef_from_gems(ruby_version, chef_version)
 
113
+            # and finally, run chef-client
 
114
+            log.debug('running chef-client')
 
115
+            subprocess.check_call(['/usr/bin/chef-client', '-d', '-i', '1800', '-s', '20'])
 
116
+        else:
 
117
+            # this will install and run the chef-client from packages
 
118
+            cc.install_packages(('chef',))
 
119
 
 
120
 def install_chef_from_gems(ruby_version, chef_version = None):
 
121
     cc.install_packages(ruby_packages[ruby_version])
 
122
-    gem_bin = get_gem_bin()
 
123
-    if not os.path.exists('/usr/bin/gem'): os.symlink(gem_bin, '/usr/bin/gem')
 
124
-    chef_version_arg = ""
 
125
-    if chef_version: chef_version_arg = "-v %s" % chef_version
 
126
-    subprocess.check_call([gem_bin,'install','chef',chef_version_arg, '--no-ri','--no-rdoc','--no-test','-q'])
 
127
-    os.mkdirs('/etc/chef', '/var/log/chef', '/var/lib/chef', '/var/cache/chef', '/var/backups/chef', '/var/run/chef')
 
128
-    os.symlink('/var/lib/gem/%s/bin/chef-client' % ruby_version, '/usr/bin/chef-client')
 
129
-    # Ohai ruby plugin breaks if there is no ruby or gem binaries at /usr/bin, so
 
130
-    try: os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem')
 
131
-    except: pass
 
132
-    try: os.symlink('/usr/bin/ruby%s' % ruby_version, '/usr/bin/ruby')
 
133
-    except: pass
 
134
-
 
135
-def get_gem_bin():
 
136
-    return '/usr/bin/gem%s' % util.get_cfg_option_str(chef_cfg, 'ruby_version', '1.8')
 
137
+    if not os.path.exists('/usr/bin/gem'):
 
138
+      os.symlink('/usr/bin/gem%s' % ruby_version, '/usr/bin/gem')
 
139
+    if not os.path.exists('/usr/bin/ruby'):
 
140
+      os.symlink('/usr/bin/ruby%s' % ruby_version, '/usr/bin/ruby')
 
141
+    if chef_version:
 
142
+        subprocess.check_call(['/usr/bin/gem','install','chef',
 
143
+                               '-v %s' % chef_version, '--no-ri',
 
144
+                               '--no-rdoc','--bindir','/usr/bin','-q'])
 
145
+    else:
 
146
+        subprocess.check_call(['/usr/bin/gem','install','chef',
 
147
+                               '--no-ri','--no-rdoc','--bindir',
 
148
+                               '/usr/bin','-q'])
 
149
+
 
150
+def ensure_dir(d):
 
151
+    if not os.path.exists(d):
 
152
+        os.makedirs(d)
 
153
+
 
154
+def mkdirs(dirs):
 
155
+    for d in dirs:
 
156
+        ensure_dir(d)
 
157
 
 
158
=== modified file 'doc/examples/cloud-config-chef.txt'
 
159
--- old/doc/examples/cloud-config-chef.txt      2011-04-21 14:57:54 +0000
 
160
+++ new/doc/examples/cloud-config-chef.txt      2011-09-13 00:38:37 +0000
 
161
@@ -9,30 +9,36 @@
 
162
 apt_mirror: http://apt.opscode.com/
 
163
 
 
164
 chef:
 
165
- # If you want to install from rubygems:
 
166
+
 
167
+ # Valid values are 'gems' and 'packages'
 
168
  install_type: "gems"
 
169
 
 
170
  # Chef settings
 
171
  server_url: "https://chef.yourorg.com:4000"
 
172
 
 
173
+ # Node Name
 
174
+ # Defaults to the instance-id if not present
 
175
+ node_name: "your-node-name"
 
176
+
 
177
+ # Environment
 
178
+ # Defaults to '_default' if not present
 
179
+ environment: "production"
 
180
+
 
181
  # Default validation name is chef-validator
 
182
  validation_name: "yourorg-validator"
 
183
- validation_cert: |
 
184
-     -----BEGIN CERTIFICATE-----
 
185
-     MIICCTCCAXKgAwIBAgIBATANBgkqhkiG9w0BAQUFADANMQswCQYDVQQDDAJjYTAe
 
186
-     Fw0xMDAyMTUxNzI5MjFaFw0xNTAyMTQxNzI5MjFaMA0xCzAJBgNVBAMMAmNhMIGf
 
187
-     MA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCu7Q40sm47/E1Pf+r8AYb/V/FWGPgc
 
188
-     b014OmNoX7dgCxTDvps/h8Vw555PdAFsW5+QhsGr31IJNI3kSYprFQcYf7A8tNWu
 
189
-     1MASW2CfaEiOEi9F1R3R4Qlz4ix+iNoHiUDTjazw/tZwEdxaQXQVLwgTGRwVa+aA
 
190
-     qbutJKi93MILLwIDAQABo3kwdzA4BglghkgBhvhCAQ0EKxYpUHVwcGV0IFJ1Ynkv
 
191
-     T3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwDwYDVR0TAQH/BAUwAwEB/zAd
 
192
-     BgNVHQ4EFgQUu4+jHB+GYE5Vxo+ol1OAhevspjAwCwYDVR0PBAQDAgEGMA0GCSqG
 
193
-     SIb3DQEBBQUAA4GBAH/rxlUIjwNb3n7TXJcDJ6MMHUlwjr03BDJXKb34Ulndkpaf
 
194
-     +GAlzPXWa7bO908M9I8RnPfvtKnteLbvgTK+h+zX1XCty+S2EQWk29i2AdoqOTxb
 
195
-     hppiGMp0tT5Havu4aceCXiy2crVcudj3NFciy8X66SoECemW9UYDCb9T5D0d
 
196
-     -----END CERTIFICATE-----
 
197
-
 
198
+ validation_key: |
 
199
+     -----BEGIN RSA PRIVATE KEY-----
 
200
+     YOUR-ORGS-VALIDATION-KEY-HERE
 
201
+     -----END RSA PRIVATE KEY-----
 
202
 
203
  # A run list for a first boot json
 
204
  run_list:
 
205
   - "recipe[apache2]"
 
206
   - "role[db]"
 
207
+
 
208
+ # Specify a list of initial attributes used by the cookbooks
 
209
+ initial_attributes:
 
210
+    apache:
 
211
+      prefork:
 
212
+        maxclients: 100
 
213
+      keepalive: "off"
 
214
 
 
215
=== modified file 'doc/examples/cloud-config.txt'
 
216
--- old/doc/examples/cloud-config.txt   2011-08-15 21:39:21 +0000
 
217
+++ new/doc/examples/cloud-config.txt   2011-09-13 15:48:08 +0000
 
218
@@ -246,7 +246,7 @@
 
219
 # This can be a single string ('smoser') or a list ([smoser, kirkland])
 
220
 ssh_import_id: [smoser]
 
221
 
 
222
-# Provide debconf answers
 
223
+# Provide debconf answers / debian preseed values
 
224
 #
 
225
 # See debconf-set-selections man page.
 
226
 #
 
227
 
 
228
=== modified file 'templates/chef_client.rb.tmpl'
 
229
--- old/templates/chef_client.rb.tmpl   2011-04-21 14:57:54 +0000
 
230
+++ new/templates/chef_client.rb.tmpl   2011-09-10 22:34:05 +0000
 
231
@@ -1,12 +1,15 @@
 
232
-log_level          :info
 
233
-log_location       "/var/log/chef/client.log"
 
234
-ssl_verify_mode    :verify_none
 
235
+log_level              :info
 
236
+log_location           "/var/log/chef/client.log"
 
237
+ssl_verify_mode        :verify_none
 
238
 validation_client_name "$validation_name"
 
239
 validation_key         "/etc/chef/validation.pem"
 
240
-client_key               "/etc/chef/client.pem"
 
241
-chef_server_url    "$server_url"
 
242
-file_cache_path    "/var/cache/chef"
 
243
-file_backup_path  "/var/backups/chef"
 
244
-pid_file           "/var/run/chef/client.pid"
 
245
+client_key             "/etc/chef/client.pem"
 
246
+chef_server_url        "$server_url"
 
247
+environment            "$environment"
 
248
+node_name              "$node_name"
 
249
+json_attribs           "/etc/chef/firstboot.json"
 
250
+file_cache_path        "/var/cache/chef"
 
251
+file_backup_path       "/var/backups/chef"
 
252
+pid_file               "/var/run/chef/client.pid"
 
253
 Chef::Log::Formatter.show_time = true
 
254
 
 
255