Ejemplo n.º 1
0
 def get_system_variables(self):
     #TESTING REQUIRED!
     conf = Configuration(self._config_format)
     conf.read(self._config_path)
     vars = {}
     for section in conf.sections('./'):
         vars[section] = conf.get(section)
     return vars
Ejemplo n.º 2
0
	def get_system_variables(self):
		#TESTING REQUIRED!
		conf = Configuration(self._config_format)
		conf.read(self._config_path)
		vars = {}
		for section in conf.sections('./'):
			vars[section] = conf.get(section)
		return vars
Ejemplo n.º 3
0
	def __init__(self, manifest_path):
		self._options = []
		ini = Configuration('ini')
		ini.read(manifest_path)
		try:
			self._defaults = dict(ini.items('__defaults__'))
		except NoPathError:
			self._defaults = dict()
		
		for name in ini.sections("./"):
			if name == '__defaults__':
				continue
			self._options.append(_OptionSpec.from_ini(ini, name, self._defaults))
Ejemplo n.º 4
0
    def __init__(self, manifest_path):
        self._options = []
        ini = Configuration('ini')
        ini.read(manifest_path)
        try:
            self._defaults = dict(ini.items('__defaults__'))
        except NoPathError:
            self._defaults = dict()

        for name in ini.sections("./"):
            if name == '__defaults__':
                continue
            self._options.append(
                _OptionSpec.from_ini(ini, name, self._defaults))
Ejemplo n.º 5
0
    def _manifest(self):
        class HeadRequest(urllib2.Request):
            def get_method(self):
                return "HEAD"

        manifest_url = bus.scalr_url + '/storage/service-configuration-manifests/%s.ini' % self.behaviour
        path = self._manifest_path

        url_handle = urllib2.urlopen(HeadRequest(manifest_url))
        headers = url_handle.info()
        url_last_modified = headers.getdate("Last-Modified")

        file_modified = tuple(time.localtime(
            os.path.getmtime(path))) if os.path.exists(path) else None

        if not file_modified or url_last_modified > file_modified:
            self._logger.debug('Fetching %s', manifest_url)
            response = urllib2.urlopen(manifest_url)
            data = response.read()
            if data:
                old_manifest = Configuration('ini')
                if os.path.exists(path):
                    old_manifest.read(path)

                new_manifest = Configuration('ini')
                o = StringIO()
                o.write(data)
                o.seek(0)
                new_manifest.readfp(o)

                new_sections = new_manifest.sections('./')
                old_sections = old_manifest.sections('./')

                diff_path = os.path.join(os.path.dirname(path),
                                         self.behaviour + '.incdiff')
                diff = Configuration('ini')

                if old_sections and old_sections != new_sections:
                    #skipping diff if no previous manifest found or it is equal to the new one
                    if os.path.exists(diff_path):
                        diff.read(diff_path)

                    sys_vars = self.get_system_variables()

                    for section in new_sections:
                        if section not in old_sections and sys_vars.has_key(
                                section):
                            sys_var = sys_vars[section]
                            if self.definitions:
                                if self.definitions.has_key(sys_var):
                                    sys_var = self.definitions[sys_var]
                            diff.add('./%s/default-value' % section,
                                     sys_var,
                                     force=True)
                            diff.write(diff_path)

                if os.path.exists(diff_path):
                    diff.read(diff_path)

                for variable in diff.sections('./'):
                    sys_value = diff.get('./%s/default-value' % variable)
                    if sys_value and variable in new_manifest.sections('./'):
                        new_manifest.set('./%s/default-value' % variable,
                                         sys_value,
                                         force=True)
                new_manifest.write(path)

        return _CnfManifest(path)
Ejemplo n.º 6
0
	def _manifest(self):		
		
		class HeadRequest(urllib2.Request):
			def get_method(self):
				return "HEAD"
		
		manifest_url = bus.scalr_url + '/storage/service-configuration-manifests/%s.ini' % self.behaviour	
		path = self._manifest_path

			
		url_handle = urllib2.urlopen(HeadRequest(manifest_url))
		headers = url_handle.info()
		url_last_modified = headers.getdate("Last-Modified")
		
		file_modified = tuple(time.localtime(os.path.getmtime(path))) if os.path.exists(path) else None
		
		if not file_modified or url_last_modified > file_modified:
			self._logger.debug('Fetching %s', manifest_url)
			response = urllib2.urlopen(manifest_url)
			data = response.read()
			if data:
				old_manifest = Configuration('ini')
				if os.path.exists(path):
					old_manifest.read(path)

				new_manifest = Configuration('ini')
				o = StringIO()
				o.write(data)
				o.seek(0)
				new_manifest.readfp(o)
				
				new_sections = new_manifest.sections('./')  
				old_sections = old_manifest.sections('./')

				diff_path = os.path.join(os.path.dirname(path), self.behaviour + '.incdiff')
				diff = Configuration('ini')
									
				if old_sections and old_sections != new_sections:
					#skipping diff if no previous manifest found or it is equal to the new one
					if os.path.exists(diff_path):
						diff.read(diff_path)

					sys_vars = self.get_system_variables()

					for section in new_sections:
						if section not in old_sections and sys_vars.has_key(section):
							sys_var = sys_vars[section]
							if self.definitions:
								if self.definitions.has_key(sys_var):
									sys_var = self.definitions[sys_var]
							diff.add('./%s/default-value' % section, sys_var, force=True)
							diff.write(diff_path)
				
				if os.path.exists(diff_path):
					diff.read(diff_path)
				
				for variable in diff.sections('./'):
					sys_value = diff.get('./%s/default-value' % variable)
					if sys_value and variable in new_manifest.sections('./'):
						new_manifest.set('./%s/default-value' % variable, sys_value, force=True)
				new_manifest.write(path)

		return _CnfManifest(path)