def add_plugin(self, dock_image_name): """ Register/add a new plugin to the system. """ # get representation from the corresponding app app_repr = self.get_plugin_app_representation(dock_image_name) name = self.get_plugin_name(app_repr) # check wether the plugin already exist existing_plugin_names = [ plugin.name for plugin in Plugin.objects.all() ] if name in existing_plugin_names: raise ValueError("Plugin '%s' already exists in the system" % name) # add plugin to the db plugin = Plugin() plugin.name = name plugin.dock_image = dock_image_name plugin.type = app_repr['type'] plugin.authors = app_repr['authors'] plugin.title = app_repr['title'] plugin.category = app_repr['category'] plugin.description = app_repr['description'] plugin.documentation = app_repr['documentation'] plugin.license = app_repr['license'] plugin.version = app_repr['version'] plugin.save() # add plugin's parameters to the db params = app_repr['parameters'] for param in params: self._save_plugin_param(plugin, param)
def add_plugin(self, dock_image_name, compute_resource_identifier): """ Register/add a new plugin to the system. """ # get representation from the corresponding app app_repr = self.get_plugin_app_representation(dock_image_name) name = self.get_plugin_name(app_repr) max_cpu_limit, min_cpu_limit = self.get_cpu_limit(app_repr) max_memory_limit, min_memory_limit = self.get_memory_limit(app_repr) max_number_of_workers, min_number_of_workers = self.get_number_of_workers( app_repr) max_gpu_limit, min_gpu_limit = self.get_gpu_limit(app_repr) # check wether the plugin already exist existing_plugin_names = [ plugin.name for plugin in Plugin.objects.all() ] if name in existing_plugin_names: raise ValueError("Plugin '%s' already exists in the system" % name) # add plugin to the db plugin = Plugin() plugin.name = name plugin.dock_image = dock_image_name plugin.type = app_repr['type'] plugin.authors = app_repr['authors'] plugin.title = app_repr['title'] plugin.category = app_repr['category'] plugin.description = app_repr['description'] plugin.documentation = app_repr['documentation'] plugin.license = app_repr['license'] plugin.version = app_repr['version'] (plugin.compute_resource, tf) = ComputeResource.objects.get_or_create( compute_resource_identifier=compute_resource_identifier) plugin.max_cpu_limit = self.insert_default( max_cpu_limit, CPUInt(Plugin.defaults['max_limit'])) plugin.min_cpu_limit = self.insert_default( min_cpu_limit, Plugin.defaults['min_cpu_limit']) plugin.max_memory_limit = self.insert_default( max_memory_limit, MemoryInt(Plugin.defaults['max_limit'])) plugin.min_memory_limit = self.insert_default( min_memory_limit, Plugin.defaults['min_memory_limit']) plugin.max_number_of_workers = self.insert_default( max_number_of_workers, Plugin.defaults['max_limit']) plugin.min_number_of_workers = self.insert_default( min_number_of_workers, 1) plugin.max_gpu_limit = self.insert_default( max_gpu_limit, Plugin.defaults['max_limit']) plugin.min_gpu_limit = self.insert_default(min_gpu_limit, 0) plugin.save() # add plugin's parameters to the db params = app_repr['parameters'] for param in params: self._save_plugin_param(plugin, param)