<commit_before>#!/usr/bin/env python
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim, vmodl
import atexit
import os
import sys
from pprint import pprint, pformat
import time
from netaddr import IPNetwork, IPAddress
import argparse
from copy import deepcopy
import yaml
import logging
from netaddr import IPNetwork, IPAddress

'''
Logging
'''
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)


'''
 Send an email
'''
def send_email(config, ip_settings):
    import smtplib
    from email.mime.text import MIMEText

    # get user who ran this script
    me = os.getenv('USER')

    email_body = 'Your VM is ready!'
    msg = MIMEText(email_body)
    msg['Subject'] = '%s - VM deploy complete' % config['hostname']
    msg['From'] = config['mailfrom'] 
    msg['To'] = me

    s = smtplib.SMTP('localhost')
    s.sendmail(config['mailfrom'] , [me], msg.as_string())
    s.quit()

'''
 Waits and provides updates on a vSphere task
'''
def WaitTask(task, actionName='job', hideResult=False):
    #print 'Waiting for %s to complete.' % actionName
    
    while task.info.state == vim.TaskInfo.State.running:
       time.sleep(2)
    
    if task.info.state == vim.TaskInfo.State.success:
       if task.info.result is not None and not hideResult:
          out = '%s completed successfully, result: %s' % (actionName, task.info.result)
       else:
          out = '%s completed successfully.' % actionName
    else:
       out = '%s did not complete successfully: %s' % (actionName, task.info.error)
       print out
       raise task.info.error # should be a Fault... check XXX
    
    # may not always be applicable, but can't hurt.
    return task.info.result

'''
 Get the vsphere object associated with a given text name
'''
def get_obj(content, vimtype, name):
    obj = None
    container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
    for c in container.view:
        if c.name == name:
            obj = c
            break
    return obj

'''
 Connect to vCenter server and deploy a VM from template
'''
def clone(config, ip_settings):
    # connect to vCenter server
    try:
        si = SmartConnect(host=config['server'], user=config['username'], pwd=config['password'], port=int(config['port']))
    except:
        logging.exception('Unable to connect to vsphere server.')
        sys.exit()
    
    # add a clean up routine
    atexit.register(Disconnect, si)
    
    content = si.RetrieveContent()
<commit_msg>remove old comments<commit_after>#!/usr/bin/env python
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim, vmodl
import atexit
import os
import sys
from pprint import pprint, pformat
import time
from netaddr import IPNetwork, IPAddress
import argparse
from copy import deepcopy
import yaml
import logging
from netaddr import IPNetwork, IPAddress

'''
Logging
'''
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)


'''
 Send an email
'''
def send_email(config, ip_settings):
    import smtplib
    from email.mime.text import MIMEText

    # get user who ran this script
    me = os.getenv('USER')

    email_body = 'Your VM is ready!'
    msg = MIMEText(email_body)
    msg['Subject'] = '%s - VM deploy complete' % config['hostname']
    msg['From'] = config['mailfrom'] 
    msg['To'] = me

    s = smtplib.SMTP('localhost')
    s.sendmail(config['mailfrom'] , [me], msg.as_string())
    s.quit()

'''
 Waits and provides updates on a vSphere task
'''
def WaitTask(task, actionName='job', hideResult=False):
    #print 'Waiting for %s to complete.' % actionName
    
    while task.info.state == vim.TaskInfo.State.running:
       time.sleep(2)
    
    if task.info.state == vim.TaskInfo.State.success:
       if task.info.result is not None and not hideResult:
          out = '%s completed successfully, result: %s' % (actionName, task.info.result)
       else:
          out = '%s completed successfully.' % actionName
    else:
       out = '%s did not complete successfully: %s' % (actionName, task.info.error)
       print out
       raise task.info.error
    
    return task.info.result

'''
 Get the vsphere object associated with a given text name
'''
def get_obj(content, vimtype, name):
    obj = None
    container = content.viewManager.CreateContainerView(content.rootFolder, vimtype, True)
    for c in container.view:
        if c.name == name:
            obj = c
            break
    return obj

'''
 Connect to vCenter server and deploy a VM from template
'''
def clone(config, ip_settings):
    # connect to vCenter server
    try:
        si = SmartConnect(host=config['server'], user=config['username'], pwd=config['password'], port=int(config['port']))
    except:
        logging.exception('Unable to connect to vsphere server.')
        sys.exit()
    
    # add a clean up routine
    atexit.register(Disconnect, si)
    
    content = si.RetrieveContent()

{'fraction_non_alphanumeric': 0.11422805247225025, 'fraction_numerical': 0.0004036326942482341, 'mean_word_length': 3.1964436917866217, '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': '6828515', 'n_tokens_mistral': 1507, 'n_tokens_neox': 1491, 'n_words': 470}