How to Migrate OpenStack Instance from one Tenant to another

asked 2020-02-12 04:34:46 -0500

linuxtechi gravatar image

Hi Folks,

I am using Mitaka OpenStack and VLAN as network type driver for tenant VMs. Initially i have provisioned all the VMs (Including Customer VMs) inside the admin. I want to segregate my internal VMs and Customer VMs, for this to accomplish i have created different tenant names and now i want customer VMs from admin tenant to Customer tenant,

On Google , i have a found a script which migrates the VMs but that script doesn't update network and security group details,

Can anyone help me and suggest what steps needs to executed to update network , security group and attached Volumes ..?

Below is the exact script:

#!/bin/bash
for i
do
if [ "$i" != "$1" ]; then
echo "moving instance id " $i " to project id" $1;
mysql -uroot -s -N <<query
use nova;
update instances set project_id="$1" where uuid="$i";
query
else
#get project id of the instance before update
old_proj_id=$(mysql -uroot -s -N <<query
use nova;
select project_id from instances where uuid="$2";
query
)
#get user id of the instance before update
user_id=$(mysql -uroot -s -N <<query
use nova;
select user_id from instances where uuid="$2";
query
)

fi
done
echo "quota_resync " $old_proj_id;
./quota_resync.sh $old_proj_id $user_id;
echo "quota_resync " $1;
./quota_resync.sh $1 $user_id;
root@xxxx:/mnt# cat quota_resync.sh
#!/bin/bash
count=$(mysql -uroot -s -N <<query
use nova;
select count(*) from instances where project_id="$1" and vm_state="active";
query
)

memory=$(mysql -uroot -s -N <<query
use nova;
select sum(memory_mb) from instances where project_id="$1" and vm_state="active";
query
)

vcpu=$(mysql -uroot -s -N <<query
use nova;
select sum(vcpus) from instances where project_id="$1" and vm_state="active";
query
)

echo "count" $count;
echo "vcpus" $vcpu;
echo "Ram" $memory;

update=$(mysql -uroot -s -N <<query
use nova;
update quota_usages set in_use=$count where project_id="$1" and user_id="$2" and resource="instances";
update quota_usages set in_use=$memory where project_id="$1" and user_id="$2" and resource="ram";
update quota_usages set in_use=$vcpu where project_id="$1" and user_id="$2" and resource="cores";
query
)
root@xxxx:/mnt#

Script Execution Method : # /vm_move.sh "destination_tenant_id" "VM_id"

edit retag flag offensive close merge delete