[GH-ISSUE #53] Question about user management and instances #31

Open
opened 2026-02-27 15:57:04 +03:00 by kerem · 6 comments
Owner

Originally created by @tboulogne on GitHub (Sep 8, 2015).
Original GitHub issue: https://github.com/retspen/webvirtcloud/issues/53

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

Originally created by @tboulogne on GitHub (Sep 8, 2015). Original GitHub issue: https://github.com/retspen/webvirtcloud/issues/53 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
Author
Owner

@tboulogne commented on GitHub (Sep 15, 2015):

[find it]

Add a VM to a user account

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 !

<!-- gh-comment-id:140292292 --> @tboulogne commented on GitHub (Sep 15, 2015): [find it] ## Add a VM to a user account 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 !
Author
Owner

@fossxplorer commented on GitHub (Oct 16, 2015):

But doesn't webvirtcloud offer an API to do this? @tboulogne

<!-- gh-comment-id:148710264 --> @fossxplorer commented on GitHub (Oct 16, 2015): But doesn't webvirtcloud offer an API to do this? @tboulogne
Author
Owner

@tboulogne commented on GitHub (Oct 18, 2015):

@fossxplorer : did not find the way via api.

<!-- gh-comment-id:149039566 --> @tboulogne commented on GitHub (Oct 18, 2015): @fossxplorer : did not find the way via api.
Author
Owner

@romu70 commented on GitHub (Nov 27, 2015):

It helps, definitely, thanks Thierry.

<!-- gh-comment-id:160167674 --> @romu70 commented on GitHub (Nov 27, 2015): It helps, definitely, thanks Thierry.
Author
Owner

@tboulogne commented on GitHub (Nov 27, 2015):

@romu70 you're welcome :-)

<!-- gh-comment-id:160168142 --> @tboulogne commented on GitHub (Nov 27, 2015): @romu70 you're welcome :-)
Author
Owner

@romu70 commented on GitHub (Jan 15, 2016):

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.

<!-- gh-comment-id:171976703 --> @romu70 commented on GitHub (Jan 15, 2016): 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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/webvirtcloud#31
No description provided.