<commit_before># Copyright 2018 Red Hat, Inc.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import os
import sys

from openstack import connection

# TODO(dalvarez): support also GRE
GENEVE_TO_VXLAN_OVERHEAD = 8


def get_connection():
    user_domain_id = os.environ.get('OS_USER_DOMAIN_ID', 'default')
    project_domain_id = os.environ.get('OS_PROJECT_DOMAIN_ID', 'default')
    conn = connection.Connection(auth_url=os.environ['OS_AUTH_URL'],
                                 project_name=os.environ['OS_PROJECT_NAME'],
                                 username=os.environ['OS_USERNAME'],
                                 password=<PASSWORD>['<PASSWORD>'],
                                 user_domain_id=user_domain_id,
                                 project_domain_id=project_domain_id)<commit_msg>ovn-migration-mtu: Support providing project/user domain by name<commit_after># Copyright 2018 Red Hat, Inc.
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import os
import sys

from openstack import connection

# TODO(dalvarez): support also GRE
GENEVE_TO_VXLAN_OVERHEAD = 8


def get_connection():
    """Get OpenStack SDK Connection object with parameters from environment.

    Project scoped authorization is used and the following environment
    variables are required:

        OS_AUTH_URL     URL to OpenStack Identity service
        OS_PROJECT_NAME Name of project for authorization
        OS_USERNAME     Username for authentication
        OS_PASSWORD     Password for authentication

    Which domain to use for authentication and authorization may be specified
    by domain name or domain ID. If none of the domain selection variables are
    set the tool will default to use the domain with literal ID of 'default'.

    To select domain by name set both of these envornment variables:

        OS_USER_DOMAIN_NAME    Name of domain to authenticate to
        OS_PROJECT_DOMAIN_NAME Name of domain for authorization

    To select domain by ID set both of these environment variables:

        OS_USER_DOMAIN_ID    ID of domain to authenticate to
        OS_PROJECT_DOMAIN_ID ID of domain for authorization

    NOTE: If both OS_*_DOMAIN_NAME and OS_*_DOMAIN_ID variables are present in
    the environment the OS_*_DOMAIN_NAME variables will be used.
    """
    user_domain_name = os.environ.get('OS_USER_DOMAIN_NAME')
    project_domain_name = os.environ.get('OS_PROJECT_DOMAIN_NAME')
    user_domain_id = os.environ.get(
        'OS_USER_DOMAIN_ID',
        'default') if not user_domain_name else None
    project_domain_id = os.environ.get(
        'OS_PROJECT_DOMAIN_ID',
        'default') if not project_domain_name else None
    conn = connection.Connection(auth_url=os.environ['OS_AUTH_URL'],
                                 project_name=os.environ['OS_PROJECT_NAME'],
                                 username=os.environ['OS_USERNAME'],
                                 password=os.environ['<PASSWORD>'],
                                 user_domain_id=user_domain_id,
                                 project_domain_id=project_domain_id,
                                 user_domain_name=user_domain_name,
                                 project_domain_name=project_domain_name)
{'fraction_non_alphanumeric': 0.06018518518518518, 'fraction_numerical': 0.004166666666666667, 'mean_word_length': 2.7121993127147768, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2209156', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1130, 'n_words': 401}