def handle(self, request, data):
        try:
            template = data["template_upload"]
            template = json.loads(template)
            template = template["cluster_template"]

            if "name" not in template.keys():
                return False

            if "neutron_management_network" in template:
                template["net_id"] = (
                    template.pop("neutron_management_network"))

            # default_image_id is not supported by the client now
            if "default_image_id" in template:
                template.pop("default_image_id")

            node_groups = []
            ids = json.loads(data['forms_ids'])
            for id in ids:
                name = data['group_name_' + str(id)]
                template_id = data['template_id_' + str(id)]
                count = data['count_' + str(id)]

                raw_ng = data.get("serialized_" + str(id))

                if raw_ng and raw_ng != 'null':
                    ng = json.loads(utils.deserialize(str(raw_ng)))
                else:
                    ng = dict()
                ng["name"] = name
                ng["count"] = count
                if template_id and template_id != u'None':
                    ng["node_group_template_id"] = template_id
                node_groups.append(ng)

            template["node_groups"] = node_groups

            saharaclient.cluster_template_create(request, **template)
            return True
        except api_base.APIException as e:
            self.error_description = str(e)
            return False
        except Exception as e:
            if isinstance(e, TypeError):
                raise exceptions.BadRequest(
                    _("Template JSON contained invalid key"))
            else:
                raise exceptions.BadRequest(_("Could not parse template"))
    def handle(self, request, data):
        try:
            template = data["template_upload"]
            template = json.loads(template)
            template = template["cluster_template"]

            if "name" not in template.keys():
                return False

            if "neutron_management_network" in template:
                template["net_id"] = (
                    template.pop("neutron_management_network"))

            # default_image_id is not supported by the client now
            if "default_image_id" in template:
                template.pop("default_image_id")

            node_groups = []
            ids = json.loads(data['forms_ids'])
            for id in ids:
                name = data['group_name_' + str(id)]
                template_id = data['template_id_' + str(id)]
                count = data['count_' + str(id)]

                raw_ng = data.get("serialized_" + str(id))

                if raw_ng and raw_ng != 'null':
                    ng = json.loads(utils.deserialize(str(raw_ng)))
                else:
                    ng = dict()
                ng["name"] = name
                ng["count"] = count
                if template_id and template_id != u'None':
                    ng["node_group_template_id"] = template_id
                node_groups.append(ng)

            template["node_groups"] = node_groups

            saharaclient.cluster_template_create(request, **template)
            return True
        except api_base.APIException as e:
            self.error_description = str(e)
            return False
        except Exception as e:
            if isinstance(e, TypeError):
                raise exceptions.BadRequest(
                    _("Template JSON contained invalid key"))
            else:
                raise exceptions.BadRequest(_("Could not parse template"))
示例#3
0
def recovery_ct(request, ct, node_groups):
    ct_ngs = get_ct_ng(node_groups)
    ct = sahara.cluster_template_create(
        request,
        name=ct['name'] + uuidutils.generate_uuid()[0:7],
        plugin_name=ct['plugin_name'],
        hadoop_version=ct['hadoop_version'],
        description=ct['description'],
        cluster_configs=ct['cluster_configs'],
        node_groups=ct_ngs,
        anti_affinity=ct['anti_affinity'],
        net_id=None,
        use_autoconfig=ct['use_autoconfig'],
        shares=ct['shares'],
        is_public=ct['is_public'],
        is_protected=ct['is_protected'],
        domain_name=ct['domain_name']).to_dict()
    ct = sahara.cluster_template_get(request, ct['id']).to_dict()
    return ct
示例#4
0
    def handle(self, request, context):
        try:
            node_groups = []
            configs_dict = whelpers.parse_configs_from_context(context,
                                                               self.defaults)

            ids = json.loads(context['ng_forms_ids'])
            for id in ids:
                name = context['ng_group_name_' + str(id)]
                template_id = context['ng_template_id_' + str(id)]
                count = context['ng_count_' + str(id)]

                raw_ng = context.get("ng_serialized_" + str(id))

                if raw_ng and raw_ng != 'null':
                    ng = json.loads(base64.urlsafe_b64decode(str(raw_ng)))
                else:
                    ng = dict()
                ng["name"] = name
                ng["count"] = count
                if template_id and template_id != u'None':
                    ng["node_group_template_id"] = template_id
                node_groups.append(ng)

            plugin, hadoop_version = whelpers.\
                get_plugin_and_hadoop_version(request)

            ct_shares = []
            if "ct_shares" in context:
                ct_shares = context["ct_shares"]

            # TODO(nkonovalov): Fix client to support default_image_id
            saharaclient.cluster_template_create(
                request,
                context["general_cluster_template_name"],
                plugin,
                hadoop_version,
                context["general_description"],
                configs_dict,
                node_groups,
                context["anti_affinity_info"],
                use_autoconfig=context['general_use_autoconfig'],
                shares=ct_shares,
                is_public=context['general_is_public'],
                is_protected=context['general_is_protected']
            )

            hlps = helpers.Helpers(request)
            if hlps.is_from_guide():
                request.session["guide_cluster_template_name"] = (
                    context["general_cluster_template_name"])
                self.success_url = (
                    "horizon:project:data_processing.clusters:cluster_guide")
            return True
        except api_base.APIException as e:
            self.error_description = str(e)
            return False
        except Exception:
            exceptions.handle(request,
                              _("Cluster template creation failed"))
            return False
示例#5
0
    def handle(self, request, context):
        try:
            node_groups = []
            configs_dict = whelpers.parse_configs_from_context(
                context, self.defaults)

            ids = json.loads(context['ng_forms_ids'])
            for id in ids:
                name = context['ng_group_name_' + str(id)]
                template_id = context['ng_template_id_' + str(id)]
                count = context['ng_count_' + str(id)]

                raw_ng = context.get("ng_serialized_" + str(id))

                if raw_ng and raw_ng != 'null':
                    ng = json.loads(utils.deserialize(str(raw_ng)))
                else:
                    ng = dict()
                ng["name"] = name
                ng["count"] = count
                if template_id and template_id != u'None':
                    ng["node_group_template_id"] = template_id
                node_groups.append(ng)

            plugin, hadoop_version = whelpers.\
                get_plugin_and_hadoop_version(request)

            ct_shares = []
            if "ct_shares" in context:
                ct_shares = context["ct_shares"]

            domain = context.get('dns_domain_name', None)
            if domain == 'None':
                domain = None

            # TODO(nkonovalov): Fix client to support default_image_id
            saharaclient.cluster_template_create(
                request,
                context["general_cluster_template_name"],
                plugin,
                hadoop_version,
                context["general_description"],
                configs_dict,
                node_groups,
                context["anti_affinity_info"],
                use_autoconfig=context['general_use_autoconfig'],
                shares=ct_shares,
                is_public=context['general_is_public'],
                is_protected=context['general_is_protected'],
                domain_name=domain)

            hlps = helpers.Helpers(request)
            if hlps.is_from_guide():
                request.session["guide_cluster_template_name"] = (
                    context["general_cluster_template_name"])
                self.success_url = (
                    "horizon:project:data_processing.clusters:cluster_guide")
            return True
        except api_base.APIException as e:
            self.error_description = str(e)
            return False
        except Exception:
            exceptions.handle(request, _("Cluster template creation failed"))
            return False