'Remove the security group associated with the instance.'

def remove_from_instance(self, context, instance, security_group_name):

    security_group = self.db.security_group_get_by_name(context, context.project_id, security_group_name)
    instance_uuid = instance.uuid
    if (not self.is_associated_with_server(security_group, instance_uuid)):
        raise exception.SecurityGroupNotExistsForInstance(security_group_id=security_group['id'], instance_id=instance_uuid)
    self.db.instance_remove_security_group(context.elevated(), instance_uuid, security_group['id'])
    if instance.host:
        self.compute_rpcapi.refresh_instance_security_rules(context, instance, instance.host)
