Skip to content
This repository was archived by the owner on Jan 15, 2020. It is now read-only.

Commit aa79ccf

Browse files
Phong Nguyensudison
authored andcommitted
CLOUDSTACK-922: LXC Support in Cloudstack.
Signed-off-by: Edison Su <sudison@gmail.com>
1 parent 6eac422 commit aa79ccf

33 files changed

Lines changed: 984 additions & 484 deletions

agent/conf/agent.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,12 @@ domr.scripts.dir=scripts/network/domr/kvm
8080
# native = com.cloud.hypervisor.kvm.resource.BridgeVifDriver
8181
# openvswitch = com.cloud.hypervisor.kvm.resource.OvsBridgeDriver
8282
#libvirt.vif.driver=com.cloud.hypervisor.kvm.resource.BridgeVifDriver
83+
84+
# set the hypervisor type, values are: kvm, lxc
85+
# hypervisor.type=kvm
86+
87+
# settings to enable direct networking in libvirt, should not be used
88+
# on hosts that run system vms, values for mode are: private, bridge, vepa
89+
# libvirt.vif.driver=com.cloud.hypervisor.kvm.resource.DirectVifDriver
90+
# network.direct.source.mode=private
91+
# network.direct.device=eth0

api/src/com/cloud/agent/api/Command.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
*/
2828
public abstract class Command {
2929

30+
public static final String HYPERVISOR_TYPE = "hypervisorType";
31+
3032
// allow command to carry over hypervisor or other environment related context info
3133
@LogLevel(Log4jLevel.Trace)
3234
protected Map<String, String> contextMap = new HashMap<String, String>();

api/src/com/cloud/agent/api/RebootCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.agent.api;
1818

19+
import com.cloud.hypervisor.Hypervisor;
1920
import com.cloud.vm.VirtualMachine;
2021

2122
public class RebootCommand extends Command {

api/src/com/cloud/agent/api/StopCommand.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ public StopCommand(VirtualMachine vm, String vnet) {
3838
super(vm);
3939
this.vnet = vnet;
4040
}
41-
42-
public StopCommand(VirtualMachine vm, String vmName, String vnet) {
43-
super(vmName);
44-
this.vnet = vnet;
41+
42+
public StopCommand(VirtualMachine vm) {
43+
super(vm);
4544
}
4645

4746
public StopCommand(String vmName) {

api/src/com/cloud/hypervisor/Hypervisor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public static enum HypervisorType {
2929
BareMetal,
3030
Simulator,
3131
Ovm,
32+
LXC,
3233

3334
Any; /*If you don't care about the hypervisor type*/
3435

@@ -54,6 +55,8 @@ public static HypervisorType getType(String hypervisor) {
5455
return HypervisorType.Simulator;
5556
} else if (hypervisor.equalsIgnoreCase("Ovm")) {
5657
return HypervisorType.Ovm;
58+
} else if (hypervisor.equalsIgnoreCase("LXC")) {
59+
return HypervisorType.LXC;
5760
} else if (hypervisor.equalsIgnoreCase("Any")) {
5861
return HypervisorType.Any;
5962
} else {

api/src/com/cloud/storage/Storage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public static enum ImageFormat {
2626
VHD(true, true, true),
2727
ISO(false, false, false),
2828
OVA(true, true, true, "ova"),
29-
BAREMETAL(false, false, false);
29+
BAREMETAL(false, false, false),
30+
TAR(false, false, false);
3031

3132
private final boolean thinProvisioned;
3233
private final boolean supportSparse;

client/tomcatconf/applicationContext.xml.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@
499499
<property name="name" value="KVM Agent"/>
500500
</bean>
501501

502+
<bean id="LxcServerDiscoverer" class="com.cloud.hypervisor.kvm.discoverer.LxcServerDiscoverer">
503+
<property name="name" value="Lxc Discover"/>
504+
</bean>
505+
502506
<bean id="HypervServerDiscoverer" class="com.cloud.hypervisor.hyperv.HypervServerDiscoverer">
503507
<property name="name" value="SCVMMServer"/>
504508
</bean>
@@ -568,6 +572,10 @@
568572
<property name="name" value="KVMGuru"/>
569573
</bean>
570574

575+
<bean id="LXCGuru" class="com.cloud.hypervisor.LXCGuru">
576+
<property name="name" value="LXCGuru"/>
577+
</bean>
578+
571579
<bean id="OvmGuru" class="com.cloud.ovm.hypervisor.OvmGuru">
572580
<property name="name" value="OvmGuru"/>
573581
</bean>

client/tomcatconf/componentContext.xml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<ref bean="XcpServerDiscoverer"/>
107107
<ref bean="SecondaryStorageDiscoverer"/>
108108
<ref bean="KvmServerDiscoverer"/>
109+
<ref bean="LxcServerDiscoverer"/>
109110

110111
<!--
111112
<ref bean="BareMetalDiscoverer"/>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package com.cloud.hypervisor.kvm.resource;
21+
22+
import com.cloud.agent.api.to.NicTO;
23+
import com.cloud.exception.InternalErrorException;
24+
import com.cloud.network.Networks;
25+
import org.apache.log4j.Logger;
26+
import org.libvirt.LibvirtException;
27+
28+
import javax.naming.ConfigurationException;
29+
import java.util.Map;
30+
31+
public class DirectVifDriver extends VifDriverBase {
32+
33+
private static final Logger s_logger = Logger.getLogger(DirectVifDriver.class);
34+
35+
/**
36+
* Experimental driver to configure direct networking in libvirt. This should only
37+
* be used on an LXC cluster that does not run any system VMs.
38+
*
39+
* @param nic
40+
* @param guestOsType
41+
* @return
42+
* @throws InternalErrorException
43+
* @throws LibvirtException
44+
*/
45+
public LibvirtVMDef.InterfaceDef plug(NicTO nic, String guestOsType) throws InternalErrorException,
46+
LibvirtException {
47+
LibvirtVMDef.InterfaceDef intf = new LibvirtVMDef.InterfaceDef();
48+
49+
if (nic.getType() == Networks.TrafficType.Guest) {
50+
intf.defDirectNet(_libvirtComputingResource.getNetworkDirectDevice(), null, nic.getMac(), getGuestNicModel(guestOsType),
51+
_libvirtComputingResource.getNetworkDirectSourceMode());
52+
53+
} else if (nic.getType() == Networks.TrafficType.Public) {
54+
intf.defDirectNet(_libvirtComputingResource.getNetworkDirectDevice(), null, nic.getMac(), getGuestNicModel(guestOsType),
55+
_libvirtComputingResource.getNetworkDirectSourceMode());
56+
}
57+
58+
return intf;
59+
}
60+
61+
public void unplug(LibvirtVMDef.InterfaceDef iface) {
62+
// not needed, libvirt will cleanup
63+
}
64+
65+
}

0 commit comments

Comments
 (0)