You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by fr...@apache.org on 2013/02/22 00:44:17 UTC
[5/7] git commit: refs/heads/master - CloudStack CLOUDSTACK-774
Supporting kickstart in CloudStack baremetal
CloudStack CLOUDSTACK-774
Supporting kickstart in CloudStack baremetal
able to start vm
Conflicts:
client/tomcatconf/componentContext.xml.in
server/src/com/cloud/baremetal/BareMetalTemplateAdapter.java
server/src/com/cloud/baremetal/BareMetalVmManagerImpl.java
server/src/com/cloud/vm/UserVmManagerImpl.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/15ead099
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/15ead099
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/15ead099
Branch: refs/heads/master
Commit: 15ead099a1d4d7436a249a742659ce404ecbf7b5
Parents: 55b77c7
Author: frank <fr...@citrix.com>
Authored: Tue Feb 19 17:10:45 2013 -0800
Committer: frank <fr...@citrix.com>
Committed: Thu Feb 21 15:48:08 2013 -0800
----------------------------------------------------------------------
.../api/command/user/vm/DeployVMCmd.java | 4 +-
client/tomcatconf/componentContext.xml.in | 21 +-
client/tomcatconf/log4j-cloud.xml.in | 2 +-
.../cloud/entity/api/VMEntityManagerImpl.java | 10 +-
.../cloud/baremetal/manager/BareMetalPlanner.java | 167 ++++
.../manager/BaremetalPlannerSelector.java | 23 +
.../com/cloud/baremetal/BareMetalDiscoverer.java | 245 ------
server/src/com/cloud/baremetal/BareMetalGuru.java | 59 --
.../cloud/baremetal/BareMetalPingServiceImpl.java | 199 -----
.../cloud/baremetal/BareMetalPxeServiceBase.java | 56 --
.../com/cloud/baremetal/BareMetalResourceBase.java | 630 ---------------
.../com/cloud/baremetal/BareMetalVmManager.java | 22 -
.../com/cloud/baremetal/DhcpServerResponse.java | 35 -
server/src/com/cloud/baremetal/DhcpdResource.java | 133 ---
.../src/com/cloud/baremetal/DnsmasqResource.java | 123 ---
.../cloud/baremetal/ExternalDhcpEntryListener.java | 44 -
.../com/cloud/baremetal/ExternalDhcpManager.java | 54 --
.../cloud/baremetal/ExternalDhcpManagerImpl.java | 250 ------
.../cloud/baremetal/ExternalDhcpResourceBase.java | 198 -----
.../src/com/cloud/baremetal/HttpCallException.java | 28 -
.../com/cloud/baremetal/PingPxeServerResource.java | 196 -----
.../src/com/cloud/baremetal/PxeServerManager.java | 54 --
.../com/cloud/baremetal/PxeServerManagerImpl.java | 145 ----
.../src/com/cloud/baremetal/PxeServerProfile.java | 90 --
.../com/cloud/baremetal/PxeServerResourceBase.java | 185 -----
.../src/com/cloud/baremetal/PxeServerResponse.java | 35 -
.../src/com/cloud/baremetal/PxeServerService.java | 35 -
.../deploy/AbstractDeployPlannerSelector.java | 58 ++
server/src/com/cloud/deploy/BareMetalPlanner.java | 163 ----
.../com/cloud/deploy/DeployPlannerSelector.java | 8 +
.../cloud/deploy/HypervisorVmPlannerSelector.java | 17 +
server/src/com/cloud/host/dao/HostDaoImpl.java | 2 +-
.../network/ExternalNetworkDeviceManagerImpl.java | 84 +--
.../src/com/cloud/network/NetworkManagerImpl.java | 2 +-
.../cloud/network/element/BareMetalElement.java | 128 ---
.../cloud/network/element/ExternalDhcpElement.java | 152 ----
server/src/com/cloud/vm/UserVmManagerImpl.java | 32 +-
.../com/cloud/vm/VirtualMachineManagerImpl.java | 12 +-
setup/db/db/schema-40to410.sql | 28 +
39 files changed, 352 insertions(+), 3377 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
old mode 100644
new mode 100755
index 70a263d..56cb460
--- a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java
@@ -388,7 +388,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
} catch (InsufficientCapacityException ex) {
s_logger.info(ex);
- s_logger.trace(ex);
+ s_logger.info(ex.getMessage(), ex);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
}
} else {
@@ -477,7 +477,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
}
} catch (InsufficientCapacityException ex) {
s_logger.info(ex);
- s_logger.trace(ex);
+ s_logger.trace(ex.getMessage(), ex);
throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
} catch (ResourceUnavailableException ex) {
s_logger.warn("Exception: ", ex);
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/client/tomcatconf/componentContext.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/componentContext.xml.in b/client/tomcatconf/componentContext.xml.in
index 8169796..1629889 100644
--- a/client/tomcatconf/componentContext.xml.in
+++ b/client/tomcatconf/componentContext.xml.in
@@ -65,9 +65,6 @@
<bean id="Ovs" class="com.cloud.network.element.OvsElement">
<property name="name" value="Ovs"/>
</bean>
- <bean id="ExternalDhcpServer" class="com.cloud.network.element.ExternalDhcpElement">
- <property name="name" value="ExternalDhcpServer"/>
- </bean>
<bean id="BareMetalDhcp" class="com.cloud.baremetal.networkservice.BaremetalDhcpElement">
<property name="name" value="BareMetalDhcp"/>
</bean>
@@ -223,9 +220,17 @@
<property name="name" value="UserConcentratedPod"/>
</bean>
- <bean id="BareMetalPlanner" class="com.cloud.deploy.BareMetalPlanner">
+ <bean id="BareMetalPlanner" class="com.cloud.baremetal.manager.BareMetalPlanner">
<property name="name" value="BareMetal Fit"/>
</bean>
+
+ <bean id="BaremetalPlannerSelector" class="com.cloud.baremetal.manager.BaremetalPlannerSelector">
+ <property name="name" value="BaremetalPlannerSelector"/>
+ </bean>
+
+ <bean id="HypervisorPlannerSelector" class="com.cloud.deploy.HypervisorVmPlannerSelector">
+ <property name="name" value="BaremetalPlannerSelector"/>
+ </bean>
<!--
@@ -279,10 +284,6 @@
<property name="name" value="KVMGuru"/>
</bean>
- <bean id="BareMetalGuru" class="com.cloud.baremetal.BareMetalGuru">
- <property name="name" value="BareMetalGuru"/>
- </bean>
-
<bean id="HypervGuru" class="com.cloud.hypervisor.guru.HypervGuru">
<property name="name" value="HypervGuru"/>
</bean>
@@ -296,5 +297,9 @@
<property name="name" value="SimulatorGuru"/>
</bean>
-->
+
+ <bean id="BaremetalGuru" class="com.cloud.baremetal.manager.BareMetalGuru">
+ <property name="name" value="BaremetalGuru"/>
+ </bean>
</beans>
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/client/tomcatconf/log4j-cloud.xml.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/log4j-cloud.xml.in b/client/tomcatconf/log4j-cloud.xml.in
index 02f7099..0866693 100755
--- a/client/tomcatconf/log4j-cloud.xml.in
+++ b/client/tomcatconf/log4j-cloud.xml.in
@@ -105,7 +105,7 @@ under the License.
</category>
<category name="org.apache.cloudstack.api.command">
- <priority value="DEBUG"/>
+ <priority value="TRACE"/>
</category>
<category name="org">
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
old mode 100644
new mode 100755
index ee08cf3..552aba4
--- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
@@ -42,6 +42,7 @@ import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InsufficientServerCapacityException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.dao.NetworkDao;
import com.cloud.org.Cluster;
import com.cloud.service.dao.ServiceOfferingDao;
@@ -168,10 +169,13 @@ public class VMEntityManagerImpl implements VMEntityManager {
//save destination with VMEntityVO
VMReservationVO vmReservation = new VMReservationVO(vm.getId(), dest.getDataCenter().getId(), dest.getPod().getId(), dest.getCluster().getId(), dest.getHost().getId());
Map<Long,Long> volumeReservationMap = new HashMap<Long,Long>();
- for(Volume vo : dest.getStorageForDisks().keySet()){
- volumeReservationMap.put(vo.getId(), dest.getStorageForDisks().get(vo).getId());
+
+ if (vm.getHypervisorType() != HypervisorType.BareMetal) {
+ for(Volume vo : dest.getStorageForDisks().keySet()){
+ volumeReservationMap.put(vo.getId(), dest.getStorageForDisks().get(vo).getId());
+ }
+ vmReservation.setVolumeReservation(volumeReservationMap);
}
- vmReservation.setVolumeReservation(volumeReservationMap);
vmEntityVO.setVmReservation(vmReservation);
_vmEntityDao.persist(vmEntityVO);
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java
new file mode 100755
index 0000000..fe51eb0
--- /dev/null
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BareMetalPlanner.java
@@ -0,0 +1,167 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.baremetal.manager;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.capacity.CapacityManager;
+import com.cloud.configuration.Config;
+import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.Pod;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.HostPodDao;
+import com.cloud.deploy.DeployDestination;
+import com.cloud.deploy.DeploymentPlan;
+import com.cloud.deploy.DeploymentPlanner;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.exception.InsufficientServerCapacityException;
+import com.cloud.host.Host;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.org.Cluster;
+import com.cloud.resource.ResourceManager;
+import com.cloud.utils.NumbersUtil;
+import com.cloud.utils.component.AdapterBase;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
+
+@Local(value=DeploymentPlanner.class)
+public class BareMetalPlanner extends AdapterBase implements DeploymentPlanner {
+ private static final Logger s_logger = Logger.getLogger(BareMetalPlanner.class);
+ @Inject protected DataCenterDao _dcDao;
+ @Inject protected HostPodDao _podDao;
+ @Inject protected ClusterDao _clusterDao;
+ @Inject protected HostDao _hostDao;
+ @Inject protected ConfigurationDao _configDao;
+ @Inject protected CapacityManager _capacityMgr;
+ @Inject protected ResourceManager _resourceMgr;
+
+ @Override
+ public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
+ VirtualMachine vm = vmProfile.getVirtualMachine();
+ ServiceOffering offering = vmProfile.getServiceOffering();
+ String hostTag = null;
+
+ String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
+ float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
+
+ String haVmTag = (String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
+
+ if (vm.getLastHostId() != null && haVmTag == null) {
+ HostVO h = _hostDao.findById(vm.getLastHostId());
+ DataCenter dc = _dcDao.findById(h.getDataCenterId());
+ Pod pod = _podDao.findById(h.getPodId());
+ Cluster c = _clusterDao.findById(h.getClusterId());
+ s_logger.debug("Start baremetal vm " + vm.getId() + " on last stayed host " + h.getId());
+ return new DeployDestination(dc, pod, c, h);
+ }
+
+ if (haVmTag != null) {
+ hostTag = haVmTag;
+ } else if (offering.getHostTag() != null) {
+ String[] tags = offering.getHostTag().split(",");
+ if (tags.length > 0) {
+ hostTag = tags[0];
+ }
+ }
+
+ List<ClusterVO> clusters = _clusterDao.listByDcHyType(vm.getDataCenterId(), HypervisorType.BareMetal.toString());
+ int cpu_requested;
+ long ram_requested;
+ HostVO target = null;
+ List<HostVO> hosts;
+ for (ClusterVO cluster : clusters) {
+ hosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
+ if (hostTag != null) {
+ for (HostVO h : hosts) {
+ _hostDao.loadDetails(h);
+ if (h.getDetail("hostTag") != null && h.getDetail("hostTag").equalsIgnoreCase(hostTag)) {
+ target = h;
+ break;
+ }
+ }
+ }
+ }
+
+ if (target == null) {
+ s_logger.warn("Cannot find host with tag " + hostTag + " use capacity from service offering");
+ cpu_requested = offering.getCpu() * offering.getSpeed();
+ ram_requested = offering.getRamSize() * 1024 * 1024;
+ } else {
+ cpu_requested = target.getCpus() * target.getSpeed().intValue();
+ ram_requested = target.getTotalMemory();
+ }
+
+ for (ClusterVO cluster : clusters) {
+ if (haVmTag == null) {
+ hosts = _resourceMgr.listAllUpAndEnabledNonHAHosts(Host.Type.Routing, cluster.getId(), cluster.getPodId(), cluster.getDataCenterId());
+ } else {
+ s_logger.warn("Cannot find HA host with tag " + haVmTag + " in cluster id=" + cluster.getId() + ", pod id=" + cluster.getPodId() + ", data center id=" + cluster.getDataCenterId());
+ return null;
+ }
+ for (HostVO h : hosts) {
+ if (_capacityMgr.checkIfHostHasCapacity(h.getId(), cpu_requested, ram_requested, false, cpuOverprovisioningFactor, true)) {
+ s_logger.debug("Find host " + h.getId() + " has enough capacity");
+ DataCenter dc = _dcDao.findById(h.getDataCenterId());
+ Pod pod = _podDao.findById(h.getPodId());
+ return new DeployDestination(dc, pod, cluster, h);
+ }
+ }
+ }
+
+ s_logger.warn(String.format("Cannot find enough capacity(requested cpu=%1$s memory=%2$s)", cpu_requested, ram_requested));
+ return null;
+ }
+
+ @Override
+ public boolean canHandle(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, ExcludeList avoid) {
+ return vm.getHypervisorType() == HypervisorType.BareMetal;
+ }
+
+ @Override
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ return true;
+ }
+
+ @Override
+ public boolean start() {
+ return true;
+ }
+
+ @Override
+ public boolean stop() {
+ return true;
+ }
+
+ @Override
+ public boolean check(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan plan, DeployDestination dest, ExcludeList exclude) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalPlannerSelector.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalPlannerSelector.java b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalPlannerSelector.java
new file mode 100755
index 0000000..08b4ad6
--- /dev/null
+++ b/plugins/hypervisors/baremetal/src/com/cloud/baremetal/manager/BaremetalPlannerSelector.java
@@ -0,0 +1,23 @@
+package com.cloud.baremetal.manager;
+
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.naming.ConfigurationException;
+
+import com.cloud.deploy.AbstractDeployPlannerSelector;
+import com.cloud.deploy.DeployPlannerSelector;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.vm.UserVmVO;
+@Local(value = {DeployPlannerSelector.class})
+public class BaremetalPlannerSelector extends AbstractDeployPlannerSelector{
+
+ @Override
+ public String selectPlanner(UserVmVO vm) {
+ if (vm.getHypervisorType() == HypervisorType.BareMetal) {
+ return "BareMetalPlanner";
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/BareMetalDiscoverer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalDiscoverer.java b/server/src/com/cloud/baremetal/BareMetalDiscoverer.java
deleted file mode 100755
index e751885..0000000
--- a/server/src/com/cloud/baremetal/BareMetalDiscoverer.java
+++ /dev/null
@@ -1,245 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.baremetal;
-
-import java.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.inject.Inject;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.StartupCommand;
-import com.cloud.agent.api.StartupRoutingCommand;
-import org.apache.cloudstack.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.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<String, Object> 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<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags)
- throws DiscoveryException {
- Map<BareMetalResourceBase, Map<String, String>> resources = new HashMap<BareMetalResourceBase, Map<String, String>>();
- Map<String, String> details = new HashMap<String, String>();
-
- 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<String, Object> params = new HashMap<String, Object>();
- 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<HostVO> 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<String, String> details,
- List<String> 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<VMInstanceVO> 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);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/BareMetalGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalGuru.java b/server/src/com/cloud/baremetal/BareMetalGuru.java
deleted file mode 100755
index 9268415..0000000
--- a/server/src/com/cloud/baremetal/BareMetalGuru.java
+++ /dev/null
@@ -1,59 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.baremetal;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-
-import com.cloud.agent.api.to.VirtualMachineTO;
-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.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 <T extends VirtualMachine> VirtualMachineTO implement(VirtualMachineProfile<T> 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;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/BareMetalPingServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalPingServiceImpl.java b/server/src/com/cloud/baremetal/BareMetalPingServiceImpl.java
deleted file mode 100755
index 3ccf298..0000000
--- a/server/src/com/cloud/baremetal/BareMetalPingServiceImpl.java
+++ /dev/null
@@ -1,199 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.baremetal;
-
-import java.net.URI;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-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.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;
-
-@Component
-@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<HostVO> pxeServers = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.PxeServer, null, podId, zoneId);
- if (pxeServers.size() != 0) {
- InvalidParameterValueException ex = new InvalidParameterValueException("Already had a PXE server in Pod with specified podId and zone with specified zoneId");
- ex.addProxyObject("pod", podId, "podId");
- ex.addProxyObject(zone, zoneId, "zoneId");
- }
-
-
- String ipAddress = profile.getUrl();
- String username = profile.getUsername();
- String password = profile.getPassword();
-
- ServerResource resource = null;
- Map params = new HashMap<String, String>();
- 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<UserVmVO> profile, DeployDestination dest, ReservationContext context, Long pxeServerId) {
- List<NicProfile> 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<NicVO> 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;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/BareMetalPxeServiceBase.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalPxeServiceBase.java b/server/src/com/cloud/baremetal/BareMetalPxeServiceBase.java
deleted file mode 100644
index 0df0650..0000000
--- a/server/src/com/cloud/baremetal/BareMetalPxeServiceBase.java
+++ /dev/null
@@ -1,56 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.baremetal;
-
-import java.util.Map;
-
-import javax.inject.Inject;
-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.ManagerBase;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.vm.ReservationContext;
-import com.cloud.vm.UserVmVO;
-import com.cloud.vm.VirtualMachineProfile;
-import com.cloud.vm.dao.NicDao;
-
-public abstract class BareMetalPxeServiceBase extends ManagerBase implements PxeServerService {
- @Inject DataCenterDao _dcDao;
- @Inject HostDao _hostDao;
- @Inject AgentManager _agentMgr;
- @Inject ExternalDhcpManager exDhcpMgr;
- @Inject HostPodDao _podDao;
- @Inject NicDao _nicDao;
-
- @Override
- public boolean prepare(VirtualMachineProfile<UserVmVO> 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);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/BareMetalResourceBase.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalResourceBase.java b/server/src/com/cloud/baremetal/BareMetalResourceBase.java
deleted file mode 100755
index 274cf07..0000000
--- a/server/src/com/cloud/baremetal/BareMetalResourceBase.java
+++ /dev/null
@@ -1,630 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.baremetal;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.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 org.apache.cloudstack.api.ApiConstants;
-import com.cloud.host.Host.Type;
-import com.cloud.hypervisor.Hypervisor;
-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<String, State> _vms = new HashMap<String, State>(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<String, Object> 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<String, State> fullSync() {
- Map<String, State> changes = new HashMap<String, State>();
-
- 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<String, String>(), 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", false);
- }
-
- return new RebootAnswer(cmd, "reboot succeeded", true);
- }
-
- 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, true) : new StopAnswer(cmd, "IPMI power off failed", false);
- }
-
- 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<String, State> deltaSync() {
- final HashMap<String, State> changes = new HashMap<String, State>();
- /*
- * 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;
- }
-
- @Override
- public void setName(String name) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void setConfigParams(Map<String, Object> params) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public Map<String, Object> getConfigParams() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public int getRunLevel() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public void setRunLevel(int level) {
- // TODO Auto-generated method stub
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/BareMetalVmManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/BareMetalVmManager.java b/server/src/com/cloud/baremetal/BareMetalVmManager.java
deleted file mode 100644
index 900c57f..0000000
--- a/server/src/com/cloud/baremetal/BareMetalVmManager.java
+++ /dev/null
@@ -1,22 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.baremetal;
-
-import com.cloud.vm.UserVmManager;
-
-public interface BareMetalVmManager extends UserVmManager {
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/DhcpServerResponse.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/DhcpServerResponse.java b/server/src/com/cloud/baremetal/DhcpServerResponse.java
deleted file mode 100644
index db46ccd..0000000
--- a/server/src/com/cloud/baremetal/DhcpServerResponse.java
+++ /dev/null
@@ -1,35 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.baremetal;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.api.BaseResponse;
-import com.cloud.serializer.Param;
-import com.google.gson.annotations.SerializedName;
-
-public class DhcpServerResponse extends BaseResponse {
- @SerializedName(ApiConstants.ID) @Param(description="the ID of the Dhcp server")
- private String id;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/DhcpdResource.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/DhcpdResource.java b/server/src/com/cloud/baremetal/DhcpdResource.java
deleted file mode 100755
index 436d275..0000000
--- a/server/src/com/cloud/baremetal/DhcpdResource.java
+++ /dev/null
@@ -1,133 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.baremetal;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.Command;
-import com.cloud.agent.api.PingCommand;
-import com.cloud.agent.api.PingRoutingCommand;
-import com.cloud.agent.api.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<String, Object> 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<ips.length-1;i++) {
- buf.append(ips[i]).append(".");
- }
- buf.append(ips[i]);
- String subnet = buf.toString();
- String cmd = String.format("sh /usr/bin/prepare_dhcpd.sh %1$s", subnet);
- if (!SSHCmdHelper.sshExecuteCmd(sshConnection, cmd)) {
- throw new ConfigurationException("prepare Dhcpd at " + _ip + " failed, command:" + cmd);
- }
-
- s_logger.debug("Dhcpd resource configure successfully");
- return true;
- } catch (Exception e) {
- s_logger.debug("Dhcpd 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<String, State>());
- }
- }
-
- 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);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/DnsmasqResource.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/DnsmasqResource.java b/server/src/com/cloud/baremetal/DnsmasqResource.java
deleted file mode 100644
index 1001dfc..0000000
--- a/server/src/com/cloud/baremetal/DnsmasqResource.java
+++ /dev/null
@@ -1,123 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.baremetal;
-
-import java.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<String, Object> 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<String, State>());
- }
- }
-
- 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);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/ExternalDhcpEntryListener.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/ExternalDhcpEntryListener.java b/server/src/com/cloud/baremetal/ExternalDhcpEntryListener.java
deleted file mode 100644
index d27d797..0000000
--- a/server/src/com/cloud/baremetal/ExternalDhcpEntryListener.java
+++ /dev/null
@@ -1,44 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.baremetal;
-
-public 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);
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/15ead099/server/src/com/cloud/baremetal/ExternalDhcpManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/baremetal/ExternalDhcpManager.java b/server/src/com/cloud/baremetal/ExternalDhcpManager.java
deleted file mode 100644
index d256ef1..0000000
--- a/server/src/com/cloud/baremetal/ExternalDhcpManager.java
+++ /dev/null
@@ -1,54 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.baremetal;
-
-import com.cloud.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);
-}