Move KVM related code into plugins/hypervisor/kvm, a new jar file is

created: cloud-kvm.jar
This commit is contained in:
Edison Su 2012-07-30 14:54:46 -07:00
parent 1fbf5952cd
commit 7a0a9231c3
39 changed files with 268 additions and 571 deletions

View File

@ -18,7 +18,7 @@
# Sample configuration file for CloudStack agent # Sample configuration file for CloudStack agent
#resource= the java class, which agent load to execute #resource= the java class, which agent load to execute
resource=com.cloud.agent.resource.computing.LibvirtComputingResource resource=com.cloud.hypervisor.kvm.resource.LibvirtComputingResource
#workers= number of threads running in agent #workers= number of threads running in agent
workers=5 workers=5

View File

@ -17,4 +17,4 @@
# under the License. # under the License.
#run.sh runs the agent client. #run.sh runs the agent client.
java $1 -Xms128M -Xmx384M -cp cglib-nodep-2.2.jar:trilead-ssh2-build213.jar:cloud-api.jar:cloud-core-extras.jar:cloud-utils.jar:cloud-agent.jar:cloud-console-proxy.jar:cloud-console-common.jar:freemarker.jar:log4j-1.2.15.jar:ws-commons-util-1.0.2.jar:xmlrpc-client-3.1.3.jar:cloud-core.jar:xmlrpc-common-3.1.3.jar:javaee-api-5.0-1.jar:gson-1.3.jar:commons-httpclient-3.1.jar:commons-logging-1.1.1.jar:commons-codec-1.4.jar:commons-collections-3.2.1.jar:commons-pool-1.4.jar:apache-log4j-extras-1.0.jar:libvirt-0.4.5.jar:jna.jar:.:/etc/cloud:./conf com.cloud.agent.AgentShell java $1 -Xms128M -Xmx384M -cp cglib-nodep-2.2.jar:trilead-ssh2-build213.jar:cloud-api.jar:cloud-core-extras.jar:cloud-utils.jar:cloud-agent.jar:cloud-console-proxy.jar:cloud-console-common.jar:freemarker.jar:log4j-1.2.15.jar:ws-commons-util-1.0.2.jar:xmlrpc-client-3.1.3.jar:cloud-core.jar:xmlrpc-common-3.1.3.jar:javaee-api-5.0-1.jar:gson-1.3.jar:commons-httpclient-3.1.jar:commons-logging-1.1.1.jar:commons-codec-1.4.jar:commons-collections-3.2.1.jar:commons-pool-1.4.jar:apache-log4j-extras-1.0.jar:libvirt-0.4.5.jar:jna.jar:.:/etc/cloud:./*:/usr/share/java/*:./conf com.cloud.agent.AgentShell

View File

@ -198,9 +198,14 @@
<!-- ===================== Hypervisors ========================= --> <!-- ===================== Hypervisors ========================= -->
<target name="compile-hypervisors" depends="compile-ovm, compile-xen, compile-vmware" description="Compile all hypervisors"/> <target name="compile-hypervisors" depends="compile-kvm, compile-ovm, compile-xen, compile-vmware" description="Compile all hypervisors"/>
<target name="build-hypervisors" depends="build-ovm, build-xen, build-vmware" description="Builds all hypervisors"/> <target name="build-hypervisors" depends="build-kvm, build-ovm, build-xen, build-vmware" description="Builds all hypervisors"/>
<target name="compile-kvm" depends="-init, compile-core, compile-agent" description="Compile KVM">
<ant antfile="${base.dir}/plugins/hypervisors/kvm/build.xml" target="build"/>
</target>
<target name="build-kvm" depends="compile-kvm" />
<target name="compile-ovm" depends="-init, compile-server" description="Compile OVM"> <target name="compile-ovm" depends="-init, compile-server" description="Compile OVM">
<ant antfile="${base.dir}/plugins/hypervisors/ovm/build.xml" target="build"/> <ant antfile="${base.dir}/plugins/hypervisors/ovm/build.xml" target="build"/>
</target> </target>

View File

@ -82,7 +82,6 @@
<include name="cloud-commons-collections-3.2.1.jar" /> <include name="cloud-commons-collections-3.2.1.jar" />
<include name="cloud-commons-codec-1.4.jar" /> <include name="cloud-commons-codec-1.4.jar" />
<include name="cloud-commons-pool-1.4.jar" /> <include name="cloud-commons-pool-1.4.jar" />
<include name="libvirt-0.4.8.jar" />
<include name="cloud-jna.jar" /> <include name="cloud-jna.jar" />
<include name="cloud-cglib.jar" /> <include name="cloud-cglib.jar" />
<include name="jetty-6.1.26.jar" /> <include name="jetty-6.1.26.jar" />
@ -93,6 +92,7 @@
<include name="${utils.jar}" /> <include name="${utils.jar}" />
<include name="${core.jar}" /> <include name="${core.jar}" />
<include name="${api.jar}" /> <include name="${api.jar}" />
<include name="${kvm.jar}" />
</zipfileset> </zipfileset>
<zipfileset dir="${agent.dist.dir}" filemode="770"> <zipfileset dir="${agent.dist.dir}" filemode="770">
@ -112,7 +112,7 @@
</target> </target>
<target name="package-agent" depends="-init-package, package-oss-systemvm, build-systemvm-patch, package-agent-common"> <target name="package-agent" depends="-init-package, package-oss-systemvm, build-systemvm-patch, package-agent-common, build-kvm">
<zip destfile="${dist.dir}/agent.zip" duplicate="preserve" update="true"> <zip destfile="${dist.dir}/agent.zip" duplicate="preserve" update="true">
<zipfileset dir="${dist.dir}" prefix="vms"> <zipfileset dir="${dist.dir}" prefix="vms">
<include name="patch.tgz" /> <include name="patch.tgz" />
@ -291,6 +291,17 @@
</zip> </zip>
</target> </target>
<target name="package-kvm" depends="package-agent">
<zip destfile="${dist.dir}/agent.zip" update="true">
<zipfileset dir="${jar.dir}">
<include name="cloud-kvm.jar"/>
</zipfileset>
<zipfileset dir="${deps.dir}">
<include name="libvirt-0.4.8.jar"/>
</zipfileset>
</zip>
</target>
<target name="clean-zip"> <target name="clean-zip">
<delete dir="${dist.dir}"> <delete dir="${dist.dir}">
<include name="*.zip" /> <include name="*.zip" />

View File

@ -532,6 +532,7 @@ fi
%files agent-libs %files agent-libs
%defattr(0644,root,root,0755) %defattr(0644,root,root,0755)
%{_javadir}/%{name}-agent.jar %{_javadir}/%{name}-agent.jar
%{_javadir}/%{name}-kvm.jar
%files agent %files agent
%defattr(0644,root,root,0755) %defattr(0644,root,root,0755)

View File

@ -1,89 +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.hypervisor.kvm.resource;
import java.util.HashMap;
import java.util.Map;
import javax.naming.ConfigurationException;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.agent.api.StartupRoutingCommand.VmState;
import com.cloud.host.Host.Type;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.resource.ServerResource;
import com.cloud.resource.ServerResourceBase;
import com.cloud.vm.VirtualMachine.State;
public class KvmDummyResourceBase extends ServerResourceBase implements ServerResource {
private String _zoneId;
private String _podId;
private String _clusterId;
private String _guid;
private String _agentIp;
@Override
public Type getType() {
// TODO Auto-generated method stub
return null;
}
@Override
public StartupCommand[] initialize() {
StartupRoutingCommand cmd = new StartupRoutingCommand(0, 0, 0, 0, null, Hypervisor.HypervisorType.KVM, new HashMap<String, String>(), new HashMap<String, VmState>());
cmd.setDataCenter(_zoneId);
cmd.setPod(_podId);
cmd.setCluster(_clusterId);
cmd.setGuid(_guid);
cmd.setName(_agentIp);
cmd.setPrivateIpAddress(_agentIp);
cmd.setStorageIpAddress(_agentIp);
cmd.setVersion(KvmDummyResourceBase.class.getPackage().getImplementationVersion());
return new StartupCommand[] { cmd };
}
@Override
public PingCommand getCurrentStatus(long id) {
// TODO Auto-generated method stub
return null;
}
@Override
public Answer executeRequest(Command cmd) {
// TODO Auto-generated method stub
return null;
}
@Override
protected String getDefaultScriptsDir() {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
_zoneId = (String)params.get("zone");
_podId = (String)params.get("pod");
_clusterId = (String)params.get("cluster");
_guid = (String)params.get("guid");
_agentIp = (String)params.get("agentIp");
return true;
}
}

View File

@ -1 +1,2 @@
/usr/share/java/cloud-agent.jar /usr/share/java/cloud-agent.jar
/usr/share/java/cloud-kvm.jar

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/agent"/>
<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
<classpathentry combineaccessrules="false" kind="src" path="/api"/>
<classpathentry combineaccessrules="false" kind="src" path="/core"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>KVM</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
</pydev_project>

137
plugins/hypervisors/kvm/build.xml Executable file
View File

@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project name="Cloud Stack KVM" default="help" basedir=".">
<description>
Cloud Stack ant build file
</description>
<dirname property="kvm.base.dir" file="${ant.file.Cloud Stack KVM}/"/>
<!-- This directory must be set -->
<property name="top.dir" location="${kvm.base.dir}/../../.."/>
<property name="build.dir" location="${top.dir}/build"/>
<echo message="build.dir=${build.dir}; top.dir=${top.dir}; kvm.base.dir=${kvm.base.dir}"/>
<!-- Import anything that the user wants to set-->
<!-- Import properties files and environment variables here -->
<property environment="env" />
<condition property="build-cloud.properties.file" value="${build.dir}/override/build-cloud.properties" else="${build.dir}/build-cloud.properties">
<available file="${build.dir}/override/build-cloud.properties" />
</condition>
<condition property="cloud.properties.file" value="${build.dir}/override/cloud.properties" else="${build.dir}/cloud.properties">
<available file="${build.dir}/override/cloud.properties" />
</condition>
<condition property="override.file" value="${build.dir}/override/replace.properties" else="${build.dir}/replace.properties">
<available file="${build.dir}/override/replace.properties" />
</condition>
<echo message="Using build parameters from ${build-cloud.properties.file}" />
<property file="${build-cloud.properties.file}" />
<echo message="Using company info from ${cloud.properties.file}" />
<property file="${cloud.properties.file}" />
<echo message="Using override file from ${override.file}" />
<property file="${override.file}" />
<property file="${build.dir}/build.number" />
<!-- In case these didn't get defined in the build-cloud.properties -->
<property name="branding.name" value="default" />
<property name="deprecation" value="off" />
<property name="target.compat.version" value="1.6" />
<property name="source.compat.version" value="1.6" />
<property name="debug" value="true" />
<property name="debuglevel" value="lines,source"/>
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
<!-- directories for build and distribution -->
<property name="target.dir" location="${top.dir}/target" />
<property name="classes.dir" location="${target.dir}/classes" />
<property name="jar.dir" location="${target.dir}/jar" />
<property name="dep.cache.dir" location="${target.dir}/dep-cache" />
<property name="build.log" location="${target.dir}/ant_verbose.txt" />
<property name="deps.dir" location="${top.dir}/deps" />
<property name="kvm.jar" value="cloud-kvm.jar" />
<property name="scripts.target.dir" location="${target.dir}/scripts"/>
<property name="kvm.scripts.dir" location="${base.dir}/plugins/hypervisors/kvm/scripts" />
<import file="${build.dir}/build-common.xml"/>
<echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
<!-- This section needs to be replaced by some kind of dependency library-->
<path id="deps.classpath">
<!--filelist files="${deps.classpath}" /-->
<fileset dir="${deps.dir}" erroronmissingdir="false">
<include name="*.jar" />
</fileset>
</path>
<path id="cloudstack.classpath">
<fileset dir="${jar.dir}">
<include name="*.jar"/>
</fileset>
</path>
<path id="kvm.classpath">
<path refid="deps.classpath"/>
<path refid="cloudstack.classpath"/>
</path>
<!-- This section needs to be replaced by some kind of dependency library-->
<target name="deploy-kvm" >
<copy todir="${server.deploy.to.dir}/webapps/client/WEB-INF/lib/scripts">
<fileset dir="${kvm.scripts.dir}">
<include name="**/*"/>
</fileset>
</copy>
</target>
<target name="init" description="Initialize binaries directory">
<mkdir dir="${classes.dir}/${kvm.jar}"/>
<mkdir dir="${jar.dir}"/>
</target>
<target name="compile-kvm" depends="init" description="Compiles Xen ">
<compile-java jar.name="${kvm.jar}" top.dir="${kvm.base.dir}" classpath="kvm.classpath" />
</target>
<target name="help" description="help">
<echo level="info" message="This is the build file for kvmserver"/>
<echo level="info" message="You can do a build by doing ant build or clean by ant clean" />
</target>
<target name="clean-kvm">
<delete dir="${classes.dir}/${kvm.jar}"/>
</target>
<target name="build" depends="compile-kvm"/>
<target name="clean" depends="clean-kvm"/>
</project>

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -97,7 +97,6 @@ import com.cloud.resource.ServerResourceBase;
import com.cloud.storage.Storage; import com.cloud.storage.Storage;
import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.Volume; import com.cloud.storage.Volume;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.template.TemplateInfo; import com.cloud.storage.template.TemplateInfo;
import com.cloud.utils.PropertiesUtil; import com.cloud.utils.PropertiesUtil;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.io.File; import java.io.File;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -23,7 +23,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import org.libvirt.Connect;
import org.libvirt.LibvirtException; import org.libvirt.LibvirtException;
import org.libvirt.StoragePool; import org.libvirt.StoragePool;
import org.libvirt.StoragePoolInfo; import org.libvirt.StoragePoolInfo;

