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

'''
    This script is not meant to be run manually. It is
    called from the main script. See the README for details.

    We assume that the usual OpenStack authentication env
    vars are defined. Addtionally, the following env vars
    are expected:
      - os_image
      - os_flavor
      - os_keyname
      - os_network
      - os_user_data
      - os_name_prefix
      - os_floating_ip_pool (optional)
'''

import os
import sys
import uuid
from novaclient import client

# XXX: clean this up

output_dir = sys.argv[1]

nova = client.Client(2, auth_url=os.environ['OS_AUTH_URL'],
                     tenant_id=os.environ['OS_TENANT_ID'],
                     username=os.environ['OS_USERNAME'],
                     password=<PASSWORD>['<PASSWORD>'])

print("INFO: authenticating")
nova.authenticate()

print("INFO: resolving image '%s'" % os.environ['os_image'])
image = nova.images.find(name=os.environ['os_image'])
print("INFO: resolving flavor '%s'" % os.environ['os_flavor'])
flavor = nova.flavors.find(name=os.environ['os_flavor'])
print("INFO: resolving network '%s'" % os.environ['os_network'])
network = nova.networks.find(label=os.environ['os_network'])

# if BUILD_ID is defined, let's add it so that it's easy to
# trace back a node to the exact Jenkins build.
meta = None
if 'BUILD_ID' in os.environ:
    meta = {'BUILD_ID': os.environ['BUILD_ID']}

print("INFO: reading user-data file '%s'" % os.environ['os_user_data'])
with open(os.environ['os_user_data']) as f:
    userdata = f.read()

<commit_msg>os_provision.py: handle multiple image results<commit_after>#!/usr/bin/env python3

'''
    This script is not meant to be run manually. It is
    called from the main script. See the README for details.

    We assume that the usual OpenStack authentication env
    vars are defined. Addtionally, the following env vars
    are expected:
      - os_image
      - os_flavor
      - os_keyname
      - os_network
      - os_user_data
      - os_name_prefix
      - os_floating_ip_pool (optional)
'''

import os
import sys
import uuid
from novaclient import client

# XXX: clean this up

output_dir = sys.argv[1]

nova = client.Client(2, auth_url=os.environ['OS_AUTH_URL'],
                     tenant_id=os.environ['OS_TENANT_ID'],
                     username=os.environ['OS_USERNAME'],
                     password=os.environ['OS_PASSWORD'])

print("INFO: authenticating")
nova.authenticate()

# it's possible multiple images match, e.g. during automated
# image uploads, in which case let's just pick the first one
print("INFO: resolving image '%s'" % os.environ['os_image'])
image = nova.images.findall(name=os.environ['os_image'])[0]

print("INFO: resolving flavor '%s'" % os.environ['os_flavor'])
flavor = nova.flavors.find(name=os.environ['os_flavor'])
print("INFO: resolving network '%s'" % os.environ['os_network'])
network = nova.networks.find(label=os.environ['os_network'])

# if BUILD_ID is defined, let's add it so that it's easy to
# trace back a node to the exact Jenkins build.
meta = None
if 'BUILD_ID' in os.environ:
    meta = {'BUILD_ID': os.environ['BUILD_ID']}

print("INFO: reading user-data file '%s'" % os.environ['os_user_data'])
with open(os.environ['os_user_data']) as f:
    userdata = f.read()


{'fraction_non_alphanumeric': 0.1254937708903069, 'fraction_numerical': 0.002127013065937405, 'mean_word_length': 3.5785813630041723, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '621956', 'n_tokens_mistral': 1084, 'n_tokens_neox': 1085, 'n_words': 297}