summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/api-objects.rst1
-rw-r--r--gitlab/v4/objects.py92
-rw-r--r--tools/python_test_v4.py40
3 files changed, 133 insertions, 0 deletions
diff --git a/docs/api-objects.rst b/docs/api-objects.rst
index 5040410..4767c48 100644
--- a/docs/api-objects.rst
+++ b/docs/api-objects.rst
@@ -9,6 +9,7 @@ API examples
gl_objects/emojis
gl_objects/badges
gl_objects/branches
+ gl_objects/clusters
gl_objects/messages
gl_objects/commits
gl_objects/deploy_keys
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 3ac7a4a..220cf12 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -743,6 +743,51 @@ class GroupBoardManager(CRUDMixin, RESTManager):
_create_attrs = (("name",), tuple())
+class GroupCluster(SaveMixin, ObjectDeleteMixin, RESTObject):
+ pass
+
+
+class GroupClusterManager(CRUDMixin, RESTManager):
+ _path = "/groups/%(group_id)s/clusters"
+ _obj_cls = GroupCluster
+ _from_parent_attrs = {"group_id": "id"}
+ _create_attrs = (
+ ("name", "platform_kubernetes_attributes",),
+ ("domain", "enabled", "managed", "environment_scope",),
+ )
+ _update_attrs = (
+ tuple(),
+ (
+ "name",
+ "domain",
+ "management_project_id",
+ "platform_kubernetes_attributes",
+ "environment_scope",
+ ),
+ )
+
+ @exc.on_http_error(exc.GitlabStopError)
+ def create(self, data, **kwargs):
+ """Create a new object.
+
+ Args:
+ data (dict): Parameters to send to the server to create the
+ resource
+ **kwargs: Extra options to send to the server (e.g. sudo or
+ 'ref_name', 'stage', 'name', 'all')
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabCreateError: If the server cannot perform the request
+
+ Returns:
+ RESTObject: A new instance of the manage object class build with
+ the data sent by the server
+ """
+ path = "%s/user" % (self.path)
+ return CreateMixin.create(self, data, path=path, **kwargs)
+
+
class GroupCustomAttribute(ObjectDeleteMixin, RESTObject):
_id_attr = "key"
@@ -1150,6 +1195,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
("projects", "GroupProjectManager"),
("subgroups", "GroupSubgroupManager"),
("variables", "GroupVariableManager"),
+ ("clusters", "GroupClusterManager"),
)
@cli.register_custom_action("Group", ("to_project_id",))
@@ -1599,6 +1645,51 @@ class ProjectBranchManager(NoUpdateMixin, RESTManager):
_create_attrs = (("branch", "ref"), tuple())
+class ProjectCluster(SaveMixin, ObjectDeleteMixin, RESTObject):
+ pass
+
+
+class ProjectClusterManager(CRUDMixin, RESTManager):
+ _path = "/projects/%(project_id)s/clusters"
+ _obj_cls = ProjectCluster
+ _from_parent_attrs = {"project_id": "id"}
+ _create_attrs = (
+ ("name", "platform_kubernetes_attributes",),
+ ("domain", "enabled", "managed", "environment_scope",),
+ )
+ _update_attrs = (
+ tuple(),
+ (
+ "name",
+ "domain",
+ "management_project_id",
+ "platform_kubernetes_attributes",
+ "environment_scope",
+ ),
+ )
+
+ @exc.on_http_error(exc.GitlabStopError)
+ def create(self, data, **kwargs):
+ """Create a new object.
+
+ Args:
+ data (dict): Parameters to send to the server to create the
+ resource
+ **kwargs: Extra options to send to the server (e.g. sudo or
+ 'ref_name', 'stage', 'name', 'all')
+
+ Raises:
+ GitlabAuthenticationError: If authentication is not correct
+ GitlabCreateError: If the server cannot perform the request
+
+ Returns:
+ RESTObject: A new instance of the manage object class build with
+ the data sent by the server
+ """
+ path = "%s/user" % (self.path)
+ return CreateMixin.create(self, data, path=path, **kwargs)
+
+
class ProjectCustomAttribute(ObjectDeleteMixin, RESTObject):
_id_attr = "key"
@@ -3943,6 +4034,7 @@ class Project(SaveMixin, ObjectDeleteMixin, RESTObject):
("triggers", "ProjectTriggerManager"),
("variables", "ProjectVariableManager"),
("wikis", "ProjectWikiManager"),
+ ("clusters", "ProjectClusterManager"),
)
@cli.register_custom_action("Project", ("submodule", "branch", "commit_sha"))
diff --git a/tools/python_test_v4.py b/tools/python_test_v4.py
index bfae8c1..841595d 100644
--- a/tools/python_test_v4.py
+++ b/tools/python_test_v4.py
@@ -503,6 +503,46 @@ env.stop()
env.delete()
assert len(admin_project.environments.list()) == 0
+# Project clusters
+admin_project.clusters.create(
+ {
+ "name": "cluster1",
+ "platform_kubernetes_attributes": {
+ "api_url": "http://url",
+ "token": "tokenval",
+ },
+ }
+)
+clusters = admin_project.clusters.list()
+assert len(clusters) == 1
+cluster = clusters[0]
+cluster.platform_kubernetes_attributes = {"api_url": "http://newurl"}
+cluster.save()
+cluster = admin_project.clusters.list()[0]
+assert cluster.platform_kubernetes["api_url"] == "http://newurl"
+cluster.delete()
+assert len(admin_project.clusters.list()) == 0
+
+# Group clusters
+group1.clusters.create(
+ {
+ "name": "cluster1",
+ "platform_kubernetes_attributes": {
+ "api_url": "http://url",
+ "token": "tokenval",
+ },
+ }
+)
+clusters = group1.clusters.list()
+assert len(clusters) == 1
+cluster = clusters[0]
+cluster.platform_kubernetes_attributes = {"api_url": "http://newurl"}
+cluster.save()
+cluster = group1.clusters.list()[0]
+assert cluster.platform_kubernetes["api_url"] == "http://newurl"
+cluster.delete()
+assert len(group1.clusters.list()) == 0
+
# project events
admin_project.events.list()