Transfer Templates Between Clouds
Issue
How to transfer a template between clouds?
We recommend using an RSA key for access between the clouds. If you haven't made or added a key, refer to the Generate and Add SSH Key page.
Environment
OnApp 3.x, 4.x, 5.x, 6.x
Resolution
Find the template in the origin cloud (refer to the MySQL Database in OnApp page):
Examplemysql> 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)
CODENow the file name is provided:
file_name: ubuntu-12.04-x64-1.8-xen.kvm.kvm_virtio.tar.gz
CODEExit the database, but remember the password. 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"
CODEYou will be asked for a password. This will dump the template information to a file in the
/onapp
directory.The relevant information from this file is as follows:
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);
CODEPlease note that the template ID should be changed. Do not overwrite anything in the new cloud.
Move the template and replace
NEWCLOUD
with the IP of the cloud you want to move it to. You will be asked for a password for the new cloud:scp -rpC /onapp/templates/ubuntu-12.04-x64-1.8-xen.kvm.kvm_virtio.tar.gz root@NEWCLOUD:/onapp/templates/
CODEIf the Control Panel server does not have an NFS mount for templates, you will need to scp the template within the cloud to the backup server. Use the above command and put the IP address in the backup server.
Once the template is moved, add the template to the database (refer to the MySQL Database in OnApp and Generate Template SQL pages ):
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);
CODEImportant 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
CODEUse it and make an insert statement that will not 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 ();
CODEand 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);
CODETo add a user, add
user_id
in the list and the ID value: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);
CODE
When the transfer process is completed, comment out the SSH key between the two clouds for security purposes.