X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FConfFiles.py;h=f15a574a808689e5eedefa5547d786fca188f2f2;hb=refs%2Fheads%2Fplanetlab-4_0-branch;hp=a81edf3c7c03cefc37abfc6201775f74651fc7da;hpb=5b592cb8a07868bca99c7dc1f9b7cd540cbeec84;p=plcapi.git diff --git a/PLC/ConfFiles.py b/PLC/ConfFiles.py index a81edf3..f15a574 100644 --- a/PLC/ConfFiles.py +++ b/PLC/ConfFiles.py @@ -4,11 +4,12 @@ # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id: ConfFiles.py,v 1.1 2006/10/20 17:44:09 mlhuang Exp $ +# $Id: ConfFiles.py 5574 2007-10-25 20:33:17Z thierry $ # from PLC.Faults import * from PLC.Parameter import Parameter +from PLC.Filter import Filter from PLC.Table import Row, Table from PLC.Nodes import Node, Nodes from PLC.NodeGroups import NodeGroup, NodeGroups @@ -30,13 +31,13 @@ class ConfFile(Row): 'file_permissions': Parameter(str, "chmod(1) permissions", max = 20), 'file_owner': Parameter(str, "chown(1) owner", max = 50), 'file_group': Parameter(str, "chgrp(1) owner", max = 50), - 'preinstall_cmd': Parameter(str, "Shell command to execute prior to installing", max = 1024), - 'postinstall_cmd': Parameter(str, "Shell command to execute after installing", max = 1024), - 'error_cmd': Parameter(str, "Shell command to execute if any error occurs", max = 1024), + 'preinstall_cmd': Parameter(str, "Shell command to execute prior to installing", max = 1024, nullok = True), + 'postinstall_cmd': Parameter(str, "Shell command to execute after installing", max = 1024, nullok = True), + 'error_cmd': Parameter(str, "Shell command to execute if any error occurs", max = 1024, nullok = True), 'ignore_cmd_errors': Parameter(bool, "Install file anyway even if an error occurs"), 'always_update': Parameter(bool, "Always attempt to install file even if unchanged"), - 'node_ids': Parameter(int, "List of nodes linked to this file", ro = True), - 'nodegroup_ids': Parameter(int, "List of node groups linked to this file", ro = True), + 'node_ids': Parameter(int, "List of nodes linked to this file"), + 'nodegroup_ids': Parameter(int, "List of node groups linked to this file"), } def add_node(self, node, commit = True): @@ -48,7 +49,7 @@ class ConfFile(Row): assert isinstance(node, Node) assert 'node_id' in node - conf_file_id = self['pcu_id'] + conf_file_id = self['conf_file_id'] node_id = node['node_id'] if node_id not in self['node_ids']: @@ -95,7 +96,7 @@ class ConfFile(Row): assert isinstance(nodegroup, NodeGroup) assert 'nodegroup_id' in nodegroup - conf_file_id = self['pcu_id'] + conf_file_id = self['conf_file_id'] nodegroup_id = nodegroup['nodegroup_id'] if nodegroup_id not in self['nodegroup_ids']: @@ -138,24 +139,17 @@ class ConfFiles(Table): Representation of the conf_files table in the database. """ - def __init__(self, api, conf_file_ids = None): - sql = "SELECT %s FROM view_conf_files" % \ - ", ".join(ConfFile.fields) - - if conf_file_ids: - # Separate the list into integers and strings - sql += " WHERE conf_file_id IN (%s)" % ", ".join(map(str, api.db.quote(conf_file_ids))) - - rows = api.db.selectall(sql) + def __init__(self, api, conf_file_filter = None, columns = None): + Table.__init__(self, api, ConfFile, columns) - for row in rows: - self[row['conf_file_id']] = ConfFile(api, row) + sql = "SELECT %s FROM view_conf_files WHERE True" % \ + ", ".join(self.columns) + if conf_file_filter is not None: + if isinstance(conf_file_filter, (list, tuple, set)): + conf_file_filter = Filter(ConfFile.fields, {'conf_file_id': conf_file_filter}) + elif isinstance(conf_file_filter, dict): + conf_file_filter = Filter(ConfFile.fields, conf_file_filter) + sql += " AND (%s) %s" % conf_file_filter.sql(api) - for row in rows: - self[row['conf_file_id']] = conf_file = ConfFile(api, row) - for aggregate in ['node_ids', 'nodegroup_ids']: - if not conf_file.has_key(aggregate) or conf_file[aggregate] is None: - conf_file[aggregate] = [] - else: - conf_file[aggregate] = map(int, conf_file[aggregate].split(',')) + self.selectall(sql)