예제 #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)
예제 #2
0
파일: forms.py 프로젝트: bigswitch/horizon
    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
            )
예제 #3
0
 def __init__(self, request, *args, **kwargs):
     tid = request.path_info.split('/')[-1]
     template = network_template_api.get_template_by_id(tid)
     super(DetailNetworkTemplate, self).__init__(request, *args, **kwargs)
     if template:
         self.fields['existing_id'].initial = tid
         self.fields['name'].initial = template.template_name
         self.fields['body'].initial = template.body
예제 #4
0
파일: tabs.py 프로젝트: bigswitch/horizon
 def __init__(self, request, *args, **kwargs):
     tid = request.path_info.split('/')[-1]
     template = network_template_api.get_template_by_id(tid)
     super(DetailNetworkTemplate, self).__init__(request, *args, **kwargs)
     if template:
         self.fields['existing_id'].initial = tid
         self.fields['name'].initial = template.template_name
         self.fields['body'].initial = template.body
예제 #5
0
 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
예제 #6
0
파일: forms.py 프로젝트: bigswitch/horizon
 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
예제 #7
0
파일: tabs.py 프로젝트: bigswitch/horizon
 def handle(self, request, data):
     template = network_template_api.get_template_by_id(data['existing_id'])
     try:
         if template:
             network_template_api.update_template_by_id(
                 data['existing_id'], data['name'], data['body'])
         else:
             network_template_api.create_network_template(
                 data['name'], data['body'])
     except:
         messages.error(
             request, _("Unable to create template. "
                        "Verify that the name is unique."))
         return False
     messages.success(request, _("Template saved."))
     return True
예제 #8
0
 def handle(self, request, data):
     template = network_template_api.get_template_by_id(data['existing_id'])
     try:
         if template:
             network_template_api.update_template_by_id(
                 data['existing_id'], data['name'], data['body'])
         else:
             network_template_api.create_network_template(
                 data['name'], data['body'])
     except:
         messages.error(
             request,
             _("Unable to create template. "
               "Verify that the name is unique."))
         return False
     messages.success(request, _("Template saved."))
     return True
예제 #9
0
    def clean(self):
        cleaned_data = super(SelectTemplateForm, self).clean()

        def update_cleaned_data(key, value):
            cleaned_data[key] = value
            self.errors.pop(key, None)

        network_template = cleaned_data.get('network_templates')

        if network_template == 'default':
            msg = _('A template must be selected.')
            raise ValidationError(msg)
        record = network_template_api.get_template_by_id(network_template)
        if not record:
            msg = _('A template must be selected.')
            raise ValidationError(msg)
        return cleaned_data
예제 #10
0
파일: forms.py 프로젝트: bigswitch/horizon
    def clean(self):
        cleaned_data = super(SelectTemplateForm, self).clean()

        def update_cleaned_data(key, value):
            cleaned_data[key] = value
            self.errors.pop(key, None)

        network_template = cleaned_data.get('network_templates')

        if network_template == 'default':
            msg = _('A template must be selected.')
            raise ValidationError(msg)
        record = network_template_api.get_template_by_id(network_template)
        if not record:
            msg = _('A template must be selected.')
            raise ValidationError(msg)
        return cleaned_data