Skip to content

Commit

Permalink
Merge pull request #473 from qingchoulove/ks_plugin
Browse files Browse the repository at this point in the history
feat: plugin api add up status
  • Loading branch information
gitautomator[bot] authored Mar 7, 2024
2 parents 2176e80 + bc765ce commit 8971a68
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 3 additions & 1 deletion kubespider/api/v2/plugin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
@plugin_blu.route('', methods=['GET'])
def list_plugin_handler():
plugins = plugin_manager.kubespider_plugin_manager.list_plugin()
return success([plugin.to_dict() for plugin in plugins])
instances = plugin_manager.kubespider_plugin_manager.list_instance()
instance_plugin = [instance.definition.name for instance in instances]
return success([dict(plugin.to_dict(), **{"up": plugin.name in instance_plugin}) for plugin in plugins])


@plugin_blu.route('', methods=['PUT'])
Expand Down
10 changes: 8 additions & 2 deletions kubespider/core/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def call_api(self, api: str, **kwargs):
**kwargs
}
response = self.request.post(
url=f"http://localhost:{port}", json=body, timeout=1)
url=f"http://localhost:{port}", json=body, timeout=30)
if response.status_code != 200:
raise Exception(
f"Failed to call plugin API: {api}")
Expand Down Expand Up @@ -200,6 +200,9 @@ def __init__(self):
def list_plugin(self) -> list[PluginDefinition]:
return self.definitions.values()

def list_instance(self) -> list[PluginInstance]:
return self.instances.values()

def get_plugin(self, plugin_name: str) -> PluginDefinition:
return self.definitions.get(plugin_name)

Expand Down Expand Up @@ -255,7 +258,10 @@ def unregister(self, plugin_name: str):
definition = self.definitions.get(plugin_name)
if not definition:
raise Exception(f"Plugin not found: {plugin_name}")
self.disable(plugin_name)
# Disable the plugin if it is enabled
if self.instances.get(plugin_name):
self.disable(plugin_name)
# Remove the plugin definition and binary
del self.definitions[plugin_name]
os.remove(PLUGIN_DEFINITION_PATH + plugin_name + ".yaml")
os.remove(PLUGIN_BINARY_PATH + plugin_name)
Expand Down
5 changes: 0 additions & 5 deletions sdk/example/Dockerfile

This file was deleted.

0 comments on commit 8971a68

Please sign in to comment.