<commit_before>from celery import logging

import libcloud.security

from mist.io.celery import app
from mist.io.methods import ssh_command, connect_provider
from mist.io.methods import notify_user, notify_admin
from mist.io.exceptions import ServiceUnavailableError


log = logging.getLogger(__name__)


@app.task
def add(x,y):
    return x+y


@app.task(bind=True, default_retry_delay=3*60)
def run_deploy_script(self, email, backend_id, machine_id, command, 
                      key_id=None, username=None, password=<PASSWORD>, port=22):
    
    try: # Multi-user environment
        from mist.core.helpers import user_from_email
        user = user_from_email(email)
        cert_path = "src/mist.io/cacert.pem"
    except ImportError: # Standalone mist.io
        from mist.io.model import User
        user = User()
        cert_path = "cacert.pem"

    # libcloud certificate fix for OS X
    libcloud.security.CA_CERTS_PATH.append(cert_path)
        
    try:
        # find the node we're looking for and get its hostname
        conn = connect_provider(user.backends[backend_id])
        nodes = conn.list_nodes()
        node = None
        for n in nodes:
            if n.id == machine_id:
                node = n
                break
    
        if node and len(node.public_ips):
            host = node.public_ips[0]
        else:
            raise self.retry(exc=Exception(), countdown=60, max_retries=5)
    
        try:
            from mist.io.shell import Shell
            shell = Shell('google.com')
            key_id, ssh_user = shell.autoconfigure(user, backend_id, node.id,
                                                   key_id, username, password, port)
            import time
            start_time = time.time()
            retval, output = shell.command(command)<commit_msg>filter out ipv6 addresses on machine deploy script<commit_after>from celery import logging

import libcloud.security

from mist.io.celery import app
from mist.io.methods import ssh_command, connect_provider
from mist.io.methods import notify_user, notify_admin
from mist.io.exceptions import ServiceUnavailableError


log = logging.getLogger(__name__)


@app.task
def add(x,y):
    return x+y


@app.task(bind=True, default_retry_delay=3*60)
def run_deploy_script(self, email, backend_id, machine_id, command, 
                      key_id=None, username=None, password=<PASSWORD>, port=22):
    
    try: # Multi-user environment
        from mist.core.helpers import user_from_email
        user = user_from_email(email)
        cert_path = "src/mist.io/cacert.pem"
    except ImportError: # Standalone mist.io
        from mist.io.model import User
        user = User()
        cert_path = "cacert.pem"

    # libcloud certificate fix for OS X
    libcloud.security.CA_CERTS_PATH.append(cert_path)
        
    try:
        # find the node we're looking for and get its hostname
        conn = connect_provider(user.backends[backend_id])
        nodes = conn.list_nodes()
        node = None
        for n in nodes:
            if n.id == machine_id:
                node = n
                break
    
        if node and len(node.public_ips):
            # filter out IPv6 addresses
            ips = filter(lambda ip: ':' not in ip, node.public_ips)
            host = ips[0]
        else:
            raise self.retry(exc=Exception(), countdown=60, max_retries=5)
    
        try:
            from mist.io.shell import Shell
            shell = Shell('google.com')
            key_id, ssh_user = shell.autoconfigure(user, backend_id, node.id,
                                                   key_id, username, password, port)
            import time
            start_time = time.time()
            retval, output = shell.command(command)
{'fraction_non_alphanumeric': 0.08313413014608234, 'fraction_numerical': 0.005312084993359893, 'mean_word_length': 2.154103852596315, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2445203', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1081, 'n_words': 285}