Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 62734D64A for ; Thu, 21 Feb 2013 23:44:18 +0000 (UTC) Received: (qmail 16997 invoked by uid 500); 21 Feb 2013 23:44:17 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 16914 invoked by uid 500); 21 Feb 2013 23:44:17 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 16710 invoked by uid 99); 21 Feb 2013 23:44:17 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Feb 2013 23:44:17 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 4A70482E63B; Thu, 21 Feb 2013 23:44:17 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: frankzhang@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [4/7] CloudStack CLOUDSTACK-774 Supporting kickstart in CloudStack baremetal Message-Id: <20130221234417.4A70482E63B@tyr.zones.apache.org> Date: Thu, 21 Feb 2013 23:44:17 +0000 (UTC) http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java b/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java deleted file mode 100755 index c534df1..0000000 --- a/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java +++ /dev/null @@ -1,250 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.baremetal; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.ejb.Local; -import javax.inject.Inject; -import javax.naming.ConfigurationException; - -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import com.cloud.agent.AgentManager; -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.StartupCommand; -import com.cloud.agent.api.StartupExternalDhcpCommand; -import com.cloud.agent.api.routing.DhcpEntryCommand; -import com.cloud.dc.DataCenter; -import com.cloud.dc.DataCenterVO; -import com.cloud.dc.HostPodVO; -import com.cloud.dc.dao.DataCenterDao; -import com.cloud.dc.dao.HostPodDao; -import com.cloud.deploy.DeployDestination; -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.host.Host; -import com.cloud.host.Host.Type; -import com.cloud.host.HostVO; -import com.cloud.host.dao.HostDao; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.network.Network; -import com.cloud.resource.ResourceManager; -import com.cloud.resource.ResourceStateAdapter; -import com.cloud.resource.ServerResource; -import com.cloud.resource.UnableDeleteHostException; -import com.cloud.utils.component.ManagerBase; -import com.cloud.utils.db.DB; -import com.cloud.utils.db.Transaction; -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.vm.NicProfile; -import com.cloud.vm.ReservationContext; -import com.cloud.vm.UserVmVO; -import com.cloud.vm.VirtualMachine; -import com.cloud.vm.VirtualMachineProfile; -import com.cloud.vm.dao.NicDao; -import com.cloud.vm.dao.UserVmDao; - -@Component -@Local(value = {ExternalDhcpManager.class}) -public class ExternalDhcpManagerImpl extends ManagerBase implements ExternalDhcpManager, ResourceStateAdapter { - private static final org.apache.log4j.Logger s_logger = Logger.getLogger(ExternalDhcpManagerImpl.class); - @Inject DataCenterDao _dcDao; - @Inject HostDao _hostDao; - @Inject AgentManager _agentMgr; - @Inject HostPodDao _podDao; - @Inject UserVmDao _userVmDao; - @Inject ResourceManager _resourceMgr; - @Inject NicDao _nicDao; - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); - return true; - } - - @Override - public boolean start() { - return true; - } - - @Override - public boolean stop() { - _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); - return true; - } - - protected String getDhcpServerGuid(String zoneId, String name, String ip) { - return zoneId + "-" + name + "-" + ip; - } - - - @Override @DB - public Host addDhcpServer(Long zoneId, Long podId, String type, String url, String username, String password) { - DataCenterVO zone = _dcDao.findById(zoneId); - if (zone == null) { - throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId); - } - - HostPodVO pod = _podDao.findById(podId); - if (pod == null) { - throw new InvalidParameterValueException("Could not find pod with ID: " + podId); - } - - List dhcps = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.ExternalDhcp, null, podId, zoneId); - if (dhcps.size() != 0) { - throw new InvalidParameterValueException("Already had a DHCP server in Pod: " + podId + " zone: " + zoneId); - } - - - String ipAddress = url; - String guid = getDhcpServerGuid(Long.toString(zoneId) + "-" + Long.toString(podId), "ExternalDhcp", ipAddress); - Map params = new HashMap(); - params.put("type", type); - params.put("zone", Long.toString(zoneId)); - params.put("pod", podId.toString()); - params.put("ip", ipAddress); - params.put("username", username); - params.put("password", password); - params.put("guid", guid); - params.put("pod", Long.toString(podId)); - params.put("gateway", pod.getGateway()); - String dns = zone.getDns1(); - if (dns == null) { - dns = zone.getDns2(); - } - params.put("dns", dns); - - ServerResource resource = null; - try { - if (type.equalsIgnoreCase(DhcpServerType.Dnsmasq.getName())) { - resource = new DnsmasqResource(); - resource.configure("Dnsmasq resource", params); - } else if (type.equalsIgnoreCase(DhcpServerType.Dhcpd.getName())) { - resource = new DhcpdResource(); - resource.configure("Dhcpd resource", params); - } else { - throw new CloudRuntimeException("Unsupport DHCP server " + type); - } - } catch (Exception e) { - s_logger.debug(e); - throw new CloudRuntimeException(e.getMessage()); - } - - Host dhcpServer = _resourceMgr.addHost(zoneId, resource, Host.Type.ExternalDhcp, params); - if (dhcpServer == null) { - throw new CloudRuntimeException("Cannot add external Dhcp server as a host"); - } - - Transaction txn = Transaction.currentTxn(); - txn.start(); - pod.setExternalDhcp(true); - _podDao.update(pod.getId(), pod); - txn.commit(); - return dhcpServer; - } - - @Override - public DhcpServerResponse getApiResponse(Host dhcpServer) { - DhcpServerResponse response = new DhcpServerResponse(); - response.setId(dhcpServer.getUuid()); - return response; - } - - private void prepareBareMetalDhcpEntry(NicProfile nic, DhcpEntryCommand cmd) { - Long vmId = nic.getVmId(); - UserVmVO vm = _userVmDao.findById(vmId); - if (vm == null || vm.getHypervisorType() != HypervisorType.BareMetal) { - s_logger.debug("VM " + vmId + " is not baremetal machine, skip preparing baremetal DHCP entry"); - return; - } - - List servers = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.PxeServer, null, vm.getPodIdToDeployIn(), vm.getDataCenterId()); - if (servers.size() != 1) { - throw new CloudRuntimeException("Wrong number of PXE server found in zone " + vm.getDataCenterId() - + " Pod " + vm.getPodIdToDeployIn() + ", number is " + servers.size()); - } - HostVO pxeServer = servers.get(0); - cmd.setNextServer(pxeServer.getPrivateIpAddress()); - s_logger.debug("Set next-server to " + pxeServer.getPrivateIpAddress() + " for VM " + vm.getId()); - } - - @Override - public boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile profile, DeployDestination dest, - ReservationContext context) throws ResourceUnavailableException { - Long zoneId = profile.getVirtualMachine().getDataCenterId(); - Long podId = profile.getVirtualMachine().getPodIdToDeployIn(); - List hosts = _resourceMgr.listAllUpAndEnabledHosts(Type.ExternalDhcp, null, podId, zoneId); - if (hosts.size() == 0) { - throw new CloudRuntimeException("No external Dhcp found in zone " + zoneId + " pod " + podId); - } - - if (hosts.size() > 1) { - throw new CloudRuntimeException("Something wrong, more than 1 external Dhcp found in zone " + zoneId + " pod " + podId); - } - - HostVO h = hosts.get(0); - String dns = nic.getDns1(); - if (dns == null) { - dns = nic.getDns2(); - } - DhcpEntryCommand dhcpCommand = new DhcpEntryCommand(nic.getMacAddress(), nic.getIp4Address(), profile.getVirtualMachine().getHostName(), null, dns, nic.getGateway(), null); - String errMsg = String.format("Set dhcp entry on external DHCP %1$s failed(ip=%2$s, mac=%3$s, vmname=%4$s)", - h.getPrivateIpAddress(), nic.getIp4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName()); - //prepareBareMetalDhcpEntry(nic, dhcpCommand); - try { - Answer ans = _agentMgr.send(h.getId(), dhcpCommand); - if (ans.getResult()) { - s_logger.debug(String.format("Set dhcp entry on external DHCP %1$s successfully(ip=%2$s, mac=%3$s, vmname=%4$s)", - h.getPrivateIpAddress(), nic.getIp4Address(), nic.getMacAddress(), profile.getVirtualMachine().getHostName())); - return true; - } else { - s_logger.debug(errMsg + " " + ans.getDetails()); - throw new ResourceUnavailableException(errMsg, DataCenter.class, zoneId); - } - } catch (Exception e) { - s_logger.debug(errMsg, e); - throw new ResourceUnavailableException(errMsg + e.getMessage(), DataCenter.class, zoneId); - } - } - - @Override - public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { - // TODO Auto-generated method stub - return null; - } - - @Override - public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map details, - List hostTags) { - if (!(startup[0] instanceof StartupExternalDhcpCommand)) { - return null; - } - - host.setType(Host.Type.ExternalDhcp); - return host; - } - - @Override - public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException { - // TODO Auto-generated method stub - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/ExternalDhcpResourceBase.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/baremetal/ExternalDhcpResourceBase.java b/server/src/com/cloud/baremetal/ExternalDhcpResourceBase.java deleted file mode 100644 index 937b4a7..0000000 --- a/server/src/com/cloud/baremetal/ExternalDhcpResourceBase.java +++ /dev/null @@ -1,198 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.baremetal; - -import java.util.HashMap; -import java.util.Map; - -import javax.naming.ConfigurationException; - -import org.apache.log4j.Logger; - -import com.cloud.agent.IAgentControl; -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.Command; -import com.cloud.agent.api.PingCommand; -import com.cloud.agent.api.PingRoutingCommand; -import com.cloud.agent.api.ReadyAnswer; -import com.cloud.agent.api.ReadyCommand; -import com.cloud.agent.api.StartupCommand; -import com.cloud.agent.api.StartupExternalDhcpCommand; -import com.cloud.agent.api.StartupPxeServerCommand; -import com.cloud.host.Host.Type; -import com.cloud.resource.ServerResource; -import com.cloud.utils.script.Script; -import com.cloud.utils.ssh.SSHCmdHelper; -import com.cloud.vm.VirtualMachine.State; -import com.trilead.ssh2.SCPClient; - -public class ExternalDhcpResourceBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(ExternalDhcpResourceBase.class); - String _name; - String _guid; - String _username; - String _password; - String _ip; - String _zoneId; - String _podId; - String _gateway; - String _dns; - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - _name = name; - _guid = (String)params.get("guid"); - _ip = (String)params.get("ip"); - _username = (String)params.get("username"); - _password = (String)params.get("password"); - _zoneId = (String)params.get("zone"); - _podId = (String)params.get("pod"); - _gateway = (String)params.get("gateway"); - _dns = (String)params.get("dns"); - - if (_guid == null) { - throw new ConfigurationException("No Guid specified"); - } - - if (_zoneId == null) { - throw new ConfigurationException("No Zone specified"); - } - - if (_podId == null) { - throw new ConfigurationException("No Pod specified"); - } - - if (_ip == null) { - throw new ConfigurationException("No IP specified"); - } - - if (_username == null) { - throw new ConfigurationException("No username specified"); - } - - if (_password == null) { - throw new ConfigurationException("No password specified"); - } - - if (_gateway == null) { - throw new ConfigurationException("No gateway specified"); - } - - if (_dns == null) { - throw new ConfigurationException("No dns specified"); - } - - return true; - } - - @Override - public boolean start() { - return true; - } - - @Override - public boolean stop() { - return true; - } - - @Override - public String getName() { - return _name; - } - - @Override - public Type getType() { - return Type.ExternalDhcp; - } - - @Override - public StartupCommand[] initialize() { - StartupExternalDhcpCommand cmd = new StartupExternalDhcpCommand(); - cmd.setName(_name); - cmd.setDataCenter(_zoneId); - cmd.setPod(_podId); - cmd.setPrivateIpAddress(_ip); - cmd.setStorageIpAddress(""); - cmd.setVersion(ExternalDhcpResourceBase.class.getPackage().getImplementationVersion()); - cmd.setGuid(_guid); - return new StartupCommand[]{cmd}; - } - - @Override - public PingCommand getCurrentStatus(long id) { - //TODO: check server - return new PingRoutingCommand(getType(), id, new HashMap()); - } - - protected ReadyAnswer execute(ReadyCommand cmd) { - s_logger.debug("External DHCP resource " + _name + " is ready"); - return new ReadyAnswer(cmd); - } - - @Override - public Answer executeRequest(Command cmd) { - if (cmd instanceof ReadyCommand) { - return execute((ReadyCommand) cmd); - } else { - return Answer.createUnsupportedCommandAnswer(cmd); - } - } - - @Override - public void disconnected() { - } - - @Override - public IAgentControl getAgentControl() { - return null; - } - - @Override - public void setAgentControl(IAgentControl agentControl) { - } - - @Override - public void setName(String name) { - // TODO Auto-generated method stub - - } - - @Override - public void setConfigParams(Map params) { - // TODO Auto-generated method stub - - } - - @Override - public Map getConfigParams() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getRunLevel() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void setRunLevel(int level) { - // TODO Auto-generated method stub - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/HttpCallException.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/baremetal/HttpCallException.java b/server/src/com/cloud/baremetal/HttpCallException.java deleted file mode 100644 index d21a37c..0000000 --- a/server/src/com/cloud/baremetal/HttpCallException.java +++ /dev/null @@ -1,28 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.baremetal; - -import com.cloud.utils.SerialVersionUID; - -import com.cloud.exception.CloudException; - -public class HttpCallException extends CloudException { - private static final long serialVersionUID= SerialVersionUID.HttpCallException; - public HttpCallException(String msg) { - super(msg); - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/PingPxeServerResource.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/baremetal/PingPxeServerResource.java b/server/src/com/cloud/baremetal/PingPxeServerResource.java deleted file mode 100755 index 6655fd8..0000000 --- a/server/src/com/cloud/baremetal/PingPxeServerResource.java +++ /dev/null @@ -1,196 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.baremetal; - -import java.util.HashMap; -import java.util.Map; - -import javax.naming.ConfigurationException; - -import org.apache.log4j.Logger; - -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.Command; -import com.cloud.agent.api.PingCommand; -import com.cloud.agent.api.PingRoutingCommand; -import com.cloud.agent.api.baremetal.PreparePxeServerAnswer; -import com.cloud.agent.api.baremetal.PreparePxeServerCommand; -import com.cloud.agent.api.baremetal.prepareCreateTemplateCommand; -import com.cloud.utils.script.Script; -import com.cloud.utils.ssh.SSHCmdHelper; -import com.cloud.vm.VirtualMachine.State; -import com.trilead.ssh2.SCPClient; - -public class PingPxeServerResource extends PxeServerResourceBase { - private static final Logger s_logger = Logger.getLogger(PingPxeServerResource.class); - String _storageServer; - String _pingDir; - String _share; - String _dir; - String _tftpDir; - String _cifsUserName; - String _cifsPassword; - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - super.configure(name, params); - - _storageServer = (String)params.get("storageServer"); - _pingDir = (String)params.get("pingDir"); - _tftpDir = (String)params.get("tftpDir"); - _cifsUserName = (String)params.get("cifsUserName"); - _cifsPassword = (String)params.get("cifsPassword"); - - if (_storageServer == null) { - throw new ConfigurationException("No stroage server specified"); - } - - if (_tftpDir == null) { - throw new ConfigurationException("No tftp directory specified"); - } - - if (_pingDir == null) { - throw new ConfigurationException("No PING directory specified"); - } - - if (_cifsUserName == null || _cifsUserName.equalsIgnoreCase("")) { - _cifsUserName = "xxx"; - } - - if (_cifsPassword == null || _cifsPassword.equalsIgnoreCase("")) { - _cifsPassword = "xxx"; - } - - String pingDirs[]= _pingDir.split("/"); - if (pingDirs.length != 2) { - throw new ConfigurationException("PING dir should have format like myshare/direcotry, eg: windows/64bit"); - } - _share = pingDirs[0]; - _dir = pingDirs[1]; - - com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22); - - s_logger.debug(String.format("Trying to connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******")); - try { - sshConnection.connect(null, 60000, 60000); - if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); - throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, - "******")); - } - - String cmd = String.format("[ -f /%1$s/pxelinux.0 ] && [ -f /%2$s/kernel ] && [ -f /%3$s/initrd.gz ] ", _tftpDir, _tftpDir, _tftpDir); - if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) { - throw new ConfigurationException("Miss files in TFTP directory at " + _tftpDir + " check if pxelinux.0, kernel initrd.gz are here"); - } - - SCPClient scp = new SCPClient(sshConnection); - String prepareScript = "scripts/network/ping/prepare_tftp_bootfile.py"; - String prepareScriptPath = Script.findScript("", prepareScript); - if (prepareScriptPath == null) { - throw new ConfigurationException("Can not find prepare_tftp_bootfile.py at " + prepareScriptPath); - } - scp.put(prepareScriptPath, "/usr/bin/", "0755"); - - return true; - } catch (Exception e) { - throw new ConfigurationException(e.getMessage()); - } finally { - if (sshConnection != null) { - sshConnection.close(); - } - } - } - - @Override - public PingCommand getCurrentStatus(long id) { - com.trilead.ssh2.Connection sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password); - if (sshConnection == null) { - return null; - } else { - SSHCmdHelper.releaseSshConnection(sshConnection); - return new PingRoutingCommand(getType(), id, new HashMap()); - } - } - - protected PreparePxeServerAnswer execute(PreparePxeServerCommand cmd) { - com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22); - try { - sshConnection.connect(null, 60000, 60000); - if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); - throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, - _password)); - } - - String script = String.format("python /usr/bin/prepare_tftp_bootfile.py restore %1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s %10$s %11$s", - _tftpDir, cmd.getMac(), _storageServer, _share, _dir, cmd.getTemplate(), _cifsUserName, _cifsPassword, cmd.getIp(), cmd.getNetMask(), cmd.getGateWay()); - s_logger.debug("Prepare Ping PXE server successfully"); - if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) { - return new PreparePxeServerAnswer(cmd, "prepare PING at " + _ip + " failed, command:" + script); - } - - return new PreparePxeServerAnswer(cmd); - } catch (Exception e){ - s_logger.debug("Prepare PING pxe server failed", e); - return new PreparePxeServerAnswer(cmd, e.getMessage()); - } finally { - if (sshConnection != null) { - sshConnection.close(); - } - } - } - - protected Answer execute(prepareCreateTemplateCommand cmd) { - com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(_ip, 22); - try { - sshConnection.connect(null, 60000, 60000); - if (!sshConnection.authenticateWithPassword(_username, _password)) { - s_logger.debug("SSH Failed to authenticate"); - throw new ConfigurationException(String.format("Cannot connect to PING PXE server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, - _password)); - } - - String script = String.format("python /usr/bin/prepare_tftp_bootfile.py backup %1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s %10$s %11$s", - _tftpDir, cmd.getMac(), _storageServer, _share, _dir, cmd.getTemplate(), _cifsUserName, _cifsPassword, cmd.getIp(), cmd.getNetMask(), cmd.getGateWay()); - s_logger.debug("Prepare for creating template successfully"); - if (!SSHCmdHelper.sshExecuteCmd(sshConnection, script)) { - return new Answer(cmd, false, "prepare for creating template failed, command:" + script); - } - - return new Answer(cmd, true, "Success"); - } catch (Exception e){ - s_logger.debug("Prepare for creating baremetal template failed", e); - return new Answer(cmd, false, e.getMessage()); - } finally { - if (sshConnection != null) { - sshConnection.close(); - } - } - } - - @Override - public Answer executeRequest(Command cmd) { - if (cmd instanceof PreparePxeServerCommand) { - return execute((PreparePxeServerCommand) cmd); - } else if (cmd instanceof prepareCreateTemplateCommand) { - return execute((prepareCreateTemplateCommand)cmd); - } else { - return super.executeRequest(cmd); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/PxeServerManager.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/baremetal/PxeServerManager.java b/server/src/com/cloud/baremetal/PxeServerManager.java deleted file mode 100644 index 1d2dde7..0000000 --- a/server/src/com/cloud/baremetal/PxeServerManager.java +++ /dev/null @@ -1,54 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.baremetal; - -import com.cloud.deploy.DeployDestination; -import com.cloud.host.Host; -import com.cloud.host.HostVO; -import com.cloud.uservm.UserVm; -import com.cloud.utils.component.Manager; -import com.cloud.vm.ReservationContext; -import com.cloud.vm.UserVmVO; -import com.cloud.vm.VirtualMachineProfile; - -public interface PxeServerManager extends Manager { - public static class PxeServerType { - private String _name; - - public static final PxeServerType PING = new PxeServerType("PING"); - public static final PxeServerType DMCD = new PxeServerType("DMCD"); - - public PxeServerType(String name) { - _name = name; - } - - public String getName() { - return _name; - } - - } - - public PxeServerResponse getApiResponse(Host pxeServer); - - public boolean prepare(PxeServerType type, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context, Long pxeServerId); - - Host addPxeServer(PxeServerProfile profile); - - public boolean prepareCreateTemplate(PxeServerType type, Long pxeServerId, UserVm vm, String templateUrl); - - public PxeServerType getPxeServerType(HostVO host); -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/PxeServerManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/baremetal/PxeServerManagerImpl.java b/server/src/com/cloud/baremetal/PxeServerManagerImpl.java deleted file mode 100755 index f45b275..0000000 --- a/server/src/com/cloud/baremetal/PxeServerManagerImpl.java +++ /dev/null @@ -1,145 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.baremetal; - - -import java.util.List; -import java.util.Map; - -import javax.ejb.Local; -import javax.inject.Inject; -import javax.naming.ConfigurationException; - -import org.apache.log4j.Logger; -import org.springframework.stereotype.Component; - -import com.cloud.agent.AgentManager; -import com.cloud.agent.api.StartupCommand; -import com.cloud.agent.api.StartupPxeServerCommand; -import com.cloud.baremetal.PxeServerManager.PxeServerType; -import com.cloud.dc.dao.DataCenterDao; -import com.cloud.deploy.DeployDestination; -import com.cloud.host.Host; -import com.cloud.host.HostVO; -import com.cloud.host.dao.HostDao; -import com.cloud.resource.ResourceManager; -import com.cloud.resource.ResourceStateAdapter; -import com.cloud.resource.ServerResource; -import com.cloud.resource.UnableDeleteHostException; -import com.cloud.uservm.UserVm; -import com.cloud.utils.component.AdapterBase; -import com.cloud.utils.component.ManagerBase; -import com.cloud.utils.exception.CloudRuntimeException; -import com.cloud.vm.ReservationContext; -import com.cloud.vm.UserVmVO; -import com.cloud.vm.VirtualMachineProfile; -import com.cloud.vm.VirtualMachineProfile.Param; - -@Component -@Local(value = {PxeServerManager.class}) -public class PxeServerManagerImpl extends ManagerBase implements PxeServerManager, ResourceStateAdapter { - private static final org.apache.log4j.Logger s_logger = Logger.getLogger(PxeServerManagerImpl.class); - @Inject DataCenterDao _dcDao; - @Inject HostDao _hostDao; - @Inject AgentManager _agentMgr; - @Inject ExternalDhcpManager exDhcpMgr; - @Inject ResourceManager _resourceMgr; - - // @com.cloud.utils.component.Inject(adapter=PxeServerService.class) - @Inject protected List _services; - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this); - return true; - } - - @Override - public boolean start() { - return true; - } - - @Override - public boolean stop() { - _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName()); - return true; - } - - protected PxeServerService getServiceByType(String type) { - PxeServerService _service; - _service = AdapterBase.getAdapterByName(_services, type); - if (_service == null) { - throw new CloudRuntimeException("Cannot find PXE service for " + type); - } - return _service; - } - - - @Override - public Host addPxeServer(PxeServerProfile profile) { - return getServiceByType(profile.getType()).addPxeServer(profile); - } - - @Override - public PxeServerResponse getApiResponse(Host pxeServer) { - PxeServerResponse response = new PxeServerResponse(); - response.setId(pxeServer.getUuid()); - return response; - } - - @Override - public boolean prepare(PxeServerType type, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context, Long pxeServerId) { - return getServiceByType(type.getName()).prepare(profile, dest, context, pxeServerId); - } - - @Override - public boolean prepareCreateTemplate(PxeServerType type, Long pxeServerId, UserVm vm, String templateUrl) { - return getServiceByType(type.getName()).prepareCreateTemplate(pxeServerId, vm, templateUrl); - } - - @Override - public PxeServerType getPxeServerType(HostVO host) { - if (host.getResource().equalsIgnoreCase(PingPxeServerResource.class.getName())) { - return PxeServerType.PING; - } else { - throw new CloudRuntimeException("Unkown PXE server resource " + host.getResource()); - } - } - - @Override - public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { - // TODO Auto-generated method stub - return null; - } - - @Override - public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map details, - List hostTags) { - if (!(startup[0] instanceof StartupPxeServerCommand)) { - return null; - } - - host.setType(Host.Type.PxeServer); - return host; - } - - @Override - public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException { - // TODO Auto-generated method stub - return null; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/PxeServerProfile.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/baremetal/PxeServerProfile.java b/server/src/com/cloud/baremetal/PxeServerProfile.java deleted file mode 100644 index e289adf..0000000 --- a/server/src/com/cloud/baremetal/PxeServerProfile.java +++ /dev/null @@ -1,90 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.baremetal; - -public class PxeServerProfile { - Long zoneId; - Long podId; - String url; - String username; - String password; - String type; - String pingStorageServerIp; - String pingDir; - String tftpDir; - String pingCifsUserName; - String pingCifspassword; - - public PxeServerProfile (Long zoneId, Long podId, String url, String username, String password, String type, - String pingStorageServerIp, String pingDir, String tftpDir, String pingCifsUserName, String pingCifsPassword) { - this.zoneId = zoneId; - this.podId = podId; - this.url = url; - this.username = username; - this.password = password; - this.type = type; - this.pingStorageServerIp = pingStorageServerIp; - this.pingDir = pingDir; - this.tftpDir = tftpDir; - this.pingCifsUserName = pingCifsUserName; - this.pingCifspassword = pingCifsPassword; - } - - public Long getZoneId() { - return zoneId; - } - - public Long getPodId() { - return podId; - } - - public String getUrl() { - return url; - } - - public String getUsername() { - return username; - } - - public String getPassword() { - return password; - } - - public String getType() { - return type; - } - - public String getPingStorageServerIp() { - return pingStorageServerIp; - } - - public String getPingDir() { - return pingDir; - } - - public String getTftpDir() { - return tftpDir; - } - - public String getPingCifsUserName() { - return pingCifsUserName; - } - - public String getPingCifspassword() { - return pingCifspassword; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/PxeServerResourceBase.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/baremetal/PxeServerResourceBase.java b/server/src/com/cloud/baremetal/PxeServerResourceBase.java deleted file mode 100644 index 4df5ea8..0000000 --- a/server/src/com/cloud/baremetal/PxeServerResourceBase.java +++ /dev/null @@ -1,185 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.baremetal; - -import java.util.Map; - -import javax.naming.ConfigurationException; - -import org.apache.log4j.Logger; - -import com.cloud.agent.IAgentControl; -import com.cloud.agent.api.Answer; -import com.cloud.agent.api.Command; -import com.cloud.agent.api.PingCommand; -import com.cloud.agent.api.ReadyAnswer; -import com.cloud.agent.api.ReadyCommand; -import com.cloud.agent.api.StartupCommand; -import com.cloud.agent.api.StartupPxeServerCommand; -import com.cloud.host.Host.Type; -import com.cloud.resource.ServerResource; - -public class PxeServerResourceBase implements ServerResource { - private static final Logger s_logger = Logger.getLogger(PxeServerResourceBase.class); - String _name; - String _guid; - String _username; - String _password; - String _ip; - String _zoneId; - String _podId; - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - _name = name; - _guid = (String)params.get("guid"); - _ip = (String)params.get("ip"); - _username = (String)params.get("username"); - _password = (String)params.get("password"); - _zoneId = (String)params.get("zone"); - _podId = (String)params.get("pod"); - - if (_guid == null) { - throw new ConfigurationException("No Guid specified"); - } - - if (_zoneId == null) { - throw new ConfigurationException("No Zone specified"); - } - - if (_podId == null) { - throw new ConfigurationException("No Pod specified"); - } - - if (_ip == null) { - throw new ConfigurationException("No IP specified"); - } - - if (_username == null) { - throw new ConfigurationException("No username specified"); - } - - if (_password == null) { - throw new ConfigurationException("No password specified"); - } - - return true; - } - - protected ReadyAnswer execute(ReadyCommand cmd) { - s_logger.debug("Pxe resource " + _name + " is ready"); - return new ReadyAnswer(cmd); - } - - @Override - public boolean start() { - return true; - } - - @Override - public boolean stop() { - return true; - } - - @Override - public String getName() { - // TODO Auto-generated method stub - return _name; - } - - @Override - public Type getType() { - return Type.PxeServer; - } - - @Override - public StartupCommand[] initialize() { - StartupPxeServerCommand cmd = new StartupPxeServerCommand(); - cmd.setName(_name); - cmd.setDataCenter(_zoneId); - cmd.setPod(_podId); - cmd.setPrivateIpAddress(_ip); - cmd.setStorageIpAddress(""); - cmd.setVersion(PxeServerResourceBase.class.getPackage().getImplementationVersion()); - cmd.setGuid(_guid); - return new StartupCommand[]{cmd}; - } - - @Override - public PingCommand getCurrentStatus(long id) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void disconnected() { - // TODO Auto-generated method stub - - } - - @Override - public IAgentControl getAgentControl() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void setAgentControl(IAgentControl agentControl) { - // TODO Auto-generated method stub - - } - - @Override - public Answer executeRequest(Command cmd) { - if (cmd instanceof ReadyCommand) { - return execute((ReadyCommand) cmd); - } else { - return Answer.createUnsupportedCommandAnswer(cmd); - } - } - - @Override - public void setName(String name) { - // TODO Auto-generated method stub - - } - - @Override - public void setConfigParams(Map params) { - // TODO Auto-generated method stub - - } - - @Override - public Map getConfigParams() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getRunLevel() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public void setRunLevel(int level) { - // TODO Auto-generated method stub - - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/PxeServerResponse.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/baremetal/PxeServerResponse.java b/server/src/com/cloud/baremetal/PxeServerResponse.java deleted file mode 100644 index 32fcc7f..0000000 --- a/server/src/com/cloud/baremetal/PxeServerResponse.java +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.baremetal; - -import org.apache.cloudstack.api.ApiConstants; -import org.apache.cloudstack.api.BaseResponse; -import com.cloud.serializer.Param; -import com.google.gson.annotations.SerializedName; - -public class PxeServerResponse extends BaseResponse { - @SerializedName(ApiConstants.ID) @Param(description="the ID of the PXE server") - private String id; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/PxeServerService.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/baremetal/PxeServerService.java b/server/src/com/cloud/baremetal/PxeServerService.java deleted file mode 100644 index 0a99184..0000000 --- a/server/src/com/cloud/baremetal/PxeServerService.java +++ /dev/null @@ -1,35 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.baremetal; - -import com.cloud.baremetal.PxeServerManager.PxeServerType; -import com.cloud.deploy.DeployDestination; -import com.cloud.host.Host; -import com.cloud.uservm.UserVm; -import com.cloud.utils.component.Adapter; -import com.cloud.vm.ReservationContext; -import com.cloud.vm.UserVmVO; -import com.cloud.vm.VirtualMachineProfile; - -public interface PxeServerService extends Adapter { - - public Host addPxeServer(PxeServerProfile profile); - - public boolean prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context, Long pxeServerId); - - public boolean prepareCreateTemplate(Long pxeServerId, UserVm vm, String templateUrl); -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/deploy/AbstractDeployPlannerSelector.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/deploy/AbstractDeployPlannerSelector.java b/server/src/com/cloud/deploy/AbstractDeployPlannerSelector.java new file mode 100755 index 0000000..1dab6c1 --- /dev/null +++ b/server/src/com/cloud/deploy/AbstractDeployPlannerSelector.java @@ -0,0 +1,58 @@ +package com.cloud.deploy; + +import java.util.Map; + +import javax.naming.ConfigurationException; + +import com.cloud.vm.UserVmVO; + +public abstract class AbstractDeployPlannerSelector implements DeployPlannerSelector { + protected Map params; + protected String name; + protected int runLevel; + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public void setConfigParams(Map params) { + this.params = params; + } + + @Override + public Map getConfigParams() { + return params; + } + + @Override + public int getRunLevel() { + return runLevel; + } + + @Override + public void setRunLevel(int level) { + this.runLevel = level; + } + + @Override + public boolean configure(String name, Map params) throws ConfigurationException { + return true; + } + + @Override + public boolean start() { + return true; + } + + @Override + public boolean stop() { + return true; + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/deploy/BareMetalPlanner.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/deploy/BareMetalPlanner.java b/server/src/com/cloud/deploy/BareMetalPlanner.java deleted file mode 100755 index 829a466..0000000 --- a/server/src/com/cloud/deploy/BareMetalPlanner.java +++ /dev/null @@ -1,163 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.deploy; - -import java.util.List; -import java.util.Map; - -import javax.ejb.Local; -import javax.inject.Inject; -import javax.naming.ConfigurationException; - -import org.apache.log4j.Logger; - -import com.cloud.capacity.CapacityManager; -import com.cloud.configuration.Config; -import com.cloud.configuration.dao.ConfigurationDao; -import com.cloud.dc.ClusterVO; -import com.cloud.dc.DataCenter; -import com.cloud.dc.Pod; -import com.cloud.dc.dao.ClusterDao; -import com.cloud.dc.dao.DataCenterDao; -import com.cloud.dc.dao.HostPodDao; -import com.cloud.exception.InsufficientServerCapacityException; -import com.cloud.host.Host; -import com.cloud.host.HostVO; -import com.cloud.host.dao.HostDao; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.offering.ServiceOffering; -import com.cloud.org.Cluster; -import com.cloud.resource.ResourceManager; -import com.cloud.utils.NumbersUtil; -import com.cloud.utils.component.AdapterBase; -import com.cloud.vm.VirtualMachine; -import com.cloud.vm.VirtualMachineProfile; - -@Local(value=DeploymentPlanner.class) -public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner { - private static final Logger s_logger = Logger.getLogger(BareMetalPlanner.class); - @Inject protected DataCenterDao _dcDao; - @Inject protected HostPodDao _podDao; - @Inject protected ClusterDao _clusterDao; - @Inject protected HostDao _hostDao; - @Inject protected ConfigurationDao _configDao; - @Inject protected CapacityManager _capacityMgr; - @Inject protected ResourceManager _resourceMgr; - - @Override - public DeployDestination plan(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException { - VirtualMachine vm = vmProfile.getVirtualMachine(); - ServiceOffering offering = vmProfile.getServiceOffering(); - String hostTag = null; - - String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key()); - float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1); - - String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag); - - if (vm.getLastHostId() != null && haVmTag == null) { - HostVO h = _hostDao.findById(vm.getLastHostId()); - DataCenter dc = _dcDao.findById(h.getDataCenterId()); - Pod pod = _podDao.findById(h.getPodId()); - Cluster c = _clusterDao.findById(h.getClusterId()); - s_logger.debug("Start baremetal vm " + vm.getId() + " on last stayed host " + h.getId()); - return new DeployDestination(dc, pod, c, h); - } - - if (haVmTag != null) { - hostTag = haVmTag; - } else if (offering.getHostTag() != null) { - String[] tags = offering.getHostTag().split(","); - if (tags.length > 0) { - hostTag = tags[0]; - } - } - - List clusters = _clusterDao.listByDcHyType(vm.getDataCenterId(), HypervisorType.BareMetal.toString()); - int cpu_requested; - long ram_requested; - HostVO target = null; - List hosts; - for (ClusterVO cluster : clusters) { - hosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId()); - if (hostTag != null) { - for (HostVO h : hosts) { - _hostDao.loadDetails(h); - if (h.getDetail("hostTag") != null && h.getDetail("hostTag").equalsIgnoreCase(hostTag)) { - target = h; - break; - } - } - } - } - - if (target == null) { - s_logger.warn("Cannot find host with tag " + hostTag + " use capacity from service offering"); - cpu_requested = offering.getCpu() * offering.getSpeed(); - ram_requested = offering.getRamSize() * 1024 * 1024; - } else { - cpu_requested = target.getCpus() * target.getSpeed().intValue(); - ram_requested = target.getTotalMemory(); - } - - for (ClusterVO cluster : clusters) { - if (haVmTag == null) { - hosts = _resourceMgr.listAllUpAndEnabledNonHAHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId()); - } else { - s_logger.warn("Cannot find HA host with tag " + haVmTag + " in cluster id=" + cluster.getId() + ", pod id=" + cluster.getPodId() + ", data center id=" + cluster.getDataCenterId()); - return null; - } - for (HostVO h : hosts) { - if (_capacityMgr.checkIfHostHasCapacity(h.getId(), cpu_requested, ram_requested, false, cpuOverprovisioningFactor, true)) { - s_logger.debug("Find host " + h.getId() + " has enough capacity"); - DataCenter dc = _dcDao.findById(h.getDataCenterId()); - Pod pod = _podDao.findById(h.getPodId()); - return new DeployDestination(dc, pod, cluster, h); - } - } - } - - s_logger.warn(String.format("Cannot find enough capacity(requested cpu=%1$s memory=%2$s)", cpu_requested, ram_requested)); - return null; - } - - @Override - public boolean canHandle(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) { - return vm.getHypervisorType() == HypervisorType.BareMetal; - } - - @Override - public boolean configure(String name, Map params) throws ConfigurationException { - return true; - } - - @Override - public boolean start() { - return true; - } - - @Override - public boolean stop() { - return true; - } - - @Override - public boolean check(VirtualMachineProfile vm, DeploymentPlan plan, DeployDestination dest, ExcludeList exclude) { - // TODO Auto-generated method stub - return false; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/deploy/DeployPlannerSelector.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/deploy/DeployPlannerSelector.java b/server/src/com/cloud/deploy/DeployPlannerSelector.java new file mode 100755 index 0000000..9154bc9 --- /dev/null +++ b/server/src/com/cloud/deploy/DeployPlannerSelector.java @@ -0,0 +1,8 @@ +package com.cloud.deploy; + +import com.cloud.utils.component.Adapter; +import com.cloud.vm.UserVmVO; + +public interface DeployPlannerSelector extends Adapter { + String selectPlanner(UserVmVO vm); +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/deploy/HypervisorVmPlannerSelector.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/deploy/HypervisorVmPlannerSelector.java b/server/src/com/cloud/deploy/HypervisorVmPlannerSelector.java new file mode 100755 index 0000000..de64e1c --- /dev/null +++ b/server/src/com/cloud/deploy/HypervisorVmPlannerSelector.java @@ -0,0 +1,17 @@ +package com.cloud.deploy; + +import javax.ejb.Local; + +import com.cloud.hypervisor.Hypervisor.HypervisorType; +import com.cloud.vm.UserVmVO; + +@Local(value = {DeployPlannerSelector.class}) +public class HypervisorVmPlannerSelector extends AbstractDeployPlannerSelector { + @Override + public String selectPlanner(UserVmVO vm) { + if (vm.getHypervisorType() != HypervisorType.BareMetal) { + return "FirstFitPlanner"; + } + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/host/dao/HostDaoImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/host/dao/HostDaoImpl.java b/server/src/com/cloud/host/dao/HostDaoImpl.java index c03611d..697c3dc 100755 --- a/server/src/com/cloud/host/dao/HostDaoImpl.java +++ b/server/src/com/cloud/host/dao/HostDaoImpl.java @@ -491,7 +491,7 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao txn.start(); SearchCriteria sc = UnmanagedApplianceSearch.create(); sc.setParameters("lastPinged", lastPingSecondsAfter); - sc.setParameters("types", Type.ExternalDhcp, Type.ExternalFirewall, Type.ExternalLoadBalancer, Type.PxeServer, Type.TrafficMonitor, Type.L2Networking); + sc.setParameters("types", Type.ExternalDhcp, Type.ExternalFirewall, Type.ExternalLoadBalancer, Type.BaremetalDhcp, Type.BaremetalPxe, Type.TrafficMonitor, Type.L2Networking); List hosts = lockRows(sc, null, true); for (HostVO host : hosts) { http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java index e2382f8..014db59 100755 --- a/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java +++ b/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java @@ -25,7 +25,6 @@ import java.util.concurrent.ScheduledExecutorService; import javax.ejb.Local; import javax.inject.Inject; -import javax.naming.ConfigurationException; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.command.admin.network.AddNetworkDeviceCmd; @@ -37,14 +36,7 @@ import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.cloud.agent.AgentManager; -import com.cloud.api.ApiDBUtils; -import com.cloud.baremetal.ExternalDhcpManager; -import com.cloud.baremetal.PxeServerManager; -import com.cloud.baremetal.PxeServerManager.PxeServerType; -import com.cloud.baremetal.PxeServerProfile; import com.cloud.configuration.dao.ConfigurationDao; -import com.cloud.dc.DataCenter; -import com.cloud.dc.Pod; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.VlanDao; import com.cloud.host.Host; @@ -63,8 +55,6 @@ import com.cloud.network.dao.PhysicalNetworkServiceProviderDao; import com.cloud.network.dao.VpnUserDao; import com.cloud.network.rules.dao.PortForwardingRulesDao; import com.cloud.offerings.dao.NetworkOfferingDao; -import com.cloud.server.api.response.NwDeviceDhcpResponse; -import com.cloud.server.api.response.PxePingResponse; import com.cloud.user.AccountManager; import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserStatisticsDao; @@ -77,8 +67,6 @@ import com.cloud.vm.dao.NicDao; @Local(value = {ExternalNetworkDeviceManager.class}) public class ExternalNetworkDeviceManagerImpl extends ManagerBase implements ExternalNetworkDeviceManager { - @Inject ExternalDhcpManager _dhcpMgr; - @Inject PxeServerManager _pxeMgr; @Inject AgentManager _agentMgr; @Inject NetworkModel _networkMgr; @Inject HostDao _hostDao; @@ -121,80 +109,12 @@ public class ExternalNetworkDeviceManagerImpl extends ManagerBase implements Ext Collection paramsCollection = paramList.values(); HashMap params = (HashMap) (paramsCollection.toArray())[0]; - if (cmd.getDeviceType().equalsIgnoreCase(NetworkDevice.ExternalDhcp.getName())) { - //Long zoneId = _identityService.getIdentityId("data_center", (String) params.get(ApiConstants.ZONE_ID)); - //Long podId = _identityService.getIdentityId("host_pod_ref", (String)params.get(ApiConstants.POD_ID)); - Long zoneId = Long.valueOf((String) params.get(ApiConstants.ZONE_ID)); - Long podId = Long.valueOf((String)params.get(ApiConstants.POD_ID)); - String type = (String) params.get(ApiConstants.DHCP_SERVER_TYPE); - String url = (String) params.get(ApiConstants.URL); - String username = (String) params.get(ApiConstants.USERNAME); - String password = (String) params.get(ApiConstants.PASSWORD); - - return _dhcpMgr.addDhcpServer(zoneId, podId, type, url, username, password); - } else if (cmd.getDeviceType().equalsIgnoreCase(NetworkDevice.PxeServer.getName())) { - Long zoneId = Long.parseLong((String) params.get(ApiConstants.ZONE_ID)); - Long podId = Long.parseLong((String)params.get(ApiConstants.POD_ID)); - //Long zoneId = _identityService.getIdentityId("data_center", (String) params.get(ApiConstants.ZONE_ID)); - //Long podId = _identityService.getIdentityId("host_pod_ref", (String)params.get(ApiConstants.POD_ID)); - String type = (String) params.get(ApiConstants.PXE_SERVER_TYPE); - String url = (String) params.get(ApiConstants.URL); - String username = (String) params.get(ApiConstants.USERNAME); - String password = (String) params.get(ApiConstants.PASSWORD); - String pingStorageServerIp = (String) params.get(ApiConstants.PING_STORAGE_SERVER_IP); - String pingDir = (String) params.get(ApiConstants.PING_DIR); - String tftpDir = (String) params.get(ApiConstants.TFTP_DIR); - String pingCifsUsername = (String) params.get(ApiConstants.PING_CIFS_USERNAME); - String pingCifsPassword = (String) params.get(ApiConstants.PING_CIFS_PASSWORD); - PxeServerProfile profile = new PxeServerProfile(zoneId, podId, url, username, password, type, pingStorageServerIp, pingDir, tftpDir, - pingCifsUsername, pingCifsPassword); - return _pxeMgr.addPxeServer(profile); - } else { - throw new CloudRuntimeException("Unsupported network device type:" + cmd.getDeviceType()); - } + return null; } @Override public NetworkDeviceResponse getApiResponse(Host device) { - NetworkDeviceResponse response; - HostVO host = (HostVO)device; - _hostDao.loadDetails(host); - if (host.getType() == Host.Type.ExternalDhcp) { - NwDeviceDhcpResponse r = new NwDeviceDhcpResponse(); - r.setZoneId(host.getDataCenterId()); - r.setPodId(host.getPodId()); - r.setUrl(host.getPrivateIpAddress()); - r.setType(host.getDetail("type")); - response = r; - } else if (host.getType() == Host.Type.PxeServer) { - String pxeType = host.getDetail("type"); - if (pxeType.equalsIgnoreCase(PxeServerType.PING.getName())) { - PxePingResponse r = new PxePingResponse(); - DataCenter zone = ApiDBUtils.findZoneById(host.getDataCenterId()); - if (zone != null) { - r.setZoneId(zone.getUuid()); - } - if (host.getPodId() != null) { - Pod pod = ApiDBUtils.findPodById(host.getPodId()); - if (pod != null) { - r.setPodId(pod.getUuid()); - } - } - r.setUrl(host.getPrivateIpAddress()); - r.setType(pxeType); - r.setStorageServerIp(host.getDetail("storageServer")); - r.setPingDir(host.getDetail("pingDir")); - r.setTftpDir(host.getDetail("tftpDir")); - response = r; - } else { - throw new CloudRuntimeException("Unsupported PXE server type:" + pxeType); - } - } else { - throw new CloudRuntimeException("Unsupported network device type:" + host.getType()); - } - - response.setId(device.getUuid()); - return response; + return null; } private List listNetworkDevice(Long zoneId, Long physicalNetworkId, Long podId, Host.Type type) { http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/network/NetworkManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 2e19fa1..1f7e1fd 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -1517,7 +1517,7 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L DeployDestination dest, ReservationContext context) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { element.prepare(network, profile, vmProfile, dest, context); - if (vmProfile.getType() == Type.User && vmProfile.getHypervisorType() != HypervisorType.BareMetal && element.getProvider() != null) { + if (vmProfile.getType() == Type.User && element.getProvider() != null) { if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Dhcp) && _networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.Dhcp, element.getProvider()) && (element instanceof DhcpServiceProvider)) { http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/network/element/BareMetalElement.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/element/BareMetalElement.java b/server/src/com/cloud/network/element/BareMetalElement.java deleted file mode 100644 index 553fe1d..0000000 --- a/server/src/com/cloud/network/element/BareMetalElement.java +++ /dev/null @@ -1,128 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.network.element; - -import java.util.Map; -import java.util.Set; - -import javax.ejb.Local; -import javax.inject.Inject; - -import org.apache.log4j.Logger; - -import com.cloud.baremetal.ExternalDhcpManager; -import com.cloud.deploy.DeployDestination; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.host.Host; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.network.Network; -import com.cloud.network.Network.Capability; -import com.cloud.network.Network.Provider; -import com.cloud.network.Network.Service; -import com.cloud.network.PhysicalNetworkServiceProvider; -import com.cloud.offering.NetworkOffering; -import com.cloud.utils.component.AdapterBase; -import com.cloud.utils.db.DB; -import com.cloud.utils.db.Transaction; -import com.cloud.vm.NicProfile; -import com.cloud.vm.NicVO; -import com.cloud.vm.ReservationContext; -import com.cloud.vm.VirtualMachine; -import com.cloud.vm.VirtualMachineProfile; -import com.cloud.vm.dao.NicDao; - -@Local(value=NetworkElement.class) -public class BareMetalElement extends AdapterBase implements NetworkElement { - private static final Logger s_logger = Logger.getLogger(BareMetalElement.class); - @Inject NicDao _nicDao; - @Inject ExternalDhcpManager _dhcpMgr; - - @Override - public Map> getCapabilities() { - return null; - } - - @Override - public Provider getProvider() { - return null; - } - - @Override - public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) - throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - return true; - } - - @Override @DB - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, - ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - Host host = dest.getHost(); - if (host == null || host.getHypervisorType() != HypervisorType.BareMetal) { - return true; - } - - Transaction txn = Transaction.currentTxn(); - txn.start(); - nic.setMacAddress(host.getPrivateMacAddress()); - NicVO vo = _nicDao.findById(nic.getId()); - assert vo != null : "Where ths nic " + nic.getId() + " going???"; - vo.setMacAddress(nic.getMacAddress()); - _nicDao.update(vo.getId(), vo); - txn.commit(); - s_logger.debug("Bare Metal changes mac address of nic " + nic.getId() + " to " + nic.getMacAddress()); - - return _dhcpMgr.addVirtualMachineIntoNetwork(network, nic, vm, dest, context); - } - - @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) - throws ConcurrentOperationException, ResourceUnavailableException { - return true; - } - - @Override - public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { - return true; - } - - @Override - public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { - return true; - } - - @Override - public boolean isReady(PhysicalNetworkServiceProvider provider) { - return true; - } - - @Override - public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { - return true; - } - - @Override - public boolean canEnableIndividualServices() { - return false; - } - - @Override - public boolean verifyServicesCombination(Set services) { - return true; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/network/element/ExternalDhcpElement.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/network/element/ExternalDhcpElement.java b/server/src/com/cloud/network/element/ExternalDhcpElement.java deleted file mode 100755 index f7c465d..0000000 --- a/server/src/com/cloud/network/element/ExternalDhcpElement.java +++ /dev/null @@ -1,152 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. -package com.cloud.network.element; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import javax.ejb.Local; -import javax.inject.Inject; - -import org.apache.log4j.Logger; - -import com.cloud.baremetal.ExternalDhcpManager; -import com.cloud.dc.DataCenter; -import com.cloud.dc.DataCenter.NetworkType; -import com.cloud.dc.Pod; -import com.cloud.deploy.DeployDestination; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InsufficientCapacityException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.host.Host; -import com.cloud.hypervisor.Hypervisor.HypervisorType; -import com.cloud.network.Network; -import com.cloud.network.Network.Capability; -import com.cloud.network.Network.GuestType; -import com.cloud.network.Network.Provider; -import com.cloud.network.Network.Service; -import com.cloud.network.Networks.TrafficType; -import com.cloud.network.PhysicalNetworkServiceProvider; -import com.cloud.offering.NetworkOffering; -import com.cloud.utils.component.AdapterBase; -import com.cloud.vm.NicProfile; -import com.cloud.vm.ReservationContext; -import com.cloud.vm.VirtualMachine; -import com.cloud.vm.VirtualMachineProfile; - -@Local(value = NetworkElement.class) -public class ExternalDhcpElement extends AdapterBase implements NetworkElement, DhcpServiceProvider { - private static final Logger s_logger = Logger.getLogger(ExternalDhcpElement.class); - @Inject - ExternalDhcpManager _dhcpMgr; - private static final Map> capabilities = setCapabilities(); - - private boolean canHandle(DeployDestination dest, TrafficType trafficType, GuestType networkType) { - DataCenter dc = dest.getDataCenter(); - Pod pod = dest.getPod(); - - if ((pod != null && pod.getExternalDhcp()) && dc.getNetworkType() == NetworkType.Basic && trafficType == TrafficType.Guest - && networkType == Network.GuestType.Shared) { - s_logger.debug("External DHCP can handle"); - return true; - } - - return false; - } - - private static Map> setCapabilities() { - // No external dhcp support for Acton release - Map> capabilities = new HashMap>(); - //capabilities.put(Service.Dhcp, null); - return capabilities; - } - - @Override - public Map> getCapabilities() { - return capabilities; - } - - @Override - public Provider getProvider() { - return Provider.ExternalDhcpServer; - } - - @Override - public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) - throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - if (!canHandle(dest, offering.getTrafficType(), network.getGuestType())) { - return false; - } - return true; - } - - @Override - public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, - ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException { - return true; - } - - @Override - public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) - throws ConcurrentOperationException, ResourceUnavailableException { - return true; - } - - @Override - public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException { - return true; - } - - @Override - public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { - return true; - } - - @Override - public boolean isReady(PhysicalNetworkServiceProvider provider) { - // TODO Auto-generated method stub - return true; - } - - @Override - public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException { - // TODO Auto-generated method stub - return true; - } - - @Override - public boolean canEnableIndividualServices() { - return false; - } - - @Override - public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) - throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException { - Host host = dest.getHost(); - if (host.getHypervisorType() == HypervisorType.BareMetal || !canHandle(dest, network.getTrafficType(), network.getGuestType())) { - // BareMetalElement or DhcpElement handle this - return false; - } - return _dhcpMgr.addVirtualMachineIntoNetwork(network, nic, vm, dest, context); - } - - @Override - public boolean verifyServicesCombination(Set services) { - return true; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/vm/UserVmManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java old mode 100644 new mode 100755 index 6022b38..cf9eb27 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -89,6 +89,7 @@ import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.HostPodDao; import com.cloud.deploy.DataCenterDeployment; import com.cloud.deploy.DeployDestination; +import com.cloud.deploy.DeployPlannerSelector; import com.cloud.deploy.DeploymentPlanner.ExcludeList; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; @@ -397,6 +398,9 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use @Inject protected VMSnapshotManager _vmSnapshotMgr; + @Inject + List plannerSelectors; + protected ScheduledExecutorService _executor = null; protected int _expungeInterval; protected int _expungeDelay; @@ -2167,14 +2171,13 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } } } - - // check if we have available pools for vm deployment - long availablePools = _storagePoolDao - .countPoolsByStatus(StoragePoolStatus.Up); - if (availablePools < 1) { - throw new StorageUnavailableException( - "There are no available pools in the UP state for vm deployment", - -1); + + if (template.getHypervisorType() != null && template.getHypervisorType() != HypervisorType.BareMetal) { + // check if we have available pools for vm deployment + long availablePools = _storagePoolDao.countPoolsByStatus(StoragePoolStatus.Up); + if (availablePools < 1) { + throw new StorageUnavailableException("There are no available pools in the UP state for vm deployment", -1); + } } if (template.getTemplateType().equals(TemplateType.SYSTEM)) { @@ -2860,8 +2863,19 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Use } VirtualMachineEntity vmEntity = _orchSrvc.getVirtualMachine(vm.getUuid()); + + String plannerName = null; + for (DeployPlannerSelector dps : plannerSelectors) { + plannerName = dps.selectPlanner(vm); + if (plannerName != null) { + break; + } + } + if (plannerName == null) { + throw new CloudRuntimeException(String.format("cannot find DeployPlannerSelector for vm[uuid:%s, hypervisorType:%s]", vm.getUuid(), vm.getHypervisorType())); + } - String reservationId = vmEntity.reserve("FirstFitPlanner", plan, new ExcludeList(), new Long(callerUser.getId()).toString()); + String reservationId = vmEntity.reserve(plannerName, plan, new ExcludeList(), new Long(callerUser.getId()).toString()); vmEntity.deploy(reservationId, new Long(callerUser.getId()).toString()); Pair> vmParamPair = new Pair(vm, params); http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/vm/VirtualMachineManagerImpl.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java index 4b7a4db..2b70ff6 100755 --- a/server/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/server/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -343,11 +343,6 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac return (VirtualMachineGuru) _vmGurus.get(vm.getType()); } - @SuppressWarnings("unchecked") - private VirtualMachineGuru getBareMetalVmGuru(T vm) { - return (VirtualMachineGuru) _vmGurus.get(VirtualMachine.Type.UserBareMetal); - } - @Override public boolean expunge(T vm, User caller, Account account) throws ResourceUnavailableException { try { @@ -593,12 +588,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac public T advanceStart(T vm, Map params, User caller, Account account, DeploymentPlan planToDeploy) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException { long vmId = vm.getId(); - VirtualMachineGuru vmGuru; - if (vm.getHypervisorType() == HypervisorType.BareMetal) { - vmGuru = getBareMetalVmGuru(vm); - } else { - vmGuru = getVmGuru(vm); - } + VirtualMachineGuru vmGuru = getVmGuru(vm); vm = vmGuru.findById(vm.getId()); Ternary start = changeToStartState(vmGuru, vm, caller, account); http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/setup/db/db/schema-40to410.sql ---------------------------------------------------------------------- diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql index 774a767..42165fc 100644 --- a/setup/db/db/schema-40to410.sql +++ b/setup/db/db/schema-40to410.sql @@ -1631,3 +1631,31 @@ CREATE VIEW `cloud`.`data_center_view` AS left join `cloud`.`domain` ON data_center.domain_id = domain.id; +INSERT INTO `cloud`.`region` values ('1','Local','http://localhost:8080/client/api','',''); +ALTER TABLE `cloud`.`account` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1'; +ALTER TABLE `cloud`.`user` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1'; +ALTER TABLE `cloud`.`domain` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1'; + +ALTER TABLE `cloud_usage`.`account` ADD COLUMN `region_id` int unsigned NOT NULL DEFAULT '1'; + +CREATE TABLE `cloud`.`baremetal_dhcp_devices` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `uuid` varchar(40) UNIQUE, + `nsp_id` bigint unsigned DEFAULT NULL COMMENT 'Network Service Provider ID', + `pod_id` bigint unsigned DEFAULT NULL COMMENT 'Pod id where this dhcp server in', + `device_type` varchar(255) DEFAULT NULL COMMENT 'type of the external device', + `physical_network_id` bigint unsigned DEFAULT NULL COMMENT 'id of the physical network in to which external dhcp device is added', + `host_id` bigint unsigned DEFAULT NULL COMMENT 'host id coresponding to the external dhcp device', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `cloud`.`baremetal_pxe_devices` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', + `uuid` varchar(40) UNIQUE, + `nsp_id` bigint unsigned DEFAULT NULL COMMENT 'Network Service Provider ID', + `pod_id` bigint unsigned DEFAULT NULL COMMENT 'Pod id where this pxe server in, for pxe per zone this field is null', + `device_type` varchar(255) DEFAULT NULL COMMENT 'type of the pxe device', + `physical_network_id` bigint unsigned DEFAULT NULL COMMENT 'id of the physical network in to which external pxe device is added', + `host_id` bigint unsigned DEFAULT NULL COMMENT 'host id coresponding to the external pxe device', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8;