#NEWLINE# def present( name , attributes , region = None , key = None , keyid = None , profile = None ) : #NEWLINE# #INDENT# '\n    Ensure the cloudwatch alarm exists.\n\n    name\n        Name of the alarm\n\n    attributes\n        A dict of key/value cloudwatch alarm attributes.\n\n    region\n        Region to connect to.\n\n    key\n        Secret key to be used.\n\n    keyid\n        Access key to be used.\n\n    profile\n        A dict with region, key and keyid, or a pillar key (string)\n        that contains a dict with region, key and keyid.\n    ' #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : '' , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# alarm_details = __salt__ [ 'boto_cloudwatch.get_alarm' ] ( name , region , key , keyid , profile ) #NEWLINE# for k in [ 'alarm_actions' , 'insufficient_data_actions' , 'ok_actions' ] : #NEWLINE# #INDENT# if ( k in attributes ) : #NEWLINE# #INDENT# attributes [ k ] = __salt__ [ 'boto_cloudwatch.convert_to_arn' ] ( attributes [ k ] , region , key , keyid , profile ) #NEWLINE# #UNINDENT# #UNINDENT# difference = [ ] #NEWLINE# if alarm_details : #NEWLINE# #INDENT# for ( k , v ) in six . iteritems ( attributes ) : #NEWLINE# #INDENT# if ( k not in alarm_details ) : #NEWLINE# #INDENT# difference . append ( '{0}={1} (new)' . format ( k , v ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# v2 = alarm_details [ k ] #NEWLINE# if ( v == v2 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( isinstance ( v , six . string_types ) and ( str ( v ) == str ( v2 ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( isinstance ( v , float ) and ( v == float ( v2 ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( isinstance ( v , int ) and ( v == int ( v2 ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( isinstance ( v , list ) and ( sorted ( v ) == sorted ( v2 ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# difference . append ( "{0}='{1}' was: '{2}'" . format ( k , v , v2 ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# difference . append ( 'new alarm' ) #NEWLINE# #UNINDENT# create_or_update_alarm_args = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'region' : region , #NEWLINE# 'key' : key , #NEWLINE# 'keyid' : keyid , #NEWLINE# 'profile' : profile , #NEWLINE# #UNINDENT# } #NEWLINE# create_or_update_alarm_args . update ( attributes ) #NEWLINE# if alarm_details : #NEWLINE# #INDENT# if ( len ( difference ) == 0 ) : #NEWLINE# #INDENT# ret [ 'comment' ] = 'alarm {0} present and matching' . format ( name ) #NEWLINE# return ret #NEWLINE# #UNINDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# msg = 'alarm {0} is to be created/updated.' . format ( name ) #NEWLINE# ret [ 'comment' ] = msg #NEWLINE# ret [ 'result' ] = None #NEWLINE# return ret #NEWLINE# #UNINDENT# result = __salt__ [ 'boto_cloudwatch.create_or_update_alarm' ] ( ** create_or_update_alarm_args ) #NEWLINE# if result : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'diff' ] = alarm_details #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = 'Failed to create {0} alarm' . format ( name ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# msg = 'alarm {0} is to be created/updated.' . format ( name ) #NEWLINE# ret [ 'comment' ] = msg #NEWLINE# ret [ 'result' ] = None #NEWLINE# return ret #NEWLINE# #UNINDENT# result = __salt__ [ 'boto_cloudwatch.create_or_update_alarm' ] ( ** create_or_update_alarm_args ) #NEWLINE# if result : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'new' ] = attributes #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = 'Failed to create {0} alarm' . format ( name ) #NEWLINE# #UNINDENT# #UNINDENT# return ret