Merge branch 'create_template' into opennebula_api
This commit is contained in:
		
				commit
				
					
						d36a83c8ac
					
				
			
		
					 2 changed files with 42 additions and 4 deletions
				
			
		|  | @ -67,12 +67,12 @@ class OpenNebulaManager(): | ||||||
|         except WrongNameError as wrong_name_err: |         except WrongNameError as wrong_name_err: | ||||||
|             opennebula_user = self.oneadmin_client.call(oca.User.METHODS['allocate'], email, |             opennebula_user = self.oneadmin_client.call(oca.User.METHODS['allocate'], email, | ||||||
|                                                         password, 'core') |                                                         password, 'core') | ||||||
|  |             return opennebula_user | ||||||
|         except ConnectionRefusedError: |         except ConnectionRefusedError: | ||||||
|             print('Could not connect to host: {host} via protocol {protocol}'.format( |             print('Could not connect to host: {host} via protocol {protocol}'.format( | ||||||
|                     host=settings.OPENNEBULA_DOMAIN, |                     host=settings.OPENNEBULA_DOMAIN, | ||||||
|                     protocol=settings.OPENNEBULA_PROTOCOL) |                     protocol=settings.OPENNEBULA_PROTOCOL) | ||||||
|                 ) |                 ) | ||||||
|             return opennebula_user |  | ||||||
|     def _get_user_pool(self): |     def _get_user_pool(self): | ||||||
|         try: |         try: | ||||||
|             user_pool = oca.UserPool(self.oneadmin_client) |             user_pool = oca.UserPool(self.oneadmin_client) | ||||||
|  | @ -99,3 +99,35 @@ class OpenNebulaManager(): | ||||||
|         ) |         ) | ||||||
|         return vm_id |         return vm_id | ||||||
| 
 | 
 | ||||||
|  |     def create_template(self, name, cores, memory, disk_size): | ||||||
|  |         """Create and add a new template to opennebula. | ||||||
|  |         :param name:      A string representation describing the template. | ||||||
|  |                           Used as label in view. | ||||||
|  |         :param cores:     Amount of virtual cpu cores for the VM. | ||||||
|  |         :param memory:    Amount of RAM for the VM (MB) | ||||||
|  |         :param disk_size: Amount of disk space for VM (MB) | ||||||
|  |         """ | ||||||
|  |         template_string_formatter = """<TEMPLATE> | ||||||
|  |                                         <NAME>{name}</NAME> | ||||||
|  |                                         <MEMORY>{memory}</MEMORY> | ||||||
|  |                                         <VCPU>{vcpu}</VCPU> | ||||||
|  |                                         <CPU>{cpu}</CPU> | ||||||
|  |                                         <DISK> | ||||||
|  |                                          <TYPE>fs</TYPE> | ||||||
|  |                                          <SIZE>{size}</SIZE> | ||||||
|  |                                          <DEV_PREFIX>vd</DEV_PREFIX> | ||||||
|  |                                         </DISK> | ||||||
|  |                                        </TEMPLATE> | ||||||
|  |                                        """ | ||||||
|  |         template_id = oca.VmTemplate.allocate( | ||||||
|  |             self.oneadmin_client, | ||||||
|  |             template_string_formatter.format( | ||||||
|  |                 name=name, | ||||||
|  |                 vcpu=cores, | ||||||
|  |                 cpu=0.1*cores, | ||||||
|  |                 size=1024 * disk_size, | ||||||
|  |                 memory=1024 * memory | ||||||
|  |             ) | ||||||
|  |         ) | ||||||
|  | 
 | ||||||
|  |         return template_id | ||||||
|  |  | ||||||
|  | @ -18,7 +18,11 @@ class OpenNebulaManagerTestCases(TestCase): | ||||||
| 
 | 
 | ||||||
|     def test_model_can_connect_to_server(self): |     def test_model_can_connect_to_server(self): | ||||||
|         """Test the opennebula manager model can connect to a server.""" |         """Test the opennebula manager model can connect to a server.""" | ||||||
|         self.assertFalse(self.manager is None) |         try: | ||||||
|  |             version = self.manager.version() | ||||||
|  |         except: | ||||||
|  |             version = None | ||||||
|  |         self.assertFalse(version is None) | ||||||
| 
 | 
 | ||||||
|     def test_model_can_create_user(self): |     def test_model_can_create_user(self): | ||||||
|         """Test the opennebula manager model can create a new user.""" |         """Test the opennebula manager model can create a new user.""" | ||||||
|  | @ -46,8 +50,10 @@ class VirtualMachineTemplateTestCase(TestCase): | ||||||
|         self.disk_size = 10.0 |         self.disk_size = 10.0 | ||||||
| 
 | 
 | ||||||
|         self.manager = OpenNebulaManager(email=None, password=None, create_user=False) |         self.manager = OpenNebulaManager(email=None, password=None, create_user=False) | ||||||
|         self.opennebula_id = self.manager.create_template(self.cores, self.memory, |         self.opennebula_id = self.manager.create_template(name=self.template_name, | ||||||
|                                                           self.disk_size) |                                                           cores=self.cores, | ||||||
|  |                                                           memory=self.memory, | ||||||
|  |                                                           disk_size=self.disk_size) | ||||||
| 
 | 
 | ||||||
|         self.template = VirtualMachineTemplate(opennebula_id=self.opennebula_id, |         self.template = VirtualMachineTemplate(opennebula_id=self.opennebula_id, | ||||||
|                                                base_price=self.base_price, |                                                base_price=self.base_price, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue