@wsgi.response(201)
    def create(self, req, body, gid):

        def _validate(context, body, gid):
            if not self.is_valid_body(body, 'securitygroup'):
                msg = _("Invalid request body")
                raise exception.InvalidInput(reason=msg)

            self._uuid_check(gid)
            db.group_get_by_gid(context, gid)
            values = body["securitygroup"]
            name = values.get("name")
            is_default = values.get("is_default")

            if is_default:
                try:
                    is_default = strutils.bool_from_string(
                        is_default, strict=True)
                except __HOLE__:
                    msg = _("is_default must be a boolean")
                    raise exception.InvalidInput(reason=msg)
            else:
                is_default = False

            valid_values = {}
            valid_values["gid"] = gid
            valid_values["display_name"] = name
            valid_values["is_default"] = is_default

            rules = values.get("securitygrouprules")
            valid_rules = []
            if rules is not None:
                if not isinstance(rules, list):
                    msg = _("securitygrouprules must be a list")
                    raise exception.InvalidInput(reason=msg)

                for rule in rules:
                    valid_rule = {}
                    valid_rule["protocol"] = rule.get("protocol")
                    valid_rule["port_range_max"] = rule.get("port_range_max")
                    valid_rule["port_range_min"] = rule.get("port_range_min")
                    valid_rule["remote_ip_prefix"] = rule.get(
                        "remote_ip_prefix")
                    remote_securitygroup_id = rule.get(
                        "remote_securitygroup_id")
                    if remote_securitygroup_id:
                        ref = db.securitygroup_get_by_securitygroup_id(
                            context, gid,
                            remote_securitygroup_id)
                        valid_rule['remote_neutron_securitygroup_id'] =\
                            ref['neutron_securitygroup_id']
                    valid_rules.append(valid_rule)

            return valid_values, valid_rules

        try:
            context = req.environ['rack.context']
            values, rules = _validate(context, body, gid)
            values["securitygroup_id"] = unicode(uuid.uuid4())
            if not values["display_name"]:
                values["display_name"] = "securitygroup-" + \
                    values["securitygroup_id"]
            result_value = self.manager.securitygroup_create(
                context, values["display_name"], rules)
            values.update(result_value)
            values["user_id"] = context.user_id
            values["project_id"] = context.project_id
            securitygroup = db.securitygroup_create(context, values)
        except exception.InvalidInput as e:
            raise webob.exc.HTTPBadRequest(explanation=e.format_message())
        except exception.GroupNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        return self._view_builder.create(securitygroup)
dataset/ETHPy150Open openstack/rack/rack/api/v1/securitygroups.py/Controller.create