mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Another clean up for unnecessary parameter conn Clean up unused
parameter conn. Add test for LibvirtVMDef Add support for ethernet type RB: https://reviews.apache.org/r/6284/ Send-by: tomoe@midokura.com
This commit is contained in:
parent
3a184a1b49
commit
05df0a1965
@ -698,7 +698,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
createControlNetwork(conn);
|
createControlNetwork();
|
||||||
} catch (LibvirtException e) {
|
} catch (LibvirtException e) {
|
||||||
throw new ConfigurationException(e.getMessage());
|
throw new ConfigurationException(e.getMessage());
|
||||||
}
|
}
|
||||||
@ -1220,7 +1220,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
|||||||
nicTO.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlanId));
|
nicTO.setBroadcastUri(BroadcastDomainType.Vlan.toUri(vlanId));
|
||||||
}
|
}
|
||||||
|
|
||||||
InterfaceDef nic = createVif(conn, nicTO, InterfaceDef.nicModel.VIRTIO);
|
InterfaceDef nic = createVif(nicTO, InterfaceDef.nicModel.VIRTIO);
|
||||||
Domain vm = getDomain(conn, vmName);
|
Domain vm = getDomain(conn, vmName);
|
||||||
vm.attachDevice(nic.toString());
|
vm.attachDevice(nic.toString());
|
||||||
}
|
}
|
||||||
@ -2122,7 +2122,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
|||||||
}
|
}
|
||||||
} else if (nic.getType() == TrafficType.Control) {
|
} else if (nic.getType() == TrafficType.Control) {
|
||||||
/* Make sure the network is still there */
|
/* Make sure the network is still there */
|
||||||
createControlNetwork(conn);
|
createControlNetwork();
|
||||||
} else if (nic.getType() == TrafficType.Public) {
|
} else if (nic.getType() == TrafficType.Public) {
|
||||||
if (nic.getBroadcastType() == BroadcastDomainType.Vlan
|
if (nic.getBroadcastType() == BroadcastDomainType.Vlan
|
||||||
&& !vlanId.equalsIgnoreCase("untagged")) {
|
&& !vlanId.equalsIgnoreCase("untagged")) {
|
||||||
@ -2516,13 +2516,13 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
|||||||
return vm;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createVifs(Connect conn, VirtualMachineTO vmSpec,
|
protected void createVifs(VirtualMachineTO vmSpec,
|
||||||
LibvirtVMDef vm) throws InternalErrorException, LibvirtException {
|
LibvirtVMDef vm) throws InternalErrorException, LibvirtException {
|
||||||
NicTO[] nics = vmSpec.getNics();
|
NicTO[] nics = vmSpec.getNics();
|
||||||
for (int i = 0; i < nics.length; i++) {
|
for (int i = 0; i < nics.length; i++) {
|
||||||
for (NicTO nic : vmSpec.getNics()) {
|
for (NicTO nic : vmSpec.getNics()) {
|
||||||
if (nic.getDeviceId() == i) {
|
if (nic.getDeviceId() == i) {
|
||||||
createVif(conn, vm, nic);
|
createVif(vm, nic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2546,7 +2546,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
|||||||
|
|
||||||
createVbd(conn, vmSpec, vmName, vm);
|
createVbd(conn, vmSpec, vmName, vm);
|
||||||
|
|
||||||
createVifs(conn, vmSpec, vm);
|
createVifs(vmSpec, vm);
|
||||||
|
|
||||||
s_logger.debug("starting " + vmName + ": " + vm.toString());
|
s_logger.debug("starting " + vmName + ": " + vm.toString());
|
||||||
startDomain(conn, vmName, vm.toString());
|
startDomain(conn, vmName, vm.toString());
|
||||||
@ -2734,8 +2734,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
|||||||
return brName;
|
return brName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InterfaceDef createVif(Connect conn, NicTO nic,
|
private InterfaceDef createVif(NicTO nic,
|
||||||
InterfaceDef.nicModel model) throws InternalErrorException,
|
InterfaceDef.nicModel model) throws InternalErrorException,
|
||||||
LibvirtException {
|
LibvirtException {
|
||||||
InterfaceDef intf = new InterfaceDef();
|
InterfaceDef intf = new InterfaceDef();
|
||||||
|
|
||||||
@ -2755,7 +2755,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
|||||||
}
|
}
|
||||||
} else if (nic.getType() == TrafficType.Control) {
|
} else if (nic.getType() == TrafficType.Control) {
|
||||||
/* Make sure the network is still there */
|
/* Make sure the network is still there */
|
||||||
createControlNetwork(conn);
|
createControlNetwork();
|
||||||
intf.defBridgeNet(_linkLocalBridgeName, null, nic.getMac(), model);
|
intf.defBridgeNet(_linkLocalBridgeName, null, nic.getMac(), model);
|
||||||
} else if (nic.getType() == TrafficType.Public) {
|
} else if (nic.getType() == TrafficType.Public) {
|
||||||
if (nic.getBroadcastType() == BroadcastDomainType.Vlan
|
if (nic.getBroadcastType() == BroadcastDomainType.Vlan
|
||||||
@ -2776,10 +2776,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
|||||||
return intf;
|
return intf;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createVif(Connect conn, LibvirtVMDef vm, NicTO nic)
|
private void createVif(LibvirtVMDef vm, NicTO nic)
|
||||||
throws InternalErrorException, LibvirtException {
|
throws InternalErrorException, LibvirtException {
|
||||||
vm.getDevices().addDevice(
|
vm.getDevices().addDevice(
|
||||||
createVif(conn, nic, getGuestNicModel(vm.getGuestOSType())));
|
createVif(nic, getGuestNicModel(vm.getGuestOSType())));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CheckSshAnswer execute(CheckSshCommand cmd) {
|
protected CheckSshAnswer execute(CheckSshCommand cmd) {
|
||||||
@ -4098,7 +4098,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements
|
|||||||
return new Pair<Double, Double>(rx, tx);
|
return new Pair<Double, Double>(rx, tx);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createControlNetwork(Connect conn) throws LibvirtException {
|
private void createControlNetwork() throws LibvirtException {
|
||||||
_virtRouterResource.createControlNetwork(_linkLocalBridgeName);
|
_virtRouterResource.createControlNetwork(_linkLocalBridgeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -665,6 +665,13 @@ public class LibvirtVMDef {
|
|||||||
_model = model;
|
_model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void defEthernet(String targetName, String macAddr, nicModel model) {
|
||||||
|
_netType = guestNetType.ETHERNET;
|
||||||
|
_networkName = targetName;
|
||||||
|
_macAddr = macAddr;
|
||||||
|
_model = model;
|
||||||
|
}
|
||||||
|
|
||||||
public void setHostNetType(hostNicType hostNetType) {
|
public void setHostNetType(hostNicType hostNetType) {
|
||||||
_hostNetType = hostNetType;
|
_hostNetType = hostNetType;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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 junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class LibvirtVMDefTest extends TestCase {
|
||||||
|
|
||||||
|
public void testInterfaceEtehrnet() {
|
||||||
|
LibvirtVMDef.InterfaceDef ifDef = new LibvirtVMDef.InterfaceDef();
|
||||||
|
ifDef.defEthernet("targetDeviceName", "00:11:22:aa:bb:dd", LibvirtVMDef.InterfaceDef.nicModel.VIRTIO);
|
||||||
|
|
||||||
|
String expected = "<interface type='ethernet'>\n" +
|
||||||
|
"<target dev='targetDeviceName'/>\n" +
|
||||||
|
"<mac address='00:11:22:aa:bb:dd'/>\n" +
|
||||||
|
"<model type='virtio'/>\n" +
|
||||||
|
"</interface>\n";
|
||||||
|
|
||||||
|
assertEquals(expected, ifDef.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user