Open tboulogne opened 9 years ago
[find it]
1/ open sqlite database :
sqlite3 db.sqlite3
and make and insert
INSERT INTO accounts_userinstance VALUES (1,0,0,42,13);
1 => id 0 => right to resize 0 => right to delete 42 => instance id 13 => user id
Hope it could help !
But doesn't webvirtcloud offer an API to do this? @tboulogne
@fossxplorer : did not find the way via api.
It helps, definitely, thanks Thierry.
@romu70 you're welcome :-)
Hi, just made a script to assign a VM to a user.
#!/bin/bash
# Run this script to affect an already known VM to an already existing user, because this feature doesn't existing
# yet in WebVirtCloud (as time of writing 2015-12-15).
# Run this script as SUDO because it has to move the database file and to restart some services
# Usage: "sudo ./assign.sh <VM> <USER>"
# Where:
# VM is the virtual machine label as it appears in WebVirtCloud
# USER is the user login WebVirtCloud
echo "### VM assignement script is starting ###"
vm=$1
user=$2
if [ "$vm" == "" ];then
echo "ERROR - Some inputs are missing."
echo "Usage: sudo ./assign-vm.sh vm user"
exit 1
fi
if [ "$user" == "" ];then
echo "ERROR - Some inputs are missing."
echo "Usage: sudo ./assign-vm.sh vm user"
exit 1
fi
# Cleanup previous databases
rm ./db.sqlite3.backup
# Copy & Backup the DB
cp /srv/webvirtcloud/db.sqlite3 .
cp ./db.sqlite3 ./db.sqlite3.backup
# Get the VM ID
temp=$(sqlite3 db.sqlite3 "SELECT * FROM instances_instance;" | grep $vm)
idvm=$(echo $temp | awk -F'|' '{print $1}')
if [ "$idvm" == "" ];then
echo "ERROR - VM $vm not found"
exit 1
fi
# Get the User ID
temp=$(sqlite3 db.sqlite3 "SELECT * FROM auth_user;" | grep $user)
iduser=$(echo $temp | awk -F'|' '{print $1}')
if [ "$iduser" == "" ];then
echo "ERROR - User $user not found"
exit 1
fi
# Build the SQL request to add the new association, according to this issue:
# https://github.com/retspen/webvirtcloud/issues/53
# The format of the association table is:
# 1 => association id
# 0 => right to resize the VM
# 0 => right to delete the VM
# 42 => VM id
# 13 => User id
# Create a new association id based on the current table number of records
nb=$(sqlite3 db.sqlite3 "SELECT count( * ) FROM accounts_userinstance;")
nb=`expr $nb + 1`
# Add the association to the database
request=$(printf "INSERT INTO accounts_userinstance VALUES (%u,0,0,%u,%u);" "$nb" "$idvm" "$iduser")
sqlite3 db.sqlite3 "$request"
# Replace the modified database
rm /srv/webvirtcloud/db.sqlite3
mv db.sqlite3 /srv/webvirtcloud/
# Restart services
service nginx restart
service supervisor restart
echo "### VM assignement done, enjoy! ###"
The management of the association id is not the best possible, but I didn't find any other solution. Any better solution would be appreciated.
Hello,
2 questions:
Users
How could i change owner of a VM . I get existing customer VM, and i'd like to delegate to customer the VM.
instances
How could i have automatically live instances group on top of list, and stop instances on bottom ?
Thanks for help.
Regards