HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/cloud/clouds/__pycache__/clc.cpython-310.pyc
o

�N�g�.�@sFdZddlZddlZddlZddlmZddlZddlm	Z	z
e�
d�ddlZdZWne
y6dZYnwzddlmZe�Wn	eyKYnwe�e�ZdZdd	�Zd
d�Zdd
�Zdd�Zdd�Zd*dd�Zd*dd�Zd*dd�Zd*dd�Zd*dd�Zd*dd�Zd+dd�Z d+d d!�Z!d+d"d#�Z"d$d%�Z#d&d'�Z$d+d(d)�Z%dS),a�
CenturyLink Cloud Module
========================

.. versionadded:: 2018.3.0

The CLC cloud module allows you to manage CLC Via the CLC SDK.

:codeauthor: Stephan Looney <slooney@stephanlooney.com>


Dependencies
============

- clc-sdk Python Module
- flask

CLC SDK
-------

clc-sdk can be installed via pip:

.. code-block:: bash

    pip install clc-sdk

.. note::
  For sdk reference see: https://github.com/CenturyLinkCloud/clc-python-sdk

Flask
-----

flask can be installed via pip:

.. code-block:: bash

    pip install flask

Configuration
=============

To use this module: set up the clc-sdk, user, password, key in the
cloud configuration at
``/etc/salt/cloud.providers`` or ``/etc/salt/cloud.providers.d/clc.conf``:

.. code-block:: yaml

    my-clc-config:
      driver: clc
      user: 'web-user'
      password: 'verybadpass'
      token: ''
      token_pass:''
      accountalias: 'ACT'
.. note::

    The ``provider`` parameter in cloud provider configuration was renamed to ``driver``.
    This change was made to avoid confusion with the ``provider`` parameter that is
    used in cloud profile configuration. Cloud provider configuration now uses ``driver``
    to refer to the salt-cloud driver that provides the underlying functionality to
    connect to a cloud provider, while cloud profile configuration continues to use
    ``provider`` to refer to the cloud provider configuration that you define.

�N)�SaltCloudSystemExit�clcTF)�disable_warningscCst�dus
t�durdStS)zI
    Check for CLC configuration and if required libs are available.
    F)�get_configured_provider�get_dependencies�__virtualname__�rr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/cloud/clouds/clc.py�__virtual__esr
cCs"zt��WStytYSw�N)Z__active_provider_name__�value�AttributeErrorrrrr	�_get_active_provider_nameos

�rcCst�tt�ptd�S)N)�token�
token_pass�user�password)�config�is_provider_configured�__opts__rrrrrr	rvs
�rcCsdti}t�t|�S)z*
    Warn if dependencies aren't met.
    r)�HAS_CLCrZcheck_driver_dependenciesr)Zdepsrrr	r�s�rcCsxtjdt�tdd�}tjdt�tdd�}tjdt�tdd�}tjdt�tdd�}tjdt�tdd�}|||||d�}|S)	NrF)�
search_globalr�accountaliasrr)rrrrr)r�get_cloud_config_valuerr)rrrrr�credsrrr	�	get_creds�s,
�
�
�
�
��rcCs\|dkrtd��t�}tj�|d|d�tjjjdd�}tjj	�
|�}tjj	�|�}|S)�;
    Return a list of the VMs that are on the provider
    �action�BThe list_nodes_full function must be called with -f or --function.rrN)�location)rrr�v1�SetCredentials�ServerZ
GetServers�salt�utils�json�dumps�loads)�call�
for_outputrZservers_rawZserversrrr	�list_nodes_full�s�r*cCs,t�}tj�|d|d�tjj��}|S)Nrr)rrr r!�QueueZList)r(r)rZcl_queuerrr	�get_queue_data�sr,cCs�t�}tj�|d|d�|dkrtd��z$tjjj|dd�}tjj	�
|�}tjj	�|�}t|dd�}d	|iWSt
yGd	d
iYSw)rrrrrr��alias�MonthlyEstimate��Monthly Estimater�rrr r!r�BillingZGetAccountSummaryr#r$r%r&r'�round�RuntimeError�r(r)r�billing_raw�billingrrr	�get_monthly_estimate�s�
�r9cCs�t�}tj�|d|d�|dkrtd��z$tjjj|dd�}tjj	�
|�}tjj	�|�}t|dd�}d	|iWSt
yDYd
Sw)rrrrrrr-ZMonthToDateTotalr0z
Month To Daterr2r6rrr	�get_month_to_date�s�
�r:cKsR|��D]\}}d}|dkr|}qt�}tj�|d|d�tj�|���}|S)zE
    Return a list of alerts from CLC as reported by their infra
    ��
