cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From frankzh...@apache.org
Subject [2/3] git commit: updated refs/heads/master to 1ee7e0c
Date Mon, 04 Aug 2014 21:58:18 GMT
CLOUDSTACK-6278
Baremetal Advanced Networking support


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

Branch: refs/heads/master
Commit: 44dff6c4262a98dc338a34b94f7b7062a070f441
Parents: 66fff6c
Author: Frank.Zhang <frank.zhang@citrix.com>
Authored: Wed Jul 30 14:33:57 2014 -0700
Committer: Frank.Zhang <frank.zhang@citrix.com>
Committed: Mon Aug 4 15:00:44 2014 -0700

----------------------------------------------------------------------
 .../manager/BareMetalTemplateAdapter.java       |  44 ++------
 .../BaremetalKickStartServiceImpl.java          | 104 +++++++++++-------
 .../BaremetalVirtualRouterCommands.java         | 106 +++++++++++++++++++
 .../BaremetalVritualRouterCommands.java         |  74 -------------
 server/src/com/cloud/configuration/Config.java  |  10 +-
 5 files changed, 190 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/44dff6c4/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java
b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java
index 3115a18..1be3439 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalTemplateAdapter.java
@@ -22,26 +22,11 @@
 // Automatically generated by addcopyright.py at 04/03/2012
 package com.cloud.baremetal.manager;
 
-import java.util.Date;
-import java.util.List;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
-import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
-import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
-import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
-
 import com.cloud.configuration.Resource.ResourceType;
 import com.cloud.dc.DataCenterVO;
 import com.cloud.event.EventTypes;
 import com.cloud.event.UsageEventVO;
 import com.cloud.exception.ResourceAllocationException;
-import com.cloud.host.Host;
-import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
 import com.cloud.resource.ResourceManager;
 import com.cloud.storage.TemplateProfile;
@@ -53,6 +38,16 @@ import com.cloud.template.TemplateAdapterBase;
 import com.cloud.user.Account;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
+import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
+import org.apache.cloudstack.api.command.user.template.RegisterTemplateCmd;
+import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
+import org.apache.log4j.Logger;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import java.util.Date;
+import java.util.List;
 
 @Local(value = TemplateAdapter.class)
 public class BareMetalTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter
{
@@ -69,24 +64,7 @@ public class BareMetalTemplateAdapter extends TemplateAdapterBase implements
Tem
 
