def load_defaults(self): for default in self.default_attributes: if default in self.store().values(): continue attr = EntityRegister.get_attribute(self.ctype, default) if attr.has_defaults(): self.add_attribute(attr(self))
def _create_component(name, component_type, command): component_class = EntityRegister.get_component(component_type) component = component_class(name, command) component.load_defaults() for attr_name in component.store().values().keys(): if attr_name in non_attributes: continue attr = EntityRegister.get_attribute(component_type, attr_name) if not attr: raise NotFound("Invalid attribute `{}` for component " "{}. Maybe Missspelled?" .format(attr_name, component.entity())) component.add_attribute(attr(component)) # check if component is correctly initialized component.validate() return component
stats = { "source": self.settings(), "type": os.path.splitext(self.settings())[1][1:], "size": self.io().stat(self._image_path()).st_size, "md5": md5, "sha256": sha256, "added": time.time() } util.yaml_write(self._image_path() + ".yml", stats) _pending.release() def _generate_hashes(self): try: self.say("generate image checksum...") md5_hash = hashlib.md5() sha256_hash = hashlib.sha256() with open(self._image_path(), 'rb') as hdl: buf = hdl.read(65536) while len(buf) > 0: md5_hash.update(buf) sha256_hash.update(buf) buf = hdl.read(65536) return (md5_hash.hexdigest(), sha256_hash.hexdigest()) except IOError as err: raise error.ExecError("Could not create validation hashes") EntityRegister.register_attribute("node", ImageAttribute)
def register(cls): EntityRegister.register_component(cls)
def register(cls): EntityRegister.register_attribute("distribution", cls)
def register(cls): EntityRegister.register_attribute("network", cls)
if not pool.isActive(): pool.create() def used_pool(self): pool = self.get_pool(self.settings(), raise_exception=False) if not pool: if not self.has_component("pool", self.settings()): raise error.NotFound("pool {} does not exist.") for i in range(self.global_get("global/retry_pool", 20)): pool = self.get_pool(name, raise_exception=False) if pool: break self.counted(i, "Waiting for pool {} to become ready.".format(self.settings())) sleep(self.global_get("global/wait", 3)) raise error.ExecError("Coult not start pool {}!".format(self.settings())) return pool def used_pool_name(self): return self.settings() def used_pool_type(self): pool = self.used_pool() xml = etree.fromstring(pool.XMLDesc()) return xml.attrib["type"] EntityRegister.register_attribute("node", PoolAttribute)