servernamerr)�itemsrr�v2r!r"ZAlerts)r(r)�kwargs�keyrr<rZalertsrrr	�get_server_alerts�s�rAcKs�|��D]\}}d}d}|dkr|}|dkr|}qt�}tj�|d|d�|dkr/td��z.tjjj||d|d	�}tj	j
�|�}tj	j
�|�}	t
|	d
d�}
t
|	dd�}|
|d
�WStygYdSw)z�
    Return a list of the VMs that are on the provider
    usage: "salt-cloud -f get_group_estimate clc group=Dev location=VA1"
    r;�grouprrrrrr)rBr.rr/r0ZMonthToDate)r1z
Month to Dater)r=rrr r!rr3ZGetGroupEstimater#r$r%r&r'r4r5)r(r)r?r@rrBrrr7r8ZestimateZ
month_to_daterrr	�get_group_estimate�s4��
��rCcCs2t�}i}|D]}|dr|�d|di�q|S)z3
    returns a list of images available to you
    Z
IsTemplatez
Template Name�Name)r*�update)r(Zall_serversZ	templatesZserverrrr	�avail_imagess�rFcCs,t�}tj�|d|d�tjj��}|S)z6
    returns a list of locations available to you
    rr)rrr r!ZAccountZGetLocations)r(rZ	locationsrrr	�avail_locationssrGcC�ddiS)z 
    use templates for this
    ZSizesz;Sizes are built into templates. Choose appropriate templater)r(rrr	�avail_sizes)�rIcCs�d}t|�}|dkrUtjjj|d�}|ddkr;|dd}t�}tj�|d|d�tj�|�j	}|dd	}|S|d
}t
�d|td|��t�
d�|dks
d
Sd
S)zM
    get the build status from CLC to make sure we don't return to early
    r�
)Z
request_idZPercentComplete�dZServersrrZinternal�z+Creating Cloud VM %s Time out in %s minutes�<N)�strrr Z	BlueprintZ	GetStatusrr>r!r"�ip_addresses�log�info�time�sleep)�req_id�nodenameZcounter�queueZserver_namerrPZinternal_ip_addressrrr	�get_build_status0s&
�
�rXc
Cs�t�}tj�|d|d�t�tt�ptd�}tj	d|tddd�}|d}tj	d	|tddd�}tj	d
|tddd�}tj	d|tddd�}tj	d|tddd�}tj	d
|tddd�}	tj	d|tddd�}
tj	d|tddd�}tj	d|tddd�}t
|�dkr�|dd�}t
|	�dkr�d}	tjjjd||||
||||||	d�}
|
d}t
||�|d<tdddd|�d�tdd|ditdd �td!|t�}||dd"�}|�|�|S)#z$
    get the system build going
    rr)rrBFN)r�default�name�description�ram�backup_level�templater�cpu�networkr�r�	r;)r.rrZr^r_r\r]rBr`r[rZ	RequestIDZssh_hostzcloud.fire_event�eventzwaiting for sshzsalt/cloud/z/waiting_for_ssh�sock_dir�
ip_address�	transport)rd�argsrfzcloud.bootstrap)zServer Namez
IP Address)rrr r!rrrrrr�lenr"ZCreaterXZ	__utils__rE)Zvm_rZ
cloud_profilerBrZr[r\r]r^rr_r`rZ
clc_returnrU�retZreturn_messagerrr	�createIs������������


�

rjcCrH)z
    destroy the vm
    �statusz?destroying must be done via https://control.ctl.io at this timer)rZr(rrr	�destroy�rJrl)NTr)&�__doc__�	importlib�loggingrSZsalt.configrZsalt.utils.jsonr#Zsalt.exceptionsr�
import_modulerr�ImportErrorZrequests.packages.urllib3r�	Exception�	getLogger�__name__rQrr
rrrrr*r,r9r:rArCrFrGrIrXrjrlrrrr	�<module>sNA
�
�













l