use of com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method createVif.
private InterfaceDef createVif(Connect conn, NicTO nic, InterfaceDef.nicModel model) throws InternalErrorException, LibvirtException {
InterfaceDef intf = new InterfaceDef();
String vlanId = null;
if (nic.getBroadcastType() == BroadcastDomainType.Vlan) {
URI broadcastUri = nic.getBroadcastUri();
vlanId = broadcastUri.getHost();
}
if (nic.getType() == TrafficType.Guest) {
if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) {
String brName = createVlanBr(vlanId, _pifs.first());
intf.defBridgeNet(brName, null, nic.getMac(), model);
} else {
intf.defBridgeNet(_guestBridgeName, null, nic.getMac(), model);
}
} else if (nic.getType() == TrafficType.Control) {
/* Make sure the network is still there */
createControlNetwork(conn);
intf.defBridgeNet(_linkLocalBridgeName, null, nic.getMac(), model);
} else if (nic.getType() == TrafficType.Public) {
if (nic.getBroadcastType() == BroadcastDomainType.Vlan && !vlanId.equalsIgnoreCase("untagged")) {
String brName = createVlanBr(vlanId, _pifs.second());
intf.defBridgeNet(brName, null, nic.getMac(), model);
} else {
intf.defBridgeNet(_publicBridgeName, null, nic.getMac(), model);
}
} else if (nic.getType() == TrafficType.Management) {
intf.defBridgeNet(_privBridgeName, null, nic.getMac(), model);
} else if (nic.getType() == TrafficType.Storage) {
String storageBrName = nic.getName() == null ? _privBridgeName : nic.getName();
intf.defBridgeNet(storageBrName, null, nic.getMac(), model);
}
return intf;
}
use of com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef in project CloudStack-archive by CloudStack-extras.
the class LibvirtComputingResource method destroy_network_rules_for_vm.
protected boolean destroy_network_rules_for_vm(Connect conn, String vmName) {
if (!_can_bridge_firewall) {
return false;
}
String vif = null;
List<InterfaceDef> intfs = getInterfaces(conn, vmName);
if (intfs.size() > 0) {
InterfaceDef intf = intfs.get(0);
vif = intf.getDevName();
}
Script cmd = new Script(_securityGroupPath, _timeout, s_logger);
cmd.add("destroy_network_rules_for_vm");
cmd.add("--vmname", vmName);
if (vif != null) {
cmd.add("--vif", vif);
}
String result = cmd.execute();
if (result != null) {
return false;
}
return true;
}
use of com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef in project CloudStack-archive by CloudStack-extras.
the class LibvirtDomainXMLParser method main.
public static void main(String[] args) {
LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
parser.parseDomainXML("<domain type='kvm' id='12'>" + "<name>r-6-CV-5002-1</name>" + "<uuid>581b5a4b-b496-8d4d-e44e-a7dcbe9df0b5</uuid>" + "<description>testVM</description>" + "<memory>131072</memory>" + "<currentMemory>131072</currentMemory>" + "<vcpu>1</vcpu>" + "<os>" + "<type arch='i686' machine='pc-0.11'>hvm</type>" + "<kernel>/var/lib/libvirt/qemu/vmlinuz-2.6.31.6-166.fc12.i686</kernel>" + "<cmdline>ro root=/dev/sda1 acpi=force selinux=0 eth0ip=10.1.1.1 eth0mask=255.255.255.0 eth2ip=192.168.10.152 eth2mask=255.255.255.0 gateway=192.168.10.1 dns1=72.52.126.11 dns2=72.52.126.12 domain=v4.myvm.com</cmdline>" + "<boot dev='hd'/>" + "</os>" + "<features>" + "<acpi/>" + "<pae/>" + "</features>" + "<clock offset='utc'/>" + "<on_poweroff>destroy</on_poweroff>" + "<on_reboot>restart</on_reboot>" + "<on_crash>destroy</on_crash>" + "<devices>" + "<emulator>/usr/bin/qemu-kvm</emulator>" + "<disk type='file' device='disk'>" + "<driver name='qemu' type='raw'/>" + "<source file='/mnt/tank//vmops/CV/vm/u000004/r000006/rootdisk'/>" + "<target dev='hda' bus='ide'/>" + "</disk>" + "<interface type='bridge'>" + "<mac address='02:00:50:02:00:01'/>" + "<source bridge='vnbr5002'/>" + "<target dev='vtap5002'/>" + "<model type='e1000'/>" + "</interface>" + "<interface type='network'>" + "<mac address='00:16:3e:77:e2:a1'/>" + "<source network='vmops-private'/>" + "<target dev='vnet3'/>" + "<model type='e1000'/>" + "</interface>" + "<interface type='bridge'>" + "<mac address='06:85:00:00:00:04'/>" + "<source bridge='br0'/>" + "<target dev='tap5002'/>" + "<model type='e1000'/>" + "</interface>" + "<input type='mouse' bus='ps2'/>" + "<graphics type='vnc' port='6031' autoport='no' listen=''/>" + "<video>" + "<model type='cirrus' vram='9216' heads='1'/>" + "</video>" + "</devices>" + "</domain>");
for (InterfaceDef intf : parser.getInterfaces()) {
System.out.println(intf);
}
for (DiskDef disk : parser.getDisks()) {
System.out.println(disk);
}
System.out.println(parser.getVncPort());
System.out.println(parser.getDescription());
List<String> test = new ArrayList<String>(1);
test.add("1");
test.add("2");
if (test.contains("1")) {
System.out.print("fdf");
}
}
use of com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef in project CloudStack-archive by CloudStack-extras.
the class LibvirtDomainXMLParser method parseDomainXML.
public boolean parseDomainXML(String domXML) {
DocumentBuilder builder;
try {
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(domXML));
Document doc = builder.parse(is);
Element rootElement = doc.getDocumentElement();
desc = getTagValue("description", rootElement);
Element devices = (Element) rootElement.getElementsByTagName("devices").item(0);
NodeList disks = devices.getElementsByTagName("disk");
for (int i = 0; i < disks.getLength(); i++) {
Element disk = (Element) disks.item(i);
String diskFmtType = getAttrValue("driver", "type", disk);
String diskFile = getAttrValue("source", "file", disk);
String diskDev = getAttrValue("source", "dev", disk);
String diskLabel = getAttrValue("target", "dev", disk);
String bus = getAttrValue("target", "bus", disk);
String type = disk.getAttribute("type");
String device = disk.getAttribute("device");
DiskDef def = new DiskDef();
if (type.equalsIgnoreCase("file")) {
if (device.equalsIgnoreCase("disk")) {
DiskDef.diskFmtType fmt = null;
if (diskFmtType != null) {
fmt = DiskDef.diskFmtType.valueOf(diskFmtType.toUpperCase());
}
def.defFileBasedDisk(diskFile, diskLabel, DiskDef.diskBus.valueOf(bus.toUpperCase()), fmt);
} else if (device.equalsIgnoreCase("cdrom")) {
def.defISODisk(diskFile);
}
} else if (type.equalsIgnoreCase("block")) {
def.defBlockBasedDisk(diskDev, diskLabel, DiskDef.diskBus.valueOf(bus.toUpperCase()));
}
diskDefs.add(def);
}
NodeList nics = devices.getElementsByTagName("interface");
for (int i = 0; i < nics.getLength(); i++) {
Element nic = (Element) nics.item(i);
String type = nic.getAttribute("type");
String mac = getAttrValue("mac", "address", nic);
String dev = getAttrValue("target", "dev", nic);
String model = getAttrValue("model", "type", nic);
InterfaceDef def = new InterfaceDef();
if (type.equalsIgnoreCase("network")) {
String network = getAttrValue("source", "network", nic);
def.defPrivateNet(network, dev, mac, nicModel.valueOf(model.toUpperCase()));
} else if (type.equalsIgnoreCase("bridge")) {
String bridge = getAttrValue("source", "bridge", nic);
def.defBridgeNet(bridge, dev, mac, nicModel.valueOf(model.toUpperCase()));
}
interfaces.add(def);
}
Element graphic = (Element) devices.getElementsByTagName("graphics").item(0);
String port = graphic.getAttribute("port");
if (port != null) {
try {
vncPort = Integer.parseInt(port);
if (vncPort != -1) {
vncPort = vncPort - 5900;
} else {
vncPort = null;
}
} catch (NumberFormatException nfe) {
vncPort = null;
}
}
return true;
} catch (ParserConfigurationException e) {
s_logger.debug(e.toString());
} catch (SAXException e) {
s_logger.debug(e.toString());
} catch (IOException e) {
s_logger.debug(e.toString());
}
return false;
}
Aggregations