import openstack
from keystoneauth1.identity import v3
from keystoneauth1 import session


class OpenStackConnection(object):
    """Class for handling the connection to the OpenStack Manager.
        It creates a connection member variable which holds the connection.
        The connection only connects when something called in it."""

    def __init__(self, auth):
        super(OpenStackConnection, self).__init__()
        self.openstack = openstack.connect(auth_url=auth["auth_url"],
                                           username=auth["username"],
                                           password=auth["password"],
                                           project_id=auth["project_id"],
                                           project_name=auth["project_name"],
                                           region_name=auth["region_name"]
                                           )
        client_auth = v3.Password(auth_url=auth["auth_url"],
                                  username=auth["username"],
                                  password=auth["password"],
                                  user_domain_id=auth["user_domain_id"],
                                  project_id=auth["project_id"],)

        self.client_session = session.Session(auth=client_auth)