The Hookpoint System

In order to hook your code into DivvyCloud’s real time detection service, your code must contain two things:

  1. One or more functions wrapped by our “@hookpoint” decorator
  2. A top level module function named “load”

The example snippet below shows the bare minimum that a plugin must contain to run:

from DivvyPlugins.hookpoints import hookpoint

def do_something(resource, user_resource_id=None, project_resource_id=None):
    This block will execute each time a new instance is created. A created event
    is fired when DivvyCloud observes a new resource for the first time; however,
    since this hookpoint is specifically calling out the instance resource type
    then we will only enter this block when new instances are observed.
    :param resource: The instance resource which we can manipulate
    :param user_resource_id: The resource ID of the user who created the resource.
                             If this was created externally it will be None
    :param project_resource_id: The project that the resource belongs to.

def load():
    """The load() function must be present for the plugin to load, but does not have to have a body"""

The Hookpoint Decorator

Must use our “”. Our backend maintains a mapping of events to functions which should be executed whenever the appropriate event occurs. Any function which is wrapped by the @hookpoint decorator will be run every time that event is emitted anywhere else in the code. The events which can be hooked into in this fashion are referred to simply by strings. While new events can be created and registered dynamically, our backend services emit three primary events which you should be aware of while building any plugin:

  1. divvycloud.resource.created: Triggered when a resource is found for the first time and does not yet exist in the local database. An example of this would be a new instance being provisioned from DivvyCloud or the Amazon Web Services Console.
  2. divvycloud.resource.modified: Triggered when any resource appears “modified”, which is flagged when the local resource stored in the database does not matched the resource that was harvested from the remote cloud. An example of this would be changing the state of an instance from “running” to “stopped.”
  3. divvycloud.resource.deleted: Triggered when a resource is deleted from within DivvyCloud or externally via the cloud provider.

You can target specific resource types by changing the word “resource” to the type of resource that you would like. For example: divvycloud.instance.deleted. The matrix below contains a full list of all the resources you could use in a hookpoint:

Hookpoint Matrix

The matrix below provides documentation as well as the created, modified and deleted hookpoints for each resource type. If you scroll the table to the right the hookpoints are the rightmost three columns.

Resource Type Documentation Description Created Hookpoint Modified Hookpoint Deleted Hookpoint
Instance DivvyInterfaceMessages.v2_interface_protocol.InstanceResourceInfo Compute instance (EC2, CloudServers, etc.) divvycloud.instance.created divvycloud.instance.modified divvycloud.instance.deleted
Volume DivvyInterfaceMessages.v2_interface_protocol.VolumeResourceInfo Network attached storage (EBS, Disks, etc.) divvycloud.volume.created divvycloud.volume.modified divvycloud.volume.deleted
Snapshot DivvyInterfaceMessages.v2_interface_protocol.SnapshotResourceInfo Snapshot backups of existing volumes divvycloud.snapshot.created divvycloud.snapshot.modified divvycloud.snapshot.deleted
ResourceAccessList DivvyInterfaceMessages.v2_interface_protocol.ResourceAccessListResourceInfo Used to protect and firewall resources divvycloud.resourceaccesslist.created divvycloud.resourceaccesslist.modified divvycloud.resourceaccesslist.deleted
Storage Container DivvyInterfaceMessages.v2_interface_protocol.StorageContainerResourceInfo Object stoarge (S3, CloudFiles, etc.) divvycloud.storagecontainer.created divvycloud.storagecontainer.modified divvycloud.storagecontainer.deleted
Database Instance DivvyInterfaceMessages.v2_interface_protocol.DatabaseInstanceResourceInfo Database instance (RDS, CloudDatabase, etc.) divvycloud.dbinstance.created divvycloud.dbinstance.modified divvycloud.dbinstance.deleted
Memcache Instance DivvyInterfaceMessages.v2_interface_protocol.MemcacheInstanceResourceInfo Memory cache instance (ElastiCache, etc.) divvycloud.mcinstance.created divvycloud.mcinstance.modified divvycloud.mcinstance.deleted
Hypervisor DivvyInterfaceMessages.v2_interface_protocol.HypervisorResourceInfo A hypervisor (private clouds only) divvycloud.hypervisor.created divvycloud.hypervisor.modified divvycloud.hypervisor.deleted
Private Image DivvyInterfaceMessages.v2_interface_protocol.PrivateImageResourceInfo Private/shared images of an instance divvycloudy.privateimage.created divvycloud.privateimage.modified divvycloudy.privateimage.deleted
Public Image DivvyInterfaceMessages.v2_interface_protocol.PublicImageResourceInfo A public image of an instance divvycloud.publicimage.created divvycloud.publicimage.modified divvycloud.publicimage.deleted
Public IP DivvyInterfaceMessages.v2_interface_protocol.PublicIPAddressResourceInfo Elastic/Floating IP addresses divvycloud.publicip.created divvycloud.publicip.modified divvycloud.publicip.deleted
Resource Group DivvyInterfaceMessages.v2_interface_protocol.ResourceGroupInfo Divvy Resource Groups which store resources divvycloud.resourcegroup.created divvycloud.resourcegroup.modified divvycloud.resourcegroup.deleted
Load Balancer DivvyInterfaceMessages.v2_interface_protocol.LoadBalancerResourceInfo Used in multi-tier apps to distribute load divvycloud.loadbalancer.created divvycloud.loadbalancer.modified divvycloud.loadbalancer.deleted
Private Network DivvyInterfaceMessages.v2_interface_protocol.NetworkResourceInfo Used to isolate compute resources divvycloud.privatenetwork.created divvycloud.privatenetwork.modified divvycloud.privatenetwork.deleted
DNS Zone DivvyInterfaceMessages.v2_interface_protocol.DNSZoneResourceInfo Used to store DNS records for lookups divvycloud.dnszone.created divvycloud.dnszone.modified divvycloud.dnszone.deleted
Service User DivvyInterfaceMessages.v2_interface_protocol.ServiceUserResourceInfo A cloud user accounts (AWS IAM) divvycloud.serviceuser.created divvycloud.serviceuser.modified divvycloud.serviceuser.deleted