def load(identity_db): args = UvnIdentityDatabase.get_load_args(identity_db=identity_db) db_file = args["basedir"] / UvnDefaults["nameserver"]["persist_file"] return yml_obj(UvnNameserver, db_file, from_file=True, identity_db=identity_db, **args)
def load(identity_db): args = UvnIdentityDatabase.get_load_args(identity_db=identity_db) registry_file = args["basedir"] / UvnDefaults["registry"][ "persist_file"] nameserver = UvnNameserver.load(identity_db=identity_db) return yml_obj(UvnRegistry, registry_file, from_file=True, identity_db=identity_db, nameserver=nameserver, **args)
def _load_deployment(self, deployment_id, store=True, deployment_dir=None): if (deployment_dir is None): deployment_dir = self.paths.dir_deployment(deployment_id) deployment_manifest_file = deployment_dir / UvnDefaults["registry"][ "deployment_file"] db_args = UvnIdentityDatabase.get_load_args( identity_db=self.identity_db) deployment = yml_obj(UvnDeployment, deployment_manifest_file, from_file=True, registry=self, **db_args) if (deployment.id != deployment_id): raise UvnException( f"Invalid deployment loaded: {deployment.id}, expected {deployment_id}" ) if (store): self.deployments.append(deployment) return deployment
def repr_py(self, yml_repr, **kwargs): identity_db = kwargs["identity_db"] nameserver = kwargs["nameserver"] deployments = kwargs.get("deployments") cells = { c["id"]["name"]: repr_py(Cell, c, **kwargs) for c in yml_repr["cells"] } particles = { p["name"]: repr_py(Particle, p, **kwargs) for p in yml_repr["particles"] } keymat = repr_py(WireGuardKeyPair, yml_repr["keymat"], **kwargs) if "vpn_config" in yml_repr: vpn_config = repr_py(UvnRegistry.RegistryVpn, yml_repr["vpn_config"], **kwargs) else: vpn_config = None if "router_ports" in yml_repr: router_ports = repr_py(RegistryRouterPorts, yml_repr["router_ports"], **kwargs) else: router_ports = None py_repr = UvnRegistry(identity_db=identity_db, cells=cells, particles=particles, keymat=keymat, ports=yml_repr["ports"], loaded=True, pkg_cell=yml_repr.get("pkg_cell", None), deployment_id=yml_repr.get( "deployment_id", None), vpn_config=vpn_config, nameserver=nameserver, router_ports=router_ports) # Register cells with identity_db for c in py_repr.cells.values(): with_secret = (py_repr.packaged and c.id.name == py_repr.pkg_cell) py_repr.identity_db.register_cell(name=c.id.name, address=c.id.address, admin=c.id.admin, admin_name=c.id.admin_name, with_secret=with_secret) deployment_loaded = False if ("deployments" in yml_repr): for d in yml_repr["deployments"]: if (deployments is not None and d in deployments): py_repr.deployments.append(deployments[d]) continue try: py_repr._load_deployment(deployment_id=d) if d == py_repr.deployment_id: deployment_loaded = True except Exception as e: # traceback.print_exc() logger.exception(e) logger.warning("failed to load deployment {}: {}", d, e) if not py_repr.packaged: # Generate particle configurations py_repr._generate_particles() else: if (py_repr.deployment_id != UvnDefaults["registry"]["deployment_bootstrap"] and not deployment_loaded): raise UvnException( f"required deployment not loaded: {py_repr.deployment_id}" ) try: file_path = py_repr.paths.basedir / UvnDefaults[ "registry"]["cell_file"] db_args = UvnIdentityDatabase.get_load_args( identity_db=identity_db) cell = yml_obj(Cell, file_path, from_file=True, identity_db=identity_db, **db_args) if cell.id.name != py_repr.pkg_cell: raise UvnException( f"invalid UVN package: expected={py_repr.pkg_cell}, found={cell.id.name}" ) py_repr.cells[cell.id.name] = cell # Generate particle server py_repr._register_particles(py_repr.deployed_cell) # logger.activity("[loaded] UVN package for {} [{}]", # cell.id.name, py_repr.deployment_id) except Exception as e: raise UvnException( f"failed to load UVN package for {py_repr.pkg_cell}: {e}" ) logger.activity( "[{}]{} loaded UVN: {}", py_repr.pkg_cell if py_repr.packaged else "root", f"[{py_repr.deployment_id}]" if py_repr.packaged else "", py_repr.identity_db.registry_id.address) return py_repr