Esempio n. 1
0
    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)
Esempio n. 2
0
    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
            )
Esempio n. 3
0
 def allowed(self, request, datum):
     tid = request.user.tenant_id
     return (False if network_template_api.get_tenant_stack_assignment(tid)
             else True)
Esempio n. 4
0
 def allowed(self, request, datum):
     tid = request.user.tenant_id
     return (False if network_template_api.get_tenant_stack_assignment(tid)
             else True)