File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/libcloud_storage.cpython-310.pyc
Back
o ;j� � @ sT d Z ddlZe�e�Zdd� Zdd� Zdd� Zd d � Zdd� Z d d� Z ddd�ZdS )a2 Apache Libcloud Storage State ============================= Manage cloud storage using libcloud :codeauthor: ``Anthony Shaw <anthonyshaw@apache.org>`` Apache Libcloud Storage (object/blob) management for a full list of supported clouds, see http://libcloud.readthedocs.io/en/latest/storage/supported_providers.html Clouds include Amazon S3, Google Storage, Aliyun, Azure Blobs, Ceph, OpenStack swift .. versionadded:: 2018.3.0 :configuration: This module uses a configuration profile for one or multiple Storage providers .. code-block:: yaml libcloud_storage: profile_test1: driver: google_storage key: GOOG0123456789ABCXYZ secret: mysecret profile_test2: driver: s3 key: 12345 secret: mysecret Examples -------- Creating a container and uploading a file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: yaml web_things: libcloud_storage.container_present: name: my_container_name profile: profile1 libcloud_storage.object_present: name: my_file.jpg container: my_container_name path: /path/to/local/file.jpg profile: profile1 Downloading a file ~~~~~~~~~~~~~~~~~~ This example will download the file from the remote cloud and keep it locally .. code-block:: yaml web_things: libcloud_storage.file_present: name: my_file.jpg container: my_container_name path: /path/to/local/file.jpg profile: profile1 :depends: apache-libcloud � Nc C s dt v rdS dS )N� libcloud_storage.list_containersT)Fz+libcloud_storage module could not be loaded)�__salt__� r r �P/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/libcloud_storage.py�__virtual__G s r c C s | |||d�S )N)�resultZcomment�name�changesr )r �messager r r r r �state_resultM s r c sT t d |�}� fdd�|D �}t|�dkrtdd� i �S t d � |�}tdd� |�S ) z� Ensures a container is present. :param name: Container name :type name: ``str`` :param profile: The profile key :type profile: ``str`` r c � g | ] }|d � kr|�qS �r r ��.0�zr r r � <listcomp>\ � z%container_present.<locals>.<listcomp>r TzContainer already existsz!libcloud_storage.create_containerzCreated new container�r �lenr �r �profileZ containers�matchr r r r �container_presentQ � r c sT t d |�}� fdd�|D �}t|�dkrtdd� i �S t d � |�}t|d� i �S ) z� Ensures a container is absent. :param name: Container name :type name: ``str`` :param profile: The profile key :type profile: ``str`` r c r r r r r r r r o r z$container_absent.<locals>.<listcomp>r TzContainer already absentz!libcloud_storage.delete_containerzDeleted containerr r r r r �container_absentd r r c C sF t d | ||�}|durtdd|i �S t d || ||�}t|d|i �S )a( Ensures a object is presnt. :param container: Container name :type container: ``str`` :param name: Object name in cloud :type name: ``str`` :param path: Local path to file :type path: ``str`` :param profile: The profile key :type profile: ``str`` �%libcloud_storage.get_container_objectNTzObject already presentzlibcloud_storage.upload_objectzUploaded object�r r )� containerr �pathr �existing_objectr r r r �object_presentw s ��r c C sD t d | ||�}|du rtdd|i �S t d | ||�}t|d|i �S )z� Ensures a object is absent. :param container: Container name :type container: ``str`` :param name: Object name in cloud :type name: ``str`` :param profile: The profile key :type profile: ``str`` r NTzObject already absentzlibcloud_storage.delete_objectzDeleted objectr )r r r r r r r r � object_absent� s �r! Fc C s"