Example #1
0
def _load_environment(environment_file: IO) -> EnvironmentConfig:
    """Load the environment JSON file and process matrix server list

    Nodes can be assigned to fixed matrix servers. To allow this, we must
    download the list of matrix severs.
    """
    environment = json.load(environment_file)
    assert isinstance(environment, dict)

    matrix_server_list = environment.pop(
        "matrix_server_list",
        DEFAULT_MATRIX_KNOWN_SERVERS[Environment(environment["environment_type"])],
    )
    matrix_servers: Sequence[URI] = get_matrix_servers(matrix_server_list)  # type: ignore
    if len(matrix_servers) < 4:
        matrix_servers = list(islice(cycle(matrix_servers), 4))

    return EnvironmentConfig(
        matrix_servers=matrix_servers,
        environment_file_name=environment_file.name,
        **environment,
    )
Example #2
0
 def convert(self, value, param, ctx):
     try:
         return Environment(value)
     except ValueError:
         self.fail(f"'{value}' is not a valid environment type", param, ctx)