<commit_before># -*- coding: utf-8 -*-
'''
The top level interface used to translate configuration data back to the
correct cloud modules
'''

# Import python libs
import copy
import os
import glob
import time
import signal
import logging
import multiprocessing
import datetime
from itertools import groupby

# Import salt.cloud libs
import salt.cloud.config
import salt.cloud.utils
import salt.cloud.loader
import salt.utils.event
from salt.utils.event import tagify
from salt.cloud.exceptions import (
    SaltCloudNotFound,
    SaltCloudException,
    SaltCloudSystemExit,
    SaltCloudConfigError
)

# Import salt libs
import salt.client
import salt.utils

# Import third party libs
import yaml

# Get logging started
log = logging.getLogger(__name__)

try:
    from mako.template import Template
    from mako.exceptions import MakoException
    MAKO_AVAILABLE = True
except ImportError:
    log.debug('Mako not available')
    MAKO_AVAILABLE = False


class CloudClient(object):
    '''
    The client class to wrap cloud interactions
    '''
    def __init__(self, path=None, opts=None, config_dir=None):
        if opts:
            self.opts = opts
        else:
            self.opts = salt.cloud.config.cloud_config(path)
        self.mapper = salt.cloud.Map(self.opts)

    def _opts_defaults(self, **kwargs):
        '''
        Set the opts dict to defaults and allow for opts to be overridden in
        the kwargs
        '''
        self.mapper.opts['parallel'] = False
        self.mapper.opts.update(kwargs)

    def low(self, fun, low):
        '''
        Pass the cloud function and low data structure to run
        '''
        l_fun = getattr(self, fun)
        f_call = salt.utils.format_call(l_fun, low)
        return l_fun(*f_call.get('args', ()), **f_call.get('kwargs', {}))

    def list_sizes(self, provider=None):
        '''
        List all available sizes in configured cloud systems
        '''
        return salt.cloud.utils.simple_types_filter(
                self.mapper.size_list(provider))

    def list_images(self, provider=None):
        '''
        List all available images in configured cloud systems
        '''
        return salt.cloud.utils.simple_types_filter(
                self.mapper.image_list(provider))

    def list_locations(self, provider=None):
        '''
        List all available locations in configured cloud systems
        '''
        return salt.cloud.utils.simple_types_filter(
                self.mapper.location_list(provider))

    def query(self, query_type='list_nodes'):
        '''
        Query basic instance information
        '''
        return self.mapper.map_providers_parallel(query_type)

    def full_query(self, query_type='list_nodes_full'):
        '''
        Query all instance information
        '''
        return self.mapper.map_providers_parallel(query_type)

    def select_query(self, query_type='list_nodes_select'):
        '''
        Query select instance information
        '''
        return self.mapper.map_providers_parallel(query_type)

    def profile(self, profile, names, **kwargs):
        '''
        Pass in a profile to create, names is a list of vm names to allocate
        '''
        self._opts_defaults(**kwargs)
        if isinstance(names, str):
            names = names.split(',')
        return salt.cloud.utils.simple_types_filter(
                self.mapper.run_profile(profile, names))

    def action(self, fun=None, cloudmap=None, names=None, provider=None,
              instance=None, kwargs=None):
        '''
        Execute a single action via the cloud plugin backend

        Examples:

            client.action(fun='show_instance', names=['myinstance'])
            client.action(fun='show_image', provider='my-ec2-config', kwargs={'image': 'ami-10314d79'})
        '''
        if names and not provider:
            self.opts['action'] = fun
            return self.mapper.do_action(names, kwargs)
        if provider:
            return self.mapper.do_function(provider, fun, kwargs)
        else:
            # This should not be called without either an instance or a
            # provider.
            raise SaltCloudConfigError(
                'Either an instance or a provider must be specified.'
            )

        return salt.cloud.utils.simple_types_filter(<commit_msg>Add destroy to base cloud client api<commit_after># -*- coding: utf-8 -*-
'''
The top level interface used to translate configuration data back to the
correct cloud modules
'''

# Import python libs
import copy
import os
import glob
import time
import signal
import logging
import multiprocessing
from itertools import groupby

# Import salt.cloud libs
import salt.cloud.config
import salt.cloud.utils
import salt.cloud.loader
import salt.utils.event
from salt.cloud.exceptions import (
    SaltCloudNotFound,
    SaltCloudException,
    SaltCloudSystemExit,
    SaltCloudConfigError
)

# Import salt libs
import salt.client
import salt.utils

# Import third party libs
import yaml

# Get logging started
log = logging.getLogger(__name__)

try:
    from mako.template import Template
    from mako.exceptions import MakoException
    MAKO_AVAILABLE = True
except ImportError:
    log.debug('Mako not available')
    MAKO_AVAILABLE = False


class CloudClient(object):
    '''
    The client class to wrap cloud interactions
    '''
    def __init__(self, path=None, opts=None, config_dir=None):
        if opts:
            self.opts = opts
        else:
            self.opts = salt.cloud.config.cloud_config(path)
        self.mapper = salt.cloud.Map(self.opts)

    def _opts_defaults(self, **kwargs):
        '''
        Set the opts dict to defaults and allow for opts to be overridden in
        the kwargs
        '''
        self.mapper.opts['parallel'] = False
        self.mapper.opts.update(kwargs)

    def low(self, fun, low):
        '''
        Pass the cloud function and low data structure to run
        '''
        l_fun = getattr(self, fun)
        f_call = salt.utils.format_call(l_fun, low)
        return l_fun(*f_call.get('args', ()), **f_call.get('kwargs', {}))

    def list_sizes(self, provider=None):
        '''
        List all available sizes in configured cloud systems
        '''
        return salt.cloud.utils.simple_types_filter(
                self.mapper.size_list(provider))

    def list_images(self, provider=None):
        '''
        List all available images in configured cloud systems
        '''
        return salt.cloud.utils.simple_types_filter(
                self.mapper.image_list(provider))

    def list_locations(self, provider=None):
        '''
        List all available locations in configured cloud systems
        '''
        return salt.cloud.utils.simple_types_filter(
                self.mapper.location_list(provider))

    def query(self, query_type='list_nodes'):
        '''
        Query basic instance information
        '''
        return self.mapper.map_providers_parallel(query_type)

    def full_query(self, query_type='list_nodes_full'):
        '''
        Query all instance information
        '''
        return self.mapper.map_providers_parallel(query_type)

    def select_query(self, query_type='list_nodes_select'):
        '''
        Query select instance information
        '''
        return self.mapper.map_providers_parallel(query_type)

    def profile(self, profile, names, **kwargs):
        '''
        Pass in a profile to create, names is a list of vm names to allocate
        '''
        self._opts_defaults(**kwargs)
        if isinstance(names, str):
            names = names.split(',')
        return salt.cloud.utils.simple_types_filter(
                self.mapper.run_profile(profile, names))

    def destroy(self, names):
        '''
        Destroy the named vms
        '''
        if isinstance(names, str):
            names = names.split(',')
        return self.mapper.destroy(names)

    def action(self, fun=None, cloudmap=None, names=None, provider=None,
              instance=None, kwargs=None):
        '''
        Execute a single action via the cloud plugin backend

        Examples:

            client.action(fun='show_instance', names=['myinstance'])
            client.action(fun='show_image', provider='my-ec2-config', kwargs={'image': 'ami-10314d79'})
        '''
        if names and not provider:
            self.opts['action'] = fun
            return self.mapper.do_action(names, kwargs)
        if provider:
            return self.mapper.do_function(provider, fun, kwargs)
        else:
            # This should not be called without either an instance or a
            # provider.
            raise SaltCloudConfigError(
                'Either an instance or a provider must be specified.'
            )

        return salt.cloud.utils.simple_types_filter(
{'fraction_non_alphanumeric': 0.09338917817523205, 'fraction_numerical': 0.0020375820692777906, 'mean_word_length': 2.4565727699530515, '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': '200225', 'n_tokens_mistral': 2431, 'n_tokens_neox': 2379, 'n_words': 677}