Submit
Path:
~
/
/
lib
/
python2.7
/
site-packages
/
cloudinit
/
sources
/
File Content:
DataSourceAltCloud.py
# Copyright (C) 2009-2010 Canonical Ltd. # Copyright (C) 2012, 2013 Hewlett-Packard Development Company, L.P. # Copyright (C) 2012 Yahoo! Inc. # # Author: Joe VLcek <JVLcek@RedHat.com> # Author: Juerg Haefliger <juerg.haefliger@hp.com> # # This file is part of cloud-init. See LICENSE file for license information. ''' This file contains code used to gather the user data passed to an instance on RHEVm and vSphere. ''' import errno import os import os.path from cloudinit import log as logging from cloudinit import sources from cloudinit import util from cloudinit.util import ProcessExecutionError LOG = logging.getLogger(__name__) # Needed file paths CLOUD_INFO_FILE = '/etc/sysconfig/cloud-info' # Shell command lists CMD_PROBE_FLOPPY = ['modprobe', 'floppy'] META_DATA_NOT_SUPPORTED = { 'block-device-mapping': {}, 'instance-id': 455, 'local-hostname': 'localhost', 'placement': {}, } def read_user_data_callback(mount_dir): ''' Description: This callback will be applied by util.mount_cb() on the mounted file. Deltacloud file name contains deltacloud. Those not using Deltacloud but instead instrumenting the injection, could drop deltacloud from the file name. Input: mount_dir - Mount directory Returns: User Data ''' deltacloud_user_data_file = mount_dir + '/deltacloud-user-data.txt' user_data_file = mount_dir + '/user-data.txt' # First try deltacloud_user_data_file. On failure try user_data_file. try: user_data = util.load_file(deltacloud_user_data_file).strip() except IOError: try: user_data = util.load_file(user_data_file).strip() except IOError: util.logexc(LOG, 'Failed accessing user data file.') return None return user_data class DataSourceAltCloud(sources.DataSource): dsname = 'AltCloud' def __init__(self, sys_cfg, distro, paths): sources.DataSource.__init__(self, sys_cfg, distro, paths) self.seed = None self.supported_seed_starts = ("/", "file://") def __str__(self): root = sources.DataSource.__str__(self) return "%s [seed=%s]" % (root, self.seed) def get_cloud_type(self): ''' Description: Get the type for the cloud back end this instance is running on by examining the string returned by reading either: CLOUD_INFO_FILE or the dmi data. Input: None Returns: One of the following strings: 'RHEV', 'VSPHERE' or 'UNKNOWN' ''' if os.path.exists(CLOUD_INFO_FILE): try: cloud_type = util.load_file(CLOUD_INFO_FILE).strip().upper() except IOError: util.logexc(LOG, 'Unable to access cloud info file at %s.', CLOUD_INFO_FILE) return 'UNKNOWN' return cloud_type system_name = util.read_dmi_data("system-product-name") if not system_name: return 'UNKNOWN' sys_name = system_name.upper() if sys_name.startswith('RHEV'): return 'RHEV' if sys_name.startswith('VMWARE'): return 'VSPHERE' return 'UNKNOWN' def _get_data(self): ''' Description: User Data is passed to the launching instance which is used to perform instance configuration. Cloud providers expose the user data differently. It is necessary to determine which cloud provider the current instance is running on to determine how to access the user data. Images built with image factory will contain a CLOUD_INFO_FILE which contains a string identifying the cloud provider. Images not built with Imagefactory will try to determine what the cloud provider is based on system information. ''' LOG.debug('Invoked get_data()') cloud_type = self.get_cloud_type() LOG.debug('cloud_type: %s', str(cloud_type)) 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 # indicating this handler should not be used. return False # No user data found util.logexc(LOG, 'Failed accessing user data.') return False def _get_subplatform(self): """Return the subplatform metadata details.""" cloud_type = self.get_cloud_type() if not hasattr(self, 'source'): self.source = sources.METADATA_UNKNOWN if cloud_type == 'RHEV': self.source = '/dev/fd0' return '%s (%s)' % (cloud_type.lower(), self.source) def user_data_rhevm(self): ''' RHEVM specific userdata read If on RHEV-M the user data will be contained on the floppy device in file <user_data_file> To access it: modprobe floppy Leverage util.mount_cb to: mkdir <tmp mount dir> mount /dev/fd0 <tmp mount dir> The call back passed to util.mount_cb will do: read <tmp mount dir>/<user_data_file> ''' return_str = None # modprobe floppy try: modprobe_floppy() except ProcessExecutionError as e: util.logexc(LOG, 'Failed modprobe: %s', e) return False floppy_dev = '/dev/fd0' # udevadm settle for floppy device try: util.udevadm_settle(exists=floppy_dev, timeout=5) except (ProcessExecutionError, OSError) as e: util.logexc(LOG, 'Failed udevadm_settle: %s\n', e) return False try: return_str = util.mount_cb(floppy_dev, read_user_data_callback) except OSError as err: if err.errno != errno.ENOENT: raise except util.MountFailedError: util.logexc(LOG, "Failed to mount %s when looking for user data", floppy_dev) self.userdata_raw = return_str self.metadata = META_DATA_NOT_SUPPORTED if return_str: return True else: return False def user_data_vsphere(self): ''' vSphere specific userdata read If on vSphere the user data will be contained on the cdrom device in file <user_data_file> To access it: Leverage util.mount_cb to: mkdir <tmp mount dir> mount /dev/fd0 <tmp mount dir> The call back passed to util.mount_cb will do: read <tmp mount dir>/<user_data_file> ''' return_str = None cdrom_list = util.find_devs_with('LABEL=CDROM') for cdrom_dev in cdrom_list: try: return_str = util.mount_cb(cdrom_dev, read_user_data_callback) if return_str: self.source = cdrom_dev break except OSError as err: if err.errno != errno.ENOENT: raise except util.MountFailedError: util.logexc(LOG, "Failed to mount %s when looking for user " "data", cdrom_dev) self.userdata_raw = return_str self.metadata = META_DATA_NOT_SUPPORTED if return_str: return True else: return False def modprobe_floppy(): out, _err = util.subp(CMD_PROBE_FLOPPY) LOG.debug('Command: %s\nOutput%s', ' '.join(CMD_PROBE_FLOPPY), out) # Used to match classes to dependencies # Source DataSourceAltCloud does not really depend on networking. # In the future 'dsmode' like behavior can be added to offer user # the ability to run before networking. datasources = [ (DataSourceAltCloud, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)), ] # Return a list of data sources that match this set of dependencies def get_datasource_list(depends): return sources.list_from_depends(depends, datasources) # vi: ts=4 expandtab
Edit
Rename
Chmod
Delete
FILE
FOLDER
Name
Size
Permission
Action
helpers
---
0755
DataSourceAliYun.py
1829 bytes
0644
DataSourceAliYun.pyc
2712 bytes
0644
DataSourceAliYun.pyo
2712 bytes
0644
DataSourceAltCloud.py
8380 bytes
0644
DataSourceAltCloud.pyc
8273 bytes
0644
DataSourceAltCloud.pyo
8273 bytes
0644
DataSourceAzure.py
57192 bytes
0644
DataSourceAzure.pyc
49487 bytes
0644
DataSourceAzure.pyo
49487 bytes
0644
DataSourceBigstep.py
1917 bytes
0644
DataSourceBigstep.pyc
2457 bytes
0644
DataSourceBigstep.pyo
2457 bytes
0644
DataSourceCloudSigma.py
3979 bytes
0644
DataSourceCloudSigma.pyc
4624 bytes
0644
DataSourceCloudSigma.pyo
4624 bytes
0644
DataSourceCloudStack.py
9750 bytes
0644
DataSourceCloudStack.pyc
9225 bytes
0644
DataSourceCloudStack.pyo
9225 bytes
0644
DataSourceConfigDrive.py
10612 bytes
0644
DataSourceConfigDrive.pyc
10014 bytes
0644
DataSourceConfigDrive.pyo
10014 bytes
0644
DataSourceDigitalOcean.py
3788 bytes
0644
DataSourceDigitalOcean.pyc
4189 bytes
0644
DataSourceDigitalOcean.pyo
4189 bytes
0644
DataSourceEc2.py
27773 bytes
0644
DataSourceEc2.pyc
23215 bytes
0644
DataSourceEc2.pyo
23215 bytes
0644
DataSourceExoscale.py
9122 bytes
0644
DataSourceExoscale.pyc
7669 bytes
0644
DataSourceExoscale.pyo
7669 bytes
0644
DataSourceGCE.py
11049 bytes
0644
DataSourceGCE.pyc
11170 bytes
0644
DataSourceGCE.pyo
11170 bytes
0644
DataSourceHetzner.py
3581 bytes
0644
DataSourceHetzner.pyc
3825 bytes
0644
DataSourceHetzner.pyo
3825 bytes
0644
DataSourceIBMCloud.py
14128 bytes
0644
DataSourceIBMCloud.pyc
14966 bytes
0644
DataSourceIBMCloud.pyo
14966 bytes
0644
DataSourceMAAS.py
14390 bytes
0644
DataSourceMAAS.pyc
14426 bytes
0644
DataSourceMAAS.pyo
14426 bytes
0644
DataSourceNoCloud.py
13791 bytes
0644
DataSourceNoCloud.pyc
11321 bytes
0644
DataSourceNoCloud.pyo
11321 bytes
0644
DataSourceNone.py
1464 bytes
0644
DataSourceNone.pyc
2148 bytes
0644
DataSourceNone.pyo
2148 bytes
0644
DataSourceOVF.py
23517 bytes
0644
DataSourceOVF.pyc
20140 bytes
0644
DataSourceOVF.pyo
20140 bytes
0644
DataSourceOpenNebula.py
15150 bytes
0644
DataSourceOpenNebula.pyc
15005 bytes
0644
DataSourceOpenNebula.pyo
15005 bytes
0644
DataSourceOpenStack.py
9450 bytes
0644
DataSourceOpenStack.pyc
9128 bytes
0644
DataSourceOpenStack.pyo
9128 bytes
0644
DataSourceOracle.py
14685 bytes
0644
DataSourceOracle.pyc
13975 bytes
0644
DataSourceOracle.pyo
13975 bytes
0644
DataSourceRbxCloud.py
7362 bytes
0644
DataSourceRbxCloud.pyc
8769 bytes
0644
DataSourceRbxCloud.pyo
8769 bytes
0644
DataSourceScaleway.py
9490 bytes
0644
DataSourceScaleway.pyc
10117 bytes
0644
DataSourceScaleway.pyo
10117 bytes
0644
DataSourceSmartOS.py
34217 bytes
0644
DataSourceSmartOS.pyc
31006 bytes
0644
DataSourceSmartOS.pyo
31006 bytes
0644
__init__.py
32500 bytes
0644
__init__.pyc
28232 bytes
0644
__init__.pyo
28232 bytes
0644
N4ST4R_ID | Naxtarrr