Commit da0aa302 authored by Santi Raffa's avatar Santi Raffa Committed by Jose A. Lopes
Browse files

OpCodes: modify InstanceReinstall for private, secret params



Modify InstanceReinstall to accept and process private and secret
parameters.
Signed-off-by: default avatarSanti Raffa <rsanti@google.com>
Reviewed-by: default avatarJose A. Lopes <jabolopes@google.com>
parent 6bce7ba2
......@@ -395,7 +395,9 @@ def ReinstallInstance(opts, args):
op = opcodes.OpInstanceReinstall(instance_name=instance_name,
os_type=os_name,
force_variant=opts.force_variant,
osparams=opts.osparams)
osparams=opts.osparams,
osparams_private=opts.osparams_private,
osparams_secret=opts.osparams_secret)
jex.QueueJob(instance_name, op)
results = jex.WaitOrShow(not opts.submit_only)
......
......@@ -292,6 +292,14 @@ class LUInstanceReinstall(LogicalUnit):
errors.ECODE_INVAL)
CheckInstanceState(self, instance, INSTANCE_DOWN, msg="cannot reinstall")
# Handle OS parameters
self._MergeValidateOsParams(instance)
self.instance = instance
def _MergeValidateOsParams(self, instance):
"Handle the OS parameter merging and validation for the target instance."
if self.op.os_type is not None:
# OS verification
CheckNodeHasOS(self, instance.primary_node, self.op.os_type,
......@@ -302,14 +310,25 @@ class LUInstanceReinstall(LogicalUnit):
node_uuids = list(instance.all_nodes)
if self.op.osparams:
i_osdict = GetUpdatedParams(instance.osparams, self.op.osparams)
CheckOSParams(self, True, node_uuids, instance_os, i_osdict)
self.os_inst = i_osdict # the new dict (without defaults)
else:
self.os_inst = None
self.op.osparams = self.op.osparams or {}
self.op.osparams_private = self.op.osparams_private or {}
self.op.osparams_secret = self.op.osparams_secret or {}
self.instance = instance
# Handle the use of 'default' values.
params_public = GetUpdatedParams(instance.osparams, self.op.osparams)
params_private = GetUpdatedParams(instance.osparams_private,
self.op.osparams_private)
params_secret = self.op.osparams_secret
cluster = self.cfg.GetClusterInfo()
self.os_inst = cluster.SimpleFillOS(
instance_os,
params_public,
os_params_private=params_private,
os_params_secret=params_secret
)
CheckOSParams(self, True, node_uuids, instance_os, self.os_inst)
def Exec(self, feedback_fn):
"""Reinstall the instance.
......
......@@ -1297,7 +1297,10 @@ REINSTALL
| **reinstall** [{-o|\--os-type} *os-type*] [\--select-os] [-f *force*]
| [\--force-multiple]
| [\--instance \| \--node \| \--primary \| \--secondary \| \--all]
| [{-O|\--os-parameters} *OS\_PARAMETERS*] [\--submit] [\--print-job-id]
| [{-O|\--os-parameters} *OS\_PARAMETERS*]
| [--os-parameters-private} *OS\_PARAMETERS*]
| [--os-parameters-secret} *OS\_PARAMETERS*]
| [\--submit] [\--print-job-id]
| {*instance*...}
Reinstalls the operating system on the given instance(s). The
......
......@@ -474,6 +474,8 @@ $(genOpCode "OpCode"
, pForceVariant
, pInstOs
, pTempOsParams
, pTempOsParamsPrivate
, pTempOsParamsSecret
],
"instance_name")
, ("OpInstanceRemove",
......
......@@ -190,6 +190,8 @@ module Ganeti.OpParams
, pInstTags
, pMultiAllocInstances
, pTempOsParams
, pTempOsParamsPrivate
, pTempOsParamsSecret
, pTempHvParams
, pTempBeParams
, pIgnoreFailures
......@@ -1210,6 +1212,18 @@ pTempOsParams =
renameField "TempOsParams" .
optionalField $ simpleField "osparams" [t| JSObject JSValue |]
pTempOsParamsPrivate :: Field
pTempOsParamsPrivate =
withDoc "Private OS parameters for instance reinstalls" .
optionalField $
simpleField "osparams_private" [t| JSObject (Private JSValue) |]
pTempOsParamsSecret :: Field
pTempOsParamsSecret =
withDoc "Secret OS parameters for instance reinstalls" .
optionalField $
simpleField "osparams_secret" [t| JSObject (Private JSValue) |]
pShutdownTimeout :: Field
pShutdownTimeout =
withDoc "How long to wait for instance to shut down" .
......
......@@ -301,6 +301,7 @@ instance Arbitrary OpCodes.OpCode where
"OP_INSTANCE_REINSTALL" ->
OpCodes.OpInstanceReinstall <$> genFQDN <*> return Nothing <*>
arbitrary <*> genMaybe genNameNE <*> genMaybe (pure emptyJSObject)
<*> genMaybe arbitraryPrivateJSObj <*> genMaybe arbitraryPrivateJSObj
"OP_INSTANCE_REMOVE" ->
OpCodes.OpInstanceRemove <$> genFQDN <*> return Nothing <*>
arbitrary <*> arbitrary
......
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