We moved this page to our Documentation Portal. You can find the latest updates here. |
Issue
How to transfer a template between clouds?
We do recommend that you use an rsa key for access between the clouds. If you haven't made a key or added a key, please see this article.
Environment
OnApp 3.x, 4.x, 5.x
Resolution
1. Find the template on the origin cloud:
(you will need this article https://onapp.zendesk.com/entries/22073502-MySQL-How-to-access-the-MySQL-database-in-OnApp)
Example:
mysql> select * from templates where label='Ubuntu 12.04 x64'\G
*************************** 1. row ***************************
id: 20
label: Ubuntu 12.04 x64
created_at: 2013-07-30 06:13:11
updated_at: NULL
version: 1.8
file_name: ubuntu-12.04-x64-1.8-xen.kvm.kvm_virtio.tar.gz
operating_system: linux
operating_system_distro: ubuntu
allowed_swap: 1
state: active
checksum: be4880d2ec3217fb942700d6ee75b141
allow_resize_without_reboot: 0
min_disk_size: 19
user_id: NULL
template_size: 477240
allowed_hot_migrate: 1
operating_system_arch: x64
operating_system_edition: NULL
operating_system_tail: NULL
virtualization: xen,kvm,kvm_virtio
parent_template_id: NULL
min_memory_size: 512
disk_target_device: ---
xen: sda
kvm: hd
cdn: 0
backup_server_id: NULL
ext4: 1
initial_password: NULL
1 row in set (0.00 sec)
Now we see the file name:
file_name: ubuntu-12.04-x64-1.8-xen.kvm.kvm_virtio.tar.gz
2. Now exit the database, but remember the password from the article that was linked before. Run:
mysqldump -P `cat /onapp/interface/config/database.yml | grep port | head -1 | awk '{print $2}' | sed "s/'$//g;s/^'//g;s/\"$//g;s/^\"//g"` -h `cat /onapp/interface/config/database.yml | grep host | head -1 | awk '{print $2}' | sed "s/'$//g;s/^'//g;s/\"$//g;s/^\"//g"` -uroot -p`cat /onapp/interface/config/database.yml | grep password | head -1 | awk '{print $2}' | sed "s/'$//g;s/^'//g;s/\"$//g;s/^\"//g"` onapp templates --compact --no-create-info --complete-insert --where="id=TEMPLATE_ID"
It will ask you for a password (which is from before). This will dump the template information to a file in the /onapp directory.
The relevant information from this file is:
INSERT INTO `templates` VALUES (20,'Ubuntu 12.04 x64','2013-07-30 06:13:11',NULL,'1.8','ubuntu-12.04-x64-1.8-xen.kvm.kvm_virtio.tar.gz','linux','ubuntu',1,'active','be4880d2ec3217fb942700d6ee75b141',0,19,NULL,477240,1,'x64',NULL,NULL,'xen,kvm,kvm_virtio',NULL,512,'---\nxen: sda\nkvm: hd\n',0,NULL,1,NULL);
Note: Keep in mind though that we do have to change the template id, so we don't overwrite anything in the new cloud!
3. Now it's time to move the template:
scp -rpC /onapp/templates/ubuntu-12.04-x64-1.8-xen.kvm.kvm_virtio.tar.gz root@NEWCLOUD:/onapp/templates/
(replace NEWCLOUD with the ip of the cloud you want to move it to). It will ask for a password for the new cloud here.
If the control server does not have a nfs mount for templates, you will need to scp the template within the cloud to the backup server. The same command as above will work, just put in the backup server ip address.
4. Once the template is moved over, it's time to add the template into the database. (use the article from step 1). Remember that output from the step 2? It is a high time to make any changes you want, like add a single user for this template. (you could also try https://docs.onapp.com/display/MISC/Generate+template+SQL)
INSERT INTO `templates` VALUES (20,'Ubuntu 12.04 x64','2013-07-30 06:13:11',NULL,'1.8','ubuntu-12.04-x64-1.8-xen.kvm.kvm_virtio.tar.gz','linux','ubuntu',1,'active','be4880d2ec3217fb942700d6ee75b141',0,19,NULL,477240,1,'x64',NULL,NULL,'xen,kvm,kvm_virtio',NULL,512,'---\nxen: sda\nkvm: hd\n',0,NULL,1,NULL);
This is the important information:
label : Ubuntu 12.04 x64 version: 1.8 file_name : ubuntu-12.04-x64-1.8-xen.kvm.kvm_virtio.tar.gz operating_system : linux operating_system_distro : ubuntu allowed_swap : 1 state : active checksum : be4880d2ec3217fb942700d6ee75b141 allow_resize_without_reboot : 0 min_disk_size : 19 template_size : 477240 operating_system_arch : x64 operating_system_edition : NULL operating_system_tail : NULL allowed_hot_migrate : 1 virtualization : xen,kvm,kvm_virtio disk_target_device : '---\nxen: sda\nkvm: hd\n' min_memory_size : 512 ext4 : 1
We can take that and make an insert statement that won't overwrite anything. Start with a blank base:
INSERT INTO `templates` (label, created_at, version, file_name, operating_system, operating_system_distro, allowed_swap, state, checksum, allow_resize_without_reboot, min_disk_size, template_size, operating_system_arch, operating_system_edition, operating_system_tail, allowed_hot_migrate, virtualization, disk_target_device, min_memory_size, ext4) VALUES ();
and add the details from above:
INSERT INTO `templates` (label, created_at, version, file_name, operating_system, operating_system_distro, allowed_swap, state, checksum, allow_resize_without_reboot, min_disk_size, template_size, operating_system_arch, operating_system_edition, operating_system_tail, allowed_hot_migrate, virtualization, disk_target_device, min_memory_size, ext4) VALUES ('Ubuntu 12.04 x64', NOW(), '1.8', 'ubuntu-12.04-x64-1.8-xen.kvm.kvm_virtio.tar.gz', 'linux', 'ubuntu', 1, 'active', 'be4880d2ec3217fb942700d6ee75b141', 0, 19, '477240', 'x64', NULL, NULL, 1, 'xen,kvm,kvm_virtio', '---\nxen: sda\nkvm: hd\n', 512, 1);
If you want to add a user, all you have to do is add the user_id in the list and the id in the values like this:
INSERT INTO `templates` (label, created_at, version, file_name, operating_system, operating_system_distro, allowed_swap, state, checksum, allow_resize_without_reboot, min_disk_size, template_size, operating_system_arch, operating_system_edition, operating_system_tail, allowed_hot_migrate, virtualization, disk_target_device, min_memory_size, ext4, user_id) VALUES ('Ubuntu 12.04 x64', NOW(), '1.8', 'ubuntu-12.04-x64-1.8-xen.kvm.kvm_virtio.tar.gz', 'linux', 'ubuntu', 1, 'active', 'be4880d2ec3217fb942700d6ee75b141', 0, 19, '477240', 'x64', NULL, NULL, 1, 'xen,kvm,kvm_virtio', '---\nxen: sda\nkvm: hd\n', 512, 1, 21);
If the transfer process is completed, please remember to comment out the ssh key between the two clouds for security purposes.