<commit_before># -*- coding: utf-8 -*-
'''
lxc / Spin up and control LXC containers
=========================================
'''
__docformat__ = 'restructuredtext en'
import traceback


def absent(name):
    '''
    Destroy a container

    name
        id of the container to destroy

    .. code-block:: yaml

        destroyer:
          lxc.absent:
            - name: my_instance_name2

    '''
    if __opts__['test']:
        return {'name': name,
                'comment': '{0} will be removed'.format(name),
                'result': True,
                'changes': {}}
    changes = {}
    exists = __salt__['lxc.exists'](name)
    ret = {'name': name, 'changes': changes,
           'result': True, 'comment': 'Absent'}
    if exists:
        ret['result'] = False
        infos = __salt__['lxc.info'](name)
        try:
            if infos['state'] == 'running':
                cret = __salt__['lxc.stop'](name)
                infos = __salt__['lxc.infos'](name)
            if infos['state'] == 'running':
                raise Exception('Container won\'t stop')
            cret = __salt__['lxc.destroy'](name)
            if not cret.get('change', False):
                raise Exception('Container was not destroy')
            ret['result'] = not __salt__['lxc.exists'](name)
            if not ret['result']:
                raise Exception('Container won`t destroy')
        except Exception, ex:
            trace = traceback.format_exc()
            ret['result'] = False
            ret['comment'] = 'Error in container removal'
            changes['msg'] = '{1}\n{0}\n'.format(ex, trace)
        return ret
    return ret


def stopped(name):
    '''
    Stop a container

    name
        id of the container to stop

    .. code-block:: yaml

        sleepingcontainer:
          lxc.stopped:
            - name: my_instance_name2

    '''
    if __opts__['test']:
        return {'name': name,
                'comment': '{0} will be stopped'.format(name),
                'result': True,
                'changes': {}}
    cret = __salt__['lxc.stop'](name)
    cret['name'] = name
    return cret
<commit_msg>lxc state py3<commit_after># -*- coding: utf-8 -*-
'''
lxc / Spin up and control LXC containers
=========================================
'''

from __future__ import absolute_import
__docformat__ = 'restructuredtext en'
import traceback


def absent(name):
    '''
    Destroy a container

    name
        id of the container to destroy

    .. code-block:: yaml

        destroyer:
          lxc.absent:
            - name: my_instance_name2

    '''
    if __opts__['test']:
        return {'name': name,
                'comment': '{0} will be removed'.format(name),
                'result': True,
                'changes': {}}
    changes = {}
    exists = __salt__['lxc.exists'](name)
    ret = {'name': name, 'changes': changes,
           'result': True, 'comment': 'Absent'}
    if exists:
        ret['result'] = False
        infos = __salt__['lxc.info'](name)
        try:
            if infos['state'] == 'running':
                cret = __salt__['lxc.stop'](name)
                infos = __salt__['lxc.infos'](name)
            if infos['state'] == 'running':
                raise Exception('Container won\'t stop')
            cret = __salt__['lxc.destroy'](name)
            if not cret.get('change', False):
                raise Exception('Container was not destroy')
            ret['result'] = not __salt__['lxc.exists'](name)
            if not ret['result']:
                raise Exception('Container won`t destroy')
        except Exception as ex:
            trace = traceback.format_exc()
            ret['result'] = False
            ret['comment'] = 'Error in container removal'
            changes['msg'] = '{1}\n{0}\n'.format(ex, trace)
        return ret
    return ret


def stopped(name):
    '''
    Stop a container

    name
        id of the container to stop

    .. code-block:: yaml

        sleepingcontainer:
          lxc.stopped:
            - name: my_instance_name2

    '''
    if __opts__['test']:
        return {'name': name,
                'comment': '{0} will be stopped'.format(name),
                'result': True,
                'changes': {}}
    cret = __salt__['lxc.stop'](name)
    cret['name'] = name
    return cret

{'fraction_non_alphanumeric': 0.15603328710124825, 'fraction_numerical': 0.0034674063800277394, 'mean_word_length': 1.856105610561056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5787748', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1222, 'n_words': 319}