Skip to content

Commit

Permalink
Add support for deferred references
Browse files Browse the repository at this point in the history
* {disk#<n>.devlist}
* {disk#<n>.devlist[0]}
* {#disk#<n>.disklist}

* {disk#<n>.disklist}
* {disk#<n>.disklist[0]}
* {#disk#<n>.disklist}
  • Loading branch information
cvaroqui committed Jul 29, 2017
1 parent 1eeaa01 commit 241c618
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions lib/svc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4248,13 +4248,19 @@ def set(self):
if self.options.value is not None:
value = self.options.value
elif self.options.remove is not None:
value = self._get(self.options.param, self.options.eval).split()
try:
value = self._get(self.options.param, self.options.eval).split()
except ex.excError as exc:
value = []
if self.options.remove not in value:
return 0
value.remove(self.options.remove)
value = " ".join(value)
elif self.options.add is not None:
value = self._get(self.options.param, self.options.eval).split()
try:
value = self._get(self.options.param, self.options.eval).split()
except ex.excError as exc:
value = []
if self.options.add in value:
return 0
index = self.options.index if self.options.index is not None else len(value)
Expand Down Expand Up @@ -5231,6 +5237,10 @@ def handle_reference(self, ref, scope=False, impersonate=None, config=None):

val = self._handle_reference(ref, _section, _v, scope=scope, impersonate=impersonate, config=config)

if val is None:
# deferred
return

if return_length or index is not None:
if is_string(val):
val = val.split()
Expand Down Expand Up @@ -5261,6 +5271,18 @@ def _handle_reference(self, ref, _section, _v, scope=False, impersonate=None, co
if _section != "DEFAULT" and not config.has_section(_section):
raise ex.excError("%s: section %s does not exist" % (ref, _section))

# deferrable refs
if _v == "devlist":
try:
return list(self.get_resource(_section).devlist())
except:
return
elif _v == "disklist":
try:
return list(self.get_resource(_section).disklist())
except:
return

try:
return self.conf_get(_section, _v, "string", scope=scope, impersonate=impersonate, config=config)
except ex.OptNotFound as exc:
Expand All @@ -5279,6 +5301,9 @@ def _handle_references(self, s, scope=False, impersonate=None, config=None):
return s
ref = m.group(0).strip("{}")
val = self.handle_reference(ref, scope=scope, impersonate=impersonate, config=config)
if val is None:
# deferred
return
s = s[:m.start()] + val + s[m.end():]

@staticmethod
Expand Down

0 comments on commit 241c618

Please sign in to comment.