incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@apache.org
Subject [31/44] git commit: refs/heads/marvin-refactor - CloudStack CLOUDSTACK-774 Supporting kickstart in CloudStack baremetal
Date Mon, 04 Mar 2013 13:43:00 GMT
CloudStack CLOUDSTACK-774
Supporting kickstart in CloudStack baremetal

make kikcstart working with ubuntu


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/31d6e546
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/31d6e546
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/31d6e546

Branch: refs/heads/marvin-refactor
Commit: 31d6e5465e8c395f310e9cfb5575b2207a8b6e4e
Parents: cec4d8b
Author: frank <frank.zhang@citrix.com>
Authored: Fri Mar 1 17:51:52 2013 -0800
Committer: frank <frank.zhang@citrix.com>
Committed: Fri Mar 1 17:55:49 2013 -0800

----------------------------------------------------------------------
 .../BaremetalKickStartPxeResource.java             |    2 +-
 .../BaremetalKickStartServiceImpl.java             |   33 ++++++++-
 .../PrepareKickstartPxeServerCommand.java          |   31 +++++---
 .../ping/prepare_kickstart_kernel_initrd.py        |   55 ++++++++-------
 4 files changed, 80 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/31d6e546/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java
b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java
index 2b9b140..58c6e86 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartPxeResource.java
@@ -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);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/31d6e546/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
index ba5fb0d..8a5ac78 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
@@ -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);

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/31d6e546/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/PrepareKickstartPxeServerCommand.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/PrepareKickstartPxeServerCommand.java
b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/PrepareKickstartPxeServerCommand.java
index 8951547..25dfeb7 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/PrepareKickstartPxeServerCommand.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/PrepareKickstartPxeServerCommand.java
@@ -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;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/31d6e546/scripts/network/ping/prepare_kickstart_kernel_initrd.py
----------------------------------------------------------------------
diff --git a/scripts/network/ping/prepare_kickstart_kernel_initrd.py b/scripts/network/ping/prepare_kickstart_kernel_initrd.py
index b234a62..ff61848 100755
--- a/scripts/network/ping/prepare_kickstart_kernel_initrd.py
+++ b/scripts/network/ping/prepare_kickstart_kernel_initrd.py
@@ -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())
     


Mime
View raw message