View File

@ -14,14 +14,13 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.libvirt.Connect;
import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.OutputInterpreter;
import com.cloud.utils.script.Script; import com.cloud.utils.script.Script;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@ -153,26 +153,26 @@ import com.cloud.agent.api.to.NicTO;
import com.cloud.agent.api.to.StorageFilerTO; import com.cloud.agent.api.to.StorageFilerTO;
import com.cloud.agent.api.to.VirtualMachineTO; import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.agent.api.to.VolumeTO; import com.cloud.agent.api.to.VolumeTO;
import com.cloud.agent.resource.computing.KVMHABase.NfsStoragePool; import com.cloud.hypervisor.kvm.resource.KVMHABase.NfsStoragePool;
import com.cloud.agent.resource.computing.LibvirtVMDef.ConsoleDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ConsoleDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.DevicesDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DevicesDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.DiskDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.DiskDef.diskProtocol; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef.diskProtocol;
import com.cloud.agent.resource.computing.LibvirtVMDef.FeaturesDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.FeaturesDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.GraphicDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.GraphicDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.GuestDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.GuestDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.GuestResourceDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.GuestResourceDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.InputDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InputDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef.hostNicType; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef.hostNicType;
import com.cloud.agent.resource.computing.LibvirtVMDef.SerialDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.SerialDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.TermPolicy; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.TermPolicy;
import com.cloud.agent.resource.computing.LibvirtVMDef.ClockDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ClockDef;
import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource; import com.cloud.agent.resource.virtualnetwork.VirtualRoutingResource;
import com.cloud.agent.storage.KVMPhysicalDisk; import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk;
import com.cloud.agent.storage.KVMPhysicalDisk.PhysicalDiskFormat; import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk.PhysicalDiskFormat;
import com.cloud.agent.storage.KVMStoragePool; import com.cloud.hypervisor.kvm.storage.KVMStoragePool;
import com.cloud.agent.storage.KVMStoragePoolManager; import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager;
import com.cloud.dc.Vlan; import com.cloud.dc.Vlan;
import com.cloud.exception.InternalErrorException; import com.cloud.exception.InternalErrorException;
import com.cloud.host.Host.Type; import com.cloud.host.Host.Type;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.libvirt.Connect; import org.libvirt.Connect;

View File

@ -14,14 +14,12 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@ -32,13 +30,12 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.cloud.agent.resource.computing.LibvirtVMDef.DiskDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef;
import com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef.nicModel; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.InterfaceDef.nicModel;
/** /**
* @author chiradeep * @author chiradeep

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
public class LibvirtSecretDef { public class LibvirtSecretDef {

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
public class LibvirtStoragePoolDef { public class LibvirtStoragePoolDef {
public enum poolType { public enum poolType {

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
public class LibvirtStorageVolumeDef { public class LibvirtStorageVolumeDef {
public enum volFormat { public enum volFormat {

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;

View File

@ -14,10 +14,9 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.resource.computing; package com.cloud.hypervisor.kvm.resource;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.storage; package com.cloud.hypervisor.kvm.storage;
public class KVMPhysicalDisk { public class KVMPhysicalDisk {
private String path; private String path;

View File

@ -14,11 +14,11 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.storage; package com.cloud.hypervisor.kvm.storage;
import java.util.List; import java.util.List;
import com.cloud.agent.storage.KVMPhysicalDisk.PhysicalDiskFormat; import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk.PhysicalDiskFormat;
import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.StoragePoolType;
public interface KVMStoragePool { public interface KVMStoragePool {

View File

@ -14,15 +14,15 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.storage; package com.cloud.hypervisor.kvm.storage;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import com.cloud.agent.resource.computing.KVMHABase; import com.cloud.hypervisor.kvm.resource.KVMHABase;
import com.cloud.agent.resource.computing.KVMHABase.PoolType; import com.cloud.hypervisor.kvm.resource.KVMHABase.PoolType;
import com.cloud.agent.resource.computing.KVMHAMonitor; import com.cloud.hypervisor.kvm.resource.KVMHAMonitor;
import com.cloud.agent.storage.KVMPhysicalDisk.PhysicalDiskFormat; import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk.PhysicalDiskFormat;
import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.StorageLayer; import com.cloud.storage.StorageLayer;

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.storage; package com.cloud.hypervisor.kvm.storage;
public class KVMVirtualDisk { public class KVMVirtualDisk {

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.storage; package com.cloud.hypervisor.kvm.storage;
import java.io.File; import java.io.File;
import java.net.URI; import java.net.URI;
@ -33,17 +33,17 @@ import org.libvirt.StorageVol;
import org.libvirt.StoragePoolInfo.StoragePoolState; import org.libvirt.StoragePoolInfo.StoragePoolState;
import com.cloud.agent.api.ManageSnapshotCommand; import com.cloud.agent.api.ManageSnapshotCommand;
import com.cloud.agent.resource.computing.LibvirtConnection; import com.cloud.hypervisor.kvm.resource.LibvirtConnection;
import com.cloud.agent.resource.computing.LibvirtSecretDef; import com.cloud.hypervisor.kvm.resource.LibvirtSecretDef;
import com.cloud.agent.resource.computing.LibvirtSecretDef.usage; import com.cloud.hypervisor.kvm.resource.LibvirtSecretDef.usage;
import com.cloud.agent.resource.computing.LibvirtStoragePoolDef; import com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef;
import com.cloud.agent.resource.computing.LibvirtStoragePoolXMLParser; import com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolXMLParser;
import com.cloud.agent.resource.computing.LibvirtStorageVolumeDef; import com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef;
import com.cloud.agent.resource.computing.LibvirtStoragePoolDef.poolType; import com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef.poolType;
import com.cloud.agent.resource.computing.LibvirtStoragePoolDef.authType; import com.cloud.hypervisor.kvm.resource.LibvirtStoragePoolDef.authType;
import com.cloud.agent.resource.computing.LibvirtStorageVolumeDef.volFormat; import com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeDef.volFormat;
import com.cloud.agent.resource.computing.LibvirtStorageVolumeXMLParser; import com.cloud.hypervisor.kvm.resource.LibvirtStorageVolumeXMLParser;
import com.cloud.agent.storage.KVMPhysicalDisk.PhysicalDiskFormat; import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk.PhysicalDiskFormat;
import com.cloud.exception.InternalErrorException; import com.cloud.exception.InternalErrorException;
import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.StorageLayer; import com.cloud.storage.StorageLayer;

View File

@ -14,13 +14,13 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.storage; package com.cloud.hypervisor.kvm.storage;
import java.util.List; import java.util.List;
import org.libvirt.StoragePool; import org.libvirt.StoragePool;
import com.cloud.agent.storage.KVMPhysicalDisk.PhysicalDiskFormat; import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk.PhysicalDiskFormat;
import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.StoragePoolType;
public class LibvirtStoragePool implements KVMStoragePool { public class LibvirtStoragePool implements KVMStoragePool {

View File

@ -14,13 +14,11 @@
// KIND, either express or implied. See the License for the // KIND, either express or implied. See the License for the
// specific language governing permissions and limitations // specific language governing permissions and limitations
// under the License. // under the License.
package com.cloud.agent.storage; package com.cloud.hypervisor.kvm.storage;
import java.util.List; import java.util.List;
import org.libvirt.StoragePool; import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk.PhysicalDiskFormat;
import com.cloud.agent.storage.KVMPhysicalDisk.PhysicalDiskFormat;
import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.StoragePoolType;
public interface StorageAdaptor { public interface StorageAdaptor {

View File

@ -88,7 +88,7 @@ import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostTagsDao; import com.cloud.host.dao.HostTagsDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.HypervisorGuruManager; import com.cloud.hypervisor.HypervisorGuruManager;
import com.cloud.hypervisor.kvm.resource.KvmDummyResourceBase; import com.cloud.hypervisor.kvm.discover.KvmDummyResourceBase;
import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressDao;
import com.cloud.resource.Discoverer; import com.cloud.resource.Discoverer;
import com.cloud.resource.ResourceManager; import com.cloud.resource.ResourceManager;

View File

@ -56,7 +56,6 @@ import com.cloud.agent.api.to.VirtualMachineTO;
import com.cloud.api.ApiConstants; import com.cloud.api.ApiConstants;
import com.cloud.host.Host.Type; import com.cloud.host.Host.Type;
import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.kvm.resource.KvmDummyResourceBase;
import com.cloud.resource.ServerResource; import com.cloud.resource.ServerResource;
import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.OutputInterpreter; import com.cloud.utils.script.OutputInterpreter;

View File

@ -1,400 +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.hypervisor.kvm.discoverer;
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.AgentManager;
import com.cloud.agent.Listener;
import com.cloud.agent.api.AgentControlAnswer;
import com.cloud.agent.api.AgentControlCommand;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.ShutdownCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupRoutingCommand;
import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.DiscoveredWithErrorException;
import com.cloud.exception.DiscoveryException;
import com.cloud.exception.OperationTimedoutException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.kvm.resource.KvmDummyResourceBase;
import com.cloud.network.NetworkManager;
import com.cloud.network.PhysicalNetworkSetupInfo;
import com.cloud.network.PhysicalNetworkVO;
import com.cloud.network.Networks.TrafficType;
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.ComponentLocator;
import com.cloud.utils.component.Inject;
import com.cloud.utils.script.Script;
import com.cloud.utils.ssh.SSHCmdHelper;
import com.trilead.ssh2.ChannelCondition;
import com.trilead.ssh2.SCPClient;
import com.trilead.ssh2.Session;
@Local(value=Discoverer.class)
public class KvmServerDiscoverer extends DiscovererBase implements Discoverer,
Listener, ResourceStateAdapter {
private static final Logger s_logger = Logger.getLogger(KvmServerDiscoverer.class);
private String _setupAgentPath;
private ConfigurationDao _configDao;
private String _hostIp;
private int _waitTime = 5; /*wait for 5 minutes*/
private String _kvmPrivateNic;
private String _kvmPublicNic;
private String _kvmGuestNic;
@Inject HostDao _hostDao = null;
@Inject ClusterDao _clusterDao;
@Inject ResourceManager _resourceMgr;
@Inject AgentManager _agentMgr;
@Inject NetworkManager _networkMgr;
@Override
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean processCommands(long agentId, long seq, Command[] commands) {
// TODO Auto-generated method stub
return false;
}
@Override
public AgentControlAnswer processControlCommand(long agentId,
AgentControlCommand cmd) {
// TODO Auto-generated method stub
return null;
}
@Override
public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance) {
}
@Override
public boolean processDisconnect(long agentId, Status state) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isRecurring() {
// TODO Auto-generated method stub
return false;
}
@Override
public int getTimeout() {
// TODO Auto-generated method stub
return 0;
}
@Override
public boolean processTimeout(long agentId, long seq) {
// TODO Auto-generated method stub
return false;
}
@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId,
Long podId, Long clusterId, URI uri, String username,
String password, List<String> hostTags) throws DiscoveryException {
ClusterVO cluster = _clusterDao.findById(clusterId);
if(cluster == null || cluster.getHypervisorType() != HypervisorType.KVM) {
if(s_logger.isInfoEnabled())
s_logger.info("invalid cluster id or cluster is not for KVM hypervisors");
return null;
}
Map<KvmDummyResourceBase, Map<String, String>> resources = new HashMap<KvmDummyResourceBase, Map<String, String>>();
Map<String, String> details = new HashMap<String, String>();
if (!uri.getScheme().equals("http")) {
String msg = "urlString is not http so we're not taking care of the discovery for this: " + uri;
s_logger.debug(msg);
return null;
}
com.trilead.ssh2.Connection sshConnection = null;
String agentIp = null;
try {
String hostname = uri.getHost();
InetAddress ia = InetAddress.getByName(hostname);
agentIp = ia.getHostAddress();
String guid = UUID.nameUUIDFromBytes(agentIp.getBytes()).toString();
String guidWithTail = guid + "-LibvirtComputingResource";/*tail added by agent.java*/
if (_resourceMgr.findHostByGuid(guidWithTail) != null) {
s_logger.debug("Skipping " + agentIp + " because " + guidWithTail + " is already in the database.");
return null;
}
sshConnection = new com.trilead.ssh2.Connection(agentIp, 22);
sshConnection.connect(null, 60000, 60000);
if (!sshConnection.authenticateWithPassword(username, password)) {
s_logger.debug("Failed to authenticate");
throw new DiscoveredWithErrorException("Authentication error");
}
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "lsmod|grep kvm", 3)) {
s_logger.debug("It's not a KVM enabled machine");
return null;
}
List <PhysicalNetworkSetupInfo> netInfos = _networkMgr.getPhysicalNetworkInfo(dcId, HypervisorType.KVM);
String kvmPrivateNic = _kvmPrivateNic;
String kvmPublicNic = _kvmPublicNic;
String kvmGuestNic = _kvmGuestNic;
for (PhysicalNetworkSetupInfo info : netInfos) {
if (info.getPrivateNetworkName() != null) {
kvmPrivateNic = info.getPrivateNetworkName();
}
if (info.getPublicNetworkName() != null) {
kvmPublicNic = info.getPublicNetworkName();
}
if (info.getGuestNetworkName() != null) {
kvmGuestNic = info.getGuestNetworkName();
}
}
String parameters = " -m " + _hostIp + " -z " + dcId + " -p " + podId + " -c " + clusterId + " -g " + guid + " -a";
if (kvmPublicNic != null) {
parameters += " --pubNic=" + kvmPublicNic;
}
if (kvmPrivateNic != null) {
parameters += " --prvNic=" + kvmPrivateNic;
}
if (kvmGuestNic != null) {
parameters += " --guestNic=" + kvmGuestNic;
}
SSHCmdHelper.sshExecuteCmd(sshConnection, "cloud-setup-agent " + parameters, 3);
KvmDummyResourceBase kvmResource = new KvmDummyResourceBase();
Map<String, Object> params = new HashMap<String, Object>();
params.put("zone", Long.toString(dcId));
params.put("pod", Long.toString(podId));
params.put("cluster", Long.toString(clusterId));
params.put("guid", guid);
params.put("agentIp", agentIp);
kvmResource.configure("kvm agent", params);
resources.put(kvmResource, details);
HostVO connectedHost = waitForHostConnect(dcId, podId, clusterId, guidWithTail);
if (connectedHost == null)
return null;
details.put("guid", guidWithTail);
// place a place holder guid derived from cluster ID
if (cluster.getGuid() == null) {
cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString());
_clusterDao.update(clusterId, cluster);
}
//save user name and password
_hostDao.loadDetails(connectedHost);
Map<String, String> hostDetails = connectedHost.getDetails();
hostDetails.put("password", password);
hostDetails.put("username", username);
_hostDao.saveDetails(connectedHost);
return resources;
} catch (DiscoveredWithErrorException e){
throw e;
}catch (Exception e) {
String msg = " can't setup agent, due to " + e.toString() + " - " + e.getMessage();
s_logger.warn(msg);
} finally {
if (sshConnection != null)
sshConnection.close();
}
return null;
}
private HostVO waitForHostConnect(long dcId, long podId, long clusterId, String guid) {
for (int i = 0; i < _waitTime *2; i++) {
List<HostVO> hosts = _resourceMgr.listAllUpAndEnabledHosts(Host.Type.Routing, clusterId, podId, dcId);
for (HostVO host : hosts) {
if (host.getGuid().equalsIgnoreCase(guid)) {
return host;
}
}
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
s_logger.debug("Failed to sleep: " + e.toString());
}
}
s_logger.debug("Timeout, to wait for the host connecting to mgt svr, assuming it is failed");
List<HostVO> hosts = _resourceMgr.findHostByGuid(dcId, guid);
if (hosts.size() == 1) {
return hosts.get(0);
} else {
return null;
}
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
ComponentLocator locator = ComponentLocator.getCurrentLocator();
_configDao = locator.getDao(ConfigurationDao.class);
_setupAgentPath = Script.findScript(getPatchPath(), "setup_agent.sh");
_kvmPrivateNic = _configDao.getValue(Config.KvmPrivateNetwork.key());
if (_kvmPrivateNic == null) {
_kvmPrivateNic = "cloudbr0";
}
_kvmPublicNic = _configDao.getValue(Config.KvmPublicNetwork.key());
if (_kvmPublicNic == null) {
_kvmPublicNic = _kvmPrivateNic;
}
_kvmGuestNic = _configDao.getValue(Config.KvmGuestNetwork.key());
if (_kvmGuestNic == null) {
_kvmGuestNic = _kvmPrivateNic;
}
if (_setupAgentPath == null) {
throw new ConfigurationException("Can't find setup_agent.sh");
}
_hostIp = _configDao.getValue("host");
if (_hostIp == null) {
throw new ConfigurationException("Can't get host IP");
}
_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
return true;
}
protected String getPatchPath() {
return "scripts/vm/hypervisor/kvm/";
}
@Override
public void postDiscovery(List<HostVO> hosts, long msId)
throws DiscoveryException {
// TODO Auto-generated method stub
}
public Hypervisor.HypervisorType getHypervisorType() {
return Hypervisor.HypervisorType.KVM;
}
@Override
public boolean matchHypervisor(String hypervisor) {
// for backwards compatibility, if not supplied, always let to try it
if(hypervisor == null)
return true;
return Hypervisor.HypervisorType.KVM.toString().equalsIgnoreCase(hypervisor);
}
@Override
public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
StartupCommand firstCmd = cmd[0];
if (!(firstCmd instanceof StartupRoutingCommand)) {
return null;
}
StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
if (ssCmd.getHypervisorType() != HypervisorType.KVM) {
return null;
}
/* KVM requires host are the same in cluster */
ClusterVO clusterVO = _clusterDao.findById(host.getClusterId());
List<HostVO> hostsInCluster = _resourceMgr.listAllHostsInCluster(clusterVO.getId());
if (!hostsInCluster.isEmpty()) {
HostVO oneHost = hostsInCluster.get(0);
_hostDao.loadDetails(oneHost);
String hostOsInCluster = oneHost.getDetail("Host.OS");
String hostOs = ssCmd.getHostDetails().get("Host.OS");
if (!hostOsInCluster.equalsIgnoreCase(hostOs)) {
throw new IllegalArgumentException("Can't add host: " + firstCmd.getPrivateIpAddress() + " with hostOS: " + hostOs + " into a cluster,"
+ "in which there are " + hostOsInCluster + " hosts added");
}
}
_hostDao.loadDetails(host);
return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.KVM, host.getDetails(), null);
}
@Override
public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details,
List<String> hostTags) {
// TODO Auto-generated method stub
return null;
}
@Override
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
if (host.getType() != Host.Type.Routing || host.getHypervisorType() != HypervisorType.KVM) {
return null;
}
_resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
try {
ShutdownCommand cmd = new ShutdownCommand(ShutdownCommand.DeleteHost, null);
_agentMgr.send(host.getId(), cmd);
} catch (AgentUnavailableException e) {
s_logger.warn("Sending ShutdownCommand failed: ", e);
} catch (OperationTimedoutException e) {
s_logger.warn("Sending ShutdownCommand failed: ", e);
}
return new DeleteHostAnswer(true);
}
@Override
public boolean stop() {
_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
return super.stop();
}
}

View File

@ -98,7 +98,7 @@ import com.cloud.host.dao.HostDetailsDao;
import com.cloud.host.dao.HostTagsDao; import com.cloud.host.dao.HostTagsDao;
import com.cloud.hypervisor.Hypervisor; import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.hypervisor.kvm.resource.KvmDummyResourceBase; import com.cloud.hypervisor.kvm.discover.KvmDummyResourceBase;
import com.cloud.network.IPAddressVO; import com.cloud.network.IPAddressVO;
import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressDao;
import com.cloud.org.Cluster; import com.cloud.org.Cluster;