def __init__(self, *args, **kwargs): super(ApplyTemplateForm, self).__init__(*args, **kwargs) try: template_id = self.request.path_info.split('/')[-1] template_db = network_template_api.get_template_by_id(template_id) if not template_db: raise Exception(_("Could not find a template with that ID.")) if network_template_api.get_tenant_stack_assignment( self.request.user.tenant_id): raise Exception( _("This tenant already has a deployed template.")) if template_db: template = network_template_api.extract_fields_from_body( self.request, template_db.body) except Exception as e: msg = _( "Failed preparing template. You may not have permissions to " "use Heat templates.") exceptions.handle(self.request, msg, redirect=reverse(self.failure_url)) # Sorts the parameters in the template. parameters = template['Parameters'].keys() parameters.sort() parameters.reverse() # Populates the form dynamically with information from the template. for parameter in parameters: self.fields[parameter] = forms.CharField( max_length="255", label=template['Parameters'][parameter]['Label'], initial=findDefault(template['Parameters'][parameter], 'Default'), help_text=template['Parameters'][parameter]['Description'], required=True)
def __init__(self, *args, **kwargs): super(ApplyTemplateForm, self).__init__(*args, **kwargs) try: template_id = self.request.path_info.split('/')[-1] template_db = network_template_api.get_template_by_id(template_id) if not template_db: raise Exception(_("Could not find a template with that ID.")) if network_template_api.get_tenant_stack_assignment( self.request.user.tenant_id): raise Exception(_("This tenant already has a deployed template.")) if template_db: template = network_template_api.extract_fields_from_body( self.request, template_db.body) except Exception as e: msg = _("Failed preparing template. You may not have permissions to " "use Heat templates.") exceptions.handle(self.request, msg, redirect=reverse(self.failure_url)) # Sorts the parameters in the template. parameters = template['Parameters'].keys() parameters.sort() parameters.reverse() # Populates the form dynamically with information from the template. for parameter in parameters: self.fields[parameter] = forms.CharField( max_length="255", label=template['Parameters'][parameter]['Label'], initial=findDefault(template['Parameters'][parameter], 'Default'), help_text=template['Parameters'][parameter]['Description'], required=True )
def handle(self, request, data): try: template_id = self.request.path_info.split('/')[-1] template_db = network_template_api.get_template_by_id(template_id) if not template_db: raise Exception(_("Could not find a template with that ID.")) if template_db: template = network_template_api.extract_fields_from_body( self.request, template_db.body) hresource = network_template_api.deploy_instance( self.request, template_db.id, data) except: msg = _("Error loading template") exceptions.handle(self.request, msg, redirect=self.failure_url) return True