MCPcopy Index your code
hub / github.com/docker/docker-py / ContextAPI

Class ContextAPI

docker/context/api.py:15–206  ·  view source on GitHub ↗

Context API. Contains methods for context management: create, list, remove, get, inspect.

Source from the content-addressed store, hash-verified

13
14
15class ContextAPI:
16 """Context API.
17 Contains methods for context management:
18 create, list, remove, get, inspect.
19 """
20 DEFAULT_CONTEXT = Context("default", "swarm")
21
22 @classmethod
23 def create_context(
24 cls, name, orchestrator=None, host=None, tls_cfg=None,
25 default_namespace=None, skip_tls_verify=False):
26 """Creates a new context.
27 Returns:
28 (Context): a Context object.
29 Raises:
30 :py:class:`docker.errors.MissingContextParameter`
31 If a context name is not provided.
32 :py:class:`docker.errors.ContextAlreadyExists`
33 If a context with the name already exists.
34 :py:class:`docker.errors.ContextException`
35 If name is default.
36
37 Example:
38
39 >>> from docker.context import ContextAPI
40 >>> ctx = ContextAPI.create_context(name='test')
41 >>> print(ctx.Metadata)
42 {
43 "Name": "test",
44 "Metadata": {},
45 "Endpoints": {
46 "docker": {
47 "Host": "unix:///var/run/docker.sock",
48 "SkipTLSVerify": false
49 }
50 }
51 }
52 """
53 if not name:
54 raise errors.MissingContextParameter("name")
55 if name == "default":
56 raise errors.ContextException(
57 '"default" is a reserved context name')
58 ctx = Context.load_context(name)
59 if ctx:
60 raise errors.ContextAlreadyExists(name)
61 endpoint = "docker"
62 if orchestrator and orchestrator != "swarm":
63 endpoint = orchestrator
64 ctx = Context(name, orchestrator)
65 ctx.set_endpoint(
66 endpoint, host, tls_cfg,
67 skip_tls_verify=skip_tls_verify,
68 def_namespace=default_namespace)
69 ctx.save()
70 return ctx
71
72 @classmethod

Callers

nothing calls this directly

Calls 1

ContextClass · 0.85

Tested by

no test coverage detected