<commit_before>from .. import Server
import logging
import os
import chef

class MongoDataNode(Server):

    log = logging.getLogger('Servers.MongoDataNode')
    log.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
            '%(asctime)s [%(name)s] %(levelname)s: %(message)s',
            datefmt = '%H:%M:%S')
    ch.setFormatter(formatter)
    log.addHandler(ch)

    def __init__(self, dry = None, verbose = None, size = None, cluster = None,
                    environment = None, ami = None, region = None, role = None,
                    keypair = None, availability_zone = None,
                    security_groups = None, block_devices = None,
                    replica_set = None, replica_set_index = None):

        super(MongoDataNode, self).__init__(dry, verbose, size, cluster,
                                            environment, ami, region, role,
                                            keypair, availability_zone,
                                            security_groups, block_devices)

        self.replica_set = replica_set
        self.replica_set_index = replica_set_index

    def configure(self):

        super(MongoDataNode, self).configure()

        if self.replica_set is None:
            self.log.warn('No replica set provided')
            self.replica_set = 1

        self.log.info('Using replica set {set}'.format(set=self.replica_set))

        if self.replica_set_index is None:
            self.log.warn('No replica set set index provided')
            self.replica_set_index = 1

        self.log.info('Using replica set index {index}'.format(
                        index=self.replica_set_index))

    @property
    def name(self):

        try:
            return self.unique_name
        except Exception:
            pass

        template = '{envcl}-rs{set}-{zone}-{index}'
        name = template.format(envcl=self.envcl, set=self.replica_set,
                                zone=self.availability_zone[-1:],
                                index=self.replica_set_index)

        self.unique_name = name

        self.log.info('Using node name {name}'.format(name=name))

        return name

    def bake(self):

        chef_path = os.path.expanduser('~/.chef')

        self.log.info('Using Chef Path \'{path}\''.format(path = chef_path))

        chef_api = chef.autoconfigure(chef_path)

        try:
            node = chef.Node('self.name')
            node.delete()

            self.log.info('Removed previous chef node \'{node}\''.format(
                                node = self.name))
        except chef.exceptions.ChefServerNotFoundError:
            pass
        except Exception as e:
            raise e

        try:
            client = chef.Client(self.name)<commit_msg>Turned the Chef path into a parameter<commit_after>from .. import Server
import logging
import os
import chef

class MongoDataNode(Server):

    log = logging.getLogger('Servers.MongoDataNode')
    log.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
            '%(asctime)s [%(name)s] %(levelname)s: %(message)s',
            datefmt = '%H:%M:%S')
    ch.setFormatter(formatter)
    log.addHandler(ch)

    def __init__(self, dry = None, verbose = None, size = None, cluster = None,
                    environment = None, ami = None, region = None, role = None,
                    keypair = None, availability_zone = None, chef_path = None,
                    security_groups = None, block_devices = None,
                    replica_set = None, replica_set_index = None):

        super(MongoDataNode, self).__init__(dry, verbose, size, cluster,
                                            environment, ami, region, role,
                                            keypair, availability_zone,
                                            security_groups, block_devices)

        self.replica_set = replica_set
        self.replica_set_index = replica_set_index
        self.chef_path = chef_path

    def configure(self):

        super(MongoDataNode, self).configure()

        if self.replica_set is None:
            self.log.warn('No replica set provided')
            self.replica_set = 1

        self.log.info('Using replica set {set}'.format(set=self.replica_set))

        if self.replica_set_index is None:
            self.log.warn('No replica set set index provided')
            self.replica_set_index = 1

        self.log.info('Using replica set index {index}'.format(
                        index=self.replica_set_index))

        if self.chef_path is None:
            self.log.warn('No Chef path provided')
            self.chef_path = '~/.chef'

        self.chef_path = os.path.expanduser(self.chef_path)

        self.log.info('Using Chef path \'{path}\''.format(
                                path = self.chef_path))

    @property
    def name(self):

        try:
            return self.unique_name
        except Exception:
            pass

        template = '{envcl}-rs{set}-{zone}-{index}'
        name = template.format(envcl=self.envcl, set=self.replica_set,
                                zone=self.availability_zone[-1:],
                                index=self.replica_set_index)

        self.unique_name = name

        self.log.info('Using node name {name}'.format(name=name))

        return name

    def bake(self):

        chef_path = os.path.expanduser(self.chef_path)
        chef_api = chef.autoconfigure(chef_path)

        try:
            node = chef.Node('self.name')
            node.delete()

            self.log.info('Removed previous chef node \'{node}\''.format(
                                node = self.name))
        except chef.exceptions.ChefServerNotFoundError:
            pass
        except Exception as e:
            raise e

        try:
            client = chef.Client(self.name)
{'fraction_non_alphanumeric': 0.10268006700167503, 'fraction_numerical': 0.0010050251256281408, 'mean_word_length': 1.774628252788104, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3703836', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1641, 'n_words': 358}