

def _addSecurityGroup(self, input_dict, req, instance_id):
    context = req.environ['nova.context']
    try:
        body = input_dict['addSecurityGroup']
        group_name = body['name']
        instance_id = int(instance_id)
    except ValueError:
        msg = _('Server id should be integer')
        raise exc.HTTPBadRequest(explanation=msg)
    except TypeError:
        msg = _('Missing parameter dict')
        raise webob.exc.HTTPBadRequest(explanation=msg)
    except KeyError:
        msg = _('Security group not specified')
        raise webob.exc.HTTPBadRequest(explanation=msg)
    if ((not group_name) or (group_name.strip() == '')):
        msg = _('Security group name cannot be empty')
        raise webob.exc.HTTPBadRequest(explanation=msg)
    try:
        self.compute_api.add_security_group(context, instance_id, group_name)
    except exception.SecurityGroupNotFound as exp:
        return exc.HTTPNotFound(explanation=unicode(exp))
    except exception.InstanceNotFound as exp:
        return exc.HTTPNotFound(explanation=unicode(exp))
    except exception.Invalid as exp:
        return exc.HTTPBadRequest(explanation=unicode(exp))
    return exc.HTTPAccepted()

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