def volume_present(name, volume_size, sparse=False, create_parent=False, properties=None, cloned_from=None):
 ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''}
 if (not properties):
  properties = {}
 log.debug('zfs.volume_present::{0}::config::volume_size = {1}'.format(name, volume_size))
 log.debug('zfs.volume_present::{0}::config::sparse = {1}'.format(name, sparse))
 log.debug('zfs.volume_present::{0}::config::create_parent = {1}'.format(name, create_parent))
 log.debug('zfs.volume_present::{0}::config::cloned_from = {1}'.format(name, cloned_from))
 log.debug('zfs.volume_present::{0}::config::properties = {1}'.format(name, properties))
 for prop in properties.keys():
  if isinstance(properties[prop], bool):
   properties[prop] = ('on' if properties[prop] else 'off')
 if (('@' in name) or ('#' in name)):
  ret['result'] = False
  ret['comment'] = 'invalid filesystem or volume name: {0}'.format(name)
 if cloned_from:
  cloned_parent = cloned_from[:cloned_from.index('@')]
  if ('@' not in cloned_from):
   ret['result'] = False
   ret['comment'] = '{0} is not a snapshot'.format(cloned_from)
  elif (cloned_from not in __salt__['zfs.list'](cloned_from, **{'type': 'snapshot'})):
   ret['result'] = False
   ret['comment'] = 'snapshot {0} does not exist'.format(cloned_from)
  elif (cloned_parent not in __salt__['zfs.list'](cloned_parent, **{'type': 'volume'})):
   ret['result'] = False
   ret['comment'] = 'snapshot {0} is not from a volume'.format(cloned_from)
 if ret['result']:
  if (name in __salt__['zfs.list'](name, **{'type': 'volume'})):
   properties['volsize'] = volume_size
   result = __salt__['zfs.get'](name, **{'properties': ','.join(properties.keys()), 'fields': 'value', 'depth': 1})
   for prop in properties.keys():
    if (properties[prop] != result[name][prop]['value']):
     if (name not in ret['changes']):
      ret['changes'][name] = {}
     ret['changes'][name][prop] = properties[prop]
   if (len(ret['changes']) > 0):
    if (not __opts__['test']):
     result = __salt__['zfs.set'](name, **ret['changes'][name])
     if (name not in result):
      ret['result'] = False
     else:
      for prop in result[name].keys():
       if (result[name][prop] != 'set'):
        ret['result'] = False
    if ret['result']:
     ret['comment'] = 'volume {0} was updated'.format(name)
    else:
     ret['changes'] = {}
     ret['comment'] = 'volume {0} failed to be updated'.format(name)
   else:
    ret['comment'] = 'volume {0} is up to date'.format(name)
  else:
   result = {name: 'created'}
   if (not __opts__['test']):
    if (not cloned_from):
     result = __salt__['zfs.create'](name, **{'volume_size': volume_size, 'sparse': sparse, 'create_parent': create_parent, 'properties': properties})
    else:
     result = __salt__['zfs.clone'](cloned_from, name, **{'create_parent': create_parent, 'properties': properties})
   ret['result'] = (name in result)
   if ret['result']:
    ret['result'] = ((result[name] == 'created') or result[name].startswith('cloned'))
   if ret['result']:
    ret['changes'][name] = (properties if (len(properties) > 0) else result[name])
    ret['comment'] = 'volume {0} was created'.format(name)
   else:
    ret['comment'] = 'failed to create volume {0}'.format(name)
    if (name in result):
     ret['comment'] = result[name]
 return ret

