mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CloudStack CLOUDSTACK-774
Supporting kickstart in CloudStack baremetal make kikcstart working with ubuntu
This commit is contained in:
parent
cec4d8b59c
commit
31d6e5465e
@ -175,7 +175,7 @@ public class BaremetalKickStartPxeResource extends BaremetalPxeResourceBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String copyTo = String.format("%s/%s", _tftpDir, cmd.getTemplateUuid());
|
String copyTo = String.format("%s/%s", _tftpDir, cmd.getTemplateUuid());
|
||||||
String script = String.format("python /usr/bin/prepare_kickstart_kernel_initrd.py %s %s", cmd.getRepo(), copyTo);
|
String script = String.format("python /usr/bin/prepare_kickstart_kernel_initrd.py %s %s %s", cmd.getKernel(), cmd.getInitrd(), copyTo);
|
||||||
|
|
||||||
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) {
|
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) {
|
||||||
return new Answer(cmd, false, "prepare kickstart at pxe server " + _ip + " failed, command:" + script);
|
return new Answer(cmd, false, "prepare kickstart at pxe server " + _ip + " failed, command:" + script);
|
||||||
|
|||||||
@ -95,11 +95,36 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase imple
|
|||||||
try {
|
try {
|
||||||
String tpl = profile.getTemplate().getUrl();
|
String tpl = profile.getTemplate().getUrl();
|
||||||
assert tpl != null : "How can a null template get here!!!";
|
assert tpl != null : "How can a null template get here!!!";
|
||||||
String[] tpls = tpl.split(";");
|
String[] tpls = tpl.split(";");
|
||||||
assert tpls.length == 2 : "Template is not correctly encoded. " + tpl;
|
CloudRuntimeException err = new CloudRuntimeException(String.format("template url[%s] is not correctly encoded. it must be in format of ks=http_link_to_kickstartfile;kernel=nfs_path_to_pxe_kernel;initrd=nfs_path_to_pxe_initrd", tpl));
|
||||||
|
if (tpls.length != 3) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
String ks = null;
|
||||||
|
String kernel = null;
|
||||||
|
String initrd = null;
|
||||||
|
|
||||||
|
for (String t : tpls) {
|
||||||
|
String[] kv = t.split("=");
|
||||||
|
if (kv.length != 2) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
if (kv[0].equals("ks")) {
|
||||||
|
ks = kv[1];
|
||||||
|
} else if (kv[0].equals("kernel")) {
|
||||||
|
kernel = kv[1];
|
||||||
|
} else if (kv[0].equals("initrd")) {
|
||||||
|
initrd = kv[1];
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PrepareKickstartPxeServerCommand cmd = new PrepareKickstartPxeServerCommand();
|
PrepareKickstartPxeServerCommand cmd = new PrepareKickstartPxeServerCommand();
|
||||||
cmd.setKsFile(tpls[0]);
|
cmd.setKsFile(ks);
|
||||||
cmd.setRepo(tpls[1]);
|
cmd.setInitrd(initrd);
|
||||||
|
cmd.setKernel(kernel);
|
||||||
cmd.setMac(nic.getMacAddress());
|
cmd.setMac(nic.getMacAddress());
|
||||||
cmd.setTemplateUuid(template.getUuid());
|
cmd.setTemplateUuid(template.getUuid());
|
||||||
Answer aws = _agentMgr.send(pxeVo.getHostId(), cmd);
|
Answer aws = _agentMgr.send(pxeVo.getHostId(), cmd);
|
||||||
|
|||||||
@ -22,10 +22,11 @@ import com.cloud.agent.api.Command;
|
|||||||
|
|
||||||
public class PrepareKickstartPxeServerCommand extends Command {
|
public class PrepareKickstartPxeServerCommand extends Command {
|
||||||
private String ksFile;
|
private String ksFile;
|
||||||
private String repo;
|
|
||||||
private String templateUuid;
|
private String templateUuid;
|
||||||
private String mac;
|
private String mac;
|
||||||
private String ksDevice;
|
private String ksDevice;
|
||||||
|
private String kernel;
|
||||||
|
private String initrd;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean executeInSequence() {
|
public boolean executeInSequence() {
|
||||||
@ -39,15 +40,23 @@ public class PrepareKickstartPxeServerCommand extends Command {
|
|||||||
public void setKsFile(String ksFile) {
|
public void setKsFile(String ksFile) {
|
||||||
this.ksFile = ksFile;
|
this.ksFile = ksFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRepo() {
|
public String getKernel() {
|
||||||
return repo;
|
return kernel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRepo(String repo) {
|
public void setKernel(String kernel) {
|
||||||
this.repo = repo;
|
this.kernel = kernel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getInitrd() {
|
||||||
|
return initrd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInitrd(String initrd) {
|
||||||
|
this.initrd = initrd;
|
||||||
|
}
|
||||||
|
|
||||||
public String getTemplateUuid() {
|
public String getTemplateUuid() {
|
||||||
return templateUuid;
|
return templateUuid;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,50 +21,55 @@ import tempfile
|
|||||||
import os.path
|
import os.path
|
||||||
import os
|
import os
|
||||||
|
|
||||||
iso_folder = ''
|
kernel = None
|
||||||
copy_to = ''
|
initrd = None
|
||||||
|
copy_to = None
|
||||||
|
|
||||||
def cmd(cmdstr, err=True):
|
def cmd(cmdstr, err=True):
|
||||||
|
print cmdstr
|
||||||
if os.system(cmdstr) != 0 and err:
|
if os.system(cmdstr) != 0 and err:
|
||||||
raise Exception("Failed to run shell command: %s" % cmdstr)
|
raise Exception("Failed to run shell command: %s" % cmdstr)
|
||||||
|
|
||||||
def prepare():
|
def prepare():
|
||||||
|
global kernel, initrd, copy_to
|
||||||
try:
|
try:
|
||||||
kernel = os.path.join(copy_to, "vmlinuz")
|
k = os.path.join(copy_to, "vmlinuz")
|
||||||
initrd = os.path.join(copy_to, "initrd.img")
|
i = os.path.join(copy_to, "initrd.img")
|
||||||
if os.path.exists(kernel) and os.path.exists(initrd):
|
if os.path.exists(k) and os.path.exists(i):
|
||||||
print "Having template(%s) prepared already, skip copying" % copy_to
|
print "Having template(%s) prepared already, skip copying" % copy_to
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
if not os.path.exists(copy_to):
|
if not os.path.exists(copy_to):
|
||||||
os.makedirs(copy_to)
|
os.makedirs(copy_to)
|
||||||
|
|
||||||
mnt_path = tempfile.mkdtemp()
|
|
||||||
try:
|
def copy_from_nfs(src, dst):
|
||||||
mnt = "mount %s %s" % (iso_folder, mnt_path)
|
mnt_path = tempfile.mkdtemp()
|
||||||
cmd(mnt)
|
try:
|
||||||
|
nfs_path = os.path.dirname(src)
|
||||||
kernel = os.path.join(mnt_path, "vmlinuz")
|
filename = os.path.basename(src)
|
||||||
initrd = os.path.join(mnt_path, "initrd.img")
|
t = os.path.join(mnt_path, filename)
|
||||||
cp = "cp -f %s %s/" % (kernel, copy_to)
|
mnt = "mount %s %s" % (nfs_path, mnt_path)
|
||||||
cmd(cp)
|
cmd(mnt)
|
||||||
cp = "cp -f %s %s/" % (initrd, copy_to)
|
cp = "cp -f %s %s" % (t, dst)
|
||||||
cmd(cp)
|
cmd(cp)
|
||||||
finally:
|
finally:
|
||||||
umnt = "umount %s" % mnt_path
|
umnt = "umount %s" % mnt_path
|
||||||
cmd(umnt, False)
|
cmd(umnt, False)
|
||||||
rm = "rm -r %s" % mnt_path
|
rm = "rm -r %s" % mnt_path
|
||||||
cmd(rm, False)
|
cmd(rm, False)
|
||||||
return 0
|
|
||||||
|
copy_from_nfs(kernel, copy_to)
|
||||||
|
copy_from_nfs(initrd, copy_to)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print e
|
print e
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) < 3:
|
if len(sys.argv) < 4:
|
||||||
print "Usage: prepare_kickstart_kerneal_initrd.py path_to_kernel_initrd_iso path_kernel_initrd_copy_to"
|
print "Usage: prepare_kickstart_kerneal_initrd.py path_to_kernel path_to_initrd path_kernel_initrd_copy_to"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
(iso_folder, copy_to) = sys.argv[1:]
|
(kernel, initrd, copy_to) = sys.argv[1:]
|
||||||
sys.exit(prepare())
|
sys.exit(prepare())
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user