Add a simple wrapper script around vm lib to start a vm.

Change-Id: Ic3238b3063d0e889c424ff6a9792d9c0f6bebca1

BUG=
TEST=Ran it

Review URL: http://codereview.chromium.org/3628002
This commit is contained in:
Chris Sosa 2010-10-07 23:20:20 -07:00
parent 45c24df9a3
commit d76a917edb
2 changed files with 38 additions and 6 deletions

32
bin/cros_start_vm Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Simple wrapper scipt to start a vm using the vm lib.
. "$(dirname $0)/../common.sh"
. "$(dirname $0)/../lib/cros_vm_lib.sh"
. "$(dirname "$0")/../lib/cros_vm_constants.sh"
DEFINE_string image_path "" "Full path of the VM image"
set -e
# Parse command line.
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Use latest if not specified.
if [ -z "${FLAGS_image_path}" ]; then
LATEST_IMAGE="$(${SCRIPTS_DIR}/get_latest_image.sh)/${DEFAULT_QEMU_IMAGE}"
info "Using latest vm image ${LATEST_IMAGE}"
FLAGS_image_path=${LATEST_IMAGE}
fi
[ -e "${FLAGS_image_path}" ] || die "Image ${FLAGS_image_path} does not exist."
start_kvm "${FLAGS_image_path}"
echo "ssh root@${HOSTNAME} -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no"

View File

@ -28,15 +28,15 @@ function start_kvm() {
local pid=$(get_pid)
# Check if the process exists.
if ps -p ${pid} > /dev/null ; then
echo "Using a pre-created KVM instance specified by ${FLAGS_kvm_pid}."
echo "Using a pre-created KVM instance specified by ${FLAGS_kvm_pid}." >&2
else
# Let's be safe in case they specified a file that isn't a pid file.
echo "File ${KVM_PID_FILE} exists but specified pid doesn't."
echo "File ${KVM_PID_FILE} exists but specified pid doesn't." >&2
exit 1
fi
else
# No pid specified by PID file. Let's create a VM instance in this case.
echo "Starting a KVM instance"
echo "Starting a KVM instance" >&2
local nographics=""
local usesnapshot=""
if [ ${FLAGS_no_graphics} -eq ${FLAGS_TRUE} ]; then
@ -65,7 +65,7 @@ function start_kvm() {
function ssh_ping() {
"$(dirname $0)"/../ssh_test.sh \
--ssh_port=${FLAGS_ssh_port} \
--remote=127.0.0.1
--remote=127.0.0.1 >&2
}
# Tries to ssh into live image $1 times. After first failure, a try involves
@ -88,12 +88,12 @@ function retry_until_ssh() {
function stop_kvm() {
if [ "${FLAGS_persist}" -eq "${FLAGS_TRUE}" ]; then
echo "Persist requested. Use --ssh_port ${FLAGS_ssh_port} " \
"--kvm_pid ${KVM_PID_FILE} to re-connect to it."
"--kvm_pid ${KVM_PID_FILE} to re-connect to it." >&2
else
echo "Stopping the KVM instance" >&2
local pid=$(get_pid)
if [ -n "${pid}" ]; then
echo "Killing ${pid}"
echo "Killing ${pid}" >&2
sudo kill ${pid}
sudo rm "${KVM_PID_FILE}"
else