<commit_before>import libvirt
import logging

from lxml import etree

from . import dehumanize
from . import image
from . import iso
from . import exc
from . import meta
from . import template
from . import wait

log = logging.getLogger(__name__)


def create(args):
    log.debug('Connecting to libvirt...')
    conn = libvirt.open(args.connect)
    if conn is None:
        raise exc.LibvirtConnectionError()

    meta_data = meta.gen_meta(
        name=args.name,
        extra_meta=args.meta_data,
        nokey=args.nokey,
        )

    user_data = meta.gen_user(
        name=args.name,
        extra_user=args.user_data,
        )

    if args.distro:
        distro = args.distro
    else:
        distro = meta_data.get('downburst', {}).get('distro')

    if distro is None:
        distro = "ubuntu"

    if args.distroversion:
        distroversion = args.distroversion
    else:
        distroversion = meta_data.get('downburst', {}).get('distroversion')

    if distroversion is None:
        defaultversion = dict(
            ubuntu="12.04",
            fedora="17",
            centos="6.3",
            opensuse="12.2",
            sles="11-sp2",
            rhel="6.3",
            )
        distroversion = defaultversion[distro]

    if args.arch:
        arch = args.arch
    else:
        arch = meta_data.get('downburst', {}).get('arch')

    if arch == "x86_64":
        arch = "amd64"

    if arch is None:
        arch = "amd64"

    # check if the vm exists already, complain if so. this would
    # normally use conn.lookupByName, but that logs on all errors;
    # avoid the noise.
    if args.name in conn.listDefinedDomains():
        raise exc.VMExistsError(args.name)

    log.debug('Opening libvirt pool...')
    pool = conn.storagePoolLookupByName('default')
    vol = image.ensure_cloud_image(conn=conn, distro=distro, distroversion=distroversion, arch=arch)

    if args.wait:
        user_data.append("""\
#!/bin/sh<commit_msg>Add default version for debian.<commit_after>import libvirt
import logging

from lxml import etree

from . import dehumanize
from . import image
from . import iso
from . import exc
from . import meta
from . import template
from . import wait

log = logging.getLogger(__name__)


def create(args):
    log.debug('Connecting to libvirt...')
    conn = libvirt.open(args.connect)
    if conn is None:
        raise exc.LibvirtConnectionError()

    meta_data = meta.gen_meta(
        name=args.name,
        extra_meta=args.meta_data,
        nokey=args.nokey,
        )

    user_data = meta.gen_user(
        name=args.name,
        extra_user=args.user_data,
        )

    if args.distro:
        distro = args.distro
    else:
        distro = meta_data.get('downburst', {}).get('distro')

    if distro is None:
        distro = "ubuntu"

    if args.distroversion:
        distroversion = args.distroversion
    else:
        distroversion = meta_data.get('downburst', {}).get('distroversion')

    if distroversion is None:
        defaultversion = dict(
            ubuntu="12.04",
            fedora="17",
            centos="6.3",
            opensuse="12.2",
            sles="11-sp2",
            rhel="6.3",
            debian='6.0'
            )
        distroversion = defaultversion[distro]

    if args.arch:
        arch = args.arch
    else:
        arch = meta_data.get('downburst', {}).get('arch')

    if arch == "x86_64":
        arch = "amd64"

    if arch is None:
        arch = "amd64"

    # check if the vm exists already, complain if so. this would
    # normally use conn.lookupByName, but that logs on all errors;
    # avoid the noise.
    if args.name in conn.listDefinedDomains():
        raise exc.VMExistsError(args.name)

    log.debug('Opening libvirt pool...')
    pool = conn.storagePoolLookupByName('default')
    vol = image.ensure_cloud_image(conn=conn, distro=distro, distroversion=distroversion, arch=arch)

    if args.wait:
        user_data.append("""\
#!/bin/sh
{'fraction_non_alphanumeric': 0.11245283018867924, 'fraction_numerical': 0.012578616352201259, 'mean_word_length': 2.264367816091954, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, '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': '467225', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1238, 'n_words': 306}