Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit32dbc6f

Browse files
nejchmax-wittig
authored andcommitted
feat(api): add support for project cluster agents
1 parentee393a1 commit32dbc6f

File tree

6 files changed

+168
-0
lines changed

6 files changed

+168
-0
lines changed

‎docs/api-objects.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ API examples
1414
gl_objects/bulk_imports
1515
gl_objects/messages
1616
gl_objects/ci_lint
17+
gl_objects/cluster_agents
1718
gl_objects/commits
1819
gl_objects/deploy_keys
1920
gl_objects/deploy_tokens

‎docs/gl_objects/cluster_agents.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
##############
2+
Cluster agents
3+
##############
4+
5+
You can list and manage project cluster agents with the GitLab agent for Kubernetes.
6+
7+
..warning::
8+
Check the GitLab API documentation linked below for project permissions
9+
required to access specific cluster agent endpoints.
10+
11+
Reference
12+
---------
13+
14+
* v4 API:
15+
16+
+:class:`gitlab.v4.objects.ProjectClusterAgent`
17+
+:class:`gitlab.v4.objects.ProjectClusterAgentManager`
18+
+:attr:`gitlab.v4.objects.Project.cluster_agents`
19+
20+
* GitLab API: https://docs.gitlab.com/ee/api/cluster_agents.html
21+
22+
Examples
23+
--------
24+
25+
List cluster agents for a project::
26+
27+
cluster_agents = project.cluster_agents.list()
28+
29+
Register a cluster agent with a project::
30+
31+
cluster_agent = project.cluster_agents.create({"name": "Agent 1"})
32+
33+
Retrieve a specific cluster agent for a project::
34+
35+
cluster_agent = project.cluster_agents.get(cluster_agent.id)
36+
37+
Delete a registered cluster agent from a project::
38+
39+
cluster_agent = project.cluster_agents.delete(cluster_agent.id)
40+
# or
41+
cluster.delete()

‎gitlab/v4/objects/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .broadcast_messagesimport*
1111
from .bulk_importsimport*
1212
from .ci_lintimport*
13+
from .cluster_agentsimport*
1314
from .clustersimport*
1415
from .commitsimport*
1516
from .container_registryimport*

‎gitlab/v4/objects/cluster_agents.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
fromtypingimportAny,cast,Union
2+
3+
fromgitlab.baseimportRESTManager,RESTObject
4+
fromgitlab.mixinsimportNoUpdateMixin,ObjectDeleteMixin,SaveMixin
5+
fromgitlab.typesimportRequiredOptional
6+
7+
__all__= [
8+
"ProjectClusterAgent",
9+
"ProjectClusterAgentManager",
10+
]
11+
12+
13+
classProjectClusterAgent(SaveMixin,ObjectDeleteMixin,RESTObject):
14+
_repr_attr="name"
15+
16+
17+
classProjectClusterAgentManager(NoUpdateMixin,RESTManager):
18+
_path="/projects/{project_id}/cluster_agents"
19+
_obj_cls=ProjectClusterAgent
20+
_from_parent_attrs= {"project_id":"id"}
21+
_create_attrs=RequiredOptional(required=("name",))
22+
23+
defget(
24+
self,id:Union[str,int],lazy:bool=False,**kwargs:Any
25+
)->ProjectClusterAgent:
26+
returncast(ProjectClusterAgent,super().get(id=id,lazy=lazy,**kwargs))

‎gitlab/v4/objects/projects.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from .boardsimportProjectBoardManager# noqa: F401
4444
from .branchesimportProjectBranchManager,ProjectProtectedBranchManager# noqa: F401
4545
from .ci_lintimportProjectCiLintManager# noqa: F401
46+
from .cluster_agentsimportProjectClusterAgentManager# noqa: F401
4647
from .clustersimportProjectClusterManager# noqa: F401
4748
from .commitsimportProjectCommitManager# noqa: F401
4849
from .container_registryimportProjectRegistryRepositoryManager# noqa: F401
@@ -183,6 +184,7 @@ class Project(
183184
branches:ProjectBranchManager
184185
ci_lint:ProjectCiLintManager
185186
clusters:ProjectClusterManager
187+
cluster_agents:ProjectClusterAgentManager
186188
commits:ProjectCommitManager
187189
customattributes:ProjectCustomAttributeManager
188190
deployments:ProjectDeploymentManager
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
"""
2+
GitLab API: https://docs.gitlab.com/ee/api/cluster_agents.html
3+
"""
4+
5+
importpytest
6+
importresponses
7+
8+
fromgitlab.v4.objectsimportProjectClusterAgent
9+
10+
agent_content= {
11+
"id":1,
12+
"name":"agent-1",
13+
"config_project": {
14+
"id":20,
15+
"description":"",
16+
"name":"test",
17+
"name_with_namespace":"Administrator / test",
18+
"path":"test",
19+
"path_with_namespace":"root/test",
20+
"created_at":"2022-03-20T20:42:40.221Z",
21+
},
22+
"created_at":"2022-04-20T20:42:40.221Z",
23+
"created_by_user_id":42,
24+
}
25+
26+
27+
@pytest.fixture
28+
defresp_list_project_cluster_agents():
29+
withresponses.RequestsMock()asrsps:
30+
rsps.add(
31+
method=responses.GET,
32+
url="http://localhost/api/v4/projects/1/cluster_agents",
33+
json=[agent_content],
34+
content_type="application/json",
35+
status=200,
36+
)
37+
yieldrsps
38+
39+
40+
@pytest.fixture
41+
defresp_get_project_cluster_agent():
42+
withresponses.RequestsMock()asrsps:
43+
rsps.add(
44+
method=responses.GET,
45+
url="http://localhost/api/v4/projects/1/cluster_agents/1",
46+
json=agent_content,
47+
content_type="application/json",
48+
status=200,
49+
)
50+
yieldrsps
51+
52+
53+
@pytest.fixture
54+
defresp_create_project_cluster_agent():
55+
withresponses.RequestsMock()asrsps:
56+
rsps.add(
57+
method=responses.POST,
58+
url="http://localhost/api/v4/projects/1/cluster_agents",
59+
json=agent_content,
60+
content_type="application/json",
61+
status=201,
62+
)
63+
yieldrsps
64+
65+
66+
@pytest.fixture
67+
defresp_delete_project_cluster_agent():
68+
withresponses.RequestsMock()asrsps:
69+
rsps.add(
70+
method=responses.DELETE,
71+
url="http://localhost/api/v4/projects/1/cluster_agents/1",
72+
status=204,
73+
)
74+
yieldrsps
75+
76+
77+
deftest_list_project_cluster_agents(project,resp_list_project_cluster_agents):
78+
agent=project.cluster_agents.list()[0]
79+
assertisinstance(agent,ProjectClusterAgent)
80+
assertagent.name=="agent-1"
81+
82+
83+
deftest_get_project_cluster_agent(project,resp_get_project_cluster_agent):
84+
agent=project.cluster_agents.get(1)
85+
assertisinstance(agent,ProjectClusterAgent)
86+
assertagent.name=="agent-1"
87+
88+
89+
deftest_create_project_cluster_agent(project,resp_create_project_cluster_agent):
90+
agent=project.cluster_agents.create({"name":"agent-1"})
91+
assertisinstance(agent,ProjectClusterAgent)
92+
assertagent.name=="agent-1"
93+
94+
95+
deftest_delete_project_cluster_agent(project,resp_delete_project_cluster_agent):
96+
agent=project.cluster_agents.get(1,lazy=True)
97+
agent.delete()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp