Commit 0894ac48 authored by Hrvoje Ribicic's avatar Hrvoje Ribicic

Add the zeroing-image option

This patch adds the zeroing-image option to gnt-cluster and the
OpBackupExport params. The many changes are all minor, yet necessary.
Signed-off-by: default avatarHrvoje Ribicic <riba@google.com>
Reviewed-by: default avatarJose A. Lopes <jabolopes@google.com>
parent 84ac8b54
......@@ -527,7 +527,8 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
default_iallocator=None, default_iallocator_params=None,
primary_ip_version=None, ipolicy=None,
prealloc_wipe_disks=False, use_external_mip_script=False,
hv_state=None, disk_state=None, enabled_disk_templates=None):
hv_state=None, disk_state=None, enabled_disk_templates=None,
zeroing_image=None):
"""Initialise the cluster.
@type candidate_pool_size: int
......@@ -795,7 +796,8 @@ def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914
enabled_disk_templates=enabled_disk_templates,
candidate_certs=candidate_certs,
osparams={},
osparams_private_cluster={}
osparams_private_cluster={},
zeroing_image=zeroing_image
)
master_node_config = objects.Node(name=hostname.name,
primary_ip=hostname.ip,
......
......@@ -228,6 +228,7 @@ __all__ = [
"VG_NAME_OPT",
"WFSYNC_OPT",
"YES_DOIT_OPT",
"ZEROING_IMAGE_OPT",
"DISK_STATE_OPT",
"HV_STATE_OPT",
"IGNORE_IPOLICY_OPT",
......@@ -1735,6 +1736,11 @@ INSTANCE_COMMUNICATION_OPT = \
help=constants.INSTANCE_COMMUNICATION_DOC,
type="bool")
ZEROING_IMAGE_OPT = \
cli_option("--zeroing-image",
dest="zeroing_image", action="store", default=None,
help="The OS image to use to zero instance disks")
#: Options provided by all commands
COMMON_OPTS = [DEBUG_OPT, REASON_OPT]
......
......@@ -265,6 +265,11 @@ def InitCluster(opts, args):
hv_state = dict(opts.hv_state)
if opts.zeroing_image:
zeroing_image = opts.zeroing_image
else:
zeroing_image = ""
default_ialloc_params = opts.default_iallocator_params
bootstrap.InitCluster(cluster_name=args[0],
secondary_ip=opts.secondary_ip,
......@@ -296,6 +301,7 @@ def InitCluster(opts, args):
hv_state=hv_state,
disk_state=disk_state,
enabled_disk_templates=enabled_disk_templates,
zeroing_image=zeroing_image
)
op = opcodes.OpClusterPostInit()
SubmitOpCode(op, opts=opts)
......@@ -548,6 +554,7 @@ def ShowClusterConfig(opts, args):
utils.CommaJoin(result["enabled_disk_templates"])),
("instance communication network",
result["instance_communication_network"]),
("zeroing image", result["zeroing_image"]),
]),
("Default node parameters",
......@@ -1124,7 +1131,8 @@ def SetClusterParams(opts, args):
opts.ipolicy_spindle_ratio is not None or
opts.modify_etc_hosts is not None or
opts.file_storage_dir is not None or
opts.instance_communication_network is not None):
opts.instance_communication_network is not None or
opts.zeroing_image is not None):
ToStderr("Please give at least one of the parameters.")
return 1
......@@ -1236,7 +1244,8 @@ def SetClusterParams(opts, args):
enabled_disk_templates=enabled_disk_templates,
force=opts.force,
file_storage_dir=opts.file_storage_dir,
instance_communication_network=opts.instance_communication_network
instance_communication_network=opts.instance_communication_network,
zeroing_image=opts.zeroing_image
)
return base.GetResult(None, opts, SubmitOrSend(op, opts))
......@@ -2101,7 +2110,7 @@ commands = {
PRIMARY_IP_VERSION_OPT, PREALLOC_WIPE_DISKS_OPT, NODE_PARAMS_OPT,
GLOBAL_SHARED_FILEDIR_OPT, USE_EXTERNAL_MIP_SCRIPT, DISK_PARAMS_OPT,
HV_STATE_OPT, DISK_STATE_OPT, ENABLED_DISK_TEMPLATES_OPT,
IPOLICY_STD_SPECS_OPT, GLOBAL_GLUSTER_FILEDIR_OPT]
IPOLICY_STD_SPECS_OPT, GLOBAL_GLUSTER_FILEDIR_OPT, ZEROING_IMAGE_OPT]
+ INSTANCE_POLICY_OPTS + SPLIT_ISPECS_OPTS,
"[opts...] <cluster_name>", "Initialises a new cluster configuration"),
"destroy": (
......@@ -2185,7 +2194,7 @@ commands = {
USE_EXTERNAL_MIP_SCRIPT, DISK_PARAMS_OPT, HV_STATE_OPT, DISK_STATE_OPT] +
SUBMIT_OPTS +
[ENABLED_DISK_TEMPLATES_OPT, IPOLICY_STD_SPECS_OPT, MODIFY_ETCHOSTS_OPT] +
INSTANCE_POLICY_OPTS + [GLOBAL_FILEDIR_OPT],
INSTANCE_POLICY_OPTS + [GLOBAL_FILEDIR_OPT, ZEROING_IMAGE_OPT],
"[opts...]",
"Alters the parameters of the cluster"),
"renew-crypto": (
......
......@@ -284,6 +284,11 @@ class LUBackupExport(LogicalUnit):
raise errors.OpPrereqError("Booting from disk must be set for zeroing "
"to work")
# Check that the zeroing image is set
if not self.cfg.GetZeroingImage():
raise errors.OpPrereqError("A zeroing image must be set for zeroing to"
" work")
def _CleanupExports(self, feedback_fn):
"""Removes exports of current instance from all other nodes.
......
......@@ -57,7 +57,8 @@ from ganeti.cmdlib.common import ShareAll, RunPostHook, \
ComputeIPolicyInstanceViolation, AnnotateDiskParams, SupportsOob, \
CheckIpolicyVsDiskTemplates, CheckDiskAccessModeValidity, \
CheckDiskAccessModeConsistency, CreateNewClientCert, \
AddInstanceCommunicationNetworkOp, ConnectInstanceCommunicationNetworkOp
AddInstanceCommunicationNetworkOp, ConnectInstanceCommunicationNetworkOp, \
CheckImageValidity
import ganeti.masterd.instance
......@@ -1611,6 +1612,11 @@ class LUClusterSetParams(LogicalUnit):
result.Warn("Could not change the master IP netmask", feedback_fn)
self.cluster.master_netmask = self.op.master_netmask
if self.op.zeroing_image is not None:
CheckImageValidity(self.op.zeroing_image,
"Zeroing image must be an absolute path or a URL")
self.cluster.zeroing_image = self.op.zeroing_image
self.cfg.Update(self.cluster, feedback_fn)
if self.op.master_netdev:
......
......@@ -1373,6 +1373,16 @@ class ConfigWriter(object):
"""
self._ConfigData().cluster.instance_communication_network = network_name
@_ConfigSync(shared=1)
def GetZeroingImage(self):
"""Get the zeroing image location
@rtype: string
@return: the location of the zeroing image
"""
return self._config_data.cluster.zeroing_image
@_ConfigSync()
def AddNodeGroup(self, group, ec_id, check_uuid=True):
"""Add a node group to the configuration.
......
......@@ -1643,6 +1643,7 @@ class Cluster(TaggableObject):
"candidate_certs",
"max_running_jobs",
"instance_communication_network",
"zeroing_image"
] + _TIMESTAMPS + _UUID
def UpgradeConfig(self):
......
......@@ -727,6 +727,7 @@ $(buildObject "Cluster" "cluster" $
, simpleField "candidate_certs" [t| CandidateCertificates |]
, simpleField "max_running_jobs" [t| Int |]
, simpleField "instance_communication_network" [t| String |]
, simpleField "zeroing_image" [t| String |]
]
++ timeStampFields
++ uuidFields
......
......@@ -240,6 +240,7 @@ $(genOpCode "OpCode"
, pClusterSharedFileStorageDir
, pClusterGlusterStorageDir
, pInstanceCommunicationNetwork
, pZeroingImage
],
[])
, ("OpClusterRedistConf",
......
......@@ -110,6 +110,7 @@ module Ganeti.OpParams
, pClusterSharedFileStorageDir
, pClusterGlusterStorageDir
, pInstanceCommunicationNetwork
, pZeroingImage
, pVgName
, pEnabledHypervisors
, pHypervisor
......@@ -596,6 +597,11 @@ pInstanceCommunicationNetwork :: Field
pInstanceCommunicationNetwork =
optionalStringField "instance_communication_network"
-- | The OS to use when zeroing instance disks
pZeroingImage :: Field
pZeroingImage =
optionalStringField "zeroing_image"
-- | Volume group name.
pVgName :: Field
pVgName =
......
......@@ -169,6 +169,7 @@ handleCall _ _ cdata QueryClusterInfo =
, ("enabled_disk_templates", showJSON diskTemplates)
, ("instance_communication_network",
showJSON (clusterInstanceCommunicationNetwork cluster))
, ("zeroing_image", showJSON $ clusterZeroingImage cluster)
]
in case master of
......
......@@ -209,6 +209,7 @@ instance Arbitrary OpCodes.OpCode where
<*> genMaybe genName -- shared_file_storage_dir
<*> genMaybe genName -- gluster_file_storage_dir
<*> arbitrary -- instance_communication_network
<*> arbitrary -- zeroing_image
"OP_CLUSTER_REDIST_CONF" -> pure OpCodes.OpClusterRedistConf
"OP_CLUSTER_ACTIVATE_MASTER_IP" ->
pure OpCodes.OpClusterActivateMasterIp
......
......@@ -49,6 +49,7 @@ def GetMinimalConfig():
"ndparams": {},
"candidate_certs": {},
"instance_communication_network": "",
"zeroing_image": "",
},
"instances": {},
"networks": {},
......
......@@ -154,6 +154,8 @@ def UpgradeCluster(config_data):
cluster["candidate_certs"] = {}
cluster["instance_communication_network"] = \
cluster.get("instance_communication_network", "")
cluster["zeroing_image"] = \
cluster.get("zeroing_image", "")
def UpgradeGroups(config_data):
......@@ -415,6 +417,9 @@ def DowngradeCluster(config_data):
if "instance_communication_network" in cluster:
del cluster["instance_communication_network"]
if "zeroing_image" in cluster:
del cluster["zeroing_image"]
def DowngradeInstances(config_data):
instances = config_data.get("instances", None)
......
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