Example #1
0
 def _fetch_metadata_from_file(self):
     cnf = bus.cnf
     if self._userdata is None:
         path = cnf.private_path('.user-data')
         if os.path.exists(path):
             rawmeta = None
             with open(path, 'r') as fp:
                 rawmeta = fp.read()
             if not rawmeta:
                 raise platform.PlatformError("Empty user-data")
             return self._parse_user_data(rawmeta)
     return self._userdata
Example #2
0
 def _fetch_metadata_from_file(self):
     self._logger.debug('fetching meta-data from files')
     cnf = bus.cnf
     if self._userdata is None:
         for path in ('/etc/.scalr-user-data',
                      cnf.private_path('.user-data')):
             if os.path.exists(path):
                 self._logger.debug('using file %s', path)
                 rawmeta = None
                 with open(path, 'r') as fp:
                     rawmeta = fp.read()
                 if not rawmeta:
                     raise platform.PlatformError("Empty user-data")
                 self._logger.info('Use user-data from %s', path)
                 return self._parse_user_data(rawmeta)
     return self._userdata
Example #3
0
 def _fetch_metadata_from_file(self):
     self._logger.debug('fetching meta-data from files')
     if self._userdata is None:
         private_dir_ud_path = os.path.join(node.__node__['private_dir'],
                                            '.user-data')
         for path in ('/etc/.scalr-user-data', private_dir_ud_path):
             if os.path.exists(path):
                 self._logger.debug('using file %s', path)
                 rawmeta = None
                 with open(path, 'r') as fp:
                     rawmeta = fp.read()
                 if not rawmeta:
                     raise platform.PlatformError("Empty user-data")
                 self._logger.info('Use user-data from %s', path)
                 return self._parse_user_data(rawmeta)
     return self._userdata
Example #4
0
 def _fetch_metadata(self):
     """
     Fetches whole metadata dict. Unlike Ec2LikePlatform,
     which fetches data for concrete key.
     """
     url = self._meta_url
     try:
         r = urllib2.urlopen(url)
         response = r.read().strip()
         return json.loads(response)
     except IOError, e:
         urllib_error = isinstance(e, urllib2.HTTPError) or \
             isinstance(e, urllib2.URLError)
         if urllib_error:
             metadata = self._fetch_metadata_from_file()
             # TODO: move some keys from metadata to parent dict,
             # that should be there when fetching from url
             return {'meta': metadata}
         raise platform.PlatformError("Cannot fetch %s metadata url '%s'. "
                                      "Error: %s" % (self.name, url, e))