コード例 #1
0
    def __init__(self, *args, **kwargs):
        try:
            request = args[0]
            template_string = ""

            if "template_upload" in kwargs:
                template_string = kwargs.pop("template_upload")
                super(ImportClusterTemplateNodegroupsForm, self).__init__(
                    *args, **kwargs)

                self.fields["template_upload"].initial = template_string

            else:
                super(ImportClusterTemplateNodegroupsForm, self).__init__(
                    *args, **kwargs)
                template_string = self.data["template_upload"]

            template_json = json.loads(template_string)
            template_json = template_json["cluster_template"]

            req = request.GET.copy()
            req.update(request.POST)

            plugin = template_json["plugin_name"]
            version = (template_json.get("hadoop_version", None) or
                       template_json["plugin_version"])

            if not plugin or not version:
                self.templates = saharaclient.nodegroup_template_find(request)
            else:
                self.templates = saharaclient.nodegroup_template_find(
                    request, plugin_name=plugin, hadoop_version=version)

            deletable = req.get("deletable", dict())

            if "forms_ids" in req:
                self.groups = []
                for id in json.loads(req["forms_ids"]):
                    group_name = "group_name_" + str(id)
                    template_id = "template_id_" + str(id)
                    count = "count_" + str(id)
                    serialized = "serialized_" + str(id)
                    self.groups.append({"name": req[group_name],
                                        "template_id": req[template_id],
                                        "count": req[count],
                                        "id": id,
                                        "deletable": deletable.get(
                                            req[group_name], "true"),
                                        "serialized": req[serialized]})

                    whelpers.build_node_group_fields(self,
                                                     group_name,
                                                     template_id,
                                                     count,
                                                     serialized)

        except (ValueError, KeyError):
            raise exceptions.BadRequest(_("Could not parse template"))
        except Exception:
            exceptions.handle(request)
コード例 #2
0
    def __init__(self, request, *args, **kwargs):
        super(ConfigureNodegroupsAction, self). \
            __init__(request, *args, **kwargs)
        # when we copy or edit a cluster template then
        # request contains valuable info in both GET and POST methods
        req = request.GET.copy()
        req.update(request.POST)
        plugin = req.get("plugin_name")
        version = req.get("hadoop_version", None) or req["plugin_version"]
        if plugin and not version:
            version_name = plugin + "_version"
            version = req.get(version_name)

        if not plugin or not version:
            self.templates = saharaclient.nodegroup_template_find(request)
        else:
            self.templates = saharaclient.nodegroup_template_find(
                request, plugin_name=plugin, hadoop_version=version)

        deletable = req.get("deletable", dict())

        if 'forms_ids' in req:
            self.groups = []
            for id in json.loads(req['forms_ids']):
                group_name = "group_name_" + str(id)
                template_id = "template_id_" + str(id)
                count = "count_" + str(id)
                serialized = "serialized_" + str(id)
                self.groups.append({
                    "name":
                    req[group_name],
                    "template_id":
                    req[template_id],
                    "count":
                    req[count],
                    "id":
                    id,
                    "deletable":
                    deletable.get(req[group_name], "true"),
                    "serialized":
                    req[serialized]
                })

                whelpers.build_node_group_fields(self, group_name, template_id,
                                                 count, serialized)
コード例 #3
0
 def populate_guide_ngt_choices(self):
     plugin = getattr(self.request, self.request.method).get("plugin_name")
     version = getattr(self.request,
                       self.request.method).get("hadoop_version")
     data = saharaclient.nodegroup_template_find(self.request,
                                                 plugin_name=plugin,
                                                 hadoop_version=version)
     choices = [("%s|%s" % (ngt.name, ngt.id), ngt.name) for ngt in data]
     return choices
コード例 #4
0
ファイル: create.py プロジェクト: gongwayne/Openstack
    def __init__(self, request, *args, **kwargs):
        super(ConfigureNodegroupsAction, self). \
            __init__(request, *args, **kwargs)

        plugin = request.REQUEST.get("plugin_name")
        version = request.REQUEST.get("hadoop_version")
        if plugin and not version:
            version_name = plugin + "_version"
            version = request.REQUEST.get(version_name)

        if not plugin or not version:
            self.templates = saharaclient.nodegroup_template_find(request)
        else:
            self.templates = saharaclient.nodegroup_template_find(
                request, plugin_name=plugin, hadoop_version=version)

        deletable = request.REQUEST.get("deletable", dict())

        request_source = None
        if 'forms_ids' in request.POST:
                request_source = request.POST
        elif 'forms_ids' in request.REQUEST:
                request_source = request.REQUEST
        if request_source:
            self.groups = []
            for id in json.loads(request_source['forms_ids']):
                group_name = "group_name_" + str(id)
                template_id = "template_id_" + str(id)
                count = "count_" + str(id)
                serialized = "serialized_" + str(id)
                self.groups.append({"name": request_source[group_name],
                                    "template_id": request_source[template_id],
                                    "count": request_source[count],
                                    "id": id,
                                    "deletable": deletable.get(
                                        request_source[group_name], "true"),
                                    "serialized": request_source[serialized]})

                whelpers.build_node_group_fields(self,
                                                 group_name,
                                                 template_id,
                                                 count,
                                                 serialized)
