@@ -120,22 +120,65 @@ def update_from_git(self, repository_url, checkout = "master", subpath=None):
120120 # Plugin uninstall/delete
121121 ########################################################
122122
123+ def list_usages (self , project_key = None ):
124+ """
125+ Get the list of usages of the plugin.
126+
127+ Returns a dict with two keys:
128+ - usages, a list of (elementKind, elementType, objectType, projectKey, objectId) tuples
129+ - missingTypes, a list of (missingType, objectType, projectKey, objectId) tuples
130+
131+ Each element of the usages list contains:
132+ - an elementKind of the plugin element, such as webapps, python-probes, python-checks, etc.
133+ - an elementType of the plugin element,
134+ - the objectType and objectId of the object using this plugin element, along with their projectKey,
135+ if pertinent. Some objects, for instance clusters, are not contained in a project.
136+
137+ Some custom types may not be found during the analysis. This typically occurs when a plugin was removed,
138+ while still being used. This prevents further analysis of the object relying on this type and may hide
139+ some uses of the plugin. Thus, those missingTypes are enumerated in the missingTypes list, which
140+ includes the missingType along with the same information on the object as for usages.
141+
142+ :param str project_key: optional key of project where to look for usages. Default is None and looking in all projects.
143+ :return: dict
144+ """
145+ params = {}
146+ if project_key :
147+ params ["projectKey" ] = project_key
148+ return self .client ._perform_json ("POST" , "/plugins/{pluginId}/actions/listUsages" % self .plugin_id , body = params )
149+
123150 def prepare_delete (self ):
124151 """
125- Prepares deletion of the plugins. Check if it is possible, warns on usages .
152+ Request pre- deletion checks, as aggregated information on the usage of the plugin .
126153
127- :return: a json object with the counts of project and plugin elements in use
154+ Information is provided as a dict with the following entries:
155+ - projectCount: count of projects using at least an element of this plugin
156+ - usedElemCount: count of elements of this plugin in use
157+ - objectAnalysisErrors: count of errors encountered while analyzing usages.
158+
159+ Detailed information can be obtained by calling :func:`list_usages`.
160+ :return: dict
128161 """
129- return self .client ._perform_json ("GET" , "/plugins/%s/actions/prepareDelete" % (self .plugin_id ))
130162
131- def delete (self , force ):
163+ return self .client ._perform_json ("POST" , "/plugins/{pluginId}/actions/prepareDelete" % self .plugin_id )
164+
165+ def delete (self , force = False ):
132166 """
133- Deletes the plugin. Will fail if a usage is specified and force is not set to true
167+ Delete a plugin.
134168
135- :return: a :class:`~dataikuapi.dss.future.DSSFuture`
169+ If not forced (default), pre-deletion checks will be run (as by :func:`prepare_delete` and the deletion will be
170+ performed if and only if no usage of the plugin is detected and no error occurred during usages analysis.
171+
172+ :param bool force: if True, plugin will be deleted even if usages are found or errors occurred during usages
173+ analysis. Default is False.
174+ :return: a :class:`dataikuapi.dssfuture.DSSFuture`
136175 """
137- ret = self .client ._perform_json ("GET" , "/plugins/%s/actions/delete" % (self .plugin_id ),
138- params = {force : force })
176+
177+ params = {
178+ "force" : force
179+ }
180+ ret = self .client ._perform_json ("POST" , "/plugins/{pluginId}/actions/prepareDelete" % self .plugin_id ,
181+ body = params )
139182 return self .client .get_future (ret ["jobId" ])
140183
141184 ########################################################
@@ -168,5 +211,3 @@ def put_file(self, path, f):
168211 file_name = path .split ('/' )[- 1 ]
169212 data = f .read () # eat it all, because making it work with a path variable and a MultifilePart in swing looks complicated
170213 return self .client ._perform_empty ("POST" , "/plugins/%s/contents/%s" % (self .plugin_id , path ), raw_body = data )
171-
172-
0 commit comments