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.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_type parameter 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_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)
Parameters:

site_name (str) – The name of the site, e.g., “CHI@UC”.