コード例 #5
0
ファイル: forms.py プロジェクト: openstack/sahara-dashboard
 def populate_guide_ngt_choices(self):
     plugin = getattr(self.request, self.request.method).get("plugin_name")
     version = getattr(
         self.request, self.request.method).get("hadoop_version")
     data = saharaclient.nodegroup_template_find(self.request,
                                                 plugin_name=plugin,
                                                 hadoop_version=version)
     choices = [("%s|%s" % (ngt.name, ngt.id), ngt.name)
                for ngt in data]
     return choices
コード例 #6
0
 def show_existing_templates(self):
     try:
         plugin = self.request.session.get("plugin_name", None)
         version = self.request.session.get("plugin_version", None)
         data = saharaclient.nodegroup_template_find(
             self.request, plugin_name=plugin, hadoop_version=version)
         if len(data) < 1:
             return False
         return True
     except Exception:
         return True
コード例 #7
0
ファイル: create.py プロジェクト: Imperat/sahara-dashboard
    def __init__(self, request, *args, **kwargs):
        super(ConfigureNodegroupsAction, self). \
            __init__(request, *args, **kwargs)
        # when we copy or edit a cluster template then
        # request contains valuable info in both GET and POST methods
        req = request.GET.copy()
        req.update(request.POST)
        plugin = req.get("plugin_name")
        version = req.get("hadoop_version")
        if plugin and not version:
            version_name = plugin + "_version"
            version = req.get(version_name)

        if not plugin or not version:
            self.templates = saharaclient.nodegroup_template_find(request)
        else:
            self.templates = saharaclient.nodegroup_template_find(
                request, plugin_name=plugin, hadoop_version=version)

        deletable = req.get("deletable", dict())

        if 'forms_ids' in req:
            self.groups = []
            for id in json.loads(req['forms_ids']):
                group_name = "group_name_" + str(id)
                template_id = "template_id_" + str(id)
                count = "count_" + str(id)
                serialized = "serialized_" + str(id)
                self.groups.append({"name": req[group_name],
                                    "template_id": req[template_id],
                                    "count": req[count],
                                    "id": id,
                                    "deletable": deletable.get(
                                        req[group_name], "true"),
                                    "serialized": req[serialized]})

                whelpers.build_node_group_fields(self,
                                                 group_name,
                                                 template_id,
                                                 count,
                                                 serialized)
コード例 #8
0
    def __init__(self, *args, **kwargs):
        try:
            request = args[0]
            template_string = ""

            if "template_upload" in kwargs:
                template_string = kwargs.pop("template_upload")
                super(ImportClusterTemplateNodegroupsForm,
                      self).__init__(*args, **kwargs)

                self.fields["template_upload"].initial = template_string

            else:
                super(ImportClusterTemplateNodegroupsForm,
                      self).__init__(*args, **kwargs)
                template_string = self.data["template_upload"]

            template_json = json.loads(template_string)
            template_json = template_json["cluster_template"]

            req = request.GET.copy()
            req.update(request.POST)

            plugin = template_json["plugin_name"]
            version = (template_json.get("hadoop_version", None)
                       or template_json["plugin_version"])

            if not plugin or not version:
                self.templates = saharaclient.nodegroup_template_find(request)
            else:
                self.templates = saharaclient.nodegroup_template_find(
                    request, plugin_name=plugin, hadoop_version=version)

            deletable = req.get("deletable", dict())

            if "forms_ids" in req:
                self.groups = []
                for id in json.loads(req["forms_ids"]):
                    group_name = "group_name_" + str(id)
                    template_id = "template_id_" + str(id)
                    count = "count_" + str(id)
                    serialized = "serialized_" + str(id)
                    self.groups.append({
                        "name":
                        req[group_name],
                        "template_id":
                        req[template_id],
                        "count":
                        req[count],
                        "id":
                        id,
                        "deletable":
                        deletable.get(req[group_name], "true"),
                        "serialized":
                        req[serialized]
                    })

                    whelpers.build_node_group_fields(self, group_name,
                                                     template_id, count,
                                                     serialized)

        except (ValueError, KeyError):
            raise exceptions.BadRequest(_("Could not parse template"))
        except Exception:
            exceptions.handle(request)