def __init__(self, version, checkpoint): super(SchemaVersionRecord, self).__init__() self.version = Version(version) self.checkpoint = checkpoint self.adds = [] self.removals = [] self._current_section = 'DEFAULT'
class SchemaVersionRecord(object): # checkpoint's data is version number def __init__(self, version, checkpoint): super(SchemaVersionRecord, self).__init__() self.version = Version(version) self.checkpoint = checkpoint self.adds = [] self.removals = [] self._current_section = 'DEFAULT' def __repr__(self): return ('<SchemaVersionRecord %s%s>' % (self.version, ' (checkpoint)' if self.checkpoint else '')) def __cmp__(self, other): return self.version.__cmp__(other.version) def section(self, name): self._current_section = name def param(self, *args, **kwargs): if not 'section' in kwargs and self._current_section: kwargs['section'] = self._current_section self.adds.append(ConfigParameterSchema(*args, **kwargs)) def remove_param(self, name): self.removals.append(name)
class SchemaVersionRecord(object): # checkpoint's data is version number def __init__(self, version, checkpoint): super(SchemaVersionRecord, self).__init__() self.version = Version(version) self.checkpoint = checkpoint self.adds = [] self.removals = [] self._current_section = 'DEFAULT' def __repr__(self): return ( '<SchemaVersionRecord %s%s>' % ( self.version, ' (checkpoint)' if self.checkpoint else '') ) def __cmp__(self, other): return self.version.__cmp__(other.version) def section(self, name): self._current_section = name def param(self, *args, **kwargs): if not 'section' in kwargs and self._current_section: kwargs['section'] = self._current_section self.adds.append(ConfigParameterSchema(*args, **kwargs)) def remove_param(self, name): self.removals.append(name)
def config(self): config = Configuration() schema = ConfigSchemaRegistry.get_schema('rabbitmq', Version(1000000)) if schema: for parameter in schema.parameters: if not parameter.default: continue config.set_default(parameter.name, parameter.default) else: print("RabbitMQ schema not found") return config
def get_schema(self, project, version, configname=None): if not configname: configname = '%s.conf' % project fullname = '%s/%s' % (project, configname) version = Version(version) if not fullname in self.__schemas: return None records = self.__schemas[fullname] i = len(records) - 1 # Find latest checkpoint prior given version while i >= 0 and not (records[i].checkpoint and records[i].version <= version): i -= 1 if i < 0: return None parameters = [] seen_parameters = set() last_version = None while i < len(records) and records[i].version <= version: last_version = records[i].version for param in records[i].adds: if param.name in seen_parameters: old_param_index = index(parameters, lambda p: p.name == param.name) if old_param_index != -1: parameters[old_param_index] = param else: parameters.append(param) seen_parameters.add(param.name) for param_name in records[i].removals: param_index = index(parameters, lambda p: p.name == param_name) if index != -1: parameters.pop(param_index) seen_parameters.remove(param_name) i += 1 return ConfigSchema(fullname, last_version, 'ini', parameters)
def __init__(self, name, version, format, parameters): self.name = name self.version = Version(version) self.format = format self.parameters = parameters
def use_openstack_version(step, version): version = Version(version) for component in [c for c in world.openstack.components if isinstance(c, OpenstackComponent)]: if not Version(component.version) >= version: stop()