File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/gcp_addon.cpython-310.pyc
Back
o ;jG � @ s� d Z ddlZzddlZddlZdZW n ey dZY nw e�e �Z dZdd� Zdd � Z d d� Z ddd �ZdS )ap A route is a rule that specifies how certain packets should be handled by the virtual network. Routes are associated with virtual machine instances by tag, and the set of routes for a particular VM is called its routing table. For each packet leaving a virtual machine, the system searches that machine's routing table for a single best matching route. .. versionadded:: 2018.3.0 This module will create a route to send traffic destined to the Internet through your gateway instance. :codeauthor: `Pratik Bandarkar <pratik.bandarkar@gmail.com>` :maturity: new :depends: google-api-python-client :platform: Linux � NTFZgcpc C s t du rdS tS )z' Check for googleapiclient api F)FzMRequired dependencies 'googleapiclient' and/or 'oauth2client' were not found.)�HAS_LIB�__virtualname__� r r �J/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/gcp_addon.py�__virtual__# s r c C s |� � j| |d��� S )z3 Fetch network selfLink from network name. )�project�network)Znetworks�get�execute)� project_idZnetwork_name�servicer r r �_get_network0 s r c C s |� � j| ||d��� S )z Get instance details )r �zone�instance)Z instancesr r )r � instance_zone�namer r r r � _get_instance7 s ��r c C sz t jj�| �} tjjdd| d�} | �� }t|�t |t|�| d�d t|�t |||| d�d ||d�}|j||d�} | �� S )aL Create a route to send traffic destined to the Internet through your gateway instance credential_file : string File location of application default credential. For more information, refer: https://developers.google.com/identity/protocols/application-default-credentials project_id : string Project ID where instance and network resides. name : string name of the route to create next_hop_instance : string the name of an instance that should handle traffic matching this route. instance_zone : string zone where instance("next_hop_instance") resides network : string Specifies the network to which the route will be applied. dest_range : string The destination range of outgoing packets that the route will apply to. tags : list (optional) Identifies the set of instances that this route will apply to. priority : int (optional) Specifies the priority of this route relative to other routes. default=1000 CLI Example: .. code-block:: bash salt 'salt-master.novalocal' gcp.route_create credential_file=/root/secret_key.json project_id=cp100-170315 name=derby-db-route1 next_hop_instance=instance-1 instance_zone=us-central1-a network=default dest_range=0.0.0.0/0 tags=['no-ip'] priority=700 In above example, the instances which are having tag "no-ip" will route the packet to instance "instance-1"(if packet is intended to other network) ZcomputeZv1)�credentials)r ZselfLink)r r Z destRangeZnextHopInstance�tags�priority)r �body) �oauth2clientZservice_accountZServiceAccountCredentialsZfrom_json_keyfile_name�googleapiclientZ discovery�build�routes�strr r �insertr )Zcredential_filer r Z dest_rangeZnext_hop_instancer r r r r r r Z routes_configZroute_create_requestr r r �route_createB s&