def setUp(self): # Cluster cluster = Cluster(hostname='test.cluster.gwm', slug='test', username='******', password='******') # cluster.info = INFO cluster.save() # Template template_data = dict( template_name='new.vm.template', description='A new template.', cluster=cluster.id, start=True, name_check=True, disk_template='plain', disk_count=0, memory=256, vcpus=2, root_path='/', kernel_path='', cdrom_image_path='', serial_console=False, nic_type='paravirtual', disk_type='paravirtual', nic_count=0, boot_order='disk', os='image+ubuntu-lucid', ) data = template_data.copy() data['cluster'] = cluster del data['disk_count'] del data['nic_count'] template = VirtualMachineTemplate(**data) template.save() # Template Fields fields = vars(template).keys() # Users self.create_users([ ('superuser', { 'is_superuser': True }), 'cluster_admin', ]) self.cluster_admin.grant('admin', cluster) self.users = [self.superuser, self.cluster_admin] self.template = template self.cluster = cluster self.template_data = template_data self.template_fields = fields
def setUp(self): # Cluster cluster = Cluster(hostname='test.cluster.gwm', slug='test', username='******', password='******') # cluster.info = INFO cluster.save() # Template template_data = dict( template_name='new.vm.template', description='A new template.', cluster=cluster.id, start=True, name_check=True, disk_template='plain', disk_count=0, memory=256, vcpus=2, root_path='/', kernel_path='', cdrom_image_path='', serial_console=False, nic_type='paravirtual', disk_type='paravirtual', nic_count=0, boot_order='disk', os='image+ubuntu-lucid', ) data = template_data.copy() data['cluster'] = cluster del data['disk_count'] del data['nic_count'] template = VirtualMachineTemplate(**data) template.save() # Template Fields fields = vars(template).keys() # Users self.create_users([ ('superuser', {'is_superuser': True}), 'cluster_admin', ]) self.cluster_admin.grant('admin', cluster) self.users = [self.superuser, self.cluster_admin] self.template = template self.cluster = cluster self.template_data = template_data self.template_fields = fields
def instance_to_template(vm, name): """ Create, save, and return a VM template representing all of the information in the VM instance. The name is given to the template to distinguish it from other templates. """ template = VirtualMachineTemplate() # Basic stuff first. template.template_name = name template.description = "" template.cluster = vm.cluster template.start = vm.info["admin_state"] template.disk_template = vm.info["disk_template"] template.os = vm.operating_system # Backend parameters. template.vcpus = vm.virtual_cpus template.memory = vm.ram if has_balloonmem(vm.cluster): template.minmem = vm.minram template.disks = [{"size": size} for size in vm.info["disk.sizes"]] template.disk_type = vm.info["hvparams"]["disk_type"] template.nics = [{ "mode": mode, "link": link } for mode, link in zip(vm.info["nic.modes"], vm.info["nic.links"])] template.nic_type = vm.info["hvparams"]["nic_type"] # Hypervisor parameters. template.kernel_path = vm.info["hvparams"]["kernel_path"] template.root_path = vm.info["hvparams"]["root_path"] template.serial_console = vm.info["hvparams"]["serial_console"] template.boot_order = vm.info["hvparams"]["boot_order"] template.cdrom_image_path = vm.info["hvparams"]["cdrom_image_path"] template.cdrom2_image_path = vm.info["hvparams"]["cdrom2_image_path"] template.save() return template
def test_vm_template_set_name_temporary(self): template = VirtualMachineTemplate() template.set_name("") self.assertEqual(template.temporary, True)
def test_vm_template_set_name_named(self): template = VirtualMachineTemplate() template.set_name("testing") self.assertEqual(template.template_name, "testing")
def instance_to_template(vm, name): """ Create, save, and return a VM template representing all of the information in the VM instance. The name is given to the template to distinguish it from other templates. """ template = VirtualMachineTemplate() # Basic stuff first. template.template_name = name template.description = "" template.cluster = vm.cluster template.start = vm.info["admin_state"] template.disk_template = vm.info["disk_template"] template.os = vm.operating_system # Backend parameters. template.vcpus = vm.virtual_cpus template.memory = vm.ram if has_balloonmem(vm.cluster): template.minmem = vm.minram template.disks = [{"size": size} for size in vm.info["disk.sizes"]] template.disk_type = vm.info["hvparams"]["disk_type"] template.nics = [{"mode": mode, "link": link} for mode, link in zip(vm.info["nic.modes"], vm.info["nic.links"])] template.nic_type = vm.info["hvparams"]["nic_type"] # Hypervisor parameters. template.kernel_path = vm.info["hvparams"]["kernel_path"] template.root_path = vm.info["hvparams"]["root_path"] template.serial_console = vm.info["hvparams"]["serial_console"] template.boot_order = vm.info["hvparams"]["boot_order"] template.cdrom_image_path = vm.info["hvparams"]["cdrom_image_path"] template.cdrom2_image_path = vm.info["hvparams"]["cdrom2_image_path"] template.save() return template