diskimage-builder/diskimage_builder/block_device/level4/fstab.py
Ian Wienand 00da1982ce Add a more generic tree->graph parser
This moves to a more generic config parser that doesn't have plugins
parsing part of the tree.

I understand why it ended up that way; we have "partitions" key which
has special semantics compared to others keys and there was a desire
to keep it isolated from core tree->graph code.  But this isn't really
isolated; you have to reverse-engineer several module-crossing
boundaries, extras classes and repetitive recursive functions.

Ultimately, plugins should have access to the node graph, but not
participate in configuration parsing.  This way we ensure that plugins
can't invent new methods of configuration parsing.

Note: unit tests produce the same tree -> graph conversion as the old
method.  i.e. this is not intended to have a functional change.

Change-Id: I8a5d62a076a5a50597f2f1df3a8615afba6dadb2
2017-05-26 10:13:14 +10:00

75 lines
2.2 KiB
Python

# Copyright 2017 Andreas Florath (andreas@florath.net)
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
from diskimage_builder.graph.digraph import Digraph
logger = logging.getLogger(__name__)
class Fstab(Digraph.Node):
type_string = "fstab"
def __init__(self, config, params):
logger.debug("Fstab object; config [%s]" % config)
self.config = config
self.params = params
self.name = self.config['name']
self.base = self.config['base']
Digraph.Node.__init__(self, self.name)
self.options = self.config.get('options', 'defaults')
self.dump_freq = self.config.get('dump-freq', 0)
self.fsck_passno = self.config.get('fsck-passno', 2)
def insert_nodes(self, dg):
logger.debug("Insert node")
dg.add_node(self)
def insert_edges(self, dg):
logger.debug("Insert edge [%s]" % self)
bnode = dg.find(self.base)
assert bnode is not None
dg.create_edge(bnode, self)
def create(self, result, rollback):
logger.debug("fstab create called [%s]" % self.name)
logger.debug("result [%s]" % result)
if 'fstab' not in result:
result['fstab'] = {}
result['fstab'][self.base] = {
'name': self.name,
'base': self.base,
'options': self.options,
'dump-freq': self.dump_freq,
'fsck-passno': self.fsck_passno
}
def umount(self, state):
"""Fstab does not need any umount task."""
pass
def cleanup(self, state):
"""Fstab does not need any cleanup."""
pass
def delete(self, state):
"""Fstab does not need any cleanup."""
pass