Revision 5643d67e
b/lib/cmdlib.py | ||
---|---|---|
3112 | 3112 |
lu.proc.LogWarning(msg) |
3113 | 3113 |
|
3114 | 3114 |
|
3115 |
def _ComputeAncillaryFiles(cluster, redist): |
|
3116 |
"""Compute files external to Ganeti which need to be consistent. |
|
3117 |
|
|
3118 |
@type redist: boolean |
|
3119 |
@param redist: Whether to include files which need to be redistributed |
|
3120 |
|
|
3121 |
""" |
|
3122 |
# Compute files for all nodes |
|
3123 |
files_all = set([ |
|
3124 |
constants.SSH_KNOWN_HOSTS_FILE, |
|
3125 |
constants.CONFD_HMAC_KEY, |
|
3126 |
constants.CLUSTER_DOMAIN_SECRET_FILE, |
|
3127 |
]) |
|
3128 |
|
|
3129 |
if not redist: |
|
3130 |
files_all.update(constants.ALL_CERT_FILES) |
|
3131 |
files_all.update(ssconf.SimpleStore().GetFileList()) |
|
3132 |
|
|
3133 |
if cluster.modify_etc_hosts: |
|
3134 |
files_all.add(constants.ETC_HOSTS) |
|
3135 |
|
|
3136 |
# Files which must either exist on all nodes or on none |
|
3137 |
files_all_opt = set([ |
|
3138 |
constants.RAPI_USERS_FILE, |
|
3139 |
]) |
|
3140 |
|
|
3141 |
# Files which should only be on master candidates |
|
3142 |
files_mc = set() |
|
3143 |
if not redist: |
|
3144 |
files_mc.add(constants.CLUSTER_CONF_FILE) |
|
3145 |
|
|
3146 |
# Files which should only be on VM-capable nodes |
|
3147 |
files_vm = set(filename |
|
3148 |
for hv_name in cluster.enabled_hypervisors |
|
3149 |
for filename in hypervisor.GetHypervisor(hv_name).GetAncillaryFiles()) |
|
3150 |
|
|
3151 |
# Filenames must be unique |
|
3152 |
assert (len(files_all | files_all_opt | files_mc | files_vm) == |
|
3153 |
sum(map(len, [files_all, files_all_opt, files_mc, files_vm]))), \ |
|
3154 |
"Found file listed in more than one file list" |
|
3155 |
|
|
3156 |
return (files_all, files_all_opt, files_mc, files_vm) |
|
3157 |
|
|
3158 |
|
|
3115 | 3159 |
def _RedistributeAncillaryFiles(lu, additional_nodes=None, additional_vm=True): |
3116 | 3160 |
"""Distribute additional files which are part of the cluster configuration. |
3117 | 3161 |
|
... | ... | |
3125 | 3169 |
@param additional_vm: whether the additional nodes are vm-capable or not |
3126 | 3170 |
|
3127 | 3171 |
""" |
3128 |
# 1. Gather target nodes |
|
3129 |
myself = lu.cfg.GetNodeInfo(lu.cfg.GetMasterNode()) |
|
3130 |
dist_nodes = lu.cfg.GetOnlineNodeList() |
|
3131 |
nvm_nodes = lu.cfg.GetNonVmCapableNodeList() |
|
3132 |
vm_nodes = [name for name in dist_nodes if name not in nvm_nodes] |
|
3172 |
# Gather target nodes |
|
3173 |
cluster = lu.cfg.GetClusterInfo() |
|
3174 |
master_info = lu.cfg.GetNodeInfo(lu.cfg.GetMasterNode()) |
|
3175 |
|
|
3176 |
online_nodes = lu.cfg.GetOnlineNodeList() |
|
3177 |
vm_nodes = lu.cfg.GetVmCapableNodeList() |
|
3178 |
|
|
3133 | 3179 |
if additional_nodes is not None: |
3134 |
dist_nodes.extend(additional_nodes)
|
|
3180 |
online_nodes.extend(additional_nodes)
|
|
3135 | 3181 |
if additional_vm: |
3136 | 3182 |
vm_nodes.extend(additional_nodes) |
3137 |
if myself.name in dist_nodes: |
|
3138 |
dist_nodes.remove(myself.name)
|
|
3139 |
if myself.name in vm_nodes:
|
|
3140 |
vm_nodes.remove(myself.name)
|
|
3141 |
|
|
3142 |
# 2. Gather files to distribute |
|
3143 |
dist_files = set([constants.ETC_HOSTS,
|
|
3144 |
constants.SSH_KNOWN_HOSTS_FILE,
|
|
3145 |
constants.RAPI_CERT_FILE,
|
|
3146 |
constants.RAPI_USERS_FILE, |
|
3147 |
constants.CONFD_HMAC_KEY,
|
|
3148 |
constants.CLUSTER_DOMAIN_SECRET_FILE,
|
|
3149 |
])
|
|
3150 |
|
|
3151 |
vm_files = set() |
|
3152 |
enabled_hypervisors = lu.cfg.GetClusterInfo().enabled_hypervisors
|
|
3153 |
for hv_name in enabled_hypervisors:
|
|
3154 |
hv_class = hypervisor.GetHypervisor(hv_name)
|
|
3155 |
vm_files.update(hv_class.GetAncillaryFiles())
|
|
3156 |
|
|
3157 |
# 3. Perform the files upload |
|
3158 |
for fname in dist_files:
|
|
3159 |
_UploadHelper(lu, dist_nodes, fname)
|
|
3160 |
for fname in vm_files:
|
|
3161 |
_UploadHelper(lu, vm_nodes, fname)
|
|
3183 |
|
|
3184 |
# Never distribute to master node
|
|
3185 |
for nodelist in [online_nodes, vm_nodes]:
|
|
3186 |
if master_info.name in nodelist:
|
|
3187 |
nodelist.remove(master_info.name) |
|
3188 |
|
|
3189 |
# Gather file lists
|
|
3190 |
(files_all, files_all_opt, files_mc, files_vm) = \
|
|
3191 |
_ComputeAncillaryFiles(cluster, True)
|
|
3192 |
|
|
3193 |
# Never re-distribute configuration file from here
|
|
3194 |
assert not (constants.CLUSTER_CONF_FILE in files_all or
|
|
3195 |
constants.CLUSTER_CONF_FILE in files_vm)
|
|
3196 |
assert not files_mc, "Master candidates not handled in this function" |
|
3197 |
|
|
3198 |
filemap = [
|
|
3199 |
(online_nodes, files_all),
|
|
3200 |
(online_nodes, files_all_opt),
|
|
3201 |
(vm_nodes, files_vm),
|
|
3202 |
] |
|
3203 |
|
|
3204 |
# Upload the files
|
|
3205 |
for (node_list, files) in filemap:
|
|
3206 |
for fname in files:
|
|
3207 |
_UploadHelper(lu, node_list, fname)
|
|
3162 | 3208 |
|
3163 | 3209 |
|
3164 | 3210 |
class LUClusterRedistConf(NoHooksLU): |
Also available in: Unified diff