Commit d693c864 authored by Iustin Pop's avatar Iustin Pop

Add ctime/mtime support to the main ConfigObjects

This patch adds ctime/mtime support to the “main” config objects - the
config data itself, and the cluster/nodes/instances objects.

These are not added on auto-upgrade, but rather should be migrated if it
makes sense when 2.0 is upgraded to 2.1.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 3b813dd2
......@@ -28,6 +28,7 @@ import os.path
import re
import logging
import tempfile
import time
from ganeti import rpc
from ganeti import ssh
......@@ -310,11 +311,13 @@ def InitConfig(version, cluster_config, master_node_config,
master_node_config.name: master_node_config,
}
now = time.time()
config_data = objects.ConfigData(version=version,
cluster=cluster_config,
nodes=nodes,
instances={},
serial_no=1)
serial_no=1,
ctime=now, mtime=now)
utils.WriteFile(cfg_file,
data=serializer.Dump(config_data.ToDict()),
mode=0600)
......
......@@ -35,6 +35,7 @@ import os
import tempfile
import random
import logging
import time
from ganeti import errors
from ganeti import locking
......@@ -708,6 +709,7 @@ class ConfigWriter:
" MAC address '%s' already in use." % (instance.name, nic.mac))
instance.serial_no = 1
instance.ctime = instance.mtime = time.time()
self._config_data.instances[instance.name] = instance
self._config_data.cluster.serial_no += 1
self._UnlockedReleaseDRBDMinors(instance.name)
......@@ -729,6 +731,7 @@ class ConfigWriter:
if instance.admin_up != status:
instance.admin_up = status
instance.serial_no += 1
instance.mtime = time.time()
self._WriteConfig()
@locking.ssynchronized(_config_lock)
......@@ -860,6 +863,7 @@ class ConfigWriter:
logging.info("Adding node %s to configuration" % node.name)
node.serial_no = 1
node.ctime = node.mtime = time.time()
self._config_data.nodes[node.name] = node
self._config_data.cluster.serial_no += 1
self._WriteConfig()
......@@ -1031,6 +1035,7 @@ class ConfigWriter:
"""
self._config_data.serial_no += 1
self._config_data.mtime = time.time()
def _OpenConfig(self):
"""Read the config data from disk.
......@@ -1249,10 +1254,12 @@ class ConfigWriter:
raise errors.ConfigurationError("Configuration updated since object"
" has been read or unknown object")
target.serial_no += 1
target.mtime = now = time.time()
if update_serial:
# for node updates, we need to increase the cluster serial too
self._config_data.cluster.serial_no += 1
self._config_data.cluster.mtime = now
if isinstance(target, objects.Instance):
self._UnlockedReleaseDRBDMinors(target.name)
......
......@@ -39,6 +39,7 @@ from ganeti import constants
__all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance",
"OS", "Node", "Cluster", "FillDict"]
_TIMESTAMPS = ["ctime", "mtime"]
def FillDict(defaults_dict, custom_dict):
"""Basic function to apply settings on top a default dict.
......@@ -284,7 +285,8 @@ class TaggableObject(ConfigObject):
class ConfigData(ConfigObject):
"""Top-level config object."""
__slots__ = ["version", "cluster", "nodes", "instances", "serial_no"]
__slots__ = ["version", "cluster", "nodes", "instances", "serial_no"] + \
_TIMESTAMPS
def ToDict(self):
"""Custom function for top-level config data.
......@@ -612,7 +614,7 @@ class Instance(TaggableObject):
"disk_template",
"network_port",
"serial_no",
]
] + _TIMESTAMPS
def _ComputeSecondaryNodes(self):
"""Compute the list of secondary nodes.
......@@ -769,7 +771,7 @@ class Node(TaggableObject):
"master_candidate",
"offline",
"drained",
]
] + _TIMESTAMPS
class Cluster(TaggableObject):
......@@ -794,7 +796,7 @@ class Cluster(TaggableObject):
"nicparams",
"candidate_pool_size",
"modify_etc_hosts",
]
] + _TIMESTAMPS
def UpgradeConfig(self):
"""Fill defaults for missing configuration values.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment