-
Notifications
You must be signed in to change notification settings - Fork 451
/
Copy pathkvm.py
32 lines (24 loc) · 1.02 KB
/
kvm.py
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
# Copyright (C) 2010-2015 Cuckoo Foundation.
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
# See the file 'docs/LICENSE' for copying permission.
from __future__ import absolute_import
import xml.etree.ElementTree as ET
from lib.cuckoo.common.abstracts import LibVirtMachinery
class KVM(LibVirtMachinery):
"""Virtualization layer for KVM based on python-libvirt."""
# Set KVM connection string.
dsn = "qemu:///system"
def _get_interface(self, label):
xml = ET.fromstring(self._lookup(label).XMLDesc())
elem = xml.find("./devices/interface[@type='network']")
if elem is None:
return elem
elem = elem.find("target")
if elem is None:
return None
return elem.attrib["dev"]
def start(self, label):
super(KVM, self).start(label)
machine = self.db.view_machine_by_label(label)
if machine and not hasattr(machine, "interface"):
self.db.set_machine_interface(label, self._get_interface(label))