def volume_present ( name , volume_size , sparse = False , create_parent = False , properties = None , cloned_from = None ) : ret = { 'name' : name , 'changes' : { } , 'result' : True , 'comment' : '' } if ( not properties ) : properties = { } log . debug ( 'zfs.volume_present::{0}::config::volume_size = {1}' . format ( name , volume_size ) ) log . debug ( 'zfs.volume_present::{0}::config::sparse = {1}' . format ( name , sparse ) ) log . debug ( 'zfs.volume_present::{0}::config::create_parent = {1}' . format ( name , create_parent ) ) log . debug ( 'zfs.volume_present::{0}::config::cloned_from = {1}' . format ( name , cloned_from ) ) log . debug ( 'zfs.volume_present::{0}::config::properties = {1}' . format ( name , properties ) ) for prop in properties . keys ( ) : if isinstance ( properties [ prop ] , bool ) : properties [ prop ] = ( 'on' if properties [ prop ] else 'off' ) if ( ( '@' in name ) or ( '#' in name ) ) : ret [ 'result' ] = False ret [ 'comment' ] = 'invalid filesystem or volume name: {0}' . format ( name ) if cloned_from : cloned_parent = cloned_from [ : cloned_from . index ( '@' ) ] if ( '@' not in cloned_from ) : ret [ 'result' ] = False ret [ 'comment' ] = '{0} is not a snapshot' . format ( cloned_from ) elif ( cloned_from not in __salt__ [ 'zfs.list' ] ( cloned_from , ** { 'type' : 'snapshot' } ) ) : ret [ 'result' ] = False ret [ 'comment' ] = 'snapshot {0} does not exist' . format ( cloned_from ) elif ( cloned_parent not in __salt__ [ 'zfs.list' ] ( cloned_parent , ** { 'type' : 'volume' } ) ) : ret [ 'result' ] = False ret [ 'comment' ] = 'snapshot {0} is not from a volume' . format ( cloned_from ) if ret [ 'result' ] : if ( name in __salt__ [ 'zfs.list' ] ( name , ** { 'type' : 'volume' } ) ) : properties [ 'volsize' ] = volume_size result = __salt__ [ 'zfs.get' ] ( name , ** { 'properties' : ',' . join ( properties . keys ( ) ) , 'fields' : 'value' , 'depth' : 1 } ) for prop in properties . keys ( ) : if ( properties [ prop ] != result [ name ] [ prop ] [ 'value' ] ) : if ( name not in ret [ 'changes' ] ) : ret [ 'changes' ] [ name ] = { } ret [ 'changes' ] [ name ] [ prop ] = properties [ prop ] if ( len ( ret [ 'changes' ] ) > 0 ) : if ( not __opts__ [ 'test' ] ) : result = __salt__ [ 'zfs.set' ] ( name , ** ret [ 'changes' ] [ name ] ) if ( name not in result ) : ret [ 'result' ] = False else : for prop in result [ name ] . keys ( ) : if ( result [ name ] [ prop ] != 'set' ) : ret [ 'result' ] = False if ret [ 'result' ] : ret [ 'comment' ] = 'volume {0} was updated' . format ( name ) else : ret [ 'changes' ] = { } ret [ 'comment' ] = 'volume {0} failed to be updated' . format ( name ) else : ret [ 'comment' ] = 'volume {0} is up to date' . format ( name ) else : result = { name : 'created' } if ( not __opts__ [ 'test' ] ) : if ( not cloned_from ) : result = __salt__ [ 'zfs.create' ] ( name , ** { 'volume_size' : volume_size , 'sparse' : sparse , 'create_parent' : create_parent , 'properties' : properties } ) else : result = __salt__ [ 'zfs.clone' ] ( cloned_from , name , ** { 'create_parent' : create_parent , 'properties' : properties } ) ret [ 'result' ] = ( name in result ) if ret [ 'result' ] : ret [ 'result' ] = ( ( result [ name ] == 'created' ) or result [ name ] . startswith ( 'cloned' ) ) if ret [ 'result' ] : ret [ 'changes' ] [ name ] = ( properties if ( len ( properties ) > 0 ) else result [ name ] ) ret [ 'comment' ] = 'volume {0} was created' . format ( name ) else : ret [ 'comment' ] = 'failed to create volume {0}' . format ( name ) if ( name in result ) : ret [ 'comment' ] = result [ name ] return ret
check that a block volume exists .