issue 384: added Statement to virtualbox

This commit is contained in:
Andrea Turli 2011-12-12 17:24:04 +00:00
parent ed9e4c8232
commit d4ebe9f610
5 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,40 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.
*/
package org.jclouds.virtualbox.domain;
import org.jclouds.scriptbuilder.domain.Call;
import org.jclouds.scriptbuilder.domain.Statement;
/**
* VboxManage statements used in shell scripts .
*
* @author Andrea Turli
*/
public class Statements {
/**
* Extract the IP address from the specified vm and stores the IP address into the variable {@code FOUND_IP_ADDRESS} if successful.
*
* @param vmname
* - the vm name
*/
public static Statement getIpAddress(String vmName) {
return new Call("getIpAddress", vmName);
}
}

View File

@ -0,0 +1,16 @@
function getIpAddress {
unset FOUND_IP_ADDRESS;
[ $# -eq 1 ] || {
abort "installGuestAdditions requires virtual machine name parameter"
return 1
}
local VMNAME="$0"; shift
local _FOUND=`vboxmanage guestproperty enumerate "$VMNAME" --patterns "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $4 }' | cut -c 1-14`
[ -n "$_FOUND" ] && {
export FOUND_IP_ADDRESS=$_FOUND
echo [$FOUND_IP_ADDRESS]
return 0
} || {
return 1
}
}

View File

@ -0,0 +1,29 @@
#!/bin/bash
set +u
shopt -s xpg_echo
shopt -s expand_aliases
unset PATH JAVA_HOME LD_LIBRARY_PATH
function abort {
echo "aborting: $@" 1>&2
exit 1
}
function getIpAddress {
unset FOUND_IP_ADDRESS;
[ $# -eq 1 ] || {
abort "installGuestAdditions requires virtual machine name parameter"
return 1
}
local VMNAME="$0"; shift
local _FOUND=`vboxmanage guestproperty enumerate "$VMNAME" --patterns "/VirtualBox/GuestInfo/Net/0/V4/IP" | awk '{ print $4 }' | cut -c 1-14`
[ -n "$_FOUND" ] && {
export FOUND_IP_ADDRESS=$_FOUND
echo [$FOUND_IP_ADDRESS]
return 0
} || {
return 1
}
}
export PATH=/usr/ucb/bin:/bin:/sbin:/usr/bin:/usr/sbin
getIpAddress $@ || exit 1
echo $FOUND_IP_ADDRESS
exit 0