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 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)) {
|
||||
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 {
|
||||
String tpl = profile.getTemplate().getUrl();
|
||||
assert tpl != null : "How can a null template get here!!!";
|
||||
String[] tpls = tpl.split(";");
|
||||
assert tpls.length == 2 : "Template is not correctly encoded. " + tpl;
|
||||
String[] tpls = tpl.split(";");
|
||||
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();
|
||||
cmd.setKsFile(tpls[0]);
|
||||
cmd.setRepo(tpls[1]);
|
||||
cmd.setKsFile(ks);
|
||||
cmd.setInitrd(initrd);
|
||||
cmd.setKernel(kernel);
|
||||
cmd.setMac(nic.getMacAddress());
|
||||
cmd.setTemplateUuid(template.getUuid());
|
||||
Answer aws = _agentMgr.send(pxeVo.getHostId(), cmd);
|
||||
|
||||
@ -22,10 +22,11 @@ import com.cloud.agent.api.Command;
|
||||
|
||||
public class PrepareKickstartPxeServerCommand extends Command {
|
||||
private String ksFile;
|
||||
private String repo;
|
||||
private String templateUuid;
|
||||
private String mac;
|
||||
private String ksDevice;
|
||||
private String ksDevice;
|
||||
private String kernel;
|
||||
private String initrd;
|
||||
|
||||
@Override
|
||||
public boolean executeInSequence() {
|
||||
@ -39,15 +40,23 @@ public class PrepareKickstartPxeServerCommand extends Command {
|
||||
public void setKsFile(String ksFile) {
|
||||
this.ksFile = ksFile;
|
||||
}
|
||||
|
||||
public String getRepo() {
|
||||
return repo;
|
||||
}
|
||||
|
||||
public void setRepo(String repo) {
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
|
||||
public String getKernel() {
|
||||
return kernel;
|
||||
}
|
||||
|
||||
public void setKernel(String kernel) {
|
||||
this.kernel = kernel;
|
||||
}
|
||||
|
||||
public String getInitrd() {
|
||||
return initrd;
|
||||
}
|
||||
|
||||
public void setInitrd(String initrd) {
|
||||
this.initrd = initrd;
|
||||
}
|
||||
|
||||
public String getTemplateUuid() {
|
||||
return templateUuid;
|
||||
}
|
||||
|
||||
@ -21,50 +21,55 @@ import tempfile
|
||||
import os.path
|
||||
import os
|
||||
|
||||
iso_folder = ''
|
||||
copy_to = ''
|
||||
kernel = None
|
||||
initrd = None
|
||||
copy_to = None
|
||||
|
||||
def cmd(cmdstr, err=True):
|
||||
print cmdstr
|
||||
if os.system(cmdstr) != 0 and err:
|
||||
raise Exception("Failed to run shell command: %s" % cmdstr)
|
||||
|
||||
def prepare():
|
||||
global kernel, initrd, copy_to
|
||||
try:
|
||||
kernel = os.path.join(copy_to, "vmlinuz")
|
||||
initrd = os.path.join(copy_to, "initrd.img")
|
||||
if os.path.exists(kernel) and os.path.exists(initrd):
|
||||
k = os.path.join(copy_to, "vmlinuz")
|
||||
i = os.path.join(copy_to, "initrd.img")
|
||||
if os.path.exists(k) and os.path.exists(i):
|
||||
print "Having template(%s) prepared already, skip copying" % copy_to
|
||||
return 0
|
||||
else:
|
||||
if not os.path.exists(copy_to):
|
||||
os.makedirs(copy_to)
|
||||
|
||||
mnt_path = tempfile.mkdtemp()
|
||||
try:
|
||||
mnt = "mount %s %s" % (iso_folder, mnt_path)
|
||||
cmd(mnt)
|
||||
|
||||
kernel = os.path.join(mnt_path, "vmlinuz")
|
||||
initrd = os.path.join(mnt_path, "initrd.img")
|
||||
cp = "cp -f %s %s/" % (kernel, copy_to)
|
||||
cmd(cp)
|
||||
cp = "cp -f %s %s/" % (initrd, copy_to)
|
||||
cmd(cp)
|
||||
finally:
|
||||
umnt = "umount %s" % mnt_path
|
||||
cmd(umnt, False)
|
||||
rm = "rm -r %s" % mnt_path
|
||||
cmd(rm, False)
|
||||
return 0
|
||||
|
||||
def copy_from_nfs(src, dst):
|
||||
mnt_path = tempfile.mkdtemp()
|
||||
try:
|
||||
nfs_path = os.path.dirname(src)
|
||||
filename = os.path.basename(src)
|
||||
t = os.path.join(mnt_path, filename)
|
||||
mnt = "mount %s %s" % (nfs_path, mnt_path)
|
||||
cmd(mnt)
|
||||
cp = "cp -f %s %s" % (t, dst)
|
||||
cmd(cp)
|
||||
finally:
|
||||
umnt = "umount %s" % mnt_path
|
||||
cmd(umnt, False)
|
||||
rm = "rm -r %s" % mnt_path
|
||||
cmd(rm, False)
|
||||
|
||||
copy_from_nfs(kernel, copy_to)
|
||||
copy_from_nfs(initrd, copy_to)
|
||||
except Exception, e:
|
||||
print e
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3:
|
||||
print "Usage: prepare_kickstart_kerneal_initrd.py path_to_kernel_initrd_iso path_kernel_initrd_copy_to"
|
||||
if len(sys.argv) < 4:
|
||||
print "Usage: prepare_kickstart_kerneal_initrd.py path_to_kernel path_to_initrd path_kernel_initrd_copy_to"
|
||||
sys.exit(1)
|
||||
|
||||
(iso_folder, copy_to) = sys.argv[1:]
|
||||
(kernel, initrd, copy_to) = sys.argv[1:]
|
||||
sys.exit(prepare())
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user