blob: 3b45de7860c13024b5ad0e75c40cfa6a54663cfd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package org.openslx.runvirt.plugin.qemu.configuration;
import java.util.ArrayList;
import org.openslx.libvirt.domain.Domain;
import org.openslx.libvirt.domain.device.Interface;
import org.openslx.runvirt.plugin.qemu.cmdln.CommandLineArgs;
import org.openslx.virtualization.configuration.VirtualizationConfigurationQemuUtils;
import org.openslx.virtualization.configuration.transformation.TransformationException;
import org.openslx.virtualization.configuration.transformation.TransformationGeneric;
public class TransformationGenericInterfaceDevices extends TransformationGeneric<Domain, CommandLineArgs>
{
private static final String FILTER_NAME = "Network interface devices";
public TransformationGenericInterfaceDevices()
{
super( TransformationGenericInterfaceDevices.FILTER_NAME );
}
private void filterInterfaceDevice( Domain config, String macAddress, int index ) throws TransformationException
{
final ArrayList<Interface> devices = config.getInterfaceDevices();
final Interface device = VirtualizationConfigurationQemuUtils.getArrayIndex( devices, index );
if ( device != null ) {
if ( macAddress == null ) {
// remove network interface device if MAC address is not set
device.remove();
} else {
// set MAC address of network interface device if network interface device is available
device.setMacAddress( macAddress );
}
}
}
@Override
public void transform( Domain config, CommandLineArgs args ) throws TransformationException
{
this.filterInterfaceDevice( config, args.getVmMacAddress0(), 0 );
// remove all additional disk storage devices
final ArrayList<Interface> devices = config.getInterfaceDevices();
for ( int i = 1; i < devices.size(); i++ ) {
devices.get( i ).remove();
}
}
}
|