How to move a instance between projects?
That's it, How I can move a instance to a specific project? I am using havana release
Thanks!
First time here? Check out the FAQ!
Each project is considered as a tenant and VMs launched will be specific to that tenant. AFAIK you cannot directly move VMs between tenants but you can migrate from one compute node to other compute node within same tenant or public snapshot it and launch wherever you want within same Openstack Controller managed projects.
There is always a way to get things done :-) what I would do is first take a snapshot of the VM you want to move to a new project, then either share it with the project or make it public in the system. Now go to the new project and just re-launch the snapshot you took in the old project and you now will have a new VM (clone of the old) in the new project. There a command line feature to just share from one project to the next "can_share". Below is a example of the command.
$ glance member-create --can-share Image-ID Project-ID
$ glance member-create --can-share 66ee4474-bace-475b-99f3-09f809060742 feb0ea0cdbe84f0abd8cac80a357b72f
This should do the job.
If you wanted to move to a new Availability Zone (Different controller managed projects) you could do almost the same, take a snapshot of the VM, then use the Glance command to download it, then use Glance again to upload it to the new Availability Zone into the right project.
Agree, but it is a way to get the job done today.
http://docs.openstack.org/user-guide/...
I have a kind of tweeky script that could move VMs between projects and update quotas of the project according to the actual servers in the project because moving the VMs will not update the quotas of the project both in source and destination project.
I don't have karma to upload file so pasting here
vm_move.sh - used to move VM to another project
usage: ./vm_move.sh "destination_tenant_id" "VM-1_id" "VM-2_id" ..... "VM-x_id"
#!/bin/bash
for i
do
if [ "$i" != "$1" ]; then
echo "moving instance id " $i " to project id" $1;
mysql -uroot -pxxxx -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 -pxxxx -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 -pxxxx -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;
quota_resync.sh
usage: ./quota_resync.sh "project_id" "user_id"
#!/bin/bash
count=$(mysql -uroot -pxxxx -s -N <<query
use nova;
select count(*) from instances where project_id="$1" and vm_state="active";
query
)
memory=$(mysql -uroot -pxxxx -s -N <<query
use nova;
select sum(memory_mb) from instances where project_id="$1" and vm_state="active";
query
)
vcpu=$(mysql -uroot -pxxxx -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 -pxxxx -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
)
Note: both the above scripts must be in same folder and should be in controller node
also do not forget networking part, you can share network with: neutron help | grep rbac
Just change the project association in the nova db.
mysql> use keystone
mysql> select id, name, enabled from project\G
*************************** 1. row ***************************
id: 111xxxxxxxxxxxxxxxxxxxxxxxxxxxxxa
name: project 1
enabled: 1
*************************** 2. row ***************************
id: 222xxxxxxxxxxxxxxxxxxxxxxxxxxxxxb
name: project 2
enabled: 1
mysql> use nova;
mysql> select project_id, reservation_id, display_name from instances where project_id = '111xxxxxxxxxxxxxxxxxxxxxxxxxxxxxa';
*************************** 1. row ***************************
project_id: 111xxxxxxxxxxxxxxxxxxxxxxxxxxxxxa
reservation_id: r-sasdf12p
display_name: instance1
mysql> update instances set project_id = '222xxxxxxxxxxxxxxxxxxxxxxxxxxxxxb' where reservation_id = 'r-sasdf12p';
We just ran this and it worked as well as it was easy.
Cheers.
This solution is too dangerous and as @Pablolibo said, it works when all VM specs are common, like security group, network and etc.
Asked: 2014-04-24 15:56:48 -0600
Seen: 26,501 times
Last updated: May 19 '14
Can you please elaborate, whether you need to move instance from demo project to admin project or specific user project and vice versa.