diff options
author | Joe VLcek <JoeV@RedHat.com> | 2012-07-20 11:02:06 -0400 |
---|---|---|
committer | Joe VLcek <JoeV@RedHat.com> | 2012-07-20 11:02:06 -0400 |
commit | e20958b9d775475dd77c27394d7ccba77a3575b2 (patch) | |
tree | 34a46f6abcb58bcc1c6d7779292fb9451344a05b /cloudinit/sources/DataSourceAltCloud.py | |
parent | 8822100158489d8f7fb5c38d440489df5df62996 (diff) | |
download | vyos-cloud-init-e20958b9d775475dd77c27394d7ccba77a3575b2.tar.gz vyos-cloud-init-e20958b9d775475dd77c27394d7ccba77a3575b2.zip |
Add retry logic to DataSourceAltCloud
Diffstat (limited to 'cloudinit/sources/DataSourceAltCloud.py')
-rw-r--r-- | cloudinit/sources/DataSourceAltCloud.py | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/cloudinit/sources/DataSourceAltCloud.py b/cloudinit/sources/DataSourceAltCloud.py index 121a3c48..53c7d8d9 100644 --- a/cloudinit/sources/DataSourceAltCloud.py +++ b/cloudinit/sources/DataSourceAltCloud.py @@ -7,6 +7,7 @@ # Author: Scott Moser <scott.moser@canonical.com> # Author: Juerg Hafliger <juerg.haefliger@hp.com> # Author: Joshua Harlow <harlowja@yahoo-inc.com> +# Author: Joe VLcek <JVLcek@RedHat.com> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3, as @@ -21,6 +22,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. import errno +import time import os import os.path import subprocess @@ -52,6 +54,12 @@ CMD_PROBE_FLOPPY = ['/sbin/modprobe', 'floppy'] CMD_MNT_FLOPPY = ['/bin/mount', '/dev/fd0', MEDIA_DIR] CMD_MNT_CDROM = ['/bin/mount', '/dev/cdrom', MEDIA_DIR] +''' +Retry times and sleep secs between each try +''' +RETRY_TIMES = 3 +SLEEP_SECS = 3 + META_DATA_NOT_SUPPORTED = { 'block-device-mapping' : {}, 'instance-id' : 455, @@ -144,14 +152,27 @@ class DataSourceAltCloud(sources.DataSource): LOG.debug('cloud_type: ' + str(cloud_type)) - if 'RHEV' in cloud_type: - return self.user_data_rhevm() - elif 'VSPHERE' in cloud_type: - return self.user_data_vsphere() - else: - # there was no recognized alternate cloud type. - # suggesting this handler should not be used. - return False + # Simple retry logic around user_data_<type>() methods + tries = RETRY_TIMES + sleep_secs = SLEEP_SECS + while tries > 0: + if 'RHEV' in cloud_type: + if self.user_data_rhevm(): + return True + elif 'VSPHERE' in cloud_type: + if self.user_data_vsphere(): + return True + else: + # there was no recognized alternate cloud type. + # suggesting this handler should not be used. + return False + + time.sleep(sleep_secs) + tries -= 1 + sleep_secs *= 3 + + # Retry loop exhausted + return False def user_data_rhevm(self): ''' |