Context list. Returns: (Context): List of context objects. Raises: :py:class:`docker.errors.APIError` If the server returns an error.
(cls)
| 99 | |
| 100 | @classmethod |
| 101 | def contexts(cls): |
| 102 | """Context list. |
| 103 | Returns: |
| 104 | (Context): List of context objects. |
| 105 | Raises: |
| 106 | :py:class:`docker.errors.APIError` |
| 107 | If the server returns an error. |
| 108 | """ |
| 109 | names = [] |
| 110 | for dirname, dirnames, fnames in os.walk(get_meta_dir()): |
| 111 | for filename in fnames + dirnames: |
| 112 | if filename == METAFILE: |
| 113 | try: |
| 114 | data = json.load( |
| 115 | open(os.path.join(dirname, filename))) |
| 116 | names.append(data["Name"]) |
| 117 | except Exception as e: |
| 118 | raise errors.ContextException( |
| 119 | f"Failed to load metafile {filename}: {e}", |
| 120 | ) from e |
| 121 | |
| 122 | contexts = [cls.DEFAULT_CONTEXT] |
| 123 | for name in names: |
| 124 | contexts.append(Context.load_context(name)) |
| 125 | return contexts |
| 126 | |
| 127 | @classmethod |
| 128 | def get_current_context(cls): |