diff --git a/.project b/.project
deleted file mode 100644
index 183860bd142..00000000000
--- a/.project
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
- mgit
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
-
- src
- 2
- /Users/john1/mgit/cloudbridge/src
-
-
-
diff --git a/server/src/com/cloud/baremetal/BareMetalDiscoverer.java b/server/src/com/cloud/baremetal/BareMetalDiscoverer.java
deleted file mode 100755
index 221a96b271c..00000000000
--- a/server/src/com/cloud/baremetal/BareMetalDiscoverer.java
+++ /dev/null
@@ -1,241 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import java.net.InetAddress;
-import java.net.URI;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.StartupCommand;
-import com.cloud.agent.api.StartupRoutingCommand;
-import com.cloud.api.ApiConstants;
-import com.cloud.dc.ClusterVO;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.dao.ClusterDao;
-import com.cloud.dc.dao.DataCenterDao;
-import com.cloud.exception.DiscoveryException;
-import com.cloud.host.Host;
-import com.cloud.host.HostVO;
-import com.cloud.host.dao.HostDao;
-import com.cloud.hypervisor.Hypervisor;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.network.Network;
-import com.cloud.resource.Discoverer;
-import com.cloud.resource.DiscovererBase;
-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.Inject;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.script.Script;
-import com.cloud.utils.script.Script2;
-import com.cloud.utils.script.Script2.ParamType;
-import com.cloud.vm.VMInstanceVO;
-import com.cloud.vm.VirtualMachine.State;
-import com.cloud.vm.dao.VMInstanceDao;
-
-@Local(value=Discoverer.class)
-public class BareMetalDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter {
- private static final Logger s_logger = Logger.getLogger(BareMetalDiscoverer.class);
- @Inject ClusterDao _clusterDao;
- @Inject protected HostDao _hostDao;
- @Inject DataCenterDao _dcDao;
- @Inject VMInstanceDao _vmDao = null;
- @Inject ResourceManager _resourceMgr;
-
- @Override
- public boolean configure(String name, Map params) throws ConfigurationException {
- _resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
- return super.configure(name, params);
- }
-
- @Override
- public boolean stop() {
- _resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
- return super.stop();
- }
-
- @Override
- public Map extends ServerResource, Map> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List hostTags)
- throws DiscoveryException {
- Map> resources = new HashMap>();
- Map details = new HashMap();
-
- if (!url.getScheme().equals("http")) {
- String msg = "urlString is not http so we're not taking care of the discovery for this: " + url;
- s_logger.debug(msg);
- return null;
- }
- if (clusterId == null) {
- String msg = "must specify cluster Id when add host";
- s_logger.debug(msg);
- throw new RuntimeException(msg);
- }
-
- if (podId == null) {
- String msg = "must specify pod Id when add host";
- s_logger.debug(msg);
- throw new RuntimeException(msg);
- }
-
- ClusterVO cluster = _clusterDao.findById(clusterId);
- if (cluster == null || (cluster.getHypervisorType() != HypervisorType.BareMetal)) {
- if (s_logger.isInfoEnabled())
- s_logger.info("invalid cluster id or cluster is not for Bare Metal hosts");
- return null;
- }
-
- DataCenterVO zone = _dcDao.findById(dcId);
- if (zone == null) {
- throw new RuntimeException("Cannot find zone " + dcId);
- }
-
- try {
- String hostname = url.getHost();
- InetAddress ia = InetAddress.getByName(hostname);
- String ipmiIp = ia.getHostAddress();
- String guid = UUID.nameUUIDFromBytes(ipmiIp.getBytes()).toString();
-
- String injectScript = "scripts/util/ipmi.py";
- String scriptPath = Script.findScript("", injectScript);
- if (scriptPath == null) {
- throw new CloudRuntimeException("Unable to find key ipmi script "
- + injectScript);
- }
-
- final Script2 command = new Script2(scriptPath, s_logger);
- command.add("ping");
- command.add("hostname="+ipmiIp);
- command.add("usrname="+username);
- command.add("password="+password, ParamType.PASSWORD);
- final String result = command.execute();
- if (result != null) {
- s_logger.warn(String.format("Can not set up ipmi connection(ip=%1$s, username=%2$s, password=%3$s, args) because %4$s", ipmiIp, username, "******", result));
- return null;
- }
-
- ClusterVO clu = _clusterDao.findById(clusterId);
- if (clu.getGuid() == null) {
- clu.setGuid(UUID.randomUUID().toString());
- _clusterDao.update(clusterId, clu);
- }
-
- Map params = new HashMap();
- params.putAll(_params);
- params.put("zone", Long.toString(dcId));
- params.put("pod", Long.toString(podId));
- params.put("cluster", Long.toString(clusterId));
- params.put("guid", guid);
- params.put(ApiConstants.PRIVATE_IP, ipmiIp);
- params.put(ApiConstants.USERNAME, username);
- params.put(ApiConstants.PASSWORD, password);
- BareMetalResourceBase resource = new BareMetalResourceBase();
- resource.configure("Bare Metal Agent", params);
-
- String memCapacity = (String)params.get(ApiConstants.MEMORY);
- String cpuCapacity = (String)params.get(ApiConstants.CPU_SPEED);
- String cpuNum = (String)params.get(ApiConstants.CPU_NUMBER);
- String mac = (String)params.get(ApiConstants.HOST_MAC);
- if (hostTags != null && hostTags.size() != 0) {
- details.put("hostTag", hostTags.get(0));
- }
- details.put(ApiConstants.MEMORY, memCapacity);
- details.put(ApiConstants.CPU_SPEED, cpuCapacity);
- details.put(ApiConstants.CPU_NUMBER, cpuNum);
- details.put(ApiConstants.HOST_MAC, mac);
- details.put(ApiConstants.USERNAME, username);
- details.put(ApiConstants.PASSWORD, password);
- details.put(ApiConstants.PRIVATE_IP, ipmiIp);
-
- resources.put(resource, details);
- resource.start();
-
- zone.setGatewayProvider(Network.Provider.ExternalGateWay.getName());
- zone.setDnsProvider(Network.Provider.ExternalDhcpServer.getName());
- zone.setDhcpProvider(Network.Provider.ExternalDhcpServer.getName());
- _dcDao.update(zone.getId(), zone);
-
- s_logger.debug(String.format("Discover Bare Metal host successfully(ip=%1$s, username=%2$s, password=%3%s," +
- "cpuNum=%4$s, cpuCapacity-%5$s, memCapacity=%6$s)", ipmiIp, username, "******", cpuNum, cpuCapacity, memCapacity));
- return resources;
- } catch (Exception e) {
- s_logger.warn("Can not set up bare metal agent", e);
- }
-
- return null;
- }
-
- @Override
- public void postDiscovery(List hosts, long msId)
- throws DiscoveryException {
- }
-
- @Override
- public boolean matchHypervisor(String hypervisor) {
- return hypervisor.equalsIgnoreCase(Hypervisor.HypervisorType.BareMetal.toString());
- }
-
- @Override
- public HypervisorType getHypervisorType() {
- return Hypervisor.HypervisorType.BareMetal;
- }
-
- @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) {
- StartupCommand firstCmd = startup[0];
- if (!(firstCmd instanceof StartupRoutingCommand)) {
- return null;
- }
-
- StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
- if (ssCmd.getHypervisorType() != HypervisorType.BareMetal) {
- return null;
- }
-
- return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.BareMetal, details, hostTags);
- }
-
- @Override
- public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
- if (host.getType() != Host.Type.Routing || host.getHypervisorType() != HypervisorType.BareMetal) {
- return null;
- }
-
- List deadVms = _vmDao.listByLastHostId(host.getId());
- for (VMInstanceVO vm : deadVms) {
- if (vm.getState() == State.Running || vm.getHostId() != null) {
- throw new CloudRuntimeException("VM " + vm.getId() + "is still running on host " + host.getId());
- }
- _vmDao.remove(vm.getId());
- }
-
- return new DeleteHostAnswer(true);
- }
-
-}
diff --git a/server/src/com/cloud/baremetal/BareMetalGuru.java b/server/src/com/cloud/baremetal/BareMetalGuru.java
deleted file mode 100755
index 403207a67b4..00000000000
--- a/server/src/com/cloud/baremetal/BareMetalGuru.java
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import javax.ejb.Local;
-
-import com.cloud.agent.api.to.VirtualMachineTO;
-import com.cloud.hypervisor.Hypervisor;
-import com.cloud.hypervisor.HypervisorGuru;
-import com.cloud.hypervisor.HypervisorGuruBase;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.storage.GuestOSVO;
-import com.cloud.storage.dao.GuestOSDao;
-import com.cloud.utils.component.Inject;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-
-@Local(value=HypervisorGuru.class)
-public class BareMetalGuru extends HypervisorGuruBase implements HypervisorGuru {
- @Inject GuestOSDao _guestOsDao;
-
- protected BareMetalGuru() {
- super();
- }
-
- @Override
- public HypervisorType getHypervisorType() {
- return HypervisorType.BareMetal;
- }
-
- @Override
- public VirtualMachineTO implement(VirtualMachineProfile vm) {
- VirtualMachineTO to = toVirtualMachineTO(vm);
-
- // Determine the VM's OS description
- GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
- to.setOs(guestOS.getDisplayName());
-
- return to;
- }
-
- @Override
- public boolean trackVmHostChange() {
- return true;
- }
-}
diff --git a/server/src/com/cloud/baremetal/BareMetalPingServiceImpl.java b/server/src/com/cloud/baremetal/BareMetalPingServiceImpl.java
deleted file mode 100755
index 71e02494800..00000000000
--- a/server/src/com/cloud/baremetal/BareMetalPingServiceImpl.java
+++ /dev/null
@@ -1,191 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import java.net.URI;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.baremetal.PreparePxeServerAnswer;
-import com.cloud.agent.api.baremetal.PreparePxeServerCommand;
-import com.cloud.agent.api.baremetal.prepareCreateTemplateCommand;
-import com.cloud.baremetal.PxeServerManager.PxeServerType;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.HostPodVO;
-import com.cloud.deploy.DeployDestination;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.host.Host;
-import com.cloud.host.HostVO;
-import com.cloud.resource.ResourceManager;
-import com.cloud.resource.ServerResource;
-import com.cloud.uservm.UserVm;
-import com.cloud.utils.component.Inject;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.vm.NicProfile;
-import com.cloud.vm.NicVO;
-import com.cloud.vm.ReservationContext;
-import com.cloud.vm.UserVmVO;
-import com.cloud.vm.VirtualMachineProfile;
-
-@Local(value=PxeServerService.class)
-public class BareMetalPingServiceImpl extends BareMetalPxeServiceBase implements PxeServerService {
- private static final Logger s_logger = Logger.getLogger(BareMetalPingServiceImpl.class);
- @Inject ResourceManager _resourceMgr;
-
- @Override
- public Host addPxeServer(PxeServerProfile profile) {
- Long zoneId = profile.getZoneId();
- Long podId = profile.getPodId();
-
- DataCenterVO zone = _dcDao.findById(zoneId);
- if (zone == null) {
- throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId);
- }
-
- List pxeServers = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.PxeServer, null, podId, zoneId);
- if (pxeServers.size() != 0) {
- throw new InvalidParameterValueException("Already had a PXE server in Pod: " + podId + " zone: " + zoneId);
- }
-
-
- String ipAddress = profile.getUrl();
- String username = profile.getUsername();
- String password = profile.getPassword();
-
- ServerResource resource = null;
- Map params = new HashMap();
- params.put("type", PxeServerType.PING.getName());
- params.put("zone", Long.toString(zoneId));
- params.put("pod", podId.toString());
- params.put("ip", ipAddress);
- params.put("username", username);
- params.put("password", password);
- if (profile.getType().equalsIgnoreCase(PxeServerType.PING.getName())) {
- String storageServerIp = profile.getPingStorageServerIp();
- if (storageServerIp == null) {
- throw new InvalidParameterValueException("No IP for storage server specified");
- }
- String pingDir = profile.getPingDir();
- if (pingDir == null) {
- throw new InvalidParameterValueException("No direcotry for storage server specified");
- }
- String tftpDir = profile.getTftpDir();
- if (tftpDir == null) {
- throw new InvalidParameterValueException("No TFTP directory specified");
- }
- String cifsUsername = profile.getPingCifsUserName();
- if (cifsUsername == null || cifsUsername.equalsIgnoreCase("")) {
- cifsUsername = "xxx";
- }
- String cifsPassword = profile.getPingCifspassword();
- if (cifsPassword == null || cifsPassword.equalsIgnoreCase("")) {
- cifsPassword = "xxx";
- }
- String guid = getPxeServerGuid(Long.toString(zoneId) + "-" + Long.toString(podId), PxeServerType.PING.getName(), ipAddress);
-
- params.put("storageServer", storageServerIp);
- params.put("pingDir", pingDir);
- params.put("tftpDir", tftpDir);
- params.put("cifsUserName", cifsUsername);
- params.put("cifsPassword", cifsPassword);
- params.put("guid", guid);
-
- resource = new PingPxeServerResource();
- try {
- resource.configure("PING PXE resource", params);
- } catch (Exception e) {
- s_logger.debug(e);
- throw new CloudRuntimeException(e.getMessage());
- }
-
- } else {
- throw new CloudRuntimeException("Unsupport PXE server type:" + profile.getType());
- }
-
- Host pxeServer = _resourceMgr.addHost(zoneId, resource, Host.Type.PxeServer, params);
- if (pxeServer == null) {
- throw new CloudRuntimeException("Cannot add PXE server as a host");
- }
-
- return pxeServer;
- }
-
-
- @Override
- public boolean prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context, Long pxeServerId) {
- List nics = profile.getNics();
- if (nics.size() == 0) {
- throw new CloudRuntimeException("Cannot do PXE start without nic");
- }
-
- NicProfile pxeNic = nics.get(0);
- String mac = pxeNic.getMacAddress();
- String ip = pxeNic.getIp4Address();
- String gateway = pxeNic.getGateway();
- String mask = pxeNic.getNetmask();
- String dns = pxeNic.getDns1();
- if (dns == null) {
- dns = pxeNic.getDns2();
- }
-
- try {
- String tpl = profile.getTemplate().getUrl();
- assert tpl != null : "How can a null template get here!!!";
- PreparePxeServerCommand cmd = new PreparePxeServerCommand(ip, mac, mask, gateway, dns, tpl,
- profile.getVirtualMachine().getInstanceName(), dest.getHost().getName());
- PreparePxeServerAnswer ans = (PreparePxeServerAnswer) _agentMgr.send(pxeServerId, cmd);
- return ans.getResult();
- } catch (Exception e) {
- s_logger.warn("Cannot prepare PXE server", e);
- return false;
- }
- }
-
-
- @Override
- public boolean prepareCreateTemplate(Long pxeServerId, UserVm vm, String templateUrl) {
- List nics = _nicDao.listByVmId(vm.getId());
- if (nics.size() != 1) {
- throw new CloudRuntimeException("Wrong nic number " + nics.size() + " of vm " + vm.getId());
- }
-
- /* use last host id when VM stopped */
- Long hostId = (vm.getHostId() == null ? vm.getLastHostId() : vm.getHostId());
- HostVO host = _hostDao.findById(hostId);
- DataCenterVO dc = _dcDao.findById(host.getDataCenterId());
- NicVO nic = nics.get(0);
- String mask = nic.getNetmask();
- String mac = nic.getMacAddress();
- String ip = nic.getIp4Address();
- String gateway = nic.getGateway();
- String dns = dc.getDns1();
- if (dns == null) {
- dns = dc.getDns2();
- }
-
- try {
- prepareCreateTemplateCommand cmd = new prepareCreateTemplateCommand(ip, mac, mask, gateway, dns, templateUrl);
- Answer ans = _agentMgr.send(pxeServerId, cmd);
- return ans.getResult();
- } catch (Exception e) {
- s_logger.debug("Prepare for creating baremetal template failed", e);
- return false;
- }
- }
-}
diff --git a/server/src/com/cloud/baremetal/BareMetalPxeServiceBase.java b/server/src/com/cloud/baremetal/BareMetalPxeServiceBase.java
deleted file mode 100644
index 6762d920b88..00000000000
--- a/server/src/com/cloud/baremetal/BareMetalPxeServiceBase.java
+++ /dev/null
@@ -1,74 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import java.util.Map;
-
-import javax.naming.ConfigurationException;
-
-import com.cloud.agent.AgentManager;
-import com.cloud.dc.dao.DataCenterDao;
-import com.cloud.dc.dao.HostPodDao;
-import com.cloud.deploy.DeployDestination;
-import com.cloud.host.Host;
-import com.cloud.host.dao.HostDao;
-import com.cloud.utils.component.Inject;
-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.dao.NicDao;
-
-public abstract class BareMetalPxeServiceBase implements PxeServerService {
- protected String _name;
- @Inject DataCenterDao _dcDao;
- @Inject HostDao _hostDao;
- @Inject AgentManager _agentMgr;
- @Inject ExternalDhcpManager exDhcpMgr;
- @Inject HostPodDao _podDao;
- @Inject NicDao _nicDao;
-
- @Override
- public boolean configure(String name, Map params) throws ConfigurationException {
- _name = name;
- return true;
- }
-
- @Override
- public String getName() {
- return _name;
- }
-
- @Override
- public boolean start() {
- return true;
- }
-
- @Override
- public boolean stop() {
- return true;
- }
-
-
- @Override
- public boolean prepare(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context, Long pxeServerId) {
- throw new CloudRuntimeException("Dervied class should implement this method");
- }
-
- protected String getPxeServerGuid(String zoneId, String name, String ip) {
- return zoneId + "-" + name + "-" + ip;
- }
-
- @Override
- public abstract Host addPxeServer(PxeServerProfile profile);
-}
diff --git a/server/src/com/cloud/baremetal/BareMetalResourceBase.java b/server/src/com/cloud/baremetal/BareMetalResourceBase.java
deleted file mode 100755
index 7b4556c4f1b..00000000000
--- a/server/src/com/cloud/baremetal/BareMetalResourceBase.java
+++ /dev/null
@@ -1,598 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.ejb.Local;
-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.CheckNetworkAnswer;
-import com.cloud.agent.api.CheckNetworkCommand;
-import com.cloud.agent.api.CheckVirtualMachineAnswer;
-import com.cloud.agent.api.CheckVirtualMachineCommand;
-import com.cloud.agent.api.Command;
-import com.cloud.agent.api.MaintainAnswer;
-import com.cloud.agent.api.MaintainCommand;
-import com.cloud.agent.api.MigrateAnswer;
-import com.cloud.agent.api.MigrateCommand;
-import com.cloud.agent.api.PingCommand;
-import com.cloud.agent.api.PingRoutingCommand;
-import com.cloud.agent.api.PrepareForMigrationAnswer;
-import com.cloud.agent.api.PrepareForMigrationCommand;
-import com.cloud.agent.api.ReadyAnswer;
-import com.cloud.agent.api.ReadyCommand;
-import com.cloud.agent.api.RebootAnswer;
-import com.cloud.agent.api.RebootCommand;
-import com.cloud.agent.api.StartAnswer;
-import com.cloud.agent.api.StartCommand;
-import com.cloud.agent.api.StartupCommand;
-import com.cloud.agent.api.StartupRoutingCommand;
-import com.cloud.agent.api.StopAnswer;
-import com.cloud.agent.api.StopCommand;
-import com.cloud.agent.api.baremetal.IpmISetBootDevCommand;
-import com.cloud.agent.api.baremetal.IpmISetBootDevCommand.BootDev;
-import com.cloud.agent.api.baremetal.IpmiBootorResetCommand;
-import com.cloud.agent.api.to.VirtualMachineTO;
-import com.cloud.api.ApiConstants;
-import com.cloud.host.Host.Type;
-import com.cloud.hypervisor.Hypervisor;
-import com.cloud.hypervisor.kvm.resource.KvmDummyResourceBase;
-import com.cloud.hypervisor.xen.resource.CitrixResourceBase;
-import com.cloud.resource.ServerResource;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.script.OutputInterpreter;
-import com.cloud.utils.script.Script;
-import com.cloud.utils.script.Script2;
-import com.cloud.utils.script.Script2.ParamType;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachine.State;
-
-@Local(value = ServerResource.class)
-public class BareMetalResourceBase implements ServerResource {
- private static final Logger s_logger = Logger.getLogger(BareMetalResourceBase.class);
- protected HashMap _vms = new HashMap(2);
- protected String _name;
- protected String _uuid;
- protected String _zone;
- protected String _pod;
- protected String _cluster;
- protected long _memCapacity;
- protected long _cpuCapacity;
- protected long _cpuNum;
- protected String _mac;
- protected String _username;
- protected String _password;
- protected String _ip;
- protected IAgentControl _agentControl;
- protected Script2 _pingCommand;
- protected Script2 _setPxeBootCommand;
- protected Script2 _setDiskBootCommand;
- protected Script2 _rebootCommand;
- protected Script2 _getStatusCommand;
- protected Script2 _powerOnCommand;
- protected Script2 _powerOffCommand;
- protected Script2 _forcePowerOffCommand;
- protected Script2 _bootOrRebootCommand;
- protected String _vmName;
-
- private void changeVmState(String vmName, VirtualMachine.State state) {
- synchronized (_vms) {
- _vms.put(vmName, state);
- }
- }
-
- private State removeVmState(String vmName) {
- synchronized (_vms) {
- return _vms.remove(vmName);
- }
- }
-
- @Override
- public boolean configure(String name, Map params) throws ConfigurationException {
- _name = name;
- _uuid = (String) params.get("guid");
- try {
- _memCapacity = Long.parseLong((String)params.get(ApiConstants.MEMORY)) * 1024L * 1024L;
- _cpuCapacity = Long.parseLong((String)params.get(ApiConstants.CPU_SPEED));
- _cpuNum = Long.parseLong((String)params.get(ApiConstants.CPU_NUMBER));
- } catch (NumberFormatException e) {
- throw new ConfigurationException(String.format("Unable to parse number of CPU or memory capacity " +
- "or cpu capacity(cpu number = %1$s memCapacity=%2$s, cpuCapacity=%3$s", (String)params.get(ApiConstants.CPU_NUMBER),
- (String)params.get(ApiConstants.MEMORY), (String)params.get(ApiConstants.CPU_SPEED)));
- }
-
- _zone = (String) params.get("zone");
- _pod = (String) params.get("pod");
- _cluster = (String) params.get("cluster");
- _ip = (String)params.get(ApiConstants.PRIVATE_IP);
- _mac = (String)params.get(ApiConstants.HOST_MAC);
- _username = (String)params.get(ApiConstants.USERNAME);
- _password = (String)params.get(ApiConstants.PASSWORD);
- _vmName = (String)params.get("vmName");
-
- if (_pod == null) {
- throw new ConfigurationException("Unable to get the pod");
- }
-
- if (_cluster == null) {
- throw new ConfigurationException("Unable to get the pod");
- }
-
- if (_ip == null) {
- throw new ConfigurationException("Unable to get the host address");
- }
-
- if (_mac.equalsIgnoreCase("unknown")) {
- throw new ConfigurationException("Unable to get the host mac address");
- }
-
- if (_mac.split(":").length != 6) {
- throw new ConfigurationException("Wrong MAC format(" + _mac + "). It must be in format of for example 00:11:ba:33:aa:dd which is not case sensitive");
- }
-
- if (_uuid == null) {
- throw new ConfigurationException("Unable to get the uuid");
- }
-
- String injectScript = "scripts/util/ipmi.py";
- String scriptPath = Script.findScript("", injectScript);
- if (scriptPath == null) {
- throw new ConfigurationException("Cannot find ping script " + scriptPath);
- }
- _pingCommand = new Script2(scriptPath, s_logger);
- _pingCommand.add("ping");
- _pingCommand.add("hostname="+_ip);
- _pingCommand.add("usrname="+_username);
- _pingCommand.add("password="+_password, ParamType.PASSWORD);
-
- _setPxeBootCommand = new Script2(scriptPath, s_logger);
- _setPxeBootCommand.add("boot_dev");
- _setPxeBootCommand.add("hostname="+_ip);
- _setPxeBootCommand.add("usrname="+_username);
- _setPxeBootCommand.add("password="+_password, ParamType.PASSWORD);
- _setPxeBootCommand.add("dev=pxe");
-
- _setDiskBootCommand = new Script2(scriptPath, s_logger);
- _setDiskBootCommand.add("boot_dev");
- _setDiskBootCommand.add("hostname="+_ip);
- _setDiskBootCommand.add("usrname="+_username);
- _setDiskBootCommand.add("password="+_password, ParamType.PASSWORD);
- _setDiskBootCommand.add("dev=disk");
-
- _rebootCommand = new Script2(scriptPath, s_logger);
- _rebootCommand.add("reboot");
- _rebootCommand.add("hostname="+_ip);
- _rebootCommand.add("usrname="+_username);
- _rebootCommand.add("password="+_password, ParamType.PASSWORD);
-
- _getStatusCommand = new Script2(scriptPath, s_logger);
- _getStatusCommand.add("ping");
- _getStatusCommand.add("hostname="+_ip);
- _getStatusCommand.add("usrname="+_username);
- _getStatusCommand.add("password="+_password, ParamType.PASSWORD);
-
- _powerOnCommand = new Script2(scriptPath, s_logger);
- _powerOnCommand.add("power");
- _powerOnCommand.add("hostname="+_ip);
- _powerOnCommand.add("usrname="+_username);
- _powerOnCommand.add("password="+_password, ParamType.PASSWORD);
- _powerOnCommand.add("action=on");
-
- _powerOffCommand = new Script2(scriptPath, s_logger);
- _powerOffCommand.add("power");
- _powerOffCommand.add("hostname="+_ip);
- _powerOffCommand.add("usrname="+_username);
- _powerOffCommand.add("password="+_password, ParamType.PASSWORD);
- _powerOffCommand.add("action=soft");
-
- _forcePowerOffCommand = new Script2(scriptPath, s_logger);
- _forcePowerOffCommand.add("power");
- _forcePowerOffCommand.add("hostname=" + _ip);
- _forcePowerOffCommand.add("usrname=" + _username);
- _forcePowerOffCommand.add("password=" + _password, ParamType.PASSWORD);
- _forcePowerOffCommand.add("action=off");
-
- _bootOrRebootCommand = new Script2(scriptPath, s_logger);
- _bootOrRebootCommand.add("boot_or_reboot");
- _bootOrRebootCommand.add("hostname="+_ip);
- _bootOrRebootCommand.add("usrname="+_username);
- _bootOrRebootCommand.add("password="+_password, ParamType.PASSWORD);
-
- return true;
- }
-
- protected boolean doScript(Script cmd) {
- return doScript(cmd, null);
- }
-
- protected boolean doScript(Script cmd, OutputInterpreter interpreter) {
- int retry = 5;
- String res = null;
- while (retry-- > 0) {
- if (interpreter == null) {
- res = cmd.execute();
- } else {
- res = cmd.execute(interpreter);
- }
- if (res != null && res.startsWith("Error: Unable to establish LAN")) {
- s_logger.warn("IPMI script timeout(" + cmd.toString() + "), will retry " + retry + " times");
- continue;
- } else if (res == null) {
- return true;
- } else {
- break;
- }
- }
-
- s_logger.warn("IPMI Scirpt failed due to " + res + "(" + cmd.toString() +")");
- return false;
- }
-
- @Override
- public boolean start() {
- return true;
- }
-
- @Override
- public boolean stop() {
- return true;
- }
-
- @Override
- public String getName() {
- return _name;
- }
-
- @Override
- public Type getType() {
- return com.cloud.host.Host.Type.Routing;
- }
-
- protected State getVmState() {
- OutputInterpreter.AllLinesParser interpreter = new OutputInterpreter.AllLinesParser();
- if (!doScript(_getStatusCommand, interpreter)) {
- s_logger.warn("Cannot get power status of " + _name + ", assume VM state was not changed");
- return null;
- }
- if (isPowerOn(interpreter.getLines())) {
- return State.Running;
- } else {
- return State.Stopped;
- }
- }
-
- protected Map fullSync() {
- Map changes = new HashMap();
-
- if (_vmName != null) {
- State state = getVmState();
- if (state != null) {
- changes.put(_vmName, state);
- }
- }
-
- return changes;
- }
-
- @Override
- public StartupCommand[] initialize() {
- StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.BareMetal,
- new HashMap(), null);
- cmd.setDataCenter(_zone);
- cmd.setPod(_pod);
- cmd.setCluster(_cluster);
- cmd.setGuid(_uuid);
- cmd.setName(_ip);
- cmd.setPrivateIpAddress(_ip);
- cmd.setStorageIpAddress(_ip);
- cmd.setVersion(BareMetalResourceBase.class.getPackage().getImplementationVersion());
- cmd.setCpus((int)_cpuNum);
- cmd.setSpeed(_cpuCapacity);
- cmd.setMemory(_memCapacity);
- cmd.setPrivateMacAddress(_mac);
- cmd.setPublicMacAddress(_mac);
- cmd.setStateChanges(fullSync());
- return new StartupCommand[] {cmd};
- }
-
- private boolean ipmiPing() {
- return doScript(_pingCommand);
- }
-
- @Override
- public PingCommand getCurrentStatus(long id) {
- try {
- if (!ipmiPing()) {
- Thread.sleep(1000);
- if (!ipmiPing()) {
- s_logger.warn("Cannot ping ipmi nic " + _ip);
- return null;
- }
- }
- } catch (Exception e) {
- s_logger.debug("Cannot ping ipmi nic " + _ip, e);
- return null;
- }
-
- return new PingRoutingCommand(getType(), id, deltaSync());
- }
-
- protected Answer execute(IpmISetBootDevCommand cmd) {
- Script bootCmd = null;
- if (cmd.getBootDev() == BootDev.disk) {
- bootCmd = _setDiskBootCommand;
- } else if (cmd.getBootDev() == BootDev.pxe) {
- bootCmd = _setPxeBootCommand;
- } else {
- throw new CloudRuntimeException("Unkonwn boot dev " + cmd.getBootDev());
- }
-
- String bootDev = cmd.getBootDev().name();
- if (!doScript(bootCmd)) {
- s_logger.warn("Set " + _ip + " boot dev to " + bootDev + "failed");
- return new Answer(cmd, false, "Set " + _ip + " boot dev to " + bootDev + "failed");
- }
-
- s_logger.warn("Set " + _ip + " boot dev to " + bootDev + "Success");
- return new Answer(cmd, true, "Set " + _ip + " boot dev to " + bootDev + "Success");
- }
-
- protected MaintainAnswer execute(MaintainCommand cmd) {
- return new MaintainAnswer(cmd, false);
- }
-
- protected PrepareForMigrationAnswer execute(PrepareForMigrationCommand cmd) {
- return new PrepareForMigrationAnswer(cmd);
- }
-
- protected MigrateAnswer execute(MigrateCommand cmd) {
- if (!doScript(_powerOffCommand)) {
- return new MigrateAnswer(cmd, false, "IPMI power off failed", null);
- }
- return new MigrateAnswer(cmd, true, "success", null);
- }
-
- protected CheckVirtualMachineAnswer execute(final CheckVirtualMachineCommand cmd) {
- return new CheckVirtualMachineAnswer(cmd, State.Stopped, null);
- }
-
- protected Answer execute(IpmiBootorResetCommand cmd) {
- if (!doScript(_bootOrRebootCommand)) {
- return new Answer(cmd ,false, "IPMI boot or reboot failed");
- }
- return new Answer(cmd, true, "Success");
-
- }
-
- protected CheckNetworkAnswer execute(CheckNetworkCommand cmd) {
- return new CheckNetworkAnswer(cmd, true, "Success");
- }
-
- @Override
- public Answer executeRequest(Command cmd) {
- if (cmd instanceof ReadyCommand) {
- return execute((ReadyCommand)cmd);
- } else if (cmd instanceof StartCommand) {
- return execute((StartCommand)cmd);
- } else if (cmd instanceof StopCommand) {
- return execute((StopCommand)cmd);
- } else if (cmd instanceof RebootCommand) {
- return execute((RebootCommand)cmd);
- } else if (cmd instanceof IpmISetBootDevCommand) {
- return execute((IpmISetBootDevCommand)cmd);
- } else if (cmd instanceof MaintainCommand) {
- return execute((MaintainCommand)cmd);
- } else if (cmd instanceof PrepareForMigrationCommand) {
- return execute((PrepareForMigrationCommand)cmd);
- } else if (cmd instanceof MigrateCommand) {
- return execute((MigrateCommand)cmd);
- } else if (cmd instanceof CheckVirtualMachineCommand) {
- return execute((CheckVirtualMachineCommand)cmd);
- } else if (cmd instanceof IpmiBootorResetCommand) {
- return execute((IpmiBootorResetCommand)cmd);
- } else if (cmd instanceof CheckNetworkCommand) {
- return execute((CheckNetworkCommand)cmd);
- } else {
- return Answer.createUnsupportedCommandAnswer(cmd);
- }
- }
-
- protected boolean isPowerOn(String str) {
- if (str.startsWith("Chassis Power is on")) {
- return true;
- } else if (str.startsWith("Chassis Power is off")) {
- return false;
- } else {
- throw new CloudRuntimeException("Cannot parse IPMI power status " + str);
- }
- }
-
- protected RebootAnswer execute(final RebootCommand cmd) {
- if (!doScript(_rebootCommand)) {
- return new RebootAnswer(cmd, "IPMI reboot failed");
- }
-
- return new RebootAnswer(cmd, "reboot succeeded", null, null);
- }
-
- protected StopAnswer execute(final StopCommand cmd) {
- boolean success = false;
- int count = 0;
- Script powerOff = _powerOffCommand;
-
- while (count < 10) {
- if (!doScript(powerOff)) {
- break;
- }
-
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- break;
- }
-
- OutputInterpreter.AllLinesParser interpreter = new OutputInterpreter.AllLinesParser();
- if (!doScript(_getStatusCommand, interpreter)) {
- s_logger.warn("Cannot get power status of " + _name + ", assume VM state was not changed");
- break;
- }
-
- if (!isPowerOn(interpreter.getLines())) {
- success = true;
- break;
- } else {
- powerOff = _forcePowerOffCommand;
- }
-
- count++;
- }
-
- return success ? new StopAnswer(cmd, "Success", null, Long.valueOf(0), Long.valueOf(0)) : new StopAnswer(cmd, "IPMI power off failed");
- }
-
- protected StartAnswer execute(StartCommand cmd) {
- VirtualMachineTO vm = cmd.getVirtualMachine();
- State state = State.Stopped;
-
- try {
- changeVmState(vm.getName(), State.Starting);
-
- boolean pxeBoot = false;
- String[] bootArgs = vm.getBootArgs().split(" ");
- for (int i = 0; i < bootArgs.length; i++) {
- if (bootArgs[i].equalsIgnoreCase("PxeBoot")) {
- pxeBoot = true;
- break;
- }
- }
-
- if (pxeBoot) {
- if (!doScript(_setPxeBootCommand)) {
- return new StartAnswer(cmd, "Set boot device to PXE failed");
- }
- s_logger.debug("Set " + vm.getHostName() + " to PXE boot successfully");
- } else {
- execute(new IpmISetBootDevCommand(BootDev.disk));
- }
-
- OutputInterpreter.AllLinesParser interpreter = new OutputInterpreter.AllLinesParser();
- if (!doScript(_getStatusCommand, interpreter)) {
- return new StartAnswer(cmd, "Cannot get current power status of " + _name);
- }
-
- if (isPowerOn(interpreter.getLines())) {
- if (pxeBoot) {
- if (!doScript(_rebootCommand)) {
- return new StartAnswer(cmd, "IPMI reboot failed");
- }
- s_logger.debug("IPMI reboot " + vm.getHostName() + " successfully");
- } else {
- s_logger.warn("Machine " + _name + " is alreay power on, why we still get a Start command? ignore it");
-
- }
- } else {
- if (!doScript(_powerOnCommand)) {
- return new StartAnswer(cmd, "IPMI power on failed");
- }
- }
-
- s_logger.debug("Start bare metal vm " + vm.getName() + "successfully");
- state = State.Running;
- _vmName = vm.getName();
- return new StartAnswer(cmd);
- } finally {
- if (state != State.Stopped) {
- changeVmState(vm.getName(), state);
- } else {
- removeVmState(vm.getName());
- }
- }
- }
-
- protected HashMap deltaSync() {
- final HashMap changes = new HashMap();
- /*
- * Disable sync until we find a way that only tracks status but not does action
- *
- * The scenario is: Baremetal will reboot host when creating template. Given most
- * servers take a long time to boot up, there would be a period that mgmt server finds
- * the host is stopped through fullsync. Then mgmt server updates database with marking the host as
- * stopped, after that, the host comes up and full sync then indicates it's running. Because
- * in database the host is already stopped, mgmt server sends out a stop command.
- * As a result, creating image gets never happened.
- *
- if (_vmName == null) {
- return null;
- }
-
- State newState = getVmState();
- if (newState == null) {
- s_logger.warn("Cannot get power state of VM " + _vmName);
- return null;
- }
-
- final State oldState = removeVmState(_vmName);
- if (oldState == null) {
- changeVmState(_vmName, newState);
- changes.put(_vmName, newState);
- } else if (oldState == State.Starting) {
- if (newState == State.Running) {
- changeVmState(_vmName, newState);
- } else if (newState == State.Stopped) {
- s_logger.debug("Ignoring vm " + _vmName + " because of a lag in starting the vm.");
- }
- } else if (oldState == State.Migrating) {
- s_logger.warn("How can baremetal VM get into migrating state???");
- } else if (oldState == State.Stopping) {
- if (newState == State.Stopped) {
- changeVmState(_vmName, newState);
- } else if (newState == State.Running) {
- s_logger.debug("Ignoring vm " + _vmName + " because of a lag in stopping the vm. ");
- }
- } else if (oldState != newState) {
- changeVmState(_vmName, newState);
- changes.put(_vmName, newState);
- }
- */
- return changes;
-
- }
-
- protected ReadyAnswer execute(ReadyCommand cmd) {
- // derived resource should check if the PXE server is ready
- s_logger.debug("Bare metal resource " + _name + " is ready");
- return new ReadyAnswer(cmd);
- }
-
- @Override
- public void disconnected() {
-
- }
-
- @Override
- public IAgentControl getAgentControl() {
- return _agentControl;
- }
-
- @Override
- public void setAgentControl(IAgentControl agentControl) {
- _agentControl = agentControl;
- }
-
-}
diff --git a/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java b/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
deleted file mode 100755
index b0f5d972f85..00000000000
--- a/server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
+++ /dev/null
@@ -1,207 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import java.util.Date;
-import java.util.List;
-
-import javax.ejb.Local;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.commands.DeleteIsoCmd;
-import com.cloud.api.commands.RegisterIsoCmd;
-import com.cloud.api.commands.RegisterTemplateCmd;
-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.VMTemplateHostVO;
-import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.VMTemplateZoneVO;
-import com.cloud.template.TemplateAdapter;
-import com.cloud.template.TemplateAdapterBase;
-import com.cloud.template.TemplateProfile;
-import com.cloud.user.Account;
-import com.cloud.utils.component.Inject;
-import com.cloud.utils.db.DB;
-import com.cloud.utils.exception.CloudRuntimeException;
-
-@Local(value=TemplateAdapter.class)
-public class BareMetalTemplateAdapter extends TemplateAdapterBase implements TemplateAdapter {
- private final static Logger s_logger = Logger.getLogger(BareMetalTemplateAdapter.class);
- @Inject HostDao _hostDao;
- @Inject ResourceManager _resourceMgr;
-
- @Override
- public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException {
- TemplateProfile profile = super.prepare(cmd);
-
- if (profile.getZoneId() == null || profile.getZoneId() == -1) {
- List dcs = _dcDao.listAllIncludingRemoved();
- for (DataCenterVO dc : dcs) {
- List pxeServers = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.PxeServer, dc.getId());
- if (pxeServers.size() == 0) {
- throw new CloudRuntimeException("Please add PXE server before adding baremetal template in zone " + dc.getName());
- }
- }
- } else {
- List pxeServers = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.PxeServer, profile.getZoneId());
- if (pxeServers.size() == 0) {
- throw new CloudRuntimeException("Please add PXE server before adding baremetal template in zone " + profile.getZoneId());
- }
- }
-
- return profile;
- }
-
- @Override
- public TemplateProfile prepare(RegisterIsoCmd cmd) throws ResourceAllocationException {
- throw new CloudRuntimeException("Baremetal doesn't support ISO template");
- }
-
- private void templateCreateUsage(VMTemplateVO template, HostVO host) {
- if (template.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
- UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_TEMPLATE_CREATE, template.getAccountId(), host.getDataCenterId(),
- template.getId(), template.getName(), null, template.getSourceTemplateId(), 0L);
- _usageEventDao.persist(usageEvent);
- }
- }
-
- @Override
- public VMTemplateVO create(TemplateProfile profile) {
- VMTemplateVO template = persistTemplate(profile);
- Long zoneId = profile.getZoneId();
-
- /* There is no secondary storage vm for baremetal, we use pxe server id.
- * Tempalte is not bound to pxeserver right now, and we assume the pxeserver
- * cannot be removed once it was added. so we use host id of first found pxe
- * server as reference in template_host_ref.
- * This maybe a FIXME in future.
- */
- VMTemplateHostVO vmTemplateHost = null;
- if (zoneId == null || zoneId == -1) {
- List dcs = _dcDao.listAllIncludingRemoved();
- for (DataCenterVO dc : dcs) {
- HostVO pxe = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.PxeServer, dc.getId()).get(0);
-
- vmTemplateHost = _tmpltHostDao.findByHostTemplate(dc.getId(), template.getId());
- if (vmTemplateHost == null) {
- vmTemplateHost = new VMTemplateHostVO(pxe.getId(), template.getId(), new Date(), 100,
- Status.DOWNLOADED, null, null, null, null, template.getUrl());
- _tmpltHostDao.persist(vmTemplateHost);
- templateCreateUsage(template, pxe);
- }
- }
- } else {
- HostVO pxe = _resourceMgr.listAllHostsInOneZoneByType(Host.Type.PxeServer, zoneId).get(0);
- vmTemplateHost = new VMTemplateHostVO(pxe.getId(), template.getId(), new Date(), 100,
- Status.DOWNLOADED, null, null, null, null, template.getUrl());
- _tmpltHostDao.persist(vmTemplateHost);
- templateCreateUsage(template, pxe);
- }
-
- _resourceLimitMgr.incrementResourceCount(profile.getAccountId(), ResourceType.template);
- return template;
- }
-
- public TemplateProfile prepareDelete(DeleteIsoCmd cmd) {
- throw new CloudRuntimeException("Baremetal doesn't support ISO, how the delete get here???");
- }
-
- @Override @DB
- public boolean delete(TemplateProfile profile) {
- VMTemplateVO template = profile.getTemplate();
- Long templateId = template.getId();
- boolean success = true;
- String zoneName;
- boolean isAllZone;
-
- if (!template.isCrossZones() && profile.getZoneId() != null) {
- isAllZone = false;
- zoneName = profile.getZoneId().toString();
- } else {
- zoneName = "all zones";
- isAllZone = true;
- }
-
- s_logger.debug("Attempting to mark template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
- Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId());
- String eventType = EventTypes.EVENT_TEMPLATE_DELETE;
- List templateHostVOs = _tmpltHostDao.listByTemplateId(templateId);
-
- for (VMTemplateHostVO vo : templateHostVOs) {
- VMTemplateHostVO lock = null;
- try {
- HostVO pxeServer = _hostDao.findById(vo.getHostId());
- if (!isAllZone && pxeServer.getDataCenterId() != profile.getZoneId()) {
- continue;
- }
-
- lock = _tmpltHostDao.acquireInLockTable(vo.getId());
- if (lock == null) {
- s_logger.debug("Failed to acquire lock when deleting templateHostVO with ID: " + vo.getId());
- success = false;
- break;
- }
-
- vo.setDestroyed(true);
- _tmpltHostDao.update(vo.getId(), vo);
- VMTemplateZoneVO templateZone = _tmpltZoneDao.findByZoneTemplate(pxeServer.getDataCenterId(), templateId);
- if (templateZone != null) {
- _tmpltZoneDao.remove(templateZone.getId());
- }
-
- UsageEventVO usageEvent = new UsageEventVO(eventType, account.getId(), pxeServer.getDataCenterId(), templateId, null);
- _usageEventDao.persist(usageEvent);
- } finally {
- if (lock != null) {
- _tmpltHostDao.releaseFromLockTable(lock.getId());
- }
- }
- }
-
- s_logger.debug("Successfully marked template host refs for template: " + template.getName() + " as destroyed in zone: " + zoneName);
-
- // If there are no more non-destroyed template host entries for this template, delete it
- if (success && (_tmpltHostDao.listByTemplateId(templateId).size() == 0)) {
- long accountId = template.getAccountId();
-
- VMTemplateVO lock = _tmpltDao.acquireInLockTable(templateId);
-
- try {
- if (lock == null) {
- s_logger.debug("Failed to acquire lock when deleting template with ID: " + templateId);
- success = false;
- } else if (_tmpltDao.remove(templateId)) {
- // Decrement the number of templates
- _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.template);
- }
-
- } finally {
- if (lock != null) {
- _tmpltDao.releaseFromLockTable(lock.getId());
- }
- }
- s_logger.debug("Removed template: " + template.getName() + " because all of its template host refs were marked as destroyed.");
- }
-
- return success;
- }
-}
diff --git a/server/src/com/cloud/baremetal/BareMetalVmManager.java b/server/src/com/cloud/baremetal/BareMetalVmManager.java
deleted file mode 100644
index 091e7744af7..00000000000
--- a/server/src/com/cloud/baremetal/BareMetalVmManager.java
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import com.cloud.vm.UserVmManager;
-
-public interface BareMetalVmManager extends UserVmManager {
-}
diff --git a/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java b/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
deleted file mode 100755
index bac191bd310..00000000000
--- a/server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
+++ /dev/null
@@ -1,559 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Executors;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.StopAnswer;
-import com.cloud.agent.api.baremetal.IpmISetBootDevCommand;
-import com.cloud.agent.api.baremetal.IpmiBootorResetCommand;
-import com.cloud.agent.manager.Commands;
-import com.cloud.api.commands.AttachVolumeCmd;
-import com.cloud.api.commands.CreateTemplateCmd;
-import com.cloud.api.commands.DeployVMCmd;
-import com.cloud.api.commands.DetachVolumeCmd;
-import com.cloud.api.commands.StartVMCmd;
-import com.cloud.api.commands.UpgradeVMCmd;
-import com.cloud.baremetal.PxeServerManager.PxeServerType;
-import com.cloud.configuration.Resource.ResourceType;
-import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.dc.DataCenter.NetworkType;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.deploy.DataCenterDeployment;
-import com.cloud.deploy.DeployDestination;
-import com.cloud.domain.DomainVO;
-import com.cloud.event.EventTypes;
-import com.cloud.event.UsageEventVO;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.PermissionDeniedException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.exception.StorageUnavailableException;
-import com.cloud.host.Host;
-import com.cloud.host.HostVO;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.network.Network;
-import com.cloud.network.NetworkVO;
-import com.cloud.network.Networks.TrafficType;
-import com.cloud.org.Grouping;
-import com.cloud.resource.ResourceManager;
-import com.cloud.service.ServiceOfferingVO;
-import com.cloud.storage.Storage;
-import com.cloud.storage.Storage.TemplateType;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.Volume;
-import com.cloud.template.TemplateAdapter;
-import com.cloud.template.TemplateAdapter.TemplateAdapterType;
-import com.cloud.template.TemplateProfile;
-import com.cloud.user.Account;
-import com.cloud.user.AccountVO;
-import com.cloud.user.SSHKeyPair;
-import com.cloud.user.User;
-import com.cloud.user.UserContext;
-import com.cloud.uservm.UserVm;
-import com.cloud.utils.NumbersUtil;
-import com.cloud.utils.Pair;
-import com.cloud.utils.component.Adapters;
-import com.cloud.utils.component.ComponentLocator;
-import com.cloud.utils.component.Inject;
-import com.cloud.utils.component.Manager;
-import com.cloud.utils.concurrency.NamedThreadFactory;
-import com.cloud.utils.db.DB;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.fsm.StateListener;
-import com.cloud.utils.net.NetUtils;
-import com.cloud.vm.BareMetalVmService;
-import com.cloud.vm.NicProfile;
-import com.cloud.vm.NicVO;
-import com.cloud.vm.ReservationContext;
-import com.cloud.vm.UserVmManagerImpl;
-import com.cloud.vm.UserVmVO;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachine.Event;
-import com.cloud.vm.VirtualMachine.State;
-import com.cloud.vm.VirtualMachine.Type;
-import com.cloud.vm.VirtualMachineName;
-import com.cloud.vm.VirtualMachineProfile;
-import com.cloud.vm.VirtualMachineProfile.Param;
-
-@Local(value={BareMetalVmManager.class, BareMetalVmService.class})
-public class BareMetalVmManagerImpl extends UserVmManagerImpl implements BareMetalVmManager, BareMetalVmService, Manager,
- StateListener {
- private static final Logger s_logger = Logger.getLogger(BareMetalVmManagerImpl.class);
- private ConfigurationDao _configDao;
- @Inject PxeServerManager _pxeMgr;
- @Inject ResourceManager _resourceMgr;
-
- @Inject (adapter=TemplateAdapter.class)
- protected Adapters _adapters;
-
- @Override
- public boolean attachISOToVM(long vmId, long isoId, boolean attach) {
- s_logger.warn("attachISOToVM is not supported by Bare Metal, just fake a true");
- return true;
- }
-
- @Override
- public Volume attachVolumeToVM(AttachVolumeCmd command) {
- s_logger.warn("attachVolumeToVM is not supported by Bare Metal, return null");
- return null;
- }
-
- @Override
- public Volume detachVolumeFromVM(DetachVolumeCmd cmd) {
- s_logger.warn("detachVolumeFromVM is not supported by Bare Metal, return null");
- return null;
- }
-
- @Override
- public UserVm upgradeVirtualMachine(UpgradeVMCmd cmd) {
- s_logger.warn("upgradeVirtualMachine is not supported by Bare Metal, return null");
- return null;
- }
-
- @Override
- public VMTemplateVO createPrivateTemplateRecord(CreateTemplateCmd cmd, Account templateOwner) throws ResourceAllocationException {
- /*Baremetal creates record after host rebooting for imaging, in createPrivateTemplate*/
- return null;
- }
-
- @Override @DB
- public VMTemplateVO createPrivateTemplate(CreateTemplateCmd cmd) throws CloudRuntimeException {
- Long vmId = cmd.getVmId();
- if (vmId == null) {
- throw new InvalidParameterValueException("VM ID is null");
- }
-
- UserVmVO vm = _vmDao.findById(vmId);
- if (vm == null) {
- throw new InvalidParameterValueException("Cannot find VM for ID " + vmId);
- }
-
- Long hostId = (vm.getHostId() == null ? vm.getLastHostId() : vm.getHostId());
- HostVO host = _hostDao.findById(hostId);
- if (host == null) {
- throw new InvalidParameterValueException("Cannot find host with id " + hostId);
- }
-
- List pxes = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.PxeServer, null, host.getPodId(), host.getDataCenterId());
- if (pxes.size() == 0) {
- throw new CloudRuntimeException("Please add PXE server in Pod before taking image");
- }
-
- if (pxes.size() > 1) {
- throw new CloudRuntimeException("Multiple PXE servers found in Pod " + host.getPodId() + " Zone " + host.getDataCenterId());
- }
-
- HostVO pxe = pxes.get(0);
- /*
- * prepare() will check if current account has right for creating
- * template
- */
- TemplateAdapter adapter = _adapters.get(TemplateAdapterType.BareMetal.getName());
- Long userId = UserContext.current().getCallerUserId();
- userId = (userId == null ? User.UID_SYSTEM : userId);
- AccountVO account = _accountDao.findById(vm.getAccountId());
-
- try {
- TemplateProfile tmplProfile;
- tmplProfile = adapter.prepare(false, userId, cmd.getTemplateName(), cmd.getDisplayText(), cmd.getBits(), false, false, cmd.getUrl(), cmd.isPublic(), cmd.isFeatured(), false,
- "BareMetal", cmd.getOsTypeId(), pxe.getDataCenterId(), HypervisorType.BareMetal, account.getAccountName(), account.getDomainId(), "0", true, cmd.getDetails());
-
- if (!_pxeMgr.prepareCreateTemplate(_pxeMgr.getPxeServerType(pxe), pxe.getId(), vm, cmd.getUrl())) {
- throw new Exception("Prepare PXE boot file for host " + hostId + " failed");
- }
-
- IpmISetBootDevCommand setBootDev = new IpmISetBootDevCommand(IpmISetBootDevCommand.BootDev.pxe);
- Answer ans = _agentMgr.send(hostId, setBootDev);
- if (!ans.getResult()) {
- throw new Exception("Set host " + hostId + " to PXE boot failed");
- }
-
- IpmiBootorResetCommand boot = new IpmiBootorResetCommand();
- ans = _agentMgr.send(hostId, boot);
- if (!ans.getResult()) {
- throw new Exception("Boot/Reboot host " + hostId + " failed");
- }
-
- VMTemplateVO tmpl = adapter.create(tmplProfile);
- s_logger.debug("Create baremetal template for host " + hostId + " successfully, template id:" + tmpl.getId());
- return tmpl;
- } catch (Exception e) {
- s_logger.debug("Create baremetal tempalte for host " + hostId + " failed", e);
- throw new CloudRuntimeException(e.getMessage());
- }
- }
-
- @Override
- public UserVm createVirtualMachine(DeployVMCmd cmd) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException,
- StorageUnavailableException, ResourceAllocationException {
- Account caller = UserContext.current().getCaller();
-
- String accountName = cmd.getAccountName();
- Long domainId = cmd.getDomainId();
- List networkList = cmd.getNetworkIds();
- String group = cmd.getGroup();
-
- Account owner = _accountDao.findActiveAccount(accountName, domainId);
- if (owner == null) {
- throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
- }
-
- _accountMgr.checkAccess(caller, null, true, owner);
- long accountId = owner.getId();
-
- DataCenterVO dc = _dcDao.findById(cmd.getZoneId());
- if (dc == null) {
- throw new InvalidParameterValueException("Unable to find zone: " + cmd.getZoneId());
- }
-
- if(Grouping.AllocationState.Disabled == dc.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())){
- throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: "+ cmd.getZoneId() );
- }
-
- if (dc.getDomainId() != null) {
- DomainVO domain = _domainDao.findById(dc.getDomainId());
- if (domain == null) {
- throw new CloudRuntimeException("Unable to find the domain " + dc.getDomainId() + " for the zone: " + dc);
- }
- _configMgr.checkZoneAccess(caller, dc);
- _configMgr.checkZoneAccess(owner, dc);
- }
-
- // check if account/domain is with in resource limits to create a new vm
- _resourceLimitMgr.checkResourceLimit(owner, ResourceType.user_vm);
-
- ServiceOfferingVO offering = _serviceOfferingDao.findById(cmd.getServiceOfferingId());
- if (offering == null || offering.getRemoved() != null) {
- throw new InvalidParameterValueException("Unable to find service offering: " + cmd.getServiceOfferingId());
- }
-
- VMTemplateVO template = _templateDao.findById(cmd.getTemplateId());
- // Make sure a valid template ID was specified
- if (template == null || template.getRemoved() != null) {
- throw new InvalidParameterValueException("Unable to use template " + cmd.getTemplateId());
- }
-
- if (template.getTemplateType().equals(TemplateType.SYSTEM)) {
- throw new InvalidParameterValueException("Unable to use system template " + cmd.getTemplateId()+" to deploy a user vm");
- }
-
- if (template.getFormat() != Storage.ImageFormat.BAREMETAL) {
- throw new InvalidParameterValueException("Unable to use non Bare Metal template" + cmd.getTemplateId() +" to deploy a bare metal vm");
- }
-
- String userData = cmd.getUserData();
- byte [] decodedUserData = null;
- if (userData != null) {
- if (userData.length() >= 2 * MAX_USER_DATA_LENGTH_BYTES) {
- throw new InvalidParameterValueException("User data is too long");
- }
- decodedUserData = org.apache.commons.codec.binary.Base64.decodeBase64(userData.getBytes());
- if (decodedUserData.length > MAX_USER_DATA_LENGTH_BYTES){
- throw new InvalidParameterValueException("User data is too long");
- }
- if (decodedUserData.length < 1) {
- throw new InvalidParameterValueException("User data is too short");
- }
- }
-
- // Find an SSH public key corresponding to the key pair name, if one is given
- String sshPublicKey = null;
- if (cmd.getSSHKeyPairName() != null && !cmd.getSSHKeyPairName().equals("")) {
- Account account = UserContext.current().getCaller();
- SSHKeyPair pair = _sshKeyPairDao.findByName(account.getAccountId(), account.getDomainId(), cmd.getSSHKeyPairName());
- if (pair == null) {
- throw new InvalidParameterValueException("A key pair with name '" + cmd.getSSHKeyPairName() + "' was not found.");
- }
-
- sshPublicKey = pair.getPublicKey();
- }
-
- _accountMgr.checkAccess(caller, null, true, template);
-
- DataCenterDeployment plan = new DataCenterDeployment(dc.getId());
-
- s_logger.debug("Allocating in the DB for bare metal vm");
-
- if (dc.getNetworkType() != NetworkType.Basic || networkList != null) {
- s_logger.warn("Bare Metal only supports basical network mode now, switch to baisc network automatically");
- }
-
- Network defaultNetwork = _networkMgr.getExclusiveGuestNetwork(dc.getId());
- if (defaultNetwork == null) {
- throw new InvalidParameterValueException("Unable to find a default network to start a vm");
- }
-
-
- networkList = new ArrayList();
- networkList.add(defaultNetwork.getId());
-
- List> networks = new ArrayList>();
- for (Long networkId : networkList) {
- NetworkVO network = _networkDao.findById(networkId);
- if (network == null) {
- throw new InvalidParameterValueException("Unable to find network by id " + networkId);
- } else {
- if (network.getGuestType() != Network.GuestType.Shared) {
- //Check account permissions
- List networkMap = _networkDao.listBy(accountId, networkId);
- if (networkMap == null || networkMap.isEmpty()) {
- throw new PermissionDeniedException("Unable to create a vm using network with id " + networkId + ", permission denied");
- }
- }
- networks.add(new Pair(network, null));
- }
- }
-
- long id = _vmDao.getNextInSequence(Long.class, "id");
-
- String hostName = cmd.getName();
- String instanceName = VirtualMachineName.getVmName(id, owner.getId(), _instance);
- if (hostName == null) {
- hostName = instanceName;
- } else {
- //verify hostName (hostname doesn't have to be unique)
- if (!NetUtils.verifyDomainNameLabel(hostName, true)) {
- throw new InvalidParameterValueException("Invalid name. Vm name can contain ASCII letters 'a' through 'z', the digits '0' through '9', " +
- "and the hyphen ('-'), must be between 1 and 63 characters long, and can't start or end with \"-\" and can't start with digit");
- }
- }
-
- UserVmVO vm = new UserVmVO(id, instanceName, cmd.getDisplayName(), template.getId(), HypervisorType.BareMetal,
- template.getGuestOSId(), offering.getOfferHA(), false, domainId, owner.getId(), offering.getId(), userData, hostName);
-
- if (sshPublicKey != null) {
- vm.setDetail("SSH.PublicKey", sshPublicKey);
- }
-
- if (_itMgr.allocate(vm, template, offering, null, null, networks, null, plan, cmd.getHypervisor(), owner) == null) {
- return null;
- }
-
-
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Successfully allocated DB entry for " + vm);
- }
-
- if (s_logger.isDebugEnabled()) {
- s_logger.debug("Successfully allocated DB entry for " + vm);
- }
- UserContext.current().setEventDetails("Vm Id: " + vm.getId());
- UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_CREATE, accountId, cmd.getZoneId(), vm.getId(), vm.getHostName(), offering.getId(), template.getId(), HypervisorType.BareMetal.toString());
- _usageEventDao.persist(usageEvent);
-
- _resourceLimitMgr.incrementResourceCount(accountId, ResourceType.user_vm);
-
- // Assign instance to the group
- try {
- if (group != null) {
- boolean addToGroup = addInstanceToGroup(Long.valueOf(id), group);
- if (!addToGroup) {
- throw new CloudRuntimeException("Unable to assign Vm to the group " + group);
- }
- }
- } catch (Exception ex) {
- throw new CloudRuntimeException("Unable to assign Vm to the group " + group);
- }
-
- return vm;
- }
-
- public UserVm startVirtualMachine(DeployVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
- UserVmVO vm = _vmDao.findById(cmd.getInstanceId());
-
- List servers = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByType(Host.Type.PxeServer, vm.getDataCenterIdToDeployIn());
- if (servers.size() == 0) {
- throw new CloudRuntimeException("Cannot find PXE server, please make sure there is one PXE server per zone");
- }
- HostVO pxeServer = servers.get(0);
-
- VMTemplateVO template = _templateDao.findById(vm.getTemplateId());
- if (template == null || template.getFormat() != Storage.ImageFormat.BAREMETAL) {
- throw new InvalidParameterValueException("Invalid template with id = " + vm.getTemplateId());
- }
-
- Map params = new HashMap();
- params.put(Param.PxeSeverType, _pxeMgr.getPxeServerType(pxeServer));
-
- return startVirtualMachine(cmd, params);
- }
-
-
- public UserVm startVirtualMachine(StartVMCmd cmd) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
- UserVmVO vm = _vmDao.findById(cmd.getInstanceId());
-
- VMTemplateVO template = _templateDao.findById(vm.getTemplateId());
- if (template == null || template.getFormat() != Storage.ImageFormat.BAREMETAL) {
- throw new InvalidParameterValueException("Invalid template with id = " + vm.getTemplateId());
- }
-
- Map params = null;
- if (vm.isUpdateParameters()) {
- List servers = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByType(Host.Type.PxeServer, vm.getDataCenterIdToDeployIn());
- if (servers.size() == 0) {
- throw new CloudRuntimeException("Cannot find PXE server, please make sure there is one PXE server per zone");
- }
- HostVO pxeServer = servers.get(0);
- params = new HashMap();
- params.put(Param.PxeSeverType, _pxeMgr.getPxeServerType(pxeServer));
- }
-
- Pair> vmDetailsPair = super.startVirtualMachine(vm.getId(), cmd.getHostId(), params);
- return vmDetailsPair.first();
- }
-
- @Override
- public boolean configure(String name, Map params) throws ConfigurationException {
- _name = name;
-
- ComponentLocator locator = ComponentLocator.getCurrentLocator();
- _configDao = locator.getDao(ConfigurationDao.class);
- if (_configDao == null) {
- throw new ConfigurationException("Unable to get the configuration dao.");
- }
-
- Map configs = _configDao.getConfiguration("AgentManager", params);
-
- _instance = configs.get("instance.name");
- if (_instance == null) {
- _instance = "DEFAULT";
- }
-
- String workers = configs.get("expunge.workers");
- int wrks = NumbersUtil.parseInt(workers, 10);
-
- String time = configs.get("expunge.interval");
- _expungeInterval = NumbersUtil.parseInt(time, 86400);
-
- time = configs.get("expunge.delay");
- _expungeDelay = NumbersUtil.parseInt(time, _expungeInterval);
-
- _executor = Executors.newScheduledThreadPool(wrks, new NamedThreadFactory("UserVm-Scavenger"));
-
- _itMgr.registerGuru(Type.UserBareMetal, this);
- VirtualMachine.State.getStateMachine().registerListener(this);
-
- s_logger.info("User VM Manager is configured.");
-
- return true;
- }
-
- @Override
- public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
- UserVmVO vm = profile.getVirtualMachine();
- Account owner = _accountDao.findById(vm.getAccountId());
-
- if (owner == null || owner.getState() == Account.State.disabled) {
- throw new PermissionDeniedException("The owner of " + vm + " either does not exist or is disabled: " + vm.getAccountId());
- }
-
- PxeServerType pxeType = (PxeServerType) profile.getParameter(Param.PxeSeverType);
- if (pxeType == null) {
- s_logger.debug("This is a normal IPMI start, skip prepartion of PXE server");
- return true;
- }
- s_logger.debug("This is a PXE start, prepare PXE server first");
-
- List servers = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.PxeServer, null, dest.getPod().getId(), dest.getDataCenter().getId());
- if (servers.size() == 0) {
- throw new CloudRuntimeException("Cannot find PXE server, please make sure there is one PXE server per zone");
- }
- if (servers.size() > 1) {
- throw new CloudRuntimeException("Find more than one PXE server, please make sure there is only one PXE server per zone in pod " + dest.getPod().getId() + " zone " + dest.getDataCenter().getId());
- }
- HostVO pxeServer = servers.get(0);
-
- if (!_pxeMgr.prepare(pxeType, profile, dest, context, pxeServer.getId())) {
- throw new CloudRuntimeException("Pepare PXE server failed");
- }
-
- profile.addBootArgs("PxeBoot");
-
- return true;
- }
-
- @Override
- public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
- UserVmVO userVm = profile.getVirtualMachine();
- List nics = _nicDao.listByVmId(userVm.getId());
- for (NicVO nic : nics) {
- NetworkVO network = _networkDao.findById(nic.getNetworkId());
- if (network.getTrafficType() == TrafficType.Guest) {
- userVm.setPrivateIpAddress(nic.getIp4Address());
- userVm.setPrivateMacAddress(nic.getMacAddress());
- }
- }
- _vmDao.update(userVm.getId(), userVm);
- return true;
- }
-
- @Override
- public void finalizeStop(VirtualMachineProfile profile, StopAnswer answer) {
- super.finalizeStop(profile, answer);
- }
-
- @Override
- public UserVm destroyVm(long vmId) throws ResourceUnavailableException, ConcurrentOperationException {
- return super.destroyVm(vmId);
- }
-
- @Override
- public boolean preStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vo, boolean status, Object opaque) {
- return true;
- }
-
- @Override
- public boolean postStateTransitionEvent(State oldState, Event event, State newState, VirtualMachine vo, boolean status, Object opaque) {
- if (newState != State.Starting && newState != State.Error && newState != State.Expunging) {
- return true;
- }
-
- if (vo.getHypervisorType() != HypervisorType.BareMetal) {
- return true;
- }
-
- HostVO host = _hostDao.findById(vo.getHostId());
- if (host == null) {
- s_logger.debug("Skip oldState " + oldState + " to " + "newState " + newState + " transimtion");
- return true;
- }
- _hostDao.loadDetails(host);
-
- if (newState == State.Starting) {
- host.setDetail("vmName", vo.getInstanceName());
- s_logger.debug("Add vmName " + host.getDetail("vmName") + " to host " + host.getId() + " details");
- } else {
- if (host.getDetail("vmName") != null && host.getDetail("vmName").equalsIgnoreCase(vo.getInstanceName())) {
- s_logger.debug("Remove vmName " + host.getDetail("vmName") + " from host " + host.getId() + " details");
- host.getDetails().remove("vmName");
- }
- }
- _hostDao.saveDetails(host);
-
-
- return true;
- }
-}
diff --git a/server/src/com/cloud/baremetal/DhcpServerResponse.java b/server/src/com/cloud/baremetal/DhcpServerResponse.java
deleted file mode 100644
index 1aeba34548d..00000000000
--- a/server/src/com/cloud/baremetal/DhcpServerResponse.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.utils.IdentityProxy;
-import com.cloud.api.response.BaseResponse;
-import com.cloud.serializer.Param;
-import com.google.gson.annotations.SerializedName;
-
-public class DhcpServerResponse extends BaseResponse {
- @SerializedName(ApiConstants.ID) @Param(description="the ID of the Dhcp server")
- private IdentityProxy id = new IdentityProxy("host");
-
- public Long getId() {
- return id.getValue();
- }
-
- public void setId(Long id) {
- this.id.setValue(id);
- }
-}
diff --git a/server/src/com/cloud/baremetal/DhcpdResource.java b/server/src/com/cloud/baremetal/DhcpdResource.java
deleted file mode 100755
index 14cb28f3eaf..00000000000
--- a/server/src/com/cloud/baremetal/DhcpdResource.java
+++ /dev/null
@@ -1,129 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-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.routing.DhcpEntryCommand;
-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 DhcpdResource extends ExternalDhcpResourceBase {
- private static final Logger s_logger = Logger.getLogger(DhcpdResource.class);
-
- public boolean configure(String name, Map params) throws ConfigurationException {
- com.trilead.ssh2.Connection sshConnection = null;
- try {
- super.configure(name, params);
- s_logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, "******"));
- sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password);
- if (sshConnection == null) {
- throw new ConfigurationException(
- String.format("Cannot connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, "******"));
- }
-
- if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "[ -f '/usr/sbin/dhcpd' ]")) {
- throw new ConfigurationException("Cannot find dhcpd.conf /etc/dhcpd.conf at on " + _ip);
- }
-
- SCPClient scp = new SCPClient(sshConnection);
-
- String editHosts = "scripts/network/exdhcp/dhcpd_edithosts.py";
- String editHostsPath = Script.findScript("", editHosts);
- if (editHostsPath == null) {
- throw new ConfigurationException("Can not find script dnsmasq_edithosts.sh at " + editHosts);
- }
- scp.put(editHostsPath, "/usr/bin/", "0755");
-
- String prepareDhcpdScript = "scripts/network/exdhcp/prepare_dhcpd.sh";
- String prepareDhcpdScriptPath = Script.findScript("", prepareDhcpdScript);
- if (prepareDhcpdScriptPath == null) {
- throw new ConfigurationException("Can not find prepare_dhcpd.sh at " + prepareDhcpdScriptPath);
- }
- scp.put(prepareDhcpdScriptPath, "/usr/bin/", "0755");
-
- //TODO: tooooooooooooooo ugly here!!!
- String[] ips = _ip.split("\\.");
- ips[3] = "0";
- StringBuffer buf = new StringBuffer();
- int i;
- for (i=0;i());
- }
- }
-
- Answer execute(DhcpEntryCommand cmd) {
- com.trilead.ssh2.Connection sshConnection = null;
- try {
- sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password);
- if (sshConnection == null) {
- return new Answer(cmd, false, "ssh authenticate failed");
- }
- String addDhcp = String.format("python /usr/bin/dhcpd_edithosts.py %1$s %2$s %3$s %4$s %5$s %6$s",
- cmd.getVmMac(), cmd.getVmIpAddress(), cmd.getVmName(), cmd.getDns(), cmd.getGateway(), cmd.getNextServer());
- if (!SSHCmdHelper.sshExecuteCmd(sshConnection, addDhcp)) {
- return new Answer(cmd, false, "add Dhcp entry failed");
- } else {
- return new Answer(cmd);
- }
- } finally {
- SSHCmdHelper.releaseSshConnection(sshConnection);
- }
- }
-
- @Override
- public Answer executeRequest(Command cmd) {
- if (cmd instanceof DhcpEntryCommand) {
- return execute((DhcpEntryCommand)cmd);
- } else {
- return super.executeRequest(cmd);
- }
- }
-}
diff --git a/server/src/com/cloud/baremetal/DnsmasqResource.java b/server/src/com/cloud/baremetal/DnsmasqResource.java
deleted file mode 100644
index ee4845abce2..00000000000
--- a/server/src/com/cloud/baremetal/DnsmasqResource.java
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import java.io.IOException;
-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.routing.DhcpEntryCommand;
-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 DnsmasqResource extends ExternalDhcpResourceBase {
- private static final Logger s_logger = Logger.getLogger(DnsmasqResource.class);
-
- public boolean configure(String name, Map params) throws ConfigurationException {
- com.trilead.ssh2.Connection sshConnection = null;
- try {
- super.configure(name, params);
- s_logger.debug(String.format("Trying to connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s)", _ip, _username, _password));
- sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password);
- if (sshConnection == null) {
- throw new ConfigurationException(
- String.format("Cannot connect to DHCP server(IP=%1$s, username=%2$s, password=%3$s", _ip, _username, _password));
- }
-
- if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "[ -f '/usr/sbin/dnsmasq' ]")) {
- throw new ConfigurationException("Cannot find dnsmasq at /usr/sbin/dnsmasq on " + _ip);
- }
-
- SCPClient scp = new SCPClient(sshConnection);
-
- String editHosts = "scripts/network/exdhcp/dnsmasq_edithosts.sh";
- String editHostsPath = Script.findScript("", editHosts);
- if (editHostsPath == null) {
- throw new ConfigurationException("Can not find script dnsmasq_edithosts.sh at " + editHosts);
- }
- scp.put(editHostsPath, "/usr/bin/", "0755");
-
- String prepareDnsmasq = "scripts/network/exdhcp/prepare_dnsmasq.sh";
- String prepareDnsmasqPath = Script.findScript("", prepareDnsmasq);
- if (prepareDnsmasqPath == null) {
- throw new ConfigurationException("Can not find script prepare_dnsmasq.sh at " + prepareDnsmasq);
- }
- scp.put(prepareDnsmasqPath, "/usr/bin/", "0755");
-
- String prepareCmd = String.format("sh /usr/bin/prepare_dnsmasq.sh %1$s %2$s %3$s", _gateway, _dns, _ip);
- if (!SSHCmdHelper.sshExecuteCmd(sshConnection, prepareCmd)) {
- throw new ConfigurationException("prepare dnsmasq at " + _ip + " failed");
- }
-
- s_logger.debug("Dnsmasq resource configure successfully");
- return true;
- } catch (Exception e) {
- s_logger.debug("Dnsmasq resorce configure failed", e);
- throw new ConfigurationException(e.getMessage());
- } finally {
- SSHCmdHelper.releaseSshConnection(sshConnection);
- }
- }
-
- @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());
- }
- }
-
- Answer execute(DhcpEntryCommand cmd) {
- com.trilead.ssh2.Connection sshConnection = null;
- try {
- sshConnection = SSHCmdHelper.acquireAuthorizedConnection(_ip, _username, _password);
- if (sshConnection == null) {
- return new Answer(cmd, false, "ssh authenticate failed");
- }
- String addDhcp = String.format("/usr/bin/dnsmasq_edithosts.sh %1$s %2$s %3$s", cmd.getVmMac(), cmd.getVmIpAddress(), cmd.getVmName());
- if (!SSHCmdHelper.sshExecuteCmd(sshConnection, addDhcp)) {
- return new Answer(cmd, false, "add Dhcp entry failed");
- } else {
- return new Answer(cmd);
- }
- } finally {
- SSHCmdHelper.releaseSshConnection(sshConnection);
- }
- }
-
- @Override
- public Answer executeRequest(Command cmd) {
- if (cmd instanceof DhcpEntryCommand) {
- return execute((DhcpEntryCommand)cmd);
- } else {
- return super.executeRequest(cmd);
- }
- }
-}
diff --git a/server/src/com/cloud/baremetal/ExternalDhcpEntryListener.java b/server/src/com/cloud/baremetal/ExternalDhcpEntryListener.java
deleted file mode 100644
index 93882fa65e8..00000000000
--- a/server/src/com/cloud/baremetal/ExternalDhcpEntryListener.java
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-public interface ExternalDhcpEntryListener {
- public class DhcpEntryState {
- String _name;
-
- public static final DhcpEntryState add = new DhcpEntryState("add");
- public static final DhcpEntryState old = new DhcpEntryState("old");
- public static final DhcpEntryState del = new DhcpEntryState("del");
-
- public DhcpEntryState(String name) {
- _name = name;
- }
-
- public String getName() {
- return _name;
- }
- }
-
- /**
- * Notify that DHCP entry state change
- * @param ip
- * @param mac
- * @param DHCP entry state
- * @return: true means continuous listen on the entry, false cancels the listener
- */
- public boolean notify(String ip, String mac, DhcpEntryState state, Object userData);
-}
diff --git a/server/src/com/cloud/baremetal/ExternalDhcpManager.java b/server/src/com/cloud/baremetal/ExternalDhcpManager.java
deleted file mode 100644
index 70c2227cfc4..00000000000
--- a/server/src/com/cloud/baremetal/ExternalDhcpManager.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import com.cloud.baremetal.ExternalDhcpEntryListener.DhcpEntryState;
-import com.cloud.deploy.DeployDestination;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.host.Host;
-import com.cloud.network.Network;
-import com.cloud.uservm.UserVm;
-import com.cloud.utils.component.Manager;
-import com.cloud.vm.NicProfile;
-import com.cloud.vm.ReservationContext;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-
-public interface ExternalDhcpManager extends Manager {
- public static class DhcpServerType {
- private String _name;
-
- public static final DhcpServerType Dnsmasq = new DhcpServerType("Dnsmasq");
- public static final DhcpServerType Dhcpd = new DhcpServerType("Dhcpd");
-
- public DhcpServerType(String name) {
- _name = name;
- }
-
- public String getName() {
- return _name;
- }
-
- }
-
-
- DhcpServerResponse getApiResponse(Host dhcpServer);
-
- boolean addVirtualMachineIntoNetwork(Network network, NicProfile nic, VirtualMachineProfile extends VirtualMachine> profile, DeployDestination dest, ReservationContext context) throws ResourceUnavailableException;
-
- Host addDhcpServer(Long zoneId, Long podId, String type, String url, String username, String password);
-}
diff --git a/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java b/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java
deleted file mode 100755
index 37a88dd02f0..00000000000
--- a/server/src/com/cloud/baremetal/ExternalDhcpManagerImpl.java
+++ /dev/null
@@ -1,249 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-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.Inject;
-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;
-
-@Local(value = {ExternalDhcpManager.class})
-public class ExternalDhcpManagerImpl implements ExternalDhcpManager, ResourceStateAdapter {
- private static final org.apache.log4j.Logger s_logger = Logger.getLogger(ExternalDhcpManagerImpl.class);
- protected String _name;
- @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;
- }
-
- @Override
- public String getName() {
- return _name;
- }
-
- 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.getId());
- 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.getDataCenterIdToDeployIn());
- if (servers.size() != 1) {
- throw new CloudRuntimeException("Wrong number of PXE server found in zone " + vm.getDataCenterIdToDeployIn()
- + " 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 extends VirtualMachine> profile, DeployDestination dest,
- ReservationContext context) throws ResourceUnavailableException {
- Long zoneId = profile.getVirtualMachine().getDataCenterIdToDeployIn();
- 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(), dns, nic.getGateway());
- 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;
- }
-}
diff --git a/server/src/com/cloud/baremetal/ExternalDhcpResourceBase.java b/server/src/com/cloud/baremetal/ExternalDhcpResourceBase.java
deleted file mode 100644
index 9340767495c..00000000000
--- a/server/src/com/cloud/baremetal/ExternalDhcpResourceBase.java
+++ /dev/null
@@ -1,164 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-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("");
- 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) {
- }
-
-}
diff --git a/server/src/com/cloud/baremetal/HttpCallException.java b/server/src/com/cloud/baremetal/HttpCallException.java
deleted file mode 100644
index 3633793bf0b..00000000000
--- a/server/src/com/cloud/baremetal/HttpCallException.java
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-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);
- }
-}
diff --git a/server/src/com/cloud/baremetal/PingPxeServerResource.java b/server/src/com/cloud/baremetal/PingPxeServerResource.java
deleted file mode 100755
index ac25697428a..00000000000
--- a/server/src/com/cloud/baremetal/PingPxeServerResource.java
+++ /dev/null
@@ -1,192 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-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);
- }
- }
-}
diff --git a/server/src/com/cloud/baremetal/PxeServerManager.java b/server/src/com/cloud/baremetal/PxeServerManager.java
deleted file mode 100644
index 2ac2aacdf9b..00000000000
--- a/server/src/com/cloud/baremetal/PxeServerManager.java
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-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);
-}
diff --git a/server/src/com/cloud/baremetal/PxeServerManagerImpl.java b/server/src/com/cloud/baremetal/PxeServerManagerImpl.java
deleted file mode 100755
index 5ddc9d14542..00000000000
--- a/server/src/com/cloud/baremetal/PxeServerManagerImpl.java
+++ /dev/null
@@ -1,143 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-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.Adapters;
-import com.cloud.utils.component.Inject;
-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;
-
-@Local(value = {PxeServerManager.class})
-public class PxeServerManagerImpl implements PxeServerManager, ResourceStateAdapter {
- private static final org.apache.log4j.Logger s_logger = Logger.getLogger(PxeServerManagerImpl.class);
- protected String _name;
- @Inject DataCenterDao _dcDao;
- @Inject HostDao _hostDao;
- @Inject AgentManager _agentMgr;
- @Inject ExternalDhcpManager exDhcpMgr;
- @Inject ResourceManager _resourceMgr;
- @Inject(adapter=PxeServerService.class)
- protected Adapters _services;
-
- @Override
- public boolean configure(String name, Map params) throws ConfigurationException {
- _name = name;
- _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;
- }
-
- @Override
- public String getName() {
- return _name;
- }
-
- protected PxeServerService getServiceByType(String type) {
- PxeServerService _service;
- _service = _services.get(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.getId());
- 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;
- }
-}
diff --git a/server/src/com/cloud/baremetal/PxeServerProfile.java b/server/src/com/cloud/baremetal/PxeServerProfile.java
deleted file mode 100644
index 72076d1280d..00000000000
--- a/server/src/com/cloud/baremetal/PxeServerProfile.java
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-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;
- }
-}
diff --git a/server/src/com/cloud/baremetal/PxeServerResourceBase.java b/server/src/com/cloud/baremetal/PxeServerResourceBase.java
deleted file mode 100644
index 7b070cde121..00000000000
--- a/server/src/com/cloud/baremetal/PxeServerResourceBase.java
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-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("");
- 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);
- }
- }
-
-}
diff --git a/server/src/com/cloud/baremetal/PxeServerResponse.java b/server/src/com/cloud/baremetal/PxeServerResponse.java
deleted file mode 100644
index 5e10958ec45..00000000000
--- a/server/src/com/cloud/baremetal/PxeServerResponse.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.baremetal;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.utils.IdentityProxy;
-import com.cloud.api.response.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 IdentityProxy id = new IdentityProxy("host");
-
- public Long getId() {
- return id.getValue();
- }
-
- public void setId(Long id) {
- this.id.setValue(id);
- }
-}
diff --git a/server/src/com/cloud/baremetal/PxeServerService.java b/server/src/com/cloud/baremetal/PxeServerService.java
deleted file mode 100644
index 684cef8f39f..00000000000
--- a/server/src/com/cloud/baremetal/PxeServerService.java
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-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);
-}
diff --git a/server/src/com/cloud/configuration/PremiumComponentLibrary.java b/server/src/com/cloud/configuration/PremiumComponentLibrary.java
index fd240f6e92a..292844a0dd2 100755
--- a/server/src/com/cloud/configuration/PremiumComponentLibrary.java
+++ b/server/src/com/cloud/configuration/PremiumComponentLibrary.java
@@ -15,13 +15,6 @@ package com.cloud.configuration;
import java.util.ArrayList;
import java.util.List;
-import com.cloud.baremetal.BareMetalPingServiceImpl;
-import com.cloud.baremetal.BareMetalTemplateAdapter;
-import com.cloud.baremetal.BareMetalVmManagerImpl;
-import com.cloud.baremetal.ExternalDhcpManagerImpl;
-import com.cloud.baremetal.PxeServerManager.PxeServerType;
-import com.cloud.baremetal.PxeServerManagerImpl;
-import com.cloud.baremetal.PxeServerService;
import com.cloud.ha.HighAvailabilityManagerExtImpl;
import com.cloud.hypervisor.vmware.VmwareManagerImpl;
import com.cloud.netapp.NetappManagerImpl;
@@ -62,9 +55,6 @@ public class PremiumComponentLibrary extends DefaultComponentLibrary {
addManager("HA Manager", HighAvailabilityManagerExtImpl.class);
addManager("VMWareManager", VmwareManagerImpl.class);
addManager("ExternalNetworkManager", ExternalNetworkDeviceManagerImpl.class);
- addManager("BareMetalVmManager", BareMetalVmManagerImpl.class);
- addManager("ExternalDhcpManager", ExternalDhcpManagerImpl.class);
- addManager("PxeServerManager", PxeServerManagerImpl.class);
addManager("NetworkUsageManager", NetworkUsageManagerImpl.class);
addManager("NetappManager", NetappManagerImpl.class);
}
@@ -72,7 +62,5 @@ public class PremiumComponentLibrary extends DefaultComponentLibrary {
@Override
protected void populateAdapters() {
super.populateAdapters();
- addAdapter(PxeServerService.class, PxeServerType.PING.getName(), BareMetalPingServiceImpl.class);
- addAdapter(TemplateAdapter.class, TemplateAdapterType.BareMetal.getName(), BareMetalTemplateAdapter.class);
}
}
diff --git a/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java b/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java
index f9357cfc7a6..adc7300b0f0 100755
--- a/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java
+++ b/server/src/com/cloud/network/ExternalNetworkDeviceManagerImpl.java
@@ -31,10 +31,6 @@ import com.cloud.api.PlugService;
import com.cloud.api.commands.AddNetworkDeviceCmd;
import com.cloud.api.commands.DeleteNetworkDeviceCmd;
import com.cloud.api.commands.ListNetworkDeviceCmd;
-import com.cloud.baremetal.ExternalDhcpManager;
-import com.cloud.baremetal.PxeServerManager;
-import com.cloud.baremetal.PxeServerProfile;
-import com.cloud.baremetal.PxeServerManager.PxeServerType;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.VlanDao;
@@ -79,8 +75,6 @@ import com.cloud.vm.dao.NicDao;
@Local(value = {ExternalNetworkDeviceManager.class})
public class ExternalNetworkDeviceManagerImpl implements ExternalNetworkDeviceManager {
- @Inject ExternalDhcpManager _dhcpMgr;
- @Inject PxeServerManager _pxeMgr;
@Inject AgentManager _agentMgr;
@Inject NetworkManager _networkMgr;
@Inject HostDao _hostDao;
@@ -147,35 +141,7 @@ public class ExternalNetworkDeviceManagerImpl implements ExternalNetworkDeviceMa
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 if (cmd.getDeviceType().equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) {
+ if (cmd.getDeviceType().equalsIgnoreCase(NetworkDevice.JuniperSRXFirewall.getName())) {
Long physicalNetworkId = (params.get(ApiConstants.PHYSICAL_NETWORK_ID)==null)?Long.parseLong((String)params.get(ApiConstants.PHYSICAL_NETWORK_ID)):null;
String url = (String) params.get(ApiConstants.URL);
String username = (String) params.get(ApiConstants.USERNAME);
@@ -225,29 +191,7 @@ public class ExternalNetworkDeviceManagerImpl implements ExternalNetworkDeviceMa
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();
- r.setZoneId(host.getDataCenterId());
- r.setPodId(host.getPodId());
- 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 if (host.getType() == Host.Type.ExternalLoadBalancer) {
+ if (host.getType() == Host.Type.ExternalLoadBalancer) {
ExternalLoadBalancerDeviceManager lbDeviceMgr = (ExternalLoadBalancerDeviceManager) _f5LbElementService;
response = _f5LbElementService.createExternalLoadBalancerResponse(host);
} else if (host.getType() == Host.Type.ExternalFirewall) {
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 bbf4ff8d69d..00000000000
--- a/server/src/com/cloud/network/element/BareMetalElement.java
+++ /dev/null
@@ -1,124 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.network.element;
-
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-
-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.component.Inject;
-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 extends VirtualMachine> vm, DeployDestination dest,
- ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
- Host host = dest.getHost();
- if (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 extends VirtualMachine> 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) 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(List services) {
- return true;
- }
-}
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 262aa8b02c4..00000000000
--- a/server/src/com/cloud/network/element/ExternalDhcpElement.java
+++ /dev/null
@@ -1,148 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License. Citrix Systems, Inc.
-// reserves all rights not expressly granted by 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.
-//
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.network.element;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-
-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.utils.component.Inject;
-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 extends VirtualMachine> vm, DeployDestination dest,
- ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
- return true;
- }
-
- @Override
- public boolean release(Network network, NicProfile nic, VirtualMachineProfile extends VirtualMachine> 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) 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 extends VirtualMachine> 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(List services) {
- return true;
- }
-}