Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/net_tools/infinity/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pyc

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
mZmZddl
mZd
efd��YZd�Zedkr�e�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys�
module: infinity
short_description: Manage Infinity IPAM using Rest API
description:
  - Manage Infinity IPAM using REST API.
version_added: "2.4"
author:
  - Meirong Liu (@MeganLiu)
options:
  server_ip:
    description:
      - Infinity server_ip with IP address.
    type: str
    required: true
  username:
    description:
      - Username to access Infinity.
      - The user must have REST API privileges.
    type: str
    required: true
  password:
    description:
      - Infinity password.
    type: str
    required: true
  action:
    description:
      - Action to perform
    type: str
    required: true
    choices: [add_network, delete_network, get_network, get_network_id, release_ip, release_network, reserve_network, reserve_next_available_ip ]
  network_id:
    description:
      - Network ID.
    type: str
    default: ''
  ip_address:
    description:
      - IP Address for a reservation or a release.
    type: str
    default: ''
  network_address:
    description:
      - Network address with CIDR format (e.g., 192.168.310.0).
    type: str
    default: ''
  network_size:
    description:
      - Network bitmask (e.g. 255.255.255.220) or CIDR format (e.g., /26).
    type: str
    default: ''
  network_name:
    description:
      - The name of a network.
    type: str
    default: ''
  network_location:
    description:
      - The parent network id for a given network.
    type: int
    default: -1
  network_type:
    description:
      - Network type defined by Infinity
    type: str
    choices: [ lan, shared_lan, supernet ]
    default: lan
  network_family:
    description:
      - Network family defined by Infinity, e.g. IPv4, IPv6 and Dual stack
    type: str
    choices: [ 4, 6, dual ]
    default: 4
s�
---
- hosts: localhost
  connection: local
  strategy: debug
  tasks:
    - name: Reserve network into Infinity IPAM
      infinity:
        server_ip: 80.75.107.12
        username: username
        password: password
        action: reserve_network
        network_name: reserve_new_ansible_network
        network_family: 4
        network_type: lan
        network_id: 1201
        network_size: /28
      register: infinity
s}
network_id:
    description: id for a given network
    returned: success
    type: str
    sample: '1501'
ip_info:
    description: when reserve next available ip address from a network, the ip address info ) is returned.
    returned: success
    type: str
    sample: '{"address": "192.168.10.3", "hostname": "", "FQDN": "", "domainname": "", "id": 3229}'
network_info:
    description: when reserving a LAN network from a Infinity supernet by providing network_size, the information about the reserved network is returned.
    returned: success
    type: str
    sample:  {"network_address": "192.168.10.32/28","network_family": "4", "network_id": 3102,
    "network_size": null,"description": null,"network_location": "3085",
    "ranges": { "id": 0, "name": null,"first_ip": null,"type": null,"last_ip": null},
    "network_type": "lan","network_name": "'reserve_new_ansible_network'"}
