-
Notifications
You must be signed in to change notification settings - Fork 64
Updating Old School Plugins
Shea Craig edited this page Mar 26, 2018
·
3 revisions
Things change... It's not you, it's me.
Plugins have evolved, and you may need to update your plugin code. No doubt, the log file is barking at you constantly about plugins in-need of updating? Familiarize yourself with the new-school plugin documentation and then follow the steps below to update old plugins.
When in doubt, consult the builtin plugins' source, which have all been updated.
import sal.plugin
- (Do not
from sal.plugin import <anything>
, as this will cause yapsy to have issues. - Replace plugin's base class from
IPlugin
tosal.plugin.Widget
,sal.plugin.DetailPlugin
, orsal.plugin.ReportPlugin
. - Remove the yapsy import as well as any other imports that aren't actually being used.
- The new plugin class will automatically use
<pluginname>/templates/<pluginname>.html
for its template. Unless there's no way to use a single template, you can remove thetemplate
selection and loading stanzas from the existingwidget_content
method. All builtin plugins now use a single template, so you probably can too. -
widget_width
anddescription
are now class attributes. You should remove these methods unless you need to do some dynamic sizing or description configuration. - Set the plugin classes'
description = 'whatever'
- Regular and machine detail plugins have a default width of 4; reports are 12. There's no need to specify widget_width unless you want to change this.
- Remove the
plugin_type
method. It's no longer used (the plugin'sclass
can tell Sal this information). - Rename the
widget_content
method toget_context
, and change the parameters. The signature should now look like this:def get_context(self, queryset, **kwargs):
- Rename all uses of the previous parameter
machines
toqueryset
in the (now)get_context
method. - Start a context dictionary by calling
context = self.super_get_context(queryset, **kwargs)
. This puts the plugin,group_type
, andgroup_id
key/value pairs into the context for you. - Make
get_context
return the context dictionary, not a rendered template. - In a lot of existing plugin code, this means making sure you don't overwrite the context you started in the previous step; insure you're adding values to it, not recreating it.
- Django no longer expects a
Context
object be passed to templates, so you can remove that invocation as well as the import ofContext
andloader
, if present. - The machine queryset passed into
get_context
has already been filtered for Business Unit, Machine Group, or "All", so you can remove any code that does that. - Likewise, you cam remove any access handling code, as user permissions have already been checked before your plugin code executes.
-
DetailPlugin
receives a single machine rather than a queryset. Keep that in mind when looking over code. - In most cases, the main body of the (now)
get_context
method does not have to be changed. - The
filter_machines
method should be renamed to justfilter
. - Check your templates and update the following
- You no longer need to pass a title into the template via context; Use
{{ plugin.title }}
instead. - Likewise, plugins have a repr method now; so you can use
{{ plugin }}
instead of passing a plugin name. The repr method returns the name of the plugin class; for exampleMunkiInstalls
. This is the name used in plugin loading / URL construction... - Update all URL constructions.
- Most reversed URLs are to list machines. The
machine_list_id
andmachine_list_front
names are deprecated; please update to simplymachine_list
. 2. Thepage
parameter should be replaced withgroup_type
(which is already in your context). 3. Thetheid
parameter should be replaced withgroup_id
(also in the context). 4. If your{% url %}
calls use a passed plugin name, just use the plugin object itself. 5. Example - Old:
{% url 'machine_list_id' 'MunkiVersion' 'abc123' page theid %}".replace(/abc123/, row['label'].toString());
- New:
{% url 'machine_list' plugin 'abc123' group_type group_id %}".replace(/abc123/, row['label'].toString());
- Most reversed URLs are to list machines. The
- If you were using different templates for "front" and "id" views, you can use a single template. Observe the auto-template naming rules from earlier, and you can probably use a very lightly modified version of your previous "id" template.
- Brute force protection
- LDAP integration
- Active Directory integration
- API
- Usage reporting
- License Management
- Maintenance
- Search
- Troubleshooting
- SAML
- IAM Authentication for AWS RDS Postgres
- Docker
- Ubuntu 14.04
- Ubuntu 16.04
- RHEL 7
- Kubernetes
- Heroku?