def present(name, DomainName, ElasticsearchClusterConfig=None, EBSOptions=None, AccessPolicies=None, SnapshotOptions=None, AdvancedOptions=None, Tags=None, region=None, key=None, keyid=None, profile=None, ElasticsearchVersion='1.5'):
 ret = {'name': DomainName, 'result': True, 'comment': '', 'changes': {}}
 if (ElasticsearchClusterConfig is None):
  ElasticsearchClusterConfig = {'DedicatedMasterEnabled': False, 'InstanceCount': 1, 'InstanceType': 'm3.medium.elasticsearch', 'ZoneAwarenessEnabled': False}
 if (EBSOptions is None):
  EBSOptions = {'EBSEnabled': False}
 if (SnapshotOptions is None):
  SnapshotOptions = {'AutomatedSnapshotStartHour': 0}
 if (AdvancedOptions is None):
  AdvancedOptions = {'rest.action.multi.allow_explicit_index': 'true'}
 if (Tags is None):
  Tags = {}
 if ((AccessPolicies is not None) and isinstance(AccessPolicies, six.string_types)):
  try:
   AccessPolicies = json.loads(AccessPolicies)
  except ValueError as e:
   ret['result'] = False
   ret['comment'] = 'Failed to create domain: {0}.'.format(e.message)
   return ret
 r = __salt__['boto_elasticsearch_domain.exists'](DomainName=DomainName, region=region, key=key, keyid=keyid, profile=profile)
 if ('error' in r):
  ret['result'] = False
  ret['comment'] = 'Failed to create domain: {0}.'.format(r['error']['message'])
  return ret
 if (not r.get('exists')):
  if __opts__['test']:
   ret['comment'] = 'Domain {0} is set to be created.'.format(DomainName)
   ret['result'] = None
   return ret
  r = __salt__['boto_elasticsearch_domain.create'](DomainName=DomainName, ElasticsearchClusterConfig=ElasticsearchClusterConfig, EBSOptions=EBSOptions, AccessPolicies=AccessPolicies, SnapshotOptions=SnapshotOptions, AdvancedOptions=AdvancedOptions, ElasticsearchVersion=str(ElasticsearchVersion), region=region, key=key, keyid=keyid, profile=profile)
  if (not r.get('created')):
   ret['result'] = False
   ret['comment'] = 'Failed to create domain: {0}.'.format(r['error']['message'])
   return ret
  _describe = __salt__['boto_elasticsearch_domain.describe'](DomainName, region=region, key=key, keyid=keyid, profile=profile)
  ret['changes']['old'] = {'domain': None}
  ret['changes']['new'] = _describe
  ret['comment'] = 'Domain {0} created.'.format(DomainName)
  return ret
 ret['comment'] = os.linesep.join([ret['comment'], 'Domain {0} is present.'.format(DomainName)])
 ret['changes'] = {}
 _status = __salt__['boto_elasticsearch_domain.status'](DomainName=DomainName, region=region, key=key, keyid=keyid, profile=profile)['domain']
 if (_status.get('ElasticsearchVersion') != str(ElasticsearchVersion)):
  ret['result'] = False
  ret['comment'] = 'Failed to update domain: version cannot be modified from {0} to {1}.'.format(_status.get('ElasticsearchVersion'), str(ElasticsearchVersion))
  return ret
 _describe = __salt__['boto_elasticsearch_domain.describe'](DomainName=DomainName, region=region, key=key, keyid=keyid, profile=profile)['domain']
 _describe['AccessPolicies'] = json.loads(_describe['AccessPolicies'])
 if (not _describe.get('EBSOptions', {}).get('EBSEnabled')):
  opts = _describe.get('EBSOptions', {})
  opts.pop('VolumeSize', None)
  opts.pop('VolumeType', None)
 comm_args = {}
 need_update = False
 es_opts = {'ElasticsearchClusterConfig': ElasticsearchClusterConfig, 'EBSOptions': EBSOptions, 'AccessPolicies': AccessPolicies, 'SnapshotOptions': SnapshotOptions, 'AdvancedOptions': AdvancedOptions}
 for (k, v) in six.iteritems(es_opts):
  if (not _compare_json(v, _describe[k])):
   need_update = True
   comm_args[k] = v
   ret['changes'].setdefault('new', {})[k] = v
   ret['changes'].setdefault('old', {})[k] = _describe[k]
 if need_update:
  if __opts__['test']:
   msg = 'Domain {0} set to be modified.'.format(DomainName)
   ret['comment'] = msg
   ret['result'] = None
   return ret
  ret['comment'] = os.linesep.join([ret['comment'], 'Domain to be modified'])
  r = __salt__['boto_elasticsearch_domain.update'](DomainName=DomainName, region=region, key=key, keyid=keyid, profile=profile, **comm_args)
  if (not r.get('updated')):
   ret['result'] = False
   ret['comment'] = 'Failed to update domain: {0}.'.format(r['error'])
   ret['changes'] = {}
   return ret
 return ret