(t
AnsibleModuletjson(topen_urltInfinitycB`s�eZdZd�Zdddddd�Zdd�Zddd�Zdd	�Zddd
�Z	ddd�Z
dddddddd
�Zdddd�Zddddddd�Z
RS(s<
    Class for manage REST API calls with the Infinity.
    cC`s2||_||_||_dt|�|_dS(Nshttps://%s/rest/v1/(tmodulet	auth_usert	auth_pasststrtbase_url(tselfRt	server_iptusernametpassword((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pyt__init__�s			tgettcC`s�|dkrdgn|}t|j�t|�}d}idd6}|sc|jjdd�n|r�t|t�r�tj|�}ntt|�d|ddd	|d
|j	d|j
dtd
td|�}	|	j
�}d}
|	j|kr|jjdtdd|	j�nTt|t�rAt|�dkrA|}
n*|j�dkrk|	jdkrkd}
nt|
t�r�d|
kr�|jjdtdd�t|
d��n|
S(sN
        Perform the HTTPS request by using ansible get/delete method
        i�sapplication/jsonsContent-TypetmsgsEWhen sending Rest api call , the resource URL is empty, please check.tmethodttimeoutitheadersturl_usernameturl_passwordtvalidate_certstforce_basic_authtdataRtchangedtmetas: openurl response_raw.code show error and error code is %ritdeletei�sDelete is done.ttexts1when calling rest api, returned data is not json N(tNoneRRRt	exit_jsont
isinstanceR	tdumpsR
R
RtFalsetTruetreadtcodetlentlowertdictt	Exception(RRtresource_urlt
stat_codestparamstpayload_datatrequest_urltresponseRtresponse_rawtpayload((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pyt_get_api_call_ansible_handler�sH


			!	!	i����cC`sQ|dkr.|dkr.|jjdd�nd}d}i}d}|rqdt|�}|j||�}n|dkrM|rMd}d}itji|d6dd	6�d
6}|j||dtj|��}|r�t|t�r�tj|�}n|rMt|t	�rMt
|�dkrM|dkrM|d
}tj|�}qMn|S(s�
        Search network_name inside Infinity by using rest api
        Network id  or network_name needs to be provided
        return the details of a given with given network_id or name
        RsDYou must specify  one of the options 'network_name' or 'network_id'.RRs	networks/tsearchtnametnetworkttypetqueryR4iiN(R%RR&RR9R	R(R'tloadstlistR-(Rt
network_idtnetwork_nametlimitRR1R3R6((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pytget_network�s0
	
tlancC`s�d}d}d
}|d
kr4|jjdd�nitji|d6dd6�d6}|j||d	tj|��}d
}|r�t|t�r�tj|�}n|r�t|t	�r�|d}|d}n|S(sZ
        query network_id from Infinity  via rest api based on given network_name
        RR:Rs*You must specify the option 'network_name'R;R<R=R>R4RitidN(
R%RR&R	R(R9R'RR?R@(RRBtnetwork_typeRR1R6R3RA((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pytget_network_id�s"
	

cC`s�d}d}d
}d}|s4|jjdd�n|r�dt|�d}|j||�}|r�|jd�dkr�|jd	�dkr�|jd
�}|jd�}|||d!}q�n|S(s�
        Reserve ip address via  Infinity by using rest api
        network_id:  the id of the network that users would like to reserve network from
        return the next available ip address from that given network
        tpostRRs)You must specify the option 'network_id'.s	networks/s/reserve_ipt[it]t{t}iN(R%RR&RR9tfind(RRARR1R6tip_infot	start_postend_pos((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pytreserve_next_available_ips 
$cC`s�d}d}d}|dks*|dkr@|jjdd�ndt|�d}|j||�}|s�|jjdd||f�ntj|�}g}x%|D]}|d}	|j|	�q�Wd}
xn|D]f}	d}d	t|	�}|j||d
dg�}|r�tj|�dt|�kr�|	}
Pq�q�W|
rzd
}d	t|
�}|j||d
dg�}n|jjdd||f�|S(sD
        Reserve ip address via  Infinity by using rest api
        RRRsCYou must specify  those two options: 'network_id' and 'ip_address'.s	networks/s	/childrens4There is an error in release ip %s from network  %s.RFs
ip_addresses/R2i�taddressR#i�sO When release ip, could not find the ip address %r from the given network %r' .N(R%RR&RR9R	R?tappend(RRAt
ip_addressRR1R6tip_listt	ip_idlisttip_itemtip_idt
deleted_ip_idtip_response((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pyt
release_ipsL



cC`s�d}d}d	}|d	kr@|d	kr@|jjdd�n|d	krg|rg|jd|�}n|r�dt|�}|j||ddg�}n|S(
sA
        delete network from  Infinity by using rest api
        R#RRsDYou must specify one of those options: 'network_id','network_name' .RBs	networks/R2i�N(R%RR&RHRR9(RRARBRR1R6((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pytdelete_networkMs
t4c	C`sd}d}	d}
|dks6|dks6|dkrL|jjdd�n|ridt|�d}	n|sxd}n|s�d}ni|d	6|d
6|d6|d6|d
6t|�d6}|r�|ji|d6�n|j||	dddgd|�}
|
S(s�
        Reserves the first available network of specified size from a given supernet
         <dt>network_name (required)</dt><dd>Name of the network</dd>
            <dt>description (optional)</dt><dd>Free description</dd>
            <dt>network_family (required)</dt><dd>Address family of the network. One of '4', '6', 'IPv4', 'IPv6', 'dual'</dd>
            <dt>network_address (optional)</dt><dd>Address of the new network. If not given, the first network available will be created.</dd>
            <dt>network_size (required)</dt><dd>Size of the new network in /&lt;prefix&gt; notation.</dd>
            <dt>network_type (required)</dt><dd>Type of network. One of 'supernet', 'lan', 'shared_lan'</dd>

        RIRRsaYou must specify those options: 'network_id', 'reserved_network_name' and 'reserved_network_size's	networks/s/reserve_networkR^RERBtdescriptiontnetwork_sizetnetwork_familyRGtnetwork_locationtnetwork_addressR2i�i�R4N(R%RR&RtinttupdateR9(RRAtreserved_network_nametreserved_network_descriptiontreserved_network_sizetreserved_network_familytreserved_network_typetreserved_network_addressRR1tnetwork_infoR4((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pytreserve_networkas0$
		c	C`sFd}d}|dks$|dkr:|jjdd�nd}dt|�d}|j||�}|s�|jjdd||f�n|r�tj|�}xA|D]6}|dr�|dd	|kr�|dd
}Pq�q�Wnd}|r%d}dt|�}|j||dd
g�}n|jjdd||f�|S(sk
        Release the network with name 'released_network_name' from the given  supernet network_id
        RRs`You must specify those options 'network_id', 'reserved_network_name' and 'reserved_network_size'Rs	networks/s	/childrens= there is an error in releasing network %r  from network  %s.R<RBRAR#R2i�sT When release network , could not find the network   %r from the given superent %r' N(R%RR&RR9R	R?(	RRAtreleased_network_nametreleased_network_typeRR6tmatched_network_idR1t	child_net((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pytrelease_network�s8

cC`s�d}d}d}	|dks6|dks6|dkrL|jjdd�n|s[d}n|sjd}n|syd}ni|d6|d	6|d
6|d6|d6|d
6}
|jddd|ddgd|
�}	|	S(s�
        add a new LAN network into a given supernet Fusionlayer Infinity via rest api  or default supernet
        required fields=['network_name', 'network_family', 'network_type',  'network_address','network_size' ]
        RItnetworksRsTYou must specify  those options 'network_name', 'network_address' and 'network_size'R^REi����RBRcR`RaRGRbRR1R2i�R4N(R%RR&R9(RRBRcR`RaRGRbRR1R6R4((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pytadd_network�s.$
			
	N(t__name__t
__module__t__doc__RR%R9RDRHRRR\R]RmRrRt(((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pyR�s,	."2+'c(C`sNtdtdtdddt�dtdddt�dtdddtdt�d	tdd�d
tdd�dtdd�dtdd
dd�dtddddddddg�dtddddddddg�dtdd�dtdd�dtdddtdddddd d!d"d#g��d$ddgf�}|jd}|jd}|jd}|jd}|jd	}|jd
}|jd}|jd}|jd}	|jd}
|jd}|jd}t||||�}
d%}|d#krZ|rJ|
j|�}|s>d&}|jd'td(|�n|jd'td(|�qJn�|d kr�|rJ|rJ|
jd	|d
|�}|jd'td(|�qJn�|dkr�|
j	d	|d|�}|jd'td(|�ng|dkr |
j
d|d|	�}|jd'td(|�n*|dkr]|
jd	|d|�}|jd'td(|�n�|d"kr�|
jd	|d)|d*|d+|d,|	d-|
�}|jd'td(|�n�|d!kr�|
j
d	|d.|d/|	�}|jd'td(|�nU|dkrJ|
jd|d|d|
d|d|d|	�}|jd'td(|�ndS(0Nt
argument_specRR=RtrequiredRRtno_logRARURBRbRdtdefaulti����RaR^tchoicest6tdualRGREt
shared_lantsupernetRcR`tactionRtR]RDRHR\RrRmRRtrequired_togetherRs@There is an error in calling method of reserve_next_available_ipR!R"RfRhRiRjRkRnRo(RR/R*R3RRRR&R)R\R]RHRDRmRrRt(RRRRR�RAtreleased_ipRBRaRGRcR`Rbtmy_infinitytresult((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pytmain�s�$$











										t__main__N(t
__future__RRRR=t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNtansible.module_utils.basicRR	tansible.module_utils.urlsR
tobjectRR�Ru(((sO/usr/lib/python2.7/site-packages/ansible/modules/net_tools/infinity/infinity.pyt<module>s


K�S	`

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]