def _create_svc_vm_hosting_devices(self, context, num, template):
hosting_devices = []<EOL>template_id = template['<STR_LIT:id>']<EOL>credentials_id = template['<STR_LIT>']<EOL>plugging_drv = self.get_hosting_device_plugging_driver(context,<EOL>template_id)<EOL>hosting_device_drv = self.get_hosting_device_driver(context,<EOL>template_id)<EOL>if plugging_drv is None or hosting_device_drv is None or num <= <NUM_LIT:0>:<EOL><INDENT>return hosting_devices<EOL><DEDENT>max_hosted = <NUM_LIT:1>  <EOL>dev_data, mgmt_context = self._get_resources_properties_for_hd(<EOL>template, credentials_id)<EOL>credentials_info = self._credentials.get(credentials_id)<EOL>if credentials_info is None:<EOL><INDENT>LOG.error('<STR_LIT>'<EOL>'<STR_LIT>',<EOL>template_id)<EOL>return hosting_devices<EOL><DEDENT>connectivity_info = self._get_mgmt_connectivity_info(<EOL>context, self.mgmt_subnet_id())<EOL>for i in range(num):<EOL><INDENT>complementary_id = uuidutils.generate_uuid()<EOL>res = plugging_drv.create_hosting_device_resources(<EOL>context, complementary_id, self.l3_tenant_id(), mgmt_context,<EOL>max_hosted)<EOL>if res.get('<STR_LIT>') is None:<EOL><INDENT>return hosting_devices<EOL><DEDENT>connectivity_info['<STR_LIT>'] = res['<STR_LIT>']<EOL>vm_instance = self.svc_vm_mgr.dispatch_service_vm(<EOL>context, template['<STR_LIT:name>'] + '<STR_LIT>', template['<STR_LIT:image>'],<EOL>template['<STR_LIT>'], hosting_device_drv, credentials_info,<EOL>connectivity_info, res.get('<STR_LIT>'))<EOL>if vm_instance is not None:<EOL><INDENT>dev_data.update(<EOL>{'<STR_LIT:id>': vm_instance['<STR_LIT:id>'],<EOL>'<STR_LIT>': complementary_id,<EOL>'<STR_LIT>': res['<STR_LIT>'][<EOL>'<STR_LIT>'][<NUM_LIT:0>]['<STR_LIT>'],<EOL>'<STR_LIT>': res['<STR_LIT>']['<STR_LIT:id>']})<EOL>self.create_hosting_device(context,<EOL>{'<STR_LIT>': dev_data})<EOL>hosting_devices.append(vm_instance)<EOL><DEDENT>else:<EOL><INDENT>plugging_drv.delete_hosting_device_resources(<EOL>context, self.l3_tenant_id(), **res)<EOL>break<EOL><DEDENT><DEDENT>LOG.info('<STR_LIT>'<EOL>'<STR_LIT>', {'<STR_LIT>': len(hosting_devices),<EOL>'<STR_LIT>': template_id})<EOL>return hosting_devices<EOL>
Creates <num> or less service VM instances based on <template>.

        These hosting devices can be bound to a certain tenant or for shared
        use. A list with the created hosting device VMs is returned.