Commit 6a408fb2 authored by Iustin Pop's avatar Iustin Pop
Browse files

Reuse common code between MarkInstance{Up,Down}

This patch creates a new method ConfigWriter._SetInstanceStatus that
consists of the common code between MarkInstanceUp and MarkInstanceDown.
These two methods become wrappers over the _SetInstanceStatus.

Reviewed-by: ultrotter
parent 8d14b30d
......@@ -305,19 +305,29 @@ class ConfigWriter:
self._config_data.instances[instance.name] = instance
self._WriteConfig()
def MarkInstanceUp(self, instance_name):
"""Mark the instance status to up in the config.
def _SetInstanceStatus(self, instance_name, status):
"""Set the instance's status to a given value.
"""
if status not in ("up", "down"):
raise errors.ProgrammerError("Invalid status '%s' passed to"
" ConfigWriter._SetInstanceStatus()" %
status)
self._OpenConfig()
if instance_name not in self._config_data.instances:
raise errors.ConfigurationError("Unknown instance '%s'" %
instance_name)
instance = self._config_data.instances[instance_name]
instance.status = "up"
instance.status = status
self._WriteConfig()
def MarkInstanceUp(self, instance_name):
"""Mark the instance status to up in the config.
"""
self._SetInstanceStatus(instance_name, "up")
def RemoveInstance(self, instance_name):
"""Remove the instance from the configuration.
......@@ -360,13 +370,7 @@ class ConfigWriter:
"""Mark the status of an instance to down in the configuration.
"""
self._OpenConfig()
if instance_name not in self._config_data.instances:
raise errors.ConfigurationError("Unknown instance '%s'" % instance_name)
instance = self._config_data.instances[instance_name]
instance.status = "down"
self._WriteConfig()
self._SetInstanceStatus(instance_name, "down")
def GetInstanceList(self):
"""Get the list of instances.
......
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