from.contextimportsession# Import all of the client classes for type annotations.# We have to do this because we lazy-import the client definitions# inside each function to reduce runtime dependencies.fromtypingimportTYPE_CHECKINGifTYPE_CHECKING:fromopenstack.connectionimportConnectionfromblazarclient.clientimportClientasBlazarClientfromcinderclient.clientimportClientasCinderClientfromglanceclient.clientimportClientasGlanceClientfrommanilaclient.clientimportClientasManilaClientfromneutronclient.v2_0.clientimportClientasNeutronClientfromnovaclient.clientimportClientasNovaClientfromironicclientimportclientasIronicClientfromkeystoneclient.v3.clientimportClientasKeystoneClientfromzunclient.clientimportClientasZunClientsession_factory=sessionNOVA_API_VERSION="2.10"ZUN_API_VERSION="1.41"
[docs]defconnection(session=None)->"Connection":"""Get connection context for OpenStack SDK. The returned :class:`openstack.connection.Connection` object has several proxy modules attached for each service provided by the cloud. .. note:: For the most part, it is more straightforward to use clients specific to the service you are targeting. However, some of the proxy modules are useful for operations that span a few services, such as assigning a Floating IP to a server instance. See `the documentation <https://docs.openstack.org/openstacksdk/latest/user/connection.html>`__ for usage. Args: session (Session): An authentication session object. By default a new session is created via :func:`chi.session`. Returns: A new connection proxy. """fromopenstack.configimportcloud_regionfromopenstack.connectionimportConnectionsess=sessionorsession_factory()ifhasattr(sess,"session"):# Handle Adapters, which have a nested Sessionsess=sess.sessioncloud_config=cloud_region.from_session(sess)returnConnection(config=cloud_config,compute_api_version=NOVA_API_VERSION,)
[docs]defblazar(session=None)->"BlazarClient":"""Get a preconfigured client for Blazar, the reservation service. See `the documentation <https://opendev.org/openstack/python-blazarclient/>`__ for usage. Args: session (Session): An authentication session object. By default a new session is created via :func:`chi.session`. Returns: A new Blazar client. """fromblazarclient.clientimportClientasBlazarClientreturnBlazarClient("1",service_type="reservation",session=(sessionorsession_factory()))
[docs]defcinder(session=None)->"CinderClient":"""Get a preconfigured client for Cinder, the persistent volume service. See `the documentation <https://docs.openstack.org/python-cinderclient/latest/>`__ for usage. Args: session (Session): An authentication session object. By default a new session is created via :func:`chi.session`. Returns: A new Cinder client. """fromcinderclient.clientimportClientasCinderClientreturnCinderClient("3",session=(sessionorsession_factory()))
[docs]defglance(session=None)->"GlanceClient":"""Get a preconfigured client for Glance, the image service. See `the documentation <https://docs.openstack.org/python-glanceclient/latest/>`__ for usage. Args: session (Session): An authentication session object. By default a new session is created via :func:`chi.session`. Returns: A new Glance client. """fromglanceclient.clientimportClientasGlanceClientreturnGlanceClient("2",session=(sessionorsession_factory()))
[docs]defmanila(session=None)->"ManilaClient":"""Get a preconfigured client for Manila, the share service. See `the documentation <https://docs.openstack.org/python-manilaclient/latest/user/api.html>`__ for usage. Args: session (Session): An authentication session object. By default a new session is created via :func:`chi.session`. Returns: A new Manila client. """frommanilaclient.clientimportClientasManilaClientreturnManilaClient("2",session=(sessionorsession_factory()))
[docs]defneutron(session=None)->"NeutronClient":"""Get a preconfigured client for Neutron, the networking service. See `the documentation <https://docs.openstack.org/python-neutronclient/latest/reference/index.html>`__ for usage. Args: session (Session): An authentication session object. By default a new session is created via :func:`chi.session`. Returns: A new Neutron client. """fromneutronclient.v2_0.clientimportClientasNeutronClientreturnNeutronClient(session=(sessionorsession_factory()))
[docs]defnova(session=None)->"NovaClient":"""Get a preconfigured client for Nova, the compute service. See `the documentation <https://docs.openstack.org/python-novaclient/latest/user/python-api.html>`__ for usage. Args: session (Session): An authentication session object. By default a new session is created via :func:`chi.session`. Returns: A new Nova client. """fromnovaclient.clientimportClientasNovaClientreturnNovaClient(NOVA_API_VERSION,session=(sessionorsession_factory()))
[docs]defironic(session=None)->"IronicClient":"""Get a preconfigured client for Ironic, the bare metal service. See `the documentation <https://docs.openstack.org/python-ironicclient/latest/api_v1.html>`__ for usage. Args: session (Session): An authentication session object. By default a new session is created via :func:`chi.session`. Returns: A new Ironic client. """fromironicclientimportclientasIronicClientreturnIronicClient.get_client("1",session=(sessionorsession_factory()),region_name=getattr(session,"region_name",None),# Ironic client defaults to 1.9 currently,# "latest" will be latest the API supportsos_ironic_api_version="latest",)
[docs]defkeystone(session=None)->"KeystoneClient":"""Get a preconfigured client for Keystone, the authentication service. See `the documentation <https://docs.openstack.org/python-keystoneclient/latest/>`__ for usage. Args: session (Session): An authentication session object. By default a new session is created via :func:`chi.session`. Returns: A new Keystone client. """fromkeystoneclient.v3.clientimportClientasKeystoneClientsess=sessionorsession_factory()# We have to set interface/region_name also on the Keystone client, as it# does not smartly inherit the value sent in on a KSA Adapter instance.returnKeystoneClient(session=sess,interface=getattr(sess,"interface",None),region_name=getattr(sess,"region_name",None),)
[docs]defzun(session=None)->"ZunClient":"""Get a preconfigured client for Zun, the edge container service. See `the documentation <https://docs.openstack.org/python-zunclient/latest/user/python-api.html>`__ for usage. Args: session (Session): An authentication session object. By default a new session is created via :func:`chi.session`. Returns: A new Zun client. """fromzunclient.clientimportClientasZunClientreturnZunClient(ZUN_API_VERSION,session=(sessionorsession_factory()))