Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/openstack/__pycache__/connection.cpython-39.pyc
Ðазад
a t�h�S � @ s� d Z ddlZddlZzddlmZ W n ey> ddlZY n0 ddlZddl Z ddlZddlm Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd lmZ dd lmZ ddlmZ ddlmZ dd lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z ddlm!Z" ddl#m$Z$ ddlm%Z% ddlm&Z& ddgZ'ej(�r�ej)dej(d� e �*d�Z+d dd�Z,G dd� dej-ej.ej/ej0ej1ej2ej3ej4ej5ej6ej7ej8ej9ej:ej;ej<e j=�Z>dS )!a� The :class:`~openstack.connection.Connection` class is the primary interface to the Python SDK. It maintains a context for a connection to a region of a cloud provider. The :class:`~openstack.connection.Connection` has an attribute to access each OpenStack service. At a minimum, the :class:`~openstack.connection.Connection` class needs to be created with a config or the parameters to build one. While the overall system is very flexible, there are four main use cases for different ways to create a :class:`~openstack.connection.Connection`. * Using config settings and keyword arguments as described in :ref:`openstack-config` * Using only keyword arguments passed to the constructor ignoring config files and environment variables. * Using an existing authenticated `keystoneauth1.session.Session`, such as might exist inside of an OpenStack service operational context. * Using an existing :class:`~openstack.config.cloud_region.CloudRegion`. Using config settings --------------------- For users who want to create a :class:`~openstack.connection.Connection` making use of named clouds in ``clouds.yaml`` files, ``OS_`` environment variables and python keyword arguments, the :func:`openstack.connect` factory function is the recommended way to go: .. code-block:: python import openstack conn = openstack.connect(cloud='example', region_name='earth1') If the application in question is a command line application that should also accept command line arguments, an `argparse.Namespace` can be passed to :func:`openstack.connect` that will have relevant arguments added to it and then subsequently consumed by the constructor: .. code-block:: python import argparse import openstack options = argparse.ArgumentParser(description='Awesome OpenStack App') conn = openstack.connect(options=options) Using Only Keyword Arguments ---------------------------- If the application wants to avoid loading any settings from ``clouds.yaml`` or environment variables, use the :class:`~openstack.connection.Connection` constructor directly. As long as the ``cloud`` argument is omitted or ``None``, the :class:`~openstack.connection.Connection` constructor will not load settings from files or the environment. .. note:: This is a different default behavior than the :func:`~openstack.connect` factory function. In :func:`~openstack.connect` if ``cloud`` is omitted or ``None``, a default cloud will be loaded, defaulting to the ``envvars`` cloud if it exists. .. code-block:: python from openstack import connection conn = connection.Connection( region_name='example-region', auth=dict( auth_url='https://auth.example.com', username='amazing-user', password='super-secret-password', project_id='33aa1afc-03fe-43b8-8201-4e0d3b4b8ab5', user_domain_id='054abd68-9ad9-418b-96d3-3437bb376703'), compute_api_version='2', identity_interface='internal') Per-service settings as needed by `keystoneauth1.adapter.Adapter` such as ``api_version``, ``service_name``, and ``interface`` can be set, as seen above, by prefixing them with the official ``service-type`` name of the service. ``region_name`` is a setting for the entire :class:`~openstack.config.cloud_region.CloudRegion` and cannot be set per service. From existing authenticated Session ----------------------------------- For applications that already have an authenticated Session, simply passing it to the :class:`~openstack.connection.Connection` constructor is all that is needed: .. code-block:: python from openstack import connection conn = connection.Connection( session=session, region_name='example-region', compute_api_version='2', identity_interface='internal') From oslo.conf CONF object -------------------------- For applications that have an oslo.config ``CONF`` object that has been populated with ``keystoneauth1.loading.register_adapter_conf_options`` in groups named by the OpenStack service's project name, it is possible to construct a Connection with the ``CONF`` object and an authenticated Session. .. note:: This is primarily intended for use by OpenStack services to talk amongst themselves. .. code-block:: python from openstack import connection conn = connection.Connection( session=session, oslo_conf=CONF) From existing CloudRegion ------------------------- If you already have an :class:`~openstack.config.cloud_region.CloudRegion` you can pass it in instead: .. code-block:: python from openstack import connection import openstack.config config = openstack.config.get_cloud_region( cloud='example', region_name='earth') conn = connection.Connection(config=config) Using the Connection -------------------- Services are accessed through an attribute named after the service's official service-type. List ~~~~ An iterator containing a list of all the projects is retrieved in this manner: .. code-block:: python projects = conn.identity.projects() Find or create ~~~~~~~~~~~~~~ If you wanted to make sure you had a network named 'zuul', you would first try to find it and if that fails, you would create it:: network = conn.network.find_network("zuul") if network is None: network = conn.network.create_network(name="zuul") Additional information about the services can be found in the :ref:`service-proxies` documentation. � N)�_log)�_services_mixin)�openstackcloud)�_accelerator)� _baremetal)�_block_storage)�_compute)�_clustering)�_coe)�_dns)�_floating_ip)� _identity)�_image)�_network)�_network_common)� _object_store)�_orchestration)�_security_group��config)�cloud_region)� exceptions)�service_description�from_config� Connection�ignore)�category� openstackc K sD |� d| �} |� d|�}|du r:t�� jf | |d�|��}t|d�S )an Create a Connection using openstack.config :param str cloud: Use the `cloud` configuration details when creating the Connection. :param openstack.config.cloud_region.CloudRegion config: An existing CloudRegion configuration. If no `config` is provided, `openstack.config.OpenStackConfig` will be called, and the provided `name` will be used in determining which cloud's configuration details will be used in creation of the `Connection` instance. :param argparse.Namespace options: Allows direct passing in of options to be added to the cloud config. This does not have to be an actual instance of argparse.Namespace, despite the naming of the `openstack.config.loader.OpenStackConfig.get_one` argument to which it is passed. :rtype: :class:`~openstack.connection.Connection` Z cloud_nameZcloud_configN)�cloud�argparser )�pop�_configZOpenStackConfigZget_oner )r r �options�kwargs� r$ ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/openstack/connection.pyr � s ��c @ s^ e Zd Zddd�Zedd� �Zdd� Zd d � Zedd� �Zd d� Z dd� Z dd� Zdd� ZdS )r NFc K s� || _ i | _|| _|r,|D ]}|| j|j<