Change XMLTemplate to JinjaTemplate

This commit is contained in:
Théophile Bastian 2020-03-11 11:27:38 +01:00
parent 95080f88ad
commit 8eb49fd01d
3 changed files with 7 additions and 7 deletions

View File

@ -2,7 +2,7 @@
from . import settings
from . import util
from .xml_template import XMLTemplate
from .jinja_template import JinjaTemplate
import libvirt
import tempfile
@ -156,7 +156,7 @@ class Container(util.LibvirtObject):
self.overlay_root = OverlayDirectory(settings.BASE_SYSTEM_ROOT, name=self.name)
xml = XMLTemplate("container.xml").inst(
xml = JinjaTemplate("container.xml").inst(
name=self.name,
uuid=self.uuid,
mem=self.mem,

View File

@ -1,17 +1,17 @@
""" Reads an XML template from a file """
""" Reads a jinja template from a file """
import os
import jinja2
class XMLTemplate:
class JinjaTemplate:
""" Reads and instanciates a template from a file """
base_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "templates")
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(base_path),
autoescape=jinja2.select_autoescape(
enabled_extensions=("xml"), default_for_string=True,
enabled_extensions=("xml", "network"), default_for_string=True,
),
)

View File

@ -2,7 +2,7 @@
from . import settings
from . import util
from .xml_template import XMLTemplate
from .jinja_template import JinjaTemplate
class Network(util.LibvirtObject):
@ -27,7 +27,7 @@ class Network(util.LibvirtObject):
if self.lxc_network:
raise self.AlreadyExists()
xml = XMLTemplate("network.xml").inst(
xml = JinjaTemplate("network.xml").inst(
name=self.name,
uuid=self.uuid,
bridge_id=self.bridge_id,