528 |
528 |
(result.cmd, result.exit_code, result.output))
|
529 |
529 |
|
530 |
530 |
|
|
531 |
def _CheckInstanceBridgesExist(instance):
|
|
532 |
"""Check that the brigdes needed by an instance exist.
|
|
533 |
|
|
534 |
"""
|
|
535 |
# check bridges existance
|
|
536 |
brlist = [nic.bridge for nic in instance.nics]
|
|
537 |
if not rpc.call_bridges_exist(instance.primary_node, brlist):
|
|
538 |
raise errors.OpPrereqError("one or more target bridges %s does not"
|
|
539 |
" exist on destination node '%s'" %
|
|
540 |
(brlist, instance.primary_node))
|
|
541 |
|
|
542 |
|
531 |
543 |
class LUInitCluster(LogicalUnit):
|
532 |
544 |
"""Initialise the cluster.
|
533 |
545 |
|
... | ... | |
1934 |
1946 |
self.op.instance_name)
|
1935 |
1947 |
|
1936 |
1948 |
# check bridges existance
|
1937 |
|
brlist = [nic.bridge for nic in instance.nics]
|
1938 |
|
if not rpc.call_bridges_exist(instance.primary_node, brlist):
|
1939 |
|
raise errors.OpPrereqError("one or more target bridges %s does not"
|
1940 |
|
" exist on destination node '%s'" %
|
1941 |
|
(brlist, instance.primary_node))
|
|
1949 |
_CheckInstanceBridgesExist(instance)
|
1942 |
1950 |
|
1943 |
1951 |
self.instance = instance
|
1944 |
1952 |
self.op.instance_name = instance.name
|
... | ... | |
1976 |
1984 |
self.cfg.MarkInstanceUp(instance.name)
|
1977 |
1985 |
|
1978 |
1986 |
|
|
1987 |
class LURebootInstance(LogicalUnit):
|
|
1988 |
"""Reboot an instance.
|
|
1989 |
|
|
1990 |
"""
|
|
1991 |
HPATH = "instance-reboot"
|
|
1992 |
HTYPE = constants.HTYPE_INSTANCE
|
|
1993 |
_OP_REQP = ["instance_name", "ignore_secondaries", "reboot_type"]
|
|
1994 |
|
|
1995 |
def BuildHooksEnv(self):
|
|
1996 |
"""Build hooks env.
|
|
1997 |
|
|
1998 |
This runs on master, primary and secondary nodes of the instance.
|
|
1999 |
|
|
2000 |
"""
|
|
2001 |
env = {
|
|
2002 |
"IGNORE_SECONDARIES": self.op.ignore_secondaries,
|
|
2003 |
}
|
|
2004 |
env.update(_BuildInstanceHookEnvByObject(self.instance))
|
|
2005 |
nl = ([self.sstore.GetMasterNode(), self.instance.primary_node] +
|
|
2006 |
list(self.instance.secondary_nodes))
|
|
2007 |
return env, nl, nl
|
|
2008 |
|
|
2009 |
def CheckPrereq(self):
|
|
2010 |
"""Check prerequisites.
|
|
2011 |
|
|
2012 |
This checks that the instance is in the cluster.
|
|
2013 |
|
|
2014 |
"""
|
|
2015 |
instance = self.cfg.GetInstanceInfo(
|
|
2016 |
self.cfg.ExpandInstanceName(self.op.instance_name))
|
|
2017 |
if instance is None:
|
|
2018 |
raise errors.OpPrereqError("Instance '%s' not known" %
|
|
2019 |
self.op.instance_name)
|
|
2020 |
|
|
2021 |
# check bridges existance
|
|
2022 |
_CheckInstanceBridgesExist(instance)
|
|
2023 |
|
|
2024 |
self.instance = instance
|
|
2025 |
self.op.instance_name = instance.name
|
|
2026 |
|
|
2027 |
def Exec(self, feedback_fn):
|
|
2028 |
"""Reboot the instance.
|
|
2029 |
|
|
2030 |
"""
|
|
2031 |
instance = self.instance
|
|
2032 |
ignore_secondaries = self.op.ignore_secondaries
|
|
2033 |
reboot_type = self.op.reboot_type
|
|
2034 |
extra_args = getattr(self.op, "extra_args", "")
|
|
2035 |
|
|
2036 |
node_current = instance.primary_node
|
|
2037 |
|
|
2038 |
if reboot_type not in [constants.INSTANCE_REBOOT_SOFT,
|
|
2039 |
constants.INSTANCE_REBOOT_HARD,
|
|
2040 |
constants.INSTANCE_REBOOT_FULL]:
|
|
2041 |
raise errors.ParameterError("reboot type not in [%s, %s, %s]" %
|
|
2042 |
(constants.INSTANCE_REBOOT_SOFT,
|
|
2043 |
constants.INSTANCE_REBOOT_HARD,
|
|
2044 |
constants.INSTANCE_REBOOT_FULL))
|
|
2045 |
|
|
2046 |
if reboot_type in [constants.INSTANCE_REBOOT_SOFT,
|
|
2047 |
constants.INSTANCE_REBOOT_HARD]:
|
|
2048 |
if not rpc.call_instance_reboot(node_current, instance,
|
|
2049 |
reboot_type, extra_args):
|
|
2050 |
raise errors.OpExecError("Could not reboot instance")
|
|
2051 |
else:
|
|
2052 |
if not rpc.call_instance_shutdown(node_current, instance):
|
|
2053 |
raise errors.OpExecError("could not shutdown instance for full reboot")
|
|
2054 |
_ShutdownInstanceDisks(instance, self.cfg)
|
|
2055 |
_StartInstanceDisks(self.cfg, instance, ignore_secondaries)
|
|
2056 |
if not rpc.call_instance_start(node_current, instance, extra_args):
|
|
2057 |
_ShutdownInstanceDisks(instance, self.cfg)
|
|
2058 |
raise errors.OpExecError("Could not start instance for full reboot")
|
|
2059 |
|
|
2060 |
self.cfg.MarkInstanceUp(instance.name)
|
|
2061 |
|
|
2062 |
|
1979 |
2063 |
class LUShutdownInstance(LogicalUnit):
|
1980 |
2064 |
"""Shutdown an instance.
|
1981 |
2065 |
|