def present ( name , DomainName , ElasticsearchClusterConfig = None , EBSOptions = None , AccessPolicies = None , SnapshotOptions = None , AdvancedOptions = None , Tags = None , region = None , key = None , keyid = None , profile = None , ElasticsearchVersion = '1.5' ) : ret = { 'name' : DomainName , 'result' : True , 'comment' : '' , 'changes' : { } } if ( ElasticsearchClusterConfig is None ) : ElasticsearchClusterConfig = { 'DedicatedMasterEnabled' : False , 'InstanceCount' : 1 , 'InstanceType' : 'm3.medium.elasticsearch' , 'ZoneAwarenessEnabled' : False } if ( EBSOptions is None ) : EBSOptions = { 'EBSEnabled' : False } if ( SnapshotOptions is None ) : SnapshotOptions = { 'AutomatedSnapshotStartHour' : 0 } if ( AdvancedOptions is None ) : AdvancedOptions = { 'rest.action.multi.allow_explicit_index' : 'true' } if ( Tags is None ) : Tags = { } if ( ( AccessPolicies is not None ) and isinstance ( AccessPolicies , six . string_types ) ) : try : AccessPolicies = json . loads ( AccessPolicies ) except ValueError as e : ret [ 'result' ] = False ret [ 'comment' ] = 'Failed to create domain: {0}.' . format ( e . message ) return ret r = __salt__ [ 'boto_elasticsearch_domain.exists' ] ( DomainName = DomainName , region = region , key = key , keyid = keyid , profile = profile ) if ( 'error' in r ) : ret [ 'result' ] = False ret [ 'comment' ] = 'Failed to create domain: {0}.' . format ( r [ 'error' ] [ 'message' ] ) return ret if ( not r . get ( 'exists' ) ) : if __opts__ [ 'test' ] : ret [ 'comment' ] = 'Domain {0} is set to be created.' . format ( DomainName ) ret [ 'result' ] = None return ret r = __salt__ [ 'boto_elasticsearch_domain.create' ] ( DomainName = DomainName , ElasticsearchClusterConfig = ElasticsearchClusterConfig , EBSOptions = EBSOptions , AccessPolicies = AccessPolicies , SnapshotOptions = SnapshotOptions , AdvancedOptions = AdvancedOptions , ElasticsearchVersion = str ( ElasticsearchVersion ) , region = region , key = key , keyid = keyid , profile = profile ) if ( not r . get ( 'created' ) ) : ret [ 'result' ] = False ret [ 'comment' ] = 'Failed to create domain: {0}.' . format ( r [ 'error' ] [ 'message' ] ) return ret _describe = __salt__ [ 'boto_elasticsearch_domain.describe' ] ( DomainName , region = region , key = key , keyid = keyid , profile = profile ) ret [ 'changes' ] [ 'old' ] = { 'domain' : None } ret [ 'changes' ] [ 'new' ] = _describe ret [ 'comment' ] = 'Domain {0} created.' . format ( DomainName ) return ret ret [ 'comment' ] = os . linesep . join ( [ ret [ 'comment' ] , 'Domain {0} is present.' . format ( DomainName ) ] ) ret [ 'changes' ] = { } _status = __salt__ [ 'boto_elasticsearch_domain.status' ] ( DomainName = DomainName , region = region , key = key , keyid = keyid , profile = profile ) [ 'domain' ] if ( _status . get ( 'ElasticsearchVersion' ) != str ( ElasticsearchVersion ) ) : ret [ 'result' ] = False ret [ 'comment' ] = 'Failed to update domain: version cannot be modified from {0} to {1}.' . format ( _status . get ( 'ElasticsearchVersion' ) , str ( ElasticsearchVersion ) ) return ret _describe = __salt__ [ 'boto_elasticsearch_domain.describe' ] ( DomainName = DomainName , region = region , key = key , keyid = keyid , profile = profile ) [ 'domain' ] _describe [ 'AccessPolicies' ] = json . loads ( _describe [ 'AccessPolicies' ] ) if ( not _describe . get ( 'EBSOptions' , { } ) . get ( 'EBSEnabled' ) ) : opts = _describe . get ( 'EBSOptions' , { } ) opts . pop ( 'VolumeSize' , None ) opts . pop ( 'VolumeType' , None ) comm_args = { } need_update = False es_opts = { 'ElasticsearchClusterConfig' : ElasticsearchClusterConfig , 'EBSOptions' : EBSOptions , 'AccessPolicies' : AccessPolicies , 'SnapshotOptions' : SnapshotOptions , 'AdvancedOptions' : AdvancedOptions } for ( k , v ) in six . iteritems ( es_opts ) : if ( not _compare_json ( v , _describe [ k ] ) ) : need_update = True comm_args [ k ] = v ret [ 'changes' ] . setdefault ( 'new' , { } ) [ k ] = v ret [ 'changes' ] . setdefault ( 'old' , { } ) [ k ] = _describe [ k ] if need_update : if __opts__ [ 'test' ] : msg = 'Domain {0} set to be modified.' . format ( DomainName ) ret [ 'comment' ] = msg ret [ 'result' ] = None return ret ret [ 'comment' ] = os . linesep . join ( [ ret [ 'comment' ] , 'Domain to be modified' ] ) r = __salt__ [ 'boto_elasticsearch_domain.update' ] ( DomainName = DomainName , region = region , key = key , keyid = keyid , profile = profile , ** comm_args ) if ( not r . get ( 'updated' ) ) : ret [ 'result' ] = False ret [ 'comment' ] = 'Failed to update domain: {0}.' . format ( r [ 'error' ] ) ret [ 'changes' ] = { } return ret return ret
ensure pagerduty service exists .