[node-patches] Change in ovirt-node[master]: Break out kdump changes into defaults.py and kdump_page
rbarry at redhat.com
rbarry at redhat.com
Wed Aug 14 19:05:04 UTC 2013
Ryan Barry has uploaded a new change for review.
Change subject: Break out kdump changes into defaults.py and kdump_page
......................................................................
Break out kdump changes into defaults.py and kdump_page
Move the logic for the kdump SSH key URL into their its own
commit so it's not all lumped in with autoinstall changes.
Change-Id: I07eb09f6ac75d9198b934d5023b73adf96da89a6
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M src/ovirt/node/config/defaults.py
M src/ovirt/node/setup/core/kdump_page.py
2 files changed, 64 insertions(+), 12 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/49/18149/1
diff --git a/src/ovirt/node/config/defaults.py b/src/ovirt/node/config/defaults.py
index d416fbb..3661c21 100644
--- a/src/ovirt/node/config/defaults.py
+++ b/src/ovirt/node/config/defaults.py
@@ -987,21 +987,25 @@
>>> n = KDump(fs.FakeFs.File("dst"))
>>> nfs_url = "host.example.com:/dst/path"
>>> ssh_url = "root at host.example.com"
- >>> n.update(nfs_url, ssh_url, True)
+ >>> ssh_key = "http://example.com/id_rsa"
+ >>> n.update(nfs_url, ssh_url, ssh_key, True)
>>> d = sorted(n.retrieve().items())
>>> d[:2]
[('local', True), ('nfs', 'host.example.com:/dst/path')]
>>> d[2:]
- [('ssh', 'root at host.example.com')]
+ [('ssh', 'root at host.example.com'), \
+('ssh_key', 'http://example.com/id_rsa')]
"""
keys = ("OVIRT_KDUMP_NFS",
"OVIRT_KDUMP_SSH",
+ "OVIRT_KDUMP_SSH_KEY",
"OVIRT_KDUMP_LOCAL")
@NodeConfigFileSection.map_and_update_defaults_decorator
- def update(self, nfs, ssh, local):
+ def update(self, nfs, ssh, ssh_key, local):
(valid.Empty(or_none=True) | valid.NFSAddress())(nfs)
(valid.Empty(or_none=True) | valid.SSHAddress())(ssh)
+ (valid.Empty(or_none=True) | valid.URL())(ssh_key)
(valid.Empty(or_none=True) | valid.Boolean())(local)
return {"OVIRT_KDUMP_LOCAL": "true" if local else None
}
@@ -1014,7 +1018,8 @@
def transaction(self):
cfg = dict(self.retrieve())
- nfs, ssh, restore = (cfg["nfs"], cfg["ssh"], cfg["local"])
+ nfs, ssh, ssh_key, restore = (cfg["nfs"], cfg["ssh"], cfg["ssh_key"],
+ cfg["local"])
class BackupKdumpConfig(utils.Transaction.Element):
title = "Backing up config files"
@@ -1039,6 +1044,42 @@
def commit(self):
import ovirtnode.kdump as okdump
okdump.write_kdump_config(nfs)
+
+ class PopulateSshKeys(utils.Transaction.Element):
+ title = "Fetching and testing SSH keys"
+
+ def commit(self):
+ import pycurl
+ import cStringIO
+ from shutil import copy2
+
+ buf = cStringIO.StringIO()
+
+ curl = pycurl.Curl()
+ curl.setopt(curl.URL, ssh_key)
+ curl.setopt(curl.WRITEFUNCTION, buf.write)
+ curl.setopt(curl.FAILONERROR, True)
+ try:
+ curl.perform()
+ except pycurl.error, error:
+ errno, err_str = error
+ self.logger.warning("Failed to fetch SSH key: %s" %
+ err_str)
+
+ os.mkdir("/tmp/kdump-ssh")
+ os.chmod("/tmp/kdump-ssh", 0600)
+ with open("/tmp/kdump/ssh/id", "w") as f:
+ f.write(buf.getvalue())
+ os.chmod("/tmp/kdump-ssh/id", 0600)
+
+ try:
+ utils.process.check_call("ssh -o BatchMode=yes "
+ "-i /tmp/kdump-ssh/id %s "
+ "true" % ssh_key)
+ copy2("/tmp/kdump-ssh/id", "/root/.ssh/kdump_id_rsa")
+ except utils.process.CalledProcessError as e:
+ self.logger.warning("Failed to authenticate using SSH "
+ "key: %s" % e)
class CreateSshKdumpConfig(utils.Transaction.Element):
title = "Creating kdump SSH config"
@@ -1117,6 +1158,8 @@
if nfs:
tx.append(CreateNfsKdumpConfig())
elif ssh:
+ if ssh_key:
+ tx.append(PopulateSshKeys())
tx.append(CreateSshKdumpConfig())
elif restore in [True, False]:
tx.append(RestoreKdumpConfig())
diff --git a/src/ovirt/node/setup/core/kdump_page.py b/src/ovirt/node/setup/core/kdump_page.py
index 5887cd4..4ff6ce2 100644
--- a/src/ovirt/node/setup/core/kdump_page.py
+++ b/src/ovirt/node/setup/core/kdump_page.py
@@ -59,8 +59,9 @@
model = {
# The target address
"kdump.type": ktype,
- "kdump.ssh_location": cfg["ssh"]or "",
- "kdump.nfs_location": cfg["nfs"]or "",
+ "kdump.ssh_location": cfg["ssh"] or "",
+ "kdump.ssh_key": cfg["ssh_key"] or "",
+ "kdump.nfs_location": cfg["nfs"] or "",
}
self.logger.debug(model)
return model
@@ -71,6 +72,7 @@
# FIXME improve validation for ssh and nfs
return {"kdump.type": valid.Options(dict(self._types).keys()),
"kdump.ssh_location": valid.Empty() | valid.SSHAddress(),
+ "kdump.ssh_key": valid.Empty() | valid.URL(),
"kdump.nfs_location": valid.Empty() | valid.NFSAddress(),
}
@@ -108,6 +110,8 @@
ui.Entry("kdump.ssh_location", "SSH Location " +
"(root at example.com):",
align_vertical=True),
+ ui.Entry("kdump.ssh_key", "SSH Key URI (optional):",
+ align_vertical=True)
])
page = ui.Page("page", ws)
self.widgets.add(page)
@@ -142,21 +146,26 @@
self.logger.debug("Changes: %s" % changes)
self.logger.debug("Effective Model: %s" % effective_model)
- kdump_keys = ["kdump.type", "kdump.ssh_location", "kdump.nfs_location"]
+ kdump_keys = ["kdump.type", "kdump.ssh_location", "kdump.ssh_key",
+ "kdump.nfs_location"]
txs = utils.Transaction("Updating kdump related configuration")
if changes.contains_any(kdump_keys):
model = defaults.KDump()
- ktype, sshloc, nfsloc = effective_model.values_for(kdump_keys)
+ ktype, sshloc, sshkey, nfsloc = effective_model.values_for(
+ kdump_keys)
if ktype == "nfs":
- model.update(nfsloc, None, None)
+ model.update(nfsloc, None, None, None)
elif ktype == "ssh":
- model.update(None, sshloc, None)
+ if "kdump.ssh_key" in changes:
+ model.update(None, sshloc, sshkey, None)
+ else:
+ model.update(None, sshloc, None, None)
elif ktype == "local":
- model.update(None, None, True)
+ model.update(None, None, None, True)
else:
- model.update(None, None, None)
+ model.update(None, None, None, None)
txs += model.transaction()
try:
--
To view, visit http://gerrit.ovirt.org/18149
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I07eb09f6ac75d9198b934d5023b73adf96da89a6
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Ryan Barry <rbarry at redhat.com>
More information about the node-patches
mailing list