Blame doc/examples/part-handler-v2.txt

Packit Service a04d08
#part-handler
Packit Service a04d08
# vi: syntax=python ts=4
Packit Service a04d08
# this is an example of a version 2 part handler.
Packit Service a04d08
# the differences between the initial part-handler version
Packit Service a04d08
# and v2 is:
Packit Service a04d08
#  * handle_part receives a 5th argument, 'frequency'
Packit Service a04d08
#    frequency will be either 'always' or 'per-instance'
Packit Service a04d08
#  * handler_version must be set
Packit Service a04d08
#
Packit Service a04d08
# A handler declaring version 2 will be called on all instance boots, with a
Packit Service a04d08
# different 'frequency' argument.
Packit Service a04d08
Packit Service a04d08
handler_version = 2
Packit Service a04d08
Packit Service a04d08
def list_types():
Packit Service a04d08
    # return a list of mime-types that are handled by this module
Packit Service a04d08
    return(["text/plain", "text/go-cubs-go"])
Packit Service a04d08
Packit Service a04d08
def handle_part(data,ctype,filename,payload,frequency):
Packit Service a04d08
    # data: the cloudinit object
Packit Service a04d08
    # ctype: '__begin__', '__end__', or the specific mime-type of the part
Packit Service a04d08
    # filename: the filename for the part, or dynamically generated part if
Packit Service a04d08
    #           no filename is given attribute is present
Packit Service a04d08
    # payload: the content of the part (empty for begin or end)
Packit Service a04d08
    # frequency: the frequency that this cloud-init run is running for
Packit Service a04d08
    #            this is either 'per-instance' or 'always'.  'per-instance'
Packit Service a04d08
    #            will be invoked only on the first boot.  'always' will
Packit Service a04d08
    #            will be called on subsequent boots.
Packit Service a04d08
    if ctype == "__begin__":
Packit Service a04d08
       print "my handler is beginning, frequency=%s" % frequency
Packit Service a04d08
       return
Packit Service a04d08
    if ctype == "__end__":
Packit Service a04d08
       print "my handler is ending, frequency=%s" % frequency
Packit Service a04d08
       return
Packit Service a04d08
Packit Service a04d08
    print "==== received ctype=%s filename=%s ====" % (ctype,filename)
Packit Service a04d08
    print payload
Packit Service a04d08
    print "==== end ctype=%s filename=%s" % (ctype, filename)