<commit_before># vim: ts=4 sw=4 expandtab

import os
import tempfile
import time
from collections import deque
from devops import xml
from devops import scancodes
from xmlbuilder import XMLBuilder
import ipaddr

def index(p, seq):
    for i in xrange(len(seq)):
        if p(seq[i]): return i
    return -1

def find(p, seq):
    for item in seq:
        if p(item): return item
    return None

class DeploymentSpec:
    def __repr__(self):
        return "<DeploymentSpec arch=\"%s\" os_type=\"%s\" hypervisor=\"%s\" emulator=\"%s\">" % (self.arch, self.os_type, self.hypervisor, self.emulator)

class LibvirtException(Exception): pass

class LibvirtXMLBuilder:

    def build_network_xml(self, network):
        network_xml = XMLBuilder('network')
        network_xml.name(network.id)
        
        if hasattr(network, 'ip_addresses') and not network.ip_addresses is None:
            with network_xml.ip(address=str(network.ip_addresses[1]), prefix=str(network.ip_addresses.prefixlen)):
                if network.dhcp_server: 
                    with network_xml.dhcp:
                        start = network.ip_addresses[2]
                        end   = network.ip_addresses[network.ip_addresses.numhosts-2]

                        network_xml.range(start=str(start), end=str(end))

        return str(network_xml)

    def build_node_xml(self, node, spec):
        node_xml = XMLBuilder("domain", type=spec.hypervisor)
        node_xml.name(node.id)
        node_xml.vcpu(str(node.cpu))
        node_xml.memory(str(node.memory*1024), unit='KiB')

        with node_xml.os:
            node_xml.type(spec.os_type, arch=node.arch)
            for boot_dev in node.boot:
                if boot_dev == 'disk':
                    node_xml.boot(dev="hd")
                else:
                    node_xml.boot(dev=boot_dev)

        ide_disk_names = deque(['hd'+c for c in list('abcdefghijklmnopqrstuvwxyz')])
        serial_disk_names = deque(['sd'+c for c in list('abcdefghijklmnopqrstuvwxyz')])

        
        def disk_name(bus='ide'):
            if str(bus) == 'ide':
                return ide_disk_names.popleft()
            return serial_disk_names.popleft()
        

        with node_xml.devices:
            node_xml.emulator(spec.emulator)

            if len(node.disks) > 0:
                node_xml.controller(type="ide")

            for disk in node.disks:
                with node_xml.disk(type="file", device="disk"):
                    node_xml.driver(name="qemu", type=disk.format)
                    node_xml.source(file=disk.path)
                    node_xml.target(dev=disk_name(disk.bus), bus=disk.bus)

            if node.cdrom:
                with node_xml.disk(type="file", device="cdrom"):
                    node_xml.driver(name="qemu", type="raw")
                    node_xml.source(file=node.cdrom.isopath)
                    node_xml.target(dev=disk_name(node.cdrom.bus), bus=node.cdrom.bus)

            for interface in node.interfaces:
                with node_xml.interface(type="network"):
                    node_xml.source(network=interface.network.id)
            
            if node.vnc:
                node_xml.graphics(type='vnc', autoport='yes')

        return str(node_xml)<commit_msg>[devops] Enabled VNC on non-local interfaces<commit_after># vim: ts=4 sw=4 expandtab

import os
import tempfile
import time
from collections import deque
from devops import xml
from devops import scancodes
from xmlbuilder import XMLBuilder
import ipaddr

def index(p, seq):
    for i in xrange(len(seq)):
        if p(seq[i]): return i
    return -1

def find(p, seq):
    for item in seq:
        if p(item): return item
    return None

class DeploymentSpec:
    def __repr__(self):
        return "<DeploymentSpec arch=\"%s\" os_type=\"%s\" hypervisor=\"%s\" emulator=\"%s\">" % (self.arch, self.os_type, self.hypervisor, self.emulator)

class LibvirtException(Exception): pass

class LibvirtXMLBuilder:

    def build_network_xml(self, network):
        network_xml = XMLBuilder('network')
        network_xml.name(network.id)
        
        if hasattr(network, 'ip_addresses') and not network.ip_addresses is None:
            with network_xml.ip(address=str(network.ip_addresses[1]), prefix=str(network.ip_addresses.prefixlen)):
                if network.dhcp_server: 
                    with network_xml.dhcp:
                        start = network.ip_addresses[2]
                        end   = network.ip_addresses[network.ip_addresses.numhosts-2]

                        network_xml.range(start=str(start), end=str(end))

        return str(network_xml)

    def build_node_xml(self, node, spec):
        node_xml = XMLBuilder("domain", type=spec.hypervisor)
        node_xml.name(node.id)
        node_xml.vcpu(str(node.cpu))
        node_xml.memory(str(node.memory*1024), unit='KiB')

        with node_xml.os:
            node_xml.type(spec.os_type, arch=node.arch)
            for boot_dev in node.boot:
                if boot_dev == 'disk':
                    node_xml.boot(dev="hd")
                else:
                    node_xml.boot(dev=boot_dev)

        ide_disk_names = deque(['hd'+c for c in list('abcdefghijklmnopqrstuvwxyz')])
        serial_disk_names = deque(['sd'+c for c in list('abcdefghijklmnopqrstuvwxyz')])

        
        def disk_name(bus='ide'):
            if str(bus) == 'ide':
                return ide_disk_names.popleft()
            return serial_disk_names.popleft()
        

        with node_xml.devices:
            node_xml.emulator(spec.emulator)

            if len(node.disks) > 0:
                node_xml.controller(type="ide")

            for disk in node.disks:
                with node_xml.disk(type="file", device="disk"):
                    node_xml.driver(name="qemu", type=disk.format)
                    node_xml.source(file=disk.path)
                    node_xml.target(dev=disk_name(disk.bus), bus=disk.bus)

            if node.cdrom:
                with node_xml.disk(type="file", device="cdrom"):
                    node_xml.driver(name="qemu", type="raw")
                    node_xml.source(file=node.cdrom.isopath)
                    node_xml.target(dev=disk_name(node.cdrom.bus), bus=node.cdrom.bus)

            for interface in node.interfaces:
                with node_xml.interface(type="network"):
                    node_xml.source(network=interface.network.id)
            
            if node.vnc:
                node_xml.graphics(type='vnc', listen='0.0.0.0', autoport='yes')

        return str(node_xml)
{'fraction_non_alphanumeric': 0.11322477552883883, 'fraction_numerical': 0.0039567797899863035, 'mean_word_length': 2.113216485078162, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 66}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5605733', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1986, 'n_words': 387}