def archived_condition( params: Union[str, Iterable], negation: bool, query_backend: Any, timezone: str = None, queryset: Any = None, ) -> Any: """ Example: >>> {"archived": CallbackCondition(callback_conditions.archived_condition)} """ params = to_list(params) if len(params) == 1 and to_bool(params[0]) is True: return (queryset.filter(live_state=live_state.STATE_ARCHIVED) if queryset else query_backend( live_state=live_state.STATE_ARCHIVED)) return query_backend(live_state=live_state.STATE_LIVE)
async def get_run_resources(request): run_uuid = request.path_params["run_uuid"] event_names = request.query_params.get("names") orient = request.query_params.get("orient") force = to_bool(request.query_params.get("force"), handle_none=True) orient = orient or V1Events.ORIENT_DICT event_names = {e for e in event_names.split(",") if e} if event_names else set([]) events = await get_archived_operation_resources( run_uuid=run_uuid, event_kind=V1ArtifactKind.METRIC, event_names=event_names, orient=orient, check_cache=not force, ) return UJSONResponse({"data": events})
async def download_artifact(request): run_uuid = request.path_params["run_uuid"] filepath = request.query_params.get("path", "") stream = to_bool(request.query_params.get("stream"), handle_none=True) if not filepath: return Response( content="A `path` query param is required to stream a file content", status_code=status.HTTP_400_BAD_REQUEST, ) subpath = "{}/{}".format(run_uuid, filepath).rstrip("/") archived_path = await download_file(subpath=subpath) if not archived_path: return Response( content="Artifact not found: filepath={}".format(archived_path), status_code=status.HTTP_404_NOT_FOUND, ) if stream: return FileResponse(archived_path) return redirect(archived_path)
async def get_logs(request: Request) -> UJSONResponse: run_uuid = request.path_params["run_uuid"] force = to_bool(request.query_params.get("force"), handle_none=True) last_time = QueryParams(request.url.query).get("last_time") if last_time: last_time = parse_datetime(last_time).astimezone() last_file = QueryParams(request.url.query).get("last_file") files = [] if last_time: resource_name = get_resource_name(run_uuid=run_uuid) k8s_manager = AsyncK8SManager( namespace=settings.CLIENT_CONFIG.namespace, in_cluster=settings.CLIENT_CONFIG.in_cluster, ) await k8s_manager.setup() k8s_operation = await get_k8s_operation( k8s_manager=k8s_manager, resource_name=resource_name ) if k8s_operation: operation_logs, last_time = await get_operation_logs( k8s_manager=k8s_manager, k8s_operation=k8s_operation, instance=run_uuid, last_time=last_time, ) else: operation_logs, last_time = await get_tmp_operation_logs( run_uuid=run_uuid, last_time=last_time ) if k8s_manager: await k8s_manager.close() else: operation_logs, last_file, files = await get_archived_operation_logs( run_uuid=run_uuid, last_file=last_file, check_cache=not force ) response = V1Logs( last_time=last_time, last_file=last_file, logs=operation_logs, files=files ) return UJSONResponse(response.to_dict())
async def get_run_events(request: Request) -> UJSONResponse: run_uuid = request.path_params["run_uuid"] event_kind = request.path_params["event_kind"] force = to_bool(request.query_params.get("force"), handle_none=True) if event_kind not in V1ArtifactKind.allowable_values: raise HTTPException( detail="received an unrecognisable event {}.".format(event_kind), status_code=status.HTTP_400_BAD_REQUEST, ) event_names = request.query_params["names"] orient = request.query_params.get("orient") orient = orient or V1Events.ORIENT_DICT event_names = {e for e in event_names.split(",") if e} if event_names else set([]) events = await get_archived_operation_events( run_uuid=run_uuid, event_kind=event_kind, event_names=event_names, orient=orient, check_cache=not force, ) return UJSONResponse({"data": events})
def get_collect_resources(): """If set, Polyaxon will collect resources""" return to_bool(os.getenv(POLYAXON_KEYS_COLLECT_RESOURCES, None), handle_none=True)
def get_collect_artifact(): """If set, Polyaxon will collect artifacts""" return to_bool(os.getenv(POLYAXON_KEYS_COLLECT_ARTIFACTS, None), handle_none=True)
def set_client_config(): global CLIENT_CONFIG try: CLIENT_CONFIG = ClientConfigManager.get_config_from_env() except (TypeError, ValidationError): ClientConfigManager.purge() Printer.print_warning("Your client Configuration was purged!") CLIENT_CONFIG = ClientConfigManager.get_config_from_env() def set_auth_config(): from polyaxon.managers.auth import AuthConfigManager global AUTH_CONFIG try: AUTH_CONFIG = AuthConfigManager.get_config_from_env() except (TypeError, ValidationError): AuthConfigManager.purge() Printer.print_warning("Your auth Configuration was purged!") if not to_bool(os.environ.get(POLYAXON_KEYS_NO_CONFIG, False)): set_auth_config() set_client_config() if to_bool(os.environ.get(POLYAXON_KEYS_SET_AGENT, False)): set_agent_config() else: CLIENT_CONFIG = ClientConfigManager.CONFIG(host=LOCALHOST)
def _eq_operator(name: str, params: Any, query_backend: Any, timezone: str) -> Any: return query_backend(**{name: to_bool(params)})
import os from polyaxon.managers.auth import AuthConfigManager from polyaxon.managers.client import ClientConfigManager from polyaxon.utils.bool_utils import to_bool MIN_TIMEOUT = 1 LONG_REQUEST_TIMEOUT = 3600 HEALTH_CHECK_INTERVAL = 60 AUTH_CONFIG = None CLIENT_CONFIG = None PROXIES_CONFIG = None AGENT_CONFIG = None if not to_bool(os.environ.get("POLYAXON_NO_CONFIG", False)): AUTH_CONFIG = AuthConfigManager.get_config_from_env() CLIENT_CONFIG = ClientConfigManager.get_config_from_env() if CLIENT_CONFIG.set_agent: from polyaxon.managers.agent import AgentManager AGENT_CONFIG = AgentManager.get_config_from_env( agent_path=CLIENT_CONFIG.agent_path ) else: CLIENT_CONFIG = ClientConfigManager.CONFIG() def set_proxies_config(): from polyaxon.managers.proxies import ProxiesManager
from polyaxon.cli.completion import completion from polyaxon.cli.config import config from polyaxon.cli.dashboard import dashboard from polyaxon.cli.hub import hub from polyaxon.cli.init import init from polyaxon.cli.operations import ops from polyaxon.cli.port_forward import port_forward from polyaxon.cli.projects import project from polyaxon.cli.run import run from polyaxon.cli.session import set_versions_config from polyaxon.cli.upload import upload from polyaxon.cli.version import check_cli_version, upgrade, version from polyaxon.logger import configure_logger from polyaxon.utils.bool_utils import to_bool DOCS_GEN = to_bool(os.environ.get("POLYAXON_DOCS_GEN", False)) click_completion.init() @click.group() @click.option("-v", "--verbose", is_flag=True, default=False, help="Turn on debug logging") @click.option( "--offline", is_flag=True, default=False, help="Run command in offline mode if supported. "
def handle(self, *args, **options): # pylint:disable=too-many-branches username = options[self.UserModel.USERNAME_FIELD].strip() password = options["password"].strip() email = options["email"].strip() force = to_bool(options["force"]) is_superuser = to_bool(options["is_superuser"]) try: username = self.username_field.clean(username, None) except exceptions.ValidationError as e: raise CommandError("; ".join(e.messages)) try: self.email_field.clean(email, None) except exceptions.ValidationError as e: raise CommandError("; ".join(e.messages)) try: self.UserModel.objects.get_by_natural_key(username) except self.UserModel.DoesNotExist: pass else: _logger.info( "Info: Username %s is already taken. Will not recreate user.", username ) return try: self.UserModel.objects.get(email=email) except self.UserModel.DoesNotExist: pass except exceptions.MultipleObjectsReturned: raise CommandError("Error: That %s is already taken." % email) else: raise CommandError("Error: That %s is already taken." % email) if not username: raise CommandError("Error: Blank username aren't allowed.") if not password: raise CommandError("Error: Blank passwords aren't allowed.") if not email: raise CommandError("Error: Blank email aren't allowed.") user_data = {self.UserModel.USERNAME_FIELD: username, "email": email} self.validate_password(password=password, user_data=user_data, force=force) user_data["password"] = password if is_superuser: self.UserModel.objects.create_superuser(**user_data) else: self.UserModel.objects.create_user(**user_data) if options["verbosity"] >= 1: self.stdout.write( "{} created successfully.".format( "Superuser" if is_superuser else "User" ) )
def get_collect_resources(arg: bool = None, default: bool = None): """If set, Polyaxon will collect resources""" return (arg if arg is not None else to_bool( os.getenv(POLYAXON_KEYS_COLLECT_RESOURCES, default), handle_none=True))
def get_collect_artifacts(arg: bool = None, default: bool = None): """If set, Polyaxon will collect artifacts""" return (arg if arg is not None else to_bool( os.getenv(POLYAXON_KEYS_COLLECT_ARTIFACTS, default), handle_none=True))