     @Override
     public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException
{
-        TemplateProfile profile = super.prepare(cmd);
-
-        if (profile.getZoneId() == null || profile.getZoneId() == -1) {
-            List<DataCenterVO> dcs = _dcDao.listAllIncludingRemoved();
-            for (DataCenterVO dc : dcs) {
-                List<HostVO> pxeServers = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.BaremetalPxe,
dc.getId());
-                if (pxeServers.size() == 0) {
-                    throw new CloudRuntimeException("Please add PXE server before adding
baremetal template in zone " + dc.getName());
-                }
-            }
-        } else {
-            List<HostVO> pxeServers = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.BaremetalPxe,
profile.getZoneId());
-            if (pxeServers.size() == 0) {
-                throw new CloudRuntimeException("Please add PXE server before adding baremetal
template in zone " + profile.getZoneId());
-            }
-        }
-
-        return profile;
+        return super.prepare(cmd);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/44dff6c4/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 cc9fce7..f154a46 100755
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalKickStartServiceImpl.java
@@ -18,44 +18,22 @@
 // Automatically generated by addcopyright.py at 01/29/2013
 package com.cloud.baremetal.networkservice;
 
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-
-import com.cloud.dc.DataCenter;
-import com.cloud.exception.AgentUnavailableException;
-import com.cloud.exception.OperationTimedoutException;
-import com.cloud.hypervisor.Hypervisor;
-import com.cloud.network.Network;
-import com.cloud.network.guru.ControlNetworkGuru;
-import com.cloud.network.guru.NetworkGuru;
-import com.cloud.network.router.VirtualRouter;
-import com.cloud.vm.DomainRouterVO;
-import com.cloud.vm.NicVO;
-import com.cloud.vm.dao.DomainRouterDao;
-import com.cloud.vm.dao.NicDao;
-import org.apache.log4j.Logger;
-
-import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd;
-import org.apache.cloudstack.api.AddBaremetalPxeCmd;
-import org.apache.cloudstack.api.ListBaremetalPxeServersCmd;
-
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.baremetal.IpmISetBootDevCommand;
 import com.cloud.agent.api.baremetal.IpmISetBootDevCommand.BootDev;
 import com.cloud.baremetal.database.BaremetalPxeDao;
 import com.cloud.baremetal.database.BaremetalPxeVO;
 import com.cloud.baremetal.networkservice.BaremetalPxeManager.BaremetalPxeType;
+import com.cloud.configuration.Config;
+import com.cloud.dc.DataCenter;
 import com.cloud.deploy.DeployDestination;
+import com.cloud.exception.AgentUnavailableException;
+import com.cloud.exception.OperationTimedoutException;
 import com.cloud.host.Host;
 import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDetailsDao;
+import com.cloud.hypervisor.Hypervisor;
+import com.cloud.network.Network;
 import com.cloud.network.PhysicalNetworkServiceProvider;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.NetworkVO;
@@ -63,21 +41,44 @@ import com.cloud.network.dao.PhysicalNetworkDao;
 import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
 import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
 import com.cloud.network.dao.PhysicalNetworkVO;
+import com.cloud.network.guru.ControlNetworkGuru;
+import com.cloud.network.router.VirtualRouter;
 import com.cloud.resource.ResourceManager;
 import com.cloud.resource.ServerResource;
 import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.uservm.UserVm;
+import com.cloud.utils.Pair;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.db.QueryBuilder;
 import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.ssh.SshHelper;
+import com.cloud.vm.DomainRouterVO;
 import com.cloud.vm.NicProfile;
+import com.cloud.vm.NicVO;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VirtualMachineProfile;
-import org.springframework.web.client.RestTemplate;
+import com.cloud.vm.dao.DomainRouterDao;
+import com.cloud.vm.dao.NicDao;
+import org.apache.cloudstack.api.AddBaremetalKickStartPxeCmd;
+import org.apache.cloudstack.api.AddBaremetalPxeCmd;
+import org.apache.cloudstack.api.ListBaremetalPxeServersCmd;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.log4j.Logger;
 import org.springframework.web.util.UriComponentsBuilder;
 
+import javax.ejb.Local;
+import javax.inject.Inject;
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 @Local(value = BaremetalPxeService.class)
 public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase implements BaremetalPxeService
{
     private static final Logger s_logger = Logger.getLogger(BaremetalKickStartServiceImpl.class);
@@ -99,6 +100,8 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase
imple
     DomainRouterDao _routerDao;
     @Inject
     NicDao _nicDao;
+    @Inject
+    ConfigurationDao _configDao;
 
     private DomainRouterVO getVirtualRouter(Network network) {
         List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(),
VirtualRouter.Role.VIRTUAL_ROUTER);
@@ -155,6 +158,22 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase
imple
         return Arrays.asList(ks, kernel, initrd);
     }
 
+    private File getSystemVMKeyFile() {
+        URL url = this.getClass().getClassLoader().getResource("scripts/vm/systemvm/id_rsa.cloud");
+        File keyFile = null;
+        if (url != null) {
+            keyFile = new File(url.getPath());
+        }
+        if (keyFile == null || !keyFile.exists()) {
+            keyFile = new File("/usr/share/cloudstack-common/scripts/vm/systemvm/id_rsa.cloud");
+        }
+        assert (keyFile != null);
+        if (!keyFile.exists()) {
+            s_logger.error("Unable to locate id_rsa.cloud in your setup at " + keyFile.toString());
+        }
+        return keyFile;
+    }
+
     private boolean preparePxeInBasicZone(VirtualMachineProfile profile, NicProfile nic,
DeployDestination dest, ReservationContext context) throws AgentUnavailableException, OperationTimedoutException
{
         NetworkVO nwVO = _nwDao.findById(nic.getNetworkId());
         QueryBuilder<BaremetalPxeVO> sc = QueryBuilder.create(BaremetalPxeVO.class);
@@ -195,7 +214,7 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase
imple
         return ub.build().toUri();
     }
 
-    private boolean preparePxeInAdvancedZone(VirtualMachineProfile profile, NicProfile nic,
Network network, DeployDestination dest, ReservationContext context) {
+    private boolean preparePxeInAdvancedZone(VirtualMachineProfile profile, NicProfile nic,
Network network, DeployDestination dest, ReservationContext context) throws Exception {
         DomainRouterVO vr = getVirtualRouter(network);
         List<NicVO> nics = _nicDao.listByVmId(vr.getId());
         NicVO mgmtNic = null;
@@ -207,19 +226,24 @@ public class BaremetalKickStartServiceImpl extends BareMetalPxeServiceBase
imple
         }
 
         if (mgmtNic == null) {
-            throw new CloudRuntimeException(String.format("cannot find management nic on
virutal router[id:%s]", vr.getId()));
+            throw new CloudRuntimeException(String.format("cannot find management nic on
virtual router[id:%s]", vr.getId()));
         }
 
-        BaremetalVritualRouterCommands.PreparePxeCmd cmd = new BaremetalVritualRouterCommands.PreparePxeCmd();
         List<String> tuple =  parseKickstartUrl(profile);
-        cmd.setKickStartUrl(tuple.get(0));
-        cmd.setKernelUrl(tuple.get(1));
-        cmd.setInitrdUrl(tuple.get(2));
-        cmd.setGuestMac(nic.getMacAddress());
-        RestTemplate rst = new RestTemplate();
-        BaremetalVritualRouterCommands.PreparePxeRsp rsp = rst.getForObject(buildUrl(mgmtNic.getIp4Address(),
BaremetalVritualRouterCommands.PREPARE_PXE_URL), BaremetalVritualRouterCommands.PreparePxeRsp.class);
-        if (!rsp.isSuccess()) {
-            throw new CloudRuntimeException(String.format("failed preparing PXE in virtual
router[id:%s], because %s", vr.getId(), rsp.getError()));
+        Pair<Boolean, String> ret = SshHelper.sshExecute(mgmtNic.getIp4Address(), 3922,
"root", getSystemVMKeyFile(), null,
+                String.format("/usr/bin/prepare_pxe.sh %s %s %s %s %s", tuple.get(1), tuple.get(2),
profile.getTemplate().getUuid(),
+                        String.format("01-%s", nic.getMacAddress().replaceAll(":", "-")),
tuple.get(0))
+        );
+        if (!ret.first()) {
+            throw new CloudRuntimeException(String.format("failed preparing PXE in virtual
router[id:%s], because %s", vr.getId(), ret.second()));
+        }
+
+        String internalServerIp = _configDao.getValue(Config.BaremetalInternalStorageServer.key());
+        ret = SshHelper.sshExecute(mgmtNic.getIp4Address(), 3922, "root", getSystemVMKeyFile(),
null,
+                String.format("/usr/bin/baremetal_snat.sh %s %s", mgmtNic.getIp4Address(),
internalServerIp)
+        );
+        if (!ret.first()) {
+            throw new CloudRuntimeException(String.format("failed preparing PXE in virtual
router[id:%s], because %s", vr.getId(), ret.second()));
         }
 
         return true;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/44dff6c4/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalVirtualRouterCommands.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalVirtualRouterCommands.java
b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalVirtualRouterCommands.java
new file mode 100755
index 0000000..17a86c9
--- /dev/null
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalVirtualRouterCommands.java
@@ -0,0 +1,106 @@
+package com.cloud.baremetal.networkservice;
+
+/**
+ * Created by frank on 7/23/14.
+ */
+public class BaremetalVirtualRouterCommands {
+
+    public abstract static class AgentCommand {
+    }
+
+    public abstract static class AgentResponse {
+        private boolean success;
+        private String error;
+
+        public boolean isSuccess() {
+            return success;
+        }
+
+        public void setSuccess(boolean success) {
+            this.success = success;
+        }
+
+        public String getError() {
+            return error;
+        }
+
+        public void setError(String error) {
+            this.error = error;
+        }
+    }
+
+    public static class PreparePxeCmd extends AgentCommand {
+        private String guestMac;
+        private String templateUuid;
+        private String kickStartUrl;
+        private String initrdUrl;
+        private String kernelUrl;
+
+        public String getTemplateUuid() {
+            return templateUuid;
+        }
+
+        public void setTemplateUuid(String templateUuid) {
+            this.templateUuid = templateUuid;
+        }
+
+        public String getGuestMac() {
+            return guestMac;
+        }
+
+        public void setGuestMac(String guestMac) {
+            this.guestMac = guestMac;
+        }
+
+        public String getKickStartUrl() {
+            return kickStartUrl;
+        }
+
+        public void setKickStartUrl(String kickStartUrl) {
+            this.kickStartUrl = kickStartUrl;
+        }
+
+        public String getInitrdUrl() {
+            return initrdUrl;
+        }
+
+        public void setInitrdUrl(String initrdUrl) {
+            this.initrdUrl = initrdUrl;
+        }
+
+        public String getKernelUrl() {
+            return kernelUrl;
+        }
+
+        public void setKernelUrl(String kernelUrl) {
+            this.kernelUrl = kernelUrl;
+        }
+    }
+
+    public static class PreparePxeRsp extends AgentResponse {
+    }
+
+    public static class PrepareSourceNatCmd extends AgentCommand {
+        private String internalStorageServerIp;
+        private String managementNicIp;
+
+        public String getInternalStorageServerIp() {
+            return internalStorageServerIp;
+        }
+
+        public void setInternalStorageServerIp(String internalStorageServerIp) {
+            this.internalStorageServerIp = internalStorageServerIp;
+        }
+
+        public String getManagementNicIp() {
+            return managementNicIp;
+        }
+
+        public void setManagementNicIp(String managementNicIp) {
+            this.managementNicIp = managementNicIp;
+        }
+    }
+
+    public static class PrepareSourceNatRsp extends AgentResponse {
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/44dff6c4/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalVritualRouterCommands.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalVritualRouterCommands.java
b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalVritualRouterCommands.java
deleted file mode 100755
index 12bffd4..0000000
--- a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/networkservice/BaremetalVritualRouterCommands.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package com.cloud.baremetal.networkservice;
-
-/**
- * Created by frank on 7/23/14.
- */
-public class BaremetalVritualRouterCommands {
-    public static String PREPARE_PXE_URL = "/baremetal/pxe/prepare";
-
-    public abstract static class AgentCommand {
-    }
-
-    public abstract static class AgentResponse {
-        private boolean success;
-        private String error;
-
-        public boolean isSuccess() {
-            return success;
-        }
-
-        public void setSuccess(boolean success) {
-            this.success = success;
-        }
-
-        public String getError() {
-            return error;
-        }
-
-        public void setError(String error) {
-            this.error = error;
-        }
-    }
-
-    public static class PreparePxeCmd extends AgentCommand {
-        private String guestMac;
-        private String kickStartUrl;
-        private String initrdUrl;
-        private String kernelUrl;
-
-        public String getGuestMac() {
-            return guestMac;
-        }
-
-        public void setGuestMac(String guestMac) {
-            this.guestMac = guestMac;
-        }
-
-        public String getKickStartUrl() {
-            return kickStartUrl;
-        }
-
-        public void setKickStartUrl(String kickStartUrl) {
-            this.kickStartUrl = kickStartUrl;
-        }
-
-        public String getInitrdUrl() {
-            return initrdUrl;
-        }
-
-        public void setInitrdUrl(String initrdUrl) {
-            this.initrdUrl = initrdUrl;
-        }
-
-        public String getKernelUrl() {
-            return kernelUrl;
-        }
-
-        public void setKernelUrl(String kernelUrl) {
-            this.kernelUrl = kernelUrl;
-        }
-    }
-
-    public static class PreparePxeRsp extends AgentResponse {
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/44dff6c4/server/src/com/cloud/configuration/Config.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java
index 1fa3164..b499df5 100755
--- a/server/src/com/cloud/configuration/Config.java
+++ b/server/src/com/cloud/configuration/Config.java
@@ -1766,9 +1766,17 @@ public enum Config {
             ManagementServer.class,
             String.class,
             "baremetal.peer.hypervisor.type",
-            "XenServer",
+            "Vmware",
             "Hypervisor[Xenserver/KVM/VMWare] used to spring up virtual router for baremetal
instances. The cluster having this hypervisor type must be in the same zone with baremetal
cluster",
             null),
+    BaremetalInternalStorageServer(
+            "Advanced",
+            ManagementServer.class,
+            String.class,
+            "baremetal.internal.storage.server.ip",
+            null,
+            "the ip address of server that stores kickstart file, kernel, initrd, ISO for
advanced networking baremetal provisioning",
+            null),
     ExternalBaremetalSystemUrl(
             "Advanced",
             ManagementServer.class,


Mime
View raw message