<commit_before>#!/bin/bash

LOG_TERMINAL=0
export LOG_TERMINAL VSM_NAME VSM_ISO_DIR VSM_VM_DIR VSM_VM_XML

VSM_NAME=$(config-get n1kv-vsm-name)
VSM_ISO_DIR="/opt/cisco/iso"
VSM_VM_DIR="/var/spool/vsm"
VSM_VM_XML="vsm_vm.xml"


function logger
{
    if [ $LOG_TERMINAL -eq 1 ]; then
        echo $1
    else
        juju-log $1
    fi
}

# Returns 0 if VSM is not running
function is_vsm_vm_running
{
    local run=$(sudo virsh list --all | grep $VSM_NAME | awk '{print $NF}')
    if [ "$run" == "running" ]; then
        return 1
    else
        return 0
    fi
}

# It creates a persistent VSM VM if it was not created already
# Returns 1 if it was not able to create it
function create_vsm_vm
{
    juju-log "start: Check if $VSM_NAME vm already exists"

    if [ `/usr/bin/virsh list --all | grep -c $VSM_NAME` -eq 1 ]; then
        return 0
    fi

    juju-log "Define vsm vm"
    if [ ! -f ${VSM_VM_DIR}/${VSM_VM_XML} ]; then
        juju-log "Error: $VSM_NAME template doesn't exists"
        return 1
    fi
    /usr/bin/virsh define ${VSM_VM_DIR}/${VSM_VM_XML}
    if [ "`sudo virsh list --all | awk '/shut off/{print $2}'`" != "$VSM_NAME" ]; then
        juju-log "start: unable to define vsm vm"
        return 1
    fi
}

function start_vsm_vm
{
    juju-log "Get vsm vm state"
    state="`sudo virsh dominfo $VSM_NAME | awk '/State:/' | cut -d: -f 2 | tr -d ' '`"
    case $state in
        running)   juju-log "vsm $VSM_NAME is already runnning
                   /usr/bin/virsh start ${VSM_NAME}"
                   ;;
        shut*)     juju-log "need to restart vsm $VSM_NAME"
                   /usr/bin/virsh start ${VSM_NAME}
                   ;;
        *)         juju-log "Unknown state($state) of vsm $VSM_NAME"
                   ;;
    esac
    return 0
}

export -f logger is_vsm_vm_running create_vsm_vm start_vsm_vm

<commit_msg>Remove unused common.sh<commit_after>#!/bin/bash

LOG_TERMINAL=0
export LOG_TERMINAL VSM_NAME VSM_ISO_DIR VSM_VM_DIR VSM_VM_XML

VSM_NAME=$(config-get n1kv-vsm-name)
VSM_ISO_DIR="/opt/cisco/iso"
VSM_VM_DIR="/var/spool/vsm"
VSM_VM_XML="vsm_vm.xml"


function logger
{
    if [ $LOG_TERMINAL -eq 1 ]; then
        echo $1
    else
        juju-log $1
    fi
}

# Returns 0 if VSM is not running
function is_vsm_vm_running
{
    local run=$(sudo virsh list --all | grep $VSM_NAME | awk '{print $NF}')
    if [ "$run" == "running" ]; then
        return 1
    else
        return 0
    fi
}

# It creates a persistent VSM VM if it was not created already
# Returns 1 if it was not able to create it
function create_vsm_vm
{
    juju-log "start: Check if $VSM_NAME vm already exists"

    if [ `/usr/bin/virsh list --all | grep -c $VSM_NAME` -eq 1 ]; then
        return 0
    fi

    juju-log "Define vsm vm"
    if [ ! -f ${VSM_VM_DIR}/${VSM_VM_XML} ]; then
        juju-log "Error: $VSM_NAME template doesn't exists"
        return 1
    fi
    /usr/bin/virsh define ${VSM_VM_DIR}/${VSM_VM_XML}
    if [ "`sudo virsh list --all | awk '/shut off/{print $2}'`" != "$VSM_NAME" ]; then
        juju-log "start: unable to define vsm vm"
        return 1
    fi
}

function start_vsm_vm
{
    juju-log "Get vsm vm state"
    state="`sudo virsh dominfo $VSM_NAME | awk '/State:/' | cut -d: -f 2 | tr -d ' '`"
    case $state in
        running)   juju-log "vsm $VSM_NAME is already runnning"
                   /usr/bin/virsh start ${VSM_NAME}
                   ;;
        shut*)     juju-log "need to restart vsm $VSM_NAME"
                   /usr/bin/virsh start ${VSM_NAME}
                   ;;
        *)         juju-log "Unknown state($state) of vsm $VSM_NAME"
                   ;;
    esac
    return 0
}

export -f logger is_vsm_vm_running create_vsm_vm start_vsm_vm


{'fraction_non_alphanumeric': 0.11447721179624665, 'fraction_numerical': 0.008579088471849867, 'mean_word_length': 2.161864406779661, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2805209', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1382, 'n_words': 398}