def get(client: ConnectionClient, conn_id: str, output_format: str, decrypted: bool): """ \b Get connections. The command without id argument retrieve all connections. \b Get all connections in json format: odahuflowctl conn get --output-format json \b Get connection with "git-repo" id: odahuflowctl conn get --id git-repo \b Using jsonpath: odahuflowctl conn get -o 'jsonpath=[*].spec.reference' \f :param decrypted: if set than decrypted connection will be returned :param client: Connection HTTP client :param conn_id: Connection ID :param output_format: Output format :return: """ if conn_id: if decrypted: conn = client.get_decrypted(conn_id) else: conn = client.get(conn_id) conns = [conn] else: conns = client.get_all() format_output(conns, output_format)
def edit(client: ConnectionClient, conn_id: str, file: str, output_format: str): """ \b Update a connection. You should specify a path to file with a connection. The file must contain only one connection. For now, CLI supports YAML and JSON file formats. If you want to update multiple connections, you should use "odahuflowctl bulk apply" instead. If you provide the connection id parameter, it will override before sending to API server. \b Usage example: * odahuflowctl conn update -f conn.yaml --id examples-git \f :param client: Connection HTTP client :param conn_id: Connection ID :param file: Path to the file with only one connection :param output_format: Output format """ conn = parse_resources_file_with_one_item(file).resource if not isinstance(conn, Connection): raise ValueError(f'Connection expected, but {type(conn)} provided') if conn_id: conn.id = conn_id click.echo(format_output([client.edit(conn)], output_format))
def build_client(resource: OdahuflowCloudResourceUpdatePair, api_client: RemoteAPIClient) -> typing.Optional[object]: """ Build client for particular resource (e.g. it builds ModelTrainingClient for ModelTraining resource) :param resource: target resource :param api_client: base API client to extract connection options from :return: remote client or None """ if isinstance(resource.resource, ModelTraining): return ModelTrainingClient.construct_from_other(api_client) elif isinstance(resource.resource, ModelDeployment): return ModelDeploymentClient.construct_from_other(api_client) elif isinstance(resource.resource, Connection): return ConnectionClient.construct_from_other(api_client) elif isinstance(resource.resource, ToolchainIntegration): return ToolchainIntegrationClient.construct_from_other(api_client) elif isinstance(resource.resource, ModelRoute): return ModelRouteClient.construct_from_other(api_client) elif isinstance(resource.resource, ModelPackaging): return ModelPackagingClient.construct_from_other(api_client) elif isinstance(resource.resource, PackagingIntegration): return PackagingIntegrationClient.construct_from_other(api_client) else: raise InvalidResourceType('{!r} is invalid resource '.format( resource.resource))
def delete(client: ConnectionClient, conn_id: str, file: str, ignore_not_found: bool): """ \b Delete a connection. For this command, you must provide a connection ID or path to file with one connection. The file must contain only one connection. If you want to delete multiple connections, you should use "odahuflowctl bulk delete" instead. For now, CLI supports YAML and JSON file formats. The command will fail if you provide both arguments. \b Usage example: * odahuflowctl conn delete --id examples-git * odahuflowctl conn delete -f conn.yaml * odahuflowctl conn delete --id examples-git --ignore-not-found \f :param client: Connection HTTP client :param conn_id: Connection ID :param file: Path to the file with only one connection :param ignore_not_found: ignore if connection is not found """ check_id_or_file_params_present(conn_id, file) if file: conn = parse_resources_file_with_one_item(file).resource if not isinstance(conn, Connection): raise ValueError(f'Connection expected, but {type(conn)} provided') conn_id = conn.id try: click.echo(client.delete(conn_id)) except WrongHttpStatusCode as e: if e.status_code != http.HTTPStatus.NOT_FOUND or not ignore_not_found: raise e click.echo(IGNORE_NOT_FOUND_ERROR_MESSAGE.format(conn_id))
def connection(ctx: click.core.Context, url: str, token: str): """ Allow you to perform actions on connections.\n Alias for the command is conn. """ ctx.obj = ConnectionClient(url, token)
def connection_delete(conn_id: str): return ConnectionClient().delete(conn_id)
def connection_post(payload_file): api_object = parse_resources_file_with_one_item(payload_file).resource return ConnectionClient().create(api_object)
def connection_get_id_decrypted(conn_id: str): return ConnectionClient().get_decrypted(conn_id)
def connection_get_id(conn_id: str): return ConnectionClient().get(conn_id)
def connection_get(): return ConnectionClient().get_all()
click_group: click.Group # For example, ModelTraining or Connection kind: str def generate_entities_for_test(metafunc, keys: typing.List[str]): if "entity_test_data" in metafunc.fixturenames: metafunc.parametrize( "entity_test_data", keys, indirect=True, ) CONNECTION = EntityTestData( ConnectionClient(), Connection( id=ENTITY_ID, spec=ConnectionSpec( key_secret="mock-key-secret", uri="mock-url", ), ), connection.connection, 'Connection', ) TRAINING = EntityTestData( ModelTrainingClient(), ModelTraining( id=ENTITY_ID,