How to Migrate OpenStack Instance from one Tenant to another
Pradeep Antil
pradeepantil at gmail.com
Wed Feb 12 10:36:33 UTC 2020
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 at 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 at xxxx:/mnt#
Script Execution Method : # /vm_move.sh "destination_tenant_id" "VM_id"
--
Best Regards
Pradeep Kumar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-discuss/attachments/20200212/3b2076bd/attachment.html>
More information about the openstack-discuss
mailing list