Skip to content

Commit

Permalink
modifié : add-nic.sh
Browse files Browse the repository at this point in the history
modifié :         deploy-image-by-profile.sh
  • Loading branch information
goffinet committed Mar 10, 2017
1 parent 78e0d3f commit df3b788
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
16 changes: 14 additions & 2 deletions add-nic.sh
Expand Up @@ -10,9 +10,10 @@ parameters=$#
check_parameters () {
# Check the numbers of parameters required
if [ "$parameters" -ne 2 ] ; then
echo "Description : This script add a new NIC on live guest to a bridged interface"
echo "Description : This script add a new NIC on live guest to an interface"
echo "Usage : $0 <guest name> <bridge_interface_name>"
echo "Example : $0 guest1 virbr0 attach the live guest1 NIC to virbr0"
echo "Example : '$0 guest1 virbr0' add the live guest1 NIC to virbr0"
echo "Example : '$0 guest1 eth0' add the live guest1 NIC to eth0"
exit
fi
# Check if the guest name chosen is in live and display help to choose
Expand Down Expand Up @@ -40,7 +41,18 @@ mac_param=" --mac $mac"
attach_nic () {
# Detach and attach the guest nic to the live guest
#virsh detach-interface $guest --type $type --source $bridge--live --persistent $mac_param
if egrep -q "eth|ens|em" <<< $bridge ; then
ip link set eth0 promisc on
cat << EOF > /tmp/direct-$guest.xml
<interface type='direct'>
<source dev='eth0' mode='bridge'/>
<model type='virtio'/>
</interface>
EOF
virsh attach-device $guest /tmp/direct-$guest.xml
else
virsh attach-interface $guest --type $type --source $bridge --model $model --live --persistent $mac_param
fi
virsh domiflist $guest
}

Expand Down
19 changes: 9 additions & 10 deletions deploy-image-by-profile.sh
@@ -1,8 +1,5 @@
#!/bin/bash
# This script define a centos7 guest by profile and network connection
# Image name : 'centos7', ...
imagename="debian7 debian8 centos7 ubuntu1604 metasploitable kali arch"
image="$4.qcow2"
image=$4
# Generate an unique string
uuid=$(uuidgen -t)
name=$1
Expand Down Expand Up @@ -49,28 +46,30 @@ case "$profile" in
big) vcpu="2"
memory="2048" ;;
desktop) ;;
*) usage_message ; exit ;;
esac
}

check_paramters () {
## Check parameters
if [ "$parameters" -eq 3 ] ; then image="centos7.qcow2" ; fi
if [ "$parameters" -eq 3 ] ; then image="centos7" ; fi
if [ "$parameters" -eq 4 ] ; then image=$image ; fi
if [ "$parameters" -gt 5 ] ; then usage_message ; exit ; fi
if [ "$parameters" -lt 3 ] ; then usage_message ; exit ; fi
#check a valid image name
if grep -qvw "$2" <<< "$imagename" ; then usage_message ; exit ; fi
if grep -qvw "$image" <<< "$imagename" ; then usage_message ; exit ; fi
# check the presence of the image
if [ ! -f /var/lib/libvirt/images/${image} ] ; then usage_message ; exit ; fi
if [ ! -f /var/lib/libvirt/images/${image}.qcow2 ] ; then usage_message ; exit ; fi
# Check the usage of the requested domain
if grep -qw ${name} <<< $(virsh list --all --name) ; then echo "Please provide an other guest name : exit" ; exit; fi
if grep -qw "$name" <<< $(virsh list --all --name) ; then echo "Please provide an other guest name : exit" ; exit; fi
# Check the network
if [ ! -e /run/libvirt/network/${network}.xml ] ; then echo "$network network does not exist"
echo "Please create a new one or choose a valid present network : " ; virsh net-list ; exit; fi
}

copy_image () {
## Local image copy to the default storage pool ##
cp /var/lib/libvirt/images/$image /var/lib/libvirt/images/$disk
cp /var/lib/libvirt/images/$image.qcow2 /var/lib/libvirt/images/$disk
## Add disk resizing
}

Expand Down Expand Up @@ -98,8 +97,8 @@ virt-install \
}

start_time="$(date -u +%s)"
profile_definition
check_paramters
profile_definition
copy_image
customize_new_disk
import_launch
Expand Down

0 comments on commit df3b788

Please sign in to comment.