refactored service interaction use names with a _, and cleanup up some of the CoreServices methods

This commit is contained in:
Blake J. Harnden 2018-06-15 14:03:27 -07:00
parent 0bf9c99910
commit e80736061f
27 changed files with 958 additions and 885 deletions

View file

@ -4,7 +4,7 @@ from core import logger
from core.conf import ConfigShim
from core.enumerations import NodeTypes
from core.misc import nodeutils
from core.service import ServiceManager
from core.service import ServiceManager, ServiceShim
from core.xml import xmlutils
@ -316,7 +316,10 @@ class CoreDocumentParser0(object):
# associate nodes with services
for objid in sorted(svclists.keys()):
n = self.session.get_object(objid)
self.session.services.addservicestonode(node=n, nodetype=n.type, services_str=svclists[objid])
services = svclists[objid]
if services:
services = services.split("|")
self.session.services.addservicestonode(node=n, node_type=n.type, services=services)
def parseservice(self, service, n):
"""
@ -367,16 +370,20 @@ class CoreDocumentParser0(object):
filename = file.getAttribute("name")
files.append(filename)
data = xmlutils.get_text_child(file)
typestr = "service:%s:%s" % (name, filename)
self.session.services.setservicefile(nodenum=n.objid, type=typestr,
filename=filename,
srcname=None, data=data)
self.session.services.setservicefile(node_id=n.objid, service_name=name, filename=filename, data=data)
if len(files):
values.append("files=%s" % files)
if not bool(service.getAttribute("custom")):
return True
values = ConfigShim.str_to_dict(values)
self.session.services.setcustomservice(n.objid, svc, values)
self.session.services.setcustomservice(n.objid, svc)
# set custom values for custom service
svc = self.session.services.getcustomservice(n.objid, None)
if not svc:
raise ValueError("custom service(%s) for node(%s) does not exist", svc.name, n.objid)
values = ConfigShim.str_to_dict("|".join(values))
for name, value in values.iteritems():
ServiceShim.setvalue(svc, name, value)
return True
def parsehooks(self, hooks):

View file

@ -8,7 +8,7 @@ from core.conf import ConfigShim
from core.enumerations import NodeTypes
from core.misc import nodeutils
from core.misc.ipaddress import MacAddress
from core.service import ServiceManager
from core.service import ServiceManager, ServiceShim
from core.xml import xmlutils
@ -639,17 +639,19 @@ class CoreDocumentParser1(object):
custom = service.getAttribute('custom')
if custom and custom.lower() == 'true':
values = ConfigShim.str_to_dict(values)
self.session.services.setcustomservice(node.objid, session_service, values)
self.session.services.setcustomservice(node.objid, session_service.name)
values = ConfigShim.str_to_dict("|".join(values))
for key, value in values.iteritems():
ServiceShim.setvalue(session_service, key, value)
# NOTE: if a custom service is used, setservicefile() must be
# called after the custom service exists
for typestr, filename, data in files:
svcname = typestr.split(":")[1]
self.session.services.setservicefile(
nodenum=node.objid,
type=typestr,
node_id=node.objid,
service_name=svcname,
filename=filename,
srcname=None,
data=data
)
return str(name)
@ -678,10 +680,13 @@ class CoreDocumentParser1(object):
services_str = None # default services will be added
else:
return
if services_str:
services_str = services_str.split("|")
self.session.services.addservicestonode(
node=node,
nodetype=node_type,
services_str=services_str
node_type=node_type,
services=services_str
)
def set_object_presentation(self, obj, element, node_type):

View file

@ -284,7 +284,7 @@ class CoreDocumentWriter0(Document):
for svc in defaults:
s = self.createElement("Service")
spn.appendChild(s)
s.setAttribute("name", str(svc._name))
s.setAttribute("name", str(svc.name))
def addservices(self, node):
"""
@ -302,17 +302,17 @@ class CoreDocumentWriter0(Document):
for svc in node.services:
s = self.createElement("Service")
spn.appendChild(s)
s.setAttribute("name", str(svc._name))
s.setAttribute("startup_idx", str(svc._startindex))
if svc._starttime != "":
s.setAttribute("start_time", str(svc._starttime))
s.setAttribute("name", str(svc.name))
s.setAttribute("startup_idx", str(svc.startindex))
if svc.starttime != "":
s.setAttribute("start_time", str(svc.starttime))
# only record service names if not a customized service
if not svc._custom:
if not svc.custom:
continue
s.setAttribute("custom", str(svc._custom))
xmlutils.add_elements_from_list(self, s, svc._dirs, "Directory", "name")
s.setAttribute("custom", str(svc.custom))
xmlutils.add_elements_from_list(self, s, svc.dirs, "Directory", "name")
for fn in svc._configs:
for fn in svc.configs:
if len(fn) == 0:
continue
f = self.createElement("File")
@ -327,9 +327,9 @@ class CoreDocumentWriter0(Document):
txt = self.createTextNode(data)
f.appendChild(txt)
xmlutils.add_text_elements_from_list(self, s, svc._startup, "Command", (("type", "start"),))
xmlutils.add_text_elements_from_list(self, s, svc._shutdown, "Command", (("type", "stop"),))
xmlutils.add_text_elements_from_list(self, s, svc._validate, "Command", (("type", "validate"),))
xmlutils.add_text_elements_from_list(self, s, svc.startup, "Command", (("type", "start"),))
xmlutils.add_text_elements_from_list(self, s, svc.shutdown, "Command", (("type", "stop"),))
xmlutils.add_text_elements_from_list(self, s, svc.validate, "Command", (("type", "validate"),))
def addaddresses(self, i, netif):
"""

View file

@ -277,7 +277,7 @@ class ScenarioPlan(XmlElement):
for svc in defaults:
s = self.createElement("service")
spn.appendChild(s)
s.setAttribute("name", str(svc._name))
s.setAttribute("name", str(svc.name))
if defaultservices.hasChildNodes():
self.appendChild(defaultservices)
@ -680,24 +680,24 @@ class DeviceElement(NamedXmlElement):
for svc in device_object.services:
s = self.createElement("service")
spn.appendChild(s)
s.setAttribute("name", str(svc._name))
s.setAttribute("startup_idx", str(svc._startindex))
if svc._starttime != "":
s.setAttribute("start_time", str(svc._starttime))
s.setAttribute("name", str(svc.name))
s.setAttribute("startup_idx", str(svc.startindex))
if svc.starttime != "":
s.setAttribute("start_time", str(svc.starttime))
# only record service names if not a customized service
if not svc._custom:
if not svc.custom:
continue
s.setAttribute("custom", str(svc._custom))
xmlutils.add_elements_from_list(self, s, svc._dirs, "directory", "name")
s.setAttribute("custom", str(svc.custom))
xmlutils.add_elements_from_list(self, s, svc.dirs, "directory", "name")
for fn in svc._configs:
for fn in svc.configs:
if len(fn) == 0:
continue
f = self.createElement("file")
f.setAttribute("name", fn)
# all file names are added to determine when a file has been deleted
s.appendChild(f)
data = self.coreSession.services.getservicefiledata(svc, fn)
data = svc.configtxt.get(fn)
if data is None:
# this includes only customized file contents and skips
# the auto-generated files
@ -705,12 +705,9 @@ class DeviceElement(NamedXmlElement):
txt = self.createTextNode("\n" + data)
f.appendChild(txt)
xmlutils.add_text_elements_from_list(self, s, svc._startup, "command",
(("type", "start"),))
xmlutils.add_text_elements_from_list(self, s, svc._shutdown, "command",
(("type", "stop"),))
xmlutils.add_text_elements_from_list(self, s, svc._validate, "command",
(("type", "validate"),))
xmlutils.add_text_elements_from_list(self, s, svc.startup, "command", (("type", "start"),))
xmlutils.add_text_elements_from_list(self, s, svc.shutdown, "command", (("type", "stop"),))
xmlutils.add_text_elements_from_list(self, s, svc.validate, "command", (("type", "validate"),))
class ChannelElement(NamedXmlElement):