OLD | NEW |
1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ | 1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ |
2 # | 2 # |
3 # Permission is hereby granted, free of charge, to any person obtaining a | 3 # Permission is hereby granted, free of charge, to any person obtaining a |
4 # copy of this software and associated documentation files (the | 4 # copy of this software and associated documentation files (the |
5 # "Software"), to deal in the Software without restriction, including | 5 # "Software"), to deal in the Software without restriction, including |
6 # without limitation the rights to use, copy, modify, merge, publish, dis- | 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
7 # tribute, sublicense, and/or sell copies of the Software, and to permit | 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
8 # persons to whom the Software is furnished to do so, subject to the fol- | 8 # persons to whom the Software is furnished to do so, subject to the fol- |
9 # lowing conditions: | 9 # lowing conditions: |
10 # | 10 # |
11 # The above copyright notice and this permission notice shall be included | 11 # The above copyright notice and this permission notice shall be included |
12 # in all copies or substantial portions of the Software. | 12 # in all copies or substantial portions of the Software. |
13 # | 13 # |
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- | 15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | 16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | 17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | 19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
20 # IN THE SOFTWARE. | 20 # IN THE SOFTWARE. |
21 # | 21 # |
22 import os | 22 import os |
23 import boto | 23 import boto |
24 from boto.utils import get_instance_metadata, get_instance_userdata | 24 from boto.utils import get_instance_metadata, get_instance_userdata |
25 from boto.pyami.config import Config, BotoConfigPath | 25 from boto.pyami.config import Config, BotoConfigPath |
26 from boto.pyami.scriptbase import ScriptBase | 26 from boto.pyami.scriptbase import ScriptBase |
| 27 import time |
27 | 28 |
28 class Bootstrap(ScriptBase): | 29 class Bootstrap(ScriptBase): |
29 """ | 30 """ |
30 The Bootstrap class is instantiated and run as part of the PyAMI | 31 The Bootstrap class is instantiated and run as part of the PyAMI |
31 instance initialization process. The methods in this class will | 32 instance initialization process. The methods in this class will |
32 be run from the rc.local script of the instance and will be run | 33 be run from the rc.local script of the instance and will be run |
33 as the root user. | 34 as the root user. |
34 | 35 |
35 The main purpose of this class is to make sure the boto distribution | 36 The main purpose of this class is to make sure the boto distribution |
36 on the instance is the one required. | 37 on the instance is the one required. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 if update.startswith('svn'): | 69 if update.startswith('svn'): |
69 if update.find(':') >= 0: | 70 if update.find(':') >= 0: |
70 method, version = update.split(':') | 71 method, version = update.split(':') |
71 version = '-r%s' % version | 72 version = '-r%s' % version |
72 else: | 73 else: |
73 version = '-rHEAD' | 74 version = '-rHEAD' |
74 location = boto.config.get('Boto', 'boto_location', '/usr/local/boto
') | 75 location = boto.config.get('Boto', 'boto_location', '/usr/local/boto
') |
75 self.run('svn update %s %s' % (version, location)) | 76 self.run('svn update %s %s' % (version, location)) |
76 elif update.startswith('git'): | 77 elif update.startswith('git'): |
77 location = boto.config.get('Boto', 'boto_location', '/usr/share/pyth
on-support/python-boto/boto') | 78 location = boto.config.get('Boto', 'boto_location', '/usr/share/pyth
on-support/python-boto/boto') |
78 self.run('git pull', cwd=location) | 79 num_remaining_attempts = 10 |
| 80 while num_remaining_attempts > 0: |
| 81 num_remaining_attempts -= 1 |
| 82 try: |
| 83 self.run('git pull', cwd=location) |
| 84 num_remaining_attempts = 0 |
| 85 except Exception, e: |
| 86 boto.log.info('git pull attempt failed with the following ex
ception. Trying again in a bit. %s', e) |
| 87 time.sleep(2) |
79 if update.find(':') >= 0: | 88 if update.find(':') >= 0: |
80 method, version = update.split(':') | 89 method, version = update.split(':') |
81 else: | 90 else: |
82 version = 'master' | 91 version = 'master' |
83 self.run('git checkout %s' % version, cwd=location) | 92 self.run('git checkout %s' % version, cwd=location) |
84 else: | 93 else: |
85 # first remove the symlink needed when running from subversion | 94 # first remove the symlink needed when running from subversion |
86 self.run('rm /usr/local/lib/python2.5/site-packages/boto') | 95 self.run('rm /usr/local/lib/python2.5/site-packages/boto') |
87 self.run('easy_install %s' % update) | 96 self.run('easy_install %s' % update) |
88 | 97 |
(...skipping 27 matching lines...) Expand all Loading... |
116 self.load_boto() | 125 self.load_boto() |
117 self.load_packages() | 126 self.load_packages() |
118 self.notify('Bootstrap Completed for %s' % boto.config.get_instance('ins
tance-id')) | 127 self.notify('Bootstrap Completed for %s' % boto.config.get_instance('ins
tance-id')) |
119 | 128 |
120 if __name__ == "__main__": | 129 if __name__ == "__main__": |
121 # because bootstrap starts before any logging configuration can be loaded fr
om | 130 # because bootstrap starts before any logging configuration can be loaded fr
om |
122 # the boto config files, we will manually enable logging to /var/log/boto.lo
g | 131 # the boto config files, we will manually enable logging to /var/log/boto.lo
g |
123 boto.set_file_logger('bootstrap', '/var/log/boto.log') | 132 boto.set_file_logger('bootstrap', '/var/log/boto.log') |
124 bs = Bootstrap() | 133 bs = Bootstrap() |
125 bs.main() | 134 bs.main() |
OLD | NEW |