Commit def62a71 authored by David Johnson's avatar David Johnson

Optionally transform values before printing.

Only for ist_authinit auth_network field for now;
FreeNAS seems to add \n "separators" in the list of
authorized networks.  So, when we print, change those
to spaces, which is what we give FreeNAS as input ;)
parent c13f0eee
...@@ -204,6 +204,11 @@ class CommandSet(object): ...@@ -204,6 +204,11 @@ class CommandSet(object):
tk = cdict['translateKeys'] tk = cdict['translateKeys']
else: else:
tk = {} tk = {}
if cdict.has_key('translateValues'):
tv = cdict['translateValues']
else:
tv = {}
pretty = False pretty = False
if command == 'plist': if command == 'plist':
pretty = True pretty = True
...@@ -246,6 +251,9 @@ class CommandSet(object): ...@@ -246,6 +251,9 @@ class CommandSet(object):
nv = {} nv = {}
for (k,v2) in v.iteritems(): for (k,v2) in v.iteritems():
nvi = "%s" % (str(v2),) nvi = "%s" % (str(v2),)
if tv.has_key(k):
nvi = tv[k](k,v2)
pass
nl = len(nvi) nl = len(nvi)
if not fieldwidths.has_key(k): if not fieldwidths.has_key(k):
fieldwidths[k] = nl fieldwidths[k] = nl
...@@ -1072,8 +1080,14 @@ class IscsiTargetAuthorizedInitiator(CommandSet): ...@@ -1072,8 +1080,14 @@ class IscsiTargetAuthorizedInitiator(CommandSet):
'kwDefaults' : {}, 'kwDefaults' : {},
'instanceFilterArgs' : [ 'tag' ], 'instanceFilterArgs' : [ 'tag' ],
'type' : 'del' }) 'type' : 'del' })
self.commands['list'] = self.commands['plist'] = {} self.commands['list'] = \
dict({ 'translateValues' : { 'iscsi_target_initiator_auth_network' : self.nlToSpace } })
self.commands['plist'] = self.commands['list']
pass pass
def nlToSpace(self,k,v):
return v.replace("\n"," ")
pass pass
class IscsiTargetToExtent(CommandSet): class IscsiTargetToExtent(CommandSet):
......
...@@ -217,6 +217,11 @@ class CommandSet(object): ...@@ -217,6 +217,11 @@ class CommandSet(object):
tk = cdict['translateKeys'] tk = cdict['translateKeys']
else: else:
tk = {} tk = {}
if cdict.has_key('translateValues'):
tv = cdict['translateValues']
else:
tv = {}
pretty = False pretty = False
if command == 'plist': if command == 'plist':
pretty = True pretty = True
...@@ -259,6 +264,9 @@ class CommandSet(object): ...@@ -259,6 +264,9 @@ class CommandSet(object):
nv = {} nv = {}
for (k,v2) in v.iteritems(): for (k,v2) in v.iteritems():
nvi = "%s" % (str(v2),) nvi = "%s" % (str(v2),)
if tv.has_key(k):
nvi = tv[k](k,v2)
pass
nl = len(nvi) nl = len(nvi)
if not fieldwidths.has_key(k): if not fieldwidths.has_key(k):
fieldwidths[k] = nl fieldwidths[k] = nl
...@@ -1102,8 +1110,14 @@ class IscsiTargetAuthorizedInitiator(CommandSet): ...@@ -1102,8 +1110,14 @@ class IscsiTargetAuthorizedInitiator(CommandSet):
'kwDefaults' : {}, 'kwDefaults' : {},
'instanceFilterArgs' : [ 'tag' ], 'instanceFilterArgs' : [ 'tag' ],
'type' : 'del' }) 'type' : 'del' })
self.commands['list'] = self.commands['plist'] = {} self.commands['list'] = \
dict({ 'translateValues' : { 'iscsi_target_initiator_auth_network' : self.nlToSpace } })
self.commands['plist'] = self.commands['list']
pass pass
def nlToSpace(self,k,v):
return v.replace("\n"," ")
pass pass
class IscsiTargetToExtent(CommandSet): class IscsiTargetToExtent(CommandSet):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment