<commit_before>#!/bin/bash

set -eu

# Copyright 2017-Present Pivotal Software, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function main() {

  local cwd
  cwd="${1}"

  export CURR_DIR=$(pwd)
  export OPSMGR_VERSION=$(cat ./pivnet-opsmgr/metadata.json | jq '.Release.Version' | sed -e 's/^"//' -e 's/"$//')
  export OPSMAN_NAME=OpsManager-${OPSMGR_VERSION}-$(date +"%Y%m%d%H%M%S")
  export OPSMAN_PATH=`ls $CURR_DIR/pivnet-opsmgr/*.{yml,yaml,ova} $CURR_DIR/pivnet-opsmgr/*_image 2>/dev/null | grep -v metadata.yaml`


IAAS_CONFIGURATION=$(cat <<-EOF
{
  "DiskProvisioning":"$OPSMAN_DISK_TYPE",
  "IPAllocationPolicy":"dhcpPolicy",
  "IPProtocol":"IPv4",
  "Name": "$OPSMAN_NAME",
  "NetworkMapping": [{
    "Name":"Network 1",
    "Network":"$OPSMAN_NETWORK"
  }],
  "PropertyMapping":[
    {"Key":"ip0","Value":"$OPSMAN_IP"},
    {"Key":"netmask0","Value":"$NETMASK"},
    {"Key":"gateway","Value":"$GATEWAY"},
    {"Key":"DNS","Value":"$DNS"},
    {"Key":"ntp_servers","Value":"$NTP"},
    {"Key":"admin_password","Value":"$OPSMAN_SSH_PASSWORD"}
  ],
  "PowerOn":false,
  "InjectOvfEnv":false,
  "WaitForIP":false
}
EOF
)
  echo $IAAS_CONFIGURATION > ./opsman_settings.json

  cat ./opsman_settings.json

  echo "Importing OVA of new OpsMgr VM..."
  echo "Running govc import.ova -options=opsman_settings.json -k=true ${OPSMAN_PATH}"
  govc import.ova -options=opsman_settings.json -k=true ${OPSMAN_PATH}
  #
  # echo "Setting CPUs on new OpsMgr VM... /${GOVC_DATACENTER}/${OPSMAN_VM_FOLDER}/${OPSMAN_NAME}"
  govc vm.change -c=2 -k=true -vm=${OPSMAN_NAME}
  #
  # echo "Shutting down OLD OpsMgr VM... ${OPSMAN_IP}"
  opsman_path="$(govc find -k=true ${GOVC_RESOURCE_POOL} -type m -guest.ipAddress ${OPSMAN_IP} -runtime.powerState poweredOn)"
  govc device.disconnect -k=true -vm.ipath=${opsman_path}
  govc vm.power -off=true -k=true -vm.ipath=${opsman_path}
  #
  # echo "Starting OpsMgr VM... /${GOVC_DATACENTER}/${OPSMAN_VM_FOLDER}/${OPSMAN_NAME}"
  govc vm.power -k=true -on=true ${OPSMAN_NAME}

  # make sure that vm and ops manager app is up
  started=false
  timeout=$((SECONDS+${OPSMAN_TIMEOUT}))
  set +e
  while ! $started; do
      OUTPUT=$(govc vm.info -vm.ipath=${GOVC_DATACENTER}/vm/${OPSMAN_NAME} -k=true 2>&1)

      if [[ $SECONDS -gt $timeout ]]; then
        echo "Timed out waiting for VM to start."
        exit 1
      fi
<commit_msg>Specify the device to disconnect<commit_after>#!/bin/bash

set -eu

# Copyright 2017-Present Pivotal Software, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#  http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function main() {

  local cwd
  cwd="${1}"

  export CURR_DIR=$(pwd)
  export OPSMGR_VERSION=$(cat ./pivnet-opsmgr/metadata.json | jq '.Release.Version' | sed -e 's/^"//' -e 's/"$//')
  export OPSMAN_NAME=OpsManager-${OPSMGR_VERSION}-$(date +"%Y%m%d%H%M%S")
  export OPSMAN_PATH=`ls $CURR_DIR/pivnet-opsmgr/*.{yml,yaml,ova} $CURR_DIR/pivnet-opsmgr/*_image 2>/dev/null | grep -v metadata.yaml`


IAAS_CONFIGURATION=$(cat <<-EOF
{
  "DiskProvisioning":"$OPSMAN_DISK_TYPE",
  "IPAllocationPolicy":"dhcpPolicy",
  "IPProtocol":"IPv4",
  "Name": "$OPSMAN_NAME",
  "NetworkMapping": [{
    "Name":"Network 1",
    "Network":"$OPSMAN_NETWORK"
  }],
  "PropertyMapping":[
    {"Key":"ip0","Value":"$OPSMAN_IP"},
    {"Key":"netmask0","Value":"$NETMASK"},
    {"Key":"gateway","Value":"$GATEWAY"},
    {"Key":"DNS","Value":"$DNS"},
    {"Key":"ntp_servers","Value":"$NTP"},
    {"Key":"admin_password","Value":"$OPSMAN_SSH_PASSWORD"}
  ],
  "PowerOn":false,
  "InjectOvfEnv":false,
  "WaitForIP":false
}
EOF
)
  echo $IAAS_CONFIGURATION > ./opsman_settings.json

  cat ./opsman_settings.json

  echo "Importing OVA of new OpsMgr VM..."
  echo "Running govc import.ova -options=opsman_settings.json -k=true ${OPSMAN_PATH}"
  govc import.ova -options=opsman_settings.json -k=true ${OPSMAN_PATH}
  #
  # echo "Setting CPUs on new OpsMgr VM... /${GOVC_DATACENTER}/${OPSMAN_VM_FOLDER}/${OPSMAN_NAME}"
  govc vm.change -c=2 -k=true -vm=${OPSMAN_NAME}
  #
  # echo "Shutting down OLD OpsMgr VM... ${OPSMAN_IP}"
  opsman_path="$(govc find -k=true ${GOVC_RESOURCE_POOL} -type m -guest.ipAddress ${OPSMAN_IP} -runtime.powerState poweredOn)"
  govc device.disconnect -k=true -vm.ipath=${opsman_path} ethernet-0
  govc vm.power -off=true -k=true -vm.ipath=${opsman_path}
  #
  # echo "Starting OpsMgr VM... /${GOVC_DATACENTER}/${OPSMAN_VM_FOLDER}/${OPSMAN_NAME}"
  govc vm.power -k=true -on=true ${OPSMAN_NAME}

  # make sure that vm and ops manager app is up
  started=false
  timeout=$((SECONDS+${OPSMAN_TIMEOUT}))
  set +e
  while ! $started; do
      OUTPUT=$(govc vm.info -vm.ipath=${GOVC_DATACENTER}/vm/${OPSMAN_NAME} -k=true 2>&1)

      if [[ $SECONDS -gt $timeout ]]; then
        echo "Timed out waiting for VM to start."
        exit 1
      fi

{'fraction_non_alphanumeric': 0.16592005513439007, 'fraction_numerical': 0.006374913852515506, 'mean_word_length': 4.272479564032698, 'pattern_counts': {'":': 46, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3843287', 'n_tokens_mistral': 2174, 'n_tokens_neox': 2149, 'n_words': 505}