chi.context¶
The chi.context module exposes a global context object and helpers for generating
clients for interfacing with the various Chameleon services.
- chi.context.check_credentials() bool[source]¶
Prints authentication metadata (e.g. username, site) and if credentials are currently valid and user is authenticated.
- Returns:
Whether the credentails are valid
- chi.context.choose_project() None[source]¶
Displays a dropdown menu to select a project.
Only works if running in a Ipynb notebook environment.
- chi.context.choose_site(default: str | None = None) None[source]¶
Displays a dropdown menu to select a chameleon site.
Only works if running in a Ipynb notebook environment.
- Parameters:
default (str, optional) – the site to default to
- chi.context.get(key)[source]¶
Get a context parameter by name.
- Parameters:
key (str) – the parameter name.
- Returns:
the parameter value.
- Return type:
any
- Raises:
cfg.NoSuchOptError – if the parameter is not supported.
- chi.context.get_lease_id()[source]¶
Returns the currently active lease ID, if one has been set.
- Returns:
The lease ID currently in use, or None if no lease has been selected.
- Return type:
str or None
- chi.context.get_project_name(project_id: str | None = None) str[source]¶
Returns the name of a project by ID, or the current project name if no ID is given.
- Parameters:
project_id (str, optional) – The ID of the project. If None, uses the current session project.
- Returns:
The name of the project.
- Return type:
- Raises:
ResourceError – If the project cannot be found or the request fails.
- chi.context.list_projects(show: str | None = None) List[str][source]¶
Retrieves a list of projects associated with the current user.
- Parameters:
show (str, optional) – Determines how the project names should be displayed.
widget (Possible values are "widget" to display as a table)
print ("text" to)
text (as plain)
None (or)
- Returns:
If show is set to “widget”, it displays the project names as a text widget. If show is set to “text”, it prints the project names as plain text. If show is set to None, it returns a list of project names.
- Raises:
ValueError – If no projects are returned or an invalid value is provided for the show parameter.
- chi.context.list_sites(show: str | None = None) dict[source]¶
Retrieves a list of Chameleon sites.
- Parameters:
show (str, optional) – Determines how the site names should be displayed.
widget (Possible values are "widget" to display as a table)
print ("text" to)
text (as plain)
None (or)
- Returns:
If show is set to “widget”, it displays the site names as a text widget. If show is set to “text”, it prints the site names as plain text. If show is set to None, it returns a dictionary of site names to their properties.
- Raises:
ValueError – If no sites are returned or if an invalid value is provided for the show parameter.
- chi.context.params()[source]¶
List all parameters currently set on the context.
- Returns:
a list of parameter names.
- Return type:
List[str]
- chi.context.reset()[source]¶
Reset the context, removing all overrides and defaults.
The
auth_typeparameter will be defaulted to the value of the OS_AUTH_TYPE environment variable, falling back to “v3token” if not defined.All context parameters will revert to the default values inferred from environment variables.
- chi.context.session()[source]¶
Get a Keystone Session object suitable for authenticating a client.
- Returns:
the authentication session object.
- Return type:
keystoneauth1.session.Session
- chi.context.set(key, value)[source]¶
Set a context parameter by name.
- Parameters:
key (str) – the parameter name.
value (any) – the parameter value.
- Raises:
cfg.NoSuchOptError – if the parameter is not supported.
- chi.context.set_log_level(level: str = 'ERROR') None[source]¶
Configures logger for python-chi. By default, only errors are shown. Set to “DEBUG” to see debug level logging, which will show calls to external APIs.
- Parameters:
level (str, optional) – The log level. Defaults to “ERROR”.
- chi.context.use_lease_id(lease_id: str) None[source]¶
Sets the current lease ID to use in the global context.
This configures the lease so it can be stored for ease of restoring suspended sessions. Further lease validation, visualizations, and selectors are available in the lease module.
- Parameters:
lease_id (str) – The ID of the lease to use.
- chi.context.use_project(project: str) None[source]¶
Sets the current project name.
- Parameters:
project (str) – The name of the project to use.
- Returns:
None
- chi.context.use_site(site_name: str) None[source]¶
Configure the global request context to target a particular CHI site.
Targeting a site will mean that leases, instance launch requests, and any other API calls will be sent to that site. By default, no site is selected, and one must be explicitly chosen.
chi.use_site("CHI@UC")
Changing the site will affect future calls the client makes, implicitly. Therefore something like this is possible:
chi.use_site("CHI@UC") chi.lease.create_lease("my-uc-lease", reservations) chi.use_site("CHI@TACC") chi.lease.create_lease("my-tacc-lease", reservations)