

def create(self, req, body):
    'Creates a new security group.'
    context = req.environ['nova.context']
    if (not body):
        return exc.HTTPUnprocessableEntity()
    security_group = body.get('security_group', None)
    if (security_group is None):
        return exc.HTTPUnprocessableEntity()
    group_name = security_group.get('name', None)
    group_description = security_group.get('description', None)
    self._validate_security_group_property(group_name, 'name')
    self._validate_security_group_property(group_description, 'description')
    group_name = group_name.strip()
    group_description = group_description.strip()
    LOG.audit(_('Create Security Group %s'), group_name, context=context)
    self.compute_api.ensure_default_security_group(context)
    if db.security_group_exists(context, context.project_id, group_name):
        msg = (_('Security group %s already exists') % group_name)
        raise exc.HTTPBadRequest(explanation=msg)
    group = {
        'user_id': context.user_id,
        'project_id': context.project_id,
        'name': group_name,
        'description': group_description,
    }
    group_ref = db.security_group_create(context, group)
    return {
        'security_group': self._format_security_group(context, group_ref),
    }

dataset/ETHPy150Open nii-cloud/dodai-compute/nova/api/openstack/contrib/security_groups.py SecurityGroupController.create/original