<commit_before>#!/usr/bin/env python

import sys
import time
import uuid
import os.path

import util
import nssh
import fastnovaboot
import argparse

i = util.logger.info
interval = 3

desc = ('Spawn a VM and run an Ansible playbook on it. The playbook comes '
        'in -p argument. the rest of the arguments are passed to '
        'fastnovaboot.')

def ask():
    l = util.NovaProxy().images.list()
    l.sort(key=lambda x: x.name.lower())
    n = 1
    print ("Current tenant is \"%s\". There are following available images:"
           % util._TENANT)
    for img in l:
        print "%d: %s, %s" % (n, img.name, img.id)
        n += 1

    ch = raw_input("Select image to spawn (give a number): ")

    num = int(ch)
    return l[num-1].id



def main(args_list):
    args, unparsed_args_list = get_args(args_list)

    if not os.path.isfile(args.playbook):
        raise util.AnsibleWrapperError("Given playbook doesn't exist")

    util.callCheck("ansible-playbook --syntax-check %s" % args.playbook)

    if not unparsed_args_list:
        unparsed_args_list = []

    if '-n' not in unparsed_args_list:
        name = args.playbook + '-' + uuid.uuid4().hex[:4]
        unparsed_args_list += ['-n', name]

    if args.image:
        image = args.image
    else:
        image = ask()

    unparsed_args_list += ['-i', image]

    if args.test:
        # this will cause nova boot to do only a test run
        unparsed_args_list += ['-t']

    i("About to run fastnovaboot with args: %s" % unparsed_args_list)
    image_id, ip = fastnovaboot.main(unparsed_args_list)

    if not args.test:
        while nssh.main(['-t', name]) != 0:
            i("The %s VM is not ready yet. Sleeping for %d seconds" %
              (name, interval))
            time.sleep(interval)
    else:
        i('A test run, _NOT_ spawning the VM')
<commit_msg>use new floating ip rather than instance name, when checking if sshd is up on the new instance<commit_after>#!/usr/bin/env python

import sys
import time
import uuid
import os.path

import util
import nssh
import fastnovaboot
import argparse

i = util.logger.info
interval = 3

desc = ('Spawn a VM and run an Ansible playbook on it. The playbook comes '
        'in -p argument. the rest of the arguments are passed to '
        'fastnovaboot.')

def ask():
    l = util.NovaProxy().images.list()
    l.sort(key=lambda x: x.name.lower())
    n = 1
    print ("Current tenant is \"%s\". There are following available images:"
           % util._TENANT)
    for img in l:
        print "%d: %s, %s" % (n, img.name, img.id)
        n += 1

    ch = raw_input("Select image to spawn (give a number): ")

    num = int(ch)
    return l[num-1].id



def main(args_list):
    args, unparsed_args_list = get_args(args_list)

    if not os.path.isfile(args.playbook):
        raise util.AnsibleWrapperError("Given playbook doesn't exist")

    util.callCheck("ansible-playbook --syntax-check %s" % args.playbook)

    if not unparsed_args_list:
        unparsed_args_list = []

    if '-n' not in unparsed_args_list:
        name = args.playbook + '-' + uuid.uuid4().hex[:4]
        unparsed_args_list += ['-n', name]

    if args.image:
        image = args.image
    else:
        image = ask()

    unparsed_args_list += ['-i', image]

    if args.test:
        # this will cause nova boot to do only a test run
        unparsed_args_list += ['-t']

    i("About to run fastnovaboot with args: %s" % unparsed_args_list)
    image_id, ip = fastnovaboot.main(unparsed_args_list)

    # ip - new floating ip associated to the machine

    user = nssh.get_ssh_user(image_id)

    if not args.test:
        i("About to spin-wait for when ssh is up on the new instance")
        while nssh.test_ssh_connection(user, ip) != 0:
            i("The VM on IP %s is not ready yet. Sleeping for %d seconds" %
              (ip, interval))
            time.sleep(interval)
    else:
        i('A test run, _NOT_ spawning the VM')

{'fraction_non_alphanumeric': 0.11543319019954534, 'fraction_numerical': 0.0035362465269007325, 'mean_word_length': 2.4828496042216357, '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': '3692395', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1320, 'n_words': 421}