From b62819ae79cbc4089ba8747df4847157cecf2dac Mon Sep 17 00:00:00 2001 From: Modulos Date: Wed, 10 May 2017 01:31:27 +0200 Subject: [PATCH] Add create vm function --- opennebula_api/models.py | 16 ++++++++++++++++ opennebula_api/tests.py | 1 + 2 files changed, 17 insertions(+) diff --git a/opennebula_api/models.py b/opennebula_api/models.py index 21151dc8..c93e4f9d 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -83,3 +83,19 @@ class OpenNebulaManager(): protocol=settings.OPENNEBULA_PROTOCOL) ) return user_pool + + def create_virtualmachine(self, template_id): + template_pool = oca.VmTemplatePool(self.oneadmin_client) + template_pool.info() + + template = template_pool.get_by_id(template_id) + + vm_id = template.instantiate() + self.oneadmin.call( + oca.VirtualMachine.METHODS['chown'], + vm_id, + self.opennebula_user.id, + self.opennebula_user.group_ids[0] + ) + return vm_id + diff --git a/opennebula_api/tests.py b/opennebula_api/tests.py index 95d9d08d..6852fd1b 100644 --- a/opennebula_api/tests.py +++ b/opennebula_api/tests.py @@ -84,6 +84,7 @@ class VirtualMachineTestCase(TestCase): def test_model_can_delete_a_virtualmachine(self): """Test the virtualmachine model can delete a virtualmachine.""" + self.virtualmachine.save() old_count = VirtualMachine.objects.count() VirtualMachine.objects.first().delete() new_count = VirtualMachine.objects.count()