def serialize(name, dataset=None, dataset_pillar=None, user=None, group=None, mode=None, backup='', makedirs=False, show_diff=True, create=True, merge_if_exists=False, **kwargs):
 if ('env' in kwargs):
  salt.utils.warn_until('Oxygen', "Parameter 'env' has been detected in the argument list.  This parameter is no longer used and has been replaced by 'saltenv' as of Salt 2016.11.0.  This warning will be removed in Salt Oxygen.")
  kwargs.pop('env')
 name = os.path.expanduser(name)
 default_serializer_opts = {'yaml.serialize': {'default_flow_style': False}, 'json.serialize': {'indent': 2, 'separators': (',', ': '), 'sort_keys': True}}
 ret = {'changes': {}, 'comment': '', 'name': name, 'result': True}
 if (not name):
  return _error(ret, 'Must provide name to file.serialize')
 if (not create):
  if (not os.path.isfile(name)):
   ret['comment'] = 'File {0} is not present and is not set for creation'.format(name)
   return ret
 formatter = kwargs.pop('formatter', 'yaml').lower()
 if (len([x for x in (dataset, dataset_pillar) if x]) > 1):
  return _error(ret, "Only one of 'dataset' and 'dataset_pillar' is permitted")
 if dataset_pillar:
  dataset = __salt__['pillar.get'](dataset_pillar)
 if (dataset is None):
  return _error(ret, "Neither 'dataset' nor 'dataset_pillar' was defined")
 if salt.utils.is_windows():
  if (group is not None):
   log.warning('The group argument for {0} has been ignored as this is a Windows system.'.format(name))
  group = user
 serializer_name = '{0}.serialize'.format(formatter)
 deserializer_name = '{0}.deserialize'.format(formatter)
 if (serializer_name not in __serializers__):
  return {'changes': {}, 'comment': '{0} format is not supported'.format(formatter.capitalize()), 'name': name, 'result': False}
 if merge_if_exists:
  if os.path.isfile(name):
   if ('{0}.deserialize'.format(formatter) not in __serializers__):
    return {'changes': {}, 'comment': '{0} format is not supported for merging'.format(formatter.capitalize()), 'name': name, 'result': False}
   with salt.utils.fopen(name, 'r') as fhr:
    existing_data = __serializers__[deserializer_name](fhr)
   if (existing_data is not None):
    merged_data = salt.utils.dictupdate.merge_recurse(existing_data, dataset)
    if (existing_data == merged_data):
     ret['result'] = True
     ret['comment'] = 'The file {0} is in the correct state'.format(name)
     return ret
    dataset = merged_data
 contents = __serializers__[serializer_name](dataset, **default_serializer_opts.get(serializer_name, {}))
 contents += '\n'
 mode = salt.utils.normalize_mode(mode)
 if __opts__['test']:
  ret['changes'] = __salt__['file.check_managed_changes'](name=name, source=None, source_hash={}, source_hash_name=None, user=user, group=group, mode=mode, template=None, context=None, defaults=None, saltenv=__env__, contents=contents, skip_verify=False, **kwargs)
  if ret['changes']:
   ret['result'] = None
   ret['comment'] = 'Dataset will be serialized and stored into {0}'.format(name)
  else:
   ret['result'] = True
   ret['comment'] = 'The file {0} is in the correct state'.format(name)
  return ret
 return __salt__['file.manage_file'](name=name, sfn='', ret=ret, source=None, source_sum={}, user=user, group=group, mode=mode, saltenv=__env__, backup=backup, makedirs=makedirs, template=None, show_changes=show_diff, contents=contents)

def serialize ( name , dataset = None , dataset_pillar = None , user = None , group = None , mode = None , backup = '' , makedirs = False , show_diff = True , create = True , merge_if_exists = False , ** kwargs ) : if ( 'env' in kwargs ) : salt . utils . warn_until ( 'Oxygen' , "Parameter 'env' has been detected in the argument list.  This parameter is no longer used and has been replaced by 'saltenv' as of Salt 2016.11.0.  This warning will be removed in Salt Oxygen." ) kwargs . pop ( 'env' ) name = os . path . expanduser ( name ) default_serializer_opts = { 'yaml.serialize' : { 'default_flow_style' : False } , 'json.serialize' : { 'indent' : 2 , 'separators' : ( ',' , ': ' ) , 'sort_keys' : True } } ret = { 'changes' : { } , 'comment' : '' , 'name' : name , 'result' : True } if ( not name ) : return _error ( ret , 'Must provide name to file.serialize' ) if ( not create ) : if ( not os . path . isfile ( name ) ) : ret [ 'comment' ] = 'File {0} is not present and is not set for creation' . format ( name ) return ret formatter = kwargs . pop ( 'formatter' , 'yaml' ) . lower ( ) if ( len ( [ x for x in ( dataset , dataset_pillar ) if x ] ) > 1 ) : return _error ( ret , "Only one of 'dataset' and 'dataset_pillar' is permitted" ) if dataset_pillar : dataset = __salt__ [ 'pillar.get' ] ( dataset_pillar ) if ( dataset is None ) : return _error ( ret , "Neither 'dataset' nor 'dataset_pillar' was defined" ) if salt . utils . is_windows ( ) : if ( group is not None ) : log . warning ( 'The group argument for {0} has been ignored as this is a Windows system.' . format ( name ) ) group = user serializer_name = '{0}.serialize' . format ( formatter ) deserializer_name = '{0}.deserialize' . format ( formatter ) if ( serializer_name not in __serializers__ ) : return { 'changes' : { } , 'comment' : '{0} format is not supported' . format ( formatter . capitalize ( ) ) , 'name' : name , 'result' : False } if merge_if_exists : if os . path . isfile ( name ) : if ( '{0}.deserialize' . format ( formatter ) not in __serializers__ ) : return { 'changes' : { } , 'comment' : '{0} format is not supported for merging' . format ( formatter . capitalize ( ) ) , 'name' : name , 'result' : False } with salt . utils . fopen ( name , 'r' ) as fhr : existing_data = __serializers__ [ deserializer_name ] ( fhr ) if ( existing_data is not None ) : merged_data = salt . utils . dictupdate . merge_recurse ( existing_data , dataset ) if ( existing_data == merged_data ) : ret [ 'result' ] = True ret [ 'comment' ] = 'The file {0} is in the correct state' . format ( name ) return ret dataset = merged_data contents = __serializers__ [ serializer_name ] ( dataset , ** default_serializer_opts . get ( serializer_name , { } ) ) contents += '\n' mode = salt . utils . normalize_mode ( mode ) if __opts__ [ 'test' ] : ret [ 'changes' ] = __salt__ [ 'file.check_managed_changes' ] ( name = name , source = None , source_hash = { } , source_hash_name = None , user = user , group = group , mode = mode , template = None , context = None , defaults = None , saltenv = __env__ , contents = contents , skip_verify = False , ** kwargs ) if ret [ 'changes' ] : ret [ 'result' ] = None ret [ 'comment' ] = 'Dataset will be serialized and stored into {0}' . format ( name ) else : ret [ 'result' ] = True ret [ 'comment' ] = 'The file {0} is in the correct state' . format ( name ) return ret return __salt__ [ 'file.manage_file' ] ( name = name , sfn = '' , ret = ret , source = None , source_sum = { } , user = user , group = group , mode = mode , saltenv = __env__ , backup = backup , makedirs = makedirs , template = None , show_changes = show_diff , contents = contents )
save a collection to database .