Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/net_tools/netbox/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_prefix.pyo

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZddlZddl
mZmZdd
lmZmZmZmZmZmZddlmZddlmZdZyddlZeZWn#e k
rej!�Ze"ZnXd�Z#e"d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*e+dkr}e#�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys

---
module: netbox_prefix
short_description: Creates or removes prefixes from Netbox
description:
  - Creates or removes prefixes from Netbox
notes:
  - Tags should be defined as a YAML list
  - This should be ran with connection C(local) and hosts C(localhost)
author:
  - Mikhail Yohman (@FragmentedPacket)
  - Anthony Ruhier (@Anthony25)
requirements:
  - pynetbox
version_added: '2.8'
options:
  netbox_url:
    description:
      - URL of the Netbox instance resolvable by Ansible control host
    required: true
    type: str
  netbox_token:
    description:
      - The token created within Netbox to authorize API access
    required: true
    type: str
  data:
    description:
      - Defines the prefix configuration
    suboptions:
      family:
        description:
          - Specifies which address family the prefix prefix belongs to
        choices:
          - 4
          - 6
        type: int
      prefix:
        description:
          - Required if state is C(present) and first_available is False. Will allocate or free this prefix.
        type: str
      parent:
        description:
          - Required if state is C(present) and first_available is C(yes). Will get a new available prefix in this parent prefix.
        type: str
      prefix_length:
        description:
          - |
            Required ONLY if state is C(present) and first_available is C(yes).
            Will get a new available prefix of the given prefix_length in this parent prefix.
        type: str
      site:
        description:
          - Site that prefix is associated with
        type: str
      vrf:
        description:
          - VRF that prefix is associated with
        type: str
      tenant:
        description:
          - The tenant that the prefix will be assigned to
        type: str
      vlan:
        description:
          - The VLAN the prefix will be assigned to
        type: dict
      status:
        description:
          - The status of the prefix
        choices:
          - Active
          - Container
          - Deprecated
          - Reserved
        type: str
      role:
        description:
          - The role of the prefix
        type: str
      is_pool:
        description:
          - All IP Addresses within this prefix are considered usable
        type: bool
      description:
        description:
          - The description of the prefix
        type: str
      tags:
        description:
          - Any tags that the prefix may need to be associated with
        type: list
      custom_fields:
        description:
          - Must exist in Netbox and in key/value format
        type: dict
    required: true
  state:
    description:
      - Use C(present) or C(absent) for adding or removing.
    choices: [ absent, present ]
    default: present
  first_available:
    description:
      - If C(yes) and state C(present), if an parent is given, it will get the
        first available prefix of the given prefix_length inside the given parent (and
        vrf, if given).
        Unused with state C(absent).
    default: 'no'
    type: bool
  validate_certs:
    description:
      - If C(no), SSL certificates will not be validated. This should only be used on personally controlled sites using self-signed certificates.
    default: "yes"
    type: bool
sG	
- name: "Test Netbox prefix module"
  connection: local
  hosts: localhost
  gather_facts: False

  tasks:
    - name: Create prefix within Netbox with only required information
      netbox_prefix:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          prefix: 10.156.0.0/19
        state: present

    - name: Delete prefix within netbox
      netbox_prefix:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          prefix: 10.156.0.0/19
        state: absent

    - name: Create prefix with several specified options
      netbox_prefix:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          family: 4
          prefix: 10.156.32.0/19
          site: Test Site
          vrf: Test VRF
          tenant: Test Tenant
          vlan:
            name: Test VLAN
            site: Test Site
            tenant: Test Tenant
            vlan_group: Test Vlan Group
          status: Reserved
          role: Network of care
          description: Test description
          is_pool: true
          tags:
            - Schnozzberry
        state: present

    - name: Get a new /24 inside 10.156.0.0/19 within Netbox - Parent doesn't exist
      netbox_prefix:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          parent: 10.156.0.0/19
          prefix_length: 24
        state: present
        first_available: yes

    - name: Create prefix within Netbox with only required information
      netbox_prefix:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          prefix: 10.156.0.0/19
        state: present

    - name: Get a new /24 inside 10.156.0.0/19 within Netbox
      netbox_prefix:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          parent: 10.156.0.0/19
          prefix_length: 24
        state: present
        first_available: yes

    - name: Get a new /24 inside 10.157.0.0/19 within Netbox with additional values
      netbox_prefix:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          parent: 10.157.0.0/19
          prefix_length: 24
          vrf: Test VRF
          site: Test Site
        state: present
        first_available: yes
s�
prefix:
  description: Serialized object as created or already existent within Netbox
  returned: on creation
  type: dict
msg:
  description: Message indicating failure or info about what has been achieved
  returned: always
  type: str
N(t
AnsibleModuletmissing_required_lib(tfind_idstnormalize_datatcreate_netbox_objecttdelete_netbox_objecttupdate_netbox_objectt
PREFIX_STATUS(t	ipaddress(tto_textcC`s�tdtdddt�dtdddtdt�dtdddt�d	tdtd
dddd
g�dtdddtd
t�dtddd
t��}td|dt�ats�tjdtd�dt�nd}d}tj	d}tj	d}tj	d}tj	d	}tj	d}tj	d}yt
j|d|d|�}	Wn!tk
rutjdd�nXyt
|	|�}
Wn%tk
r�tjdd|�nXt
|
|�}t|�}yTt|	|�}d|krtjt|	|||��Stjt|	||��SWnyt
jk
rQ}
tjdtj|
j��Stk
rv}
tjdt|
��Stk
r�}
tjdt|
��SXdS(s/
    Main entry point for module execution
    t
netbox_urlttypetstrtrequiredtnetbox_tokentno_logtdatatdicttstatetdefaulttpresenttchoicestabsenttfirst_availabletbooltvalidate_certst
argument_spectsupports_check_modetmsgtpynetboxt	exceptiontipamtprefixesttokent
ssl_verifys,Failed to establish connection to Netbox APIs#Incorrect application specified: %sN(RtTruetFalseRtmoduletHAS_PYNETBOXt	fail_jsonR	tPYNETBOX_IMP_ERRtparamsR%tapit	ExceptiontgetattrtAttributeErrorRt_check_and_adapt_datat	exit_jsontensure_prefix_presenttensure_prefix_absenttRequestErrortjsontloadsterrort
ValueErrorR(R"tapptendpointturlR)RRRR!tnbtnb_apptnb_endpointt	norm_datate((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_prefix.pytmain�sT!	







	cC`s�t|t�s't}i|d6|d6S|rjx-d	D]%}||kr4td|��q4q4Wt||�Sd|kr�td��nt||�SdS(
s�
    :returns dict(prefix, msg, changed): dictionary resulting of the request,
    where 'prefix' is the serialized device fetched or newly created in Netbox
    R$tchangedtparentt
prefix_lengths%'%s' is required with first_availabletprefixs,'prefix' is required without first_availableN(RIRJ(t
isinstanceRR,R>tget_new_available_prefixtget_or_create_prefix(RBRDRRRHtk((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_prefix.pyR8;s

cC`s|t||�}|jd�rIt|dt�rItd|d��n|jd�rxtj|dj��|d<n|S(Ntvrfs%%s does not exist - Please create VRFR(R
tgetRLtintR>Rtlower(RBR((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_prefix.pyR6Qs# cC`s�|jd�r%tj|d�}n%|jd�rJtj|d�}nt|j�}|j}|jd�r�t|dt�s�td|d��q�|jd|d|d|d�}n|jd|d|dd�}|S(	NRKRIRPs%%s does not exist - Please create VRFtqtmask_lengthtvrf_idtnull(	RQRt
ip_networkRtnetwork_addresst	prefixlenRLRRR>(RDRRKtnetworktmask((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_prefix.pyt_search_prefix_s	%cC`s=t}|jd�r'idd6|d6Sidd6|d6SdS(NRPsReturned more than one resultR$RHs3Returned more than one result - Try specifying VRF.(R,RQ(RRH((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_prefix.pyt_error_multiple_prefix_resultssscC`syt||�}Wntk
r-t|�SXt�}|syt||tj�\}}t}d|d}||d<n}t||tj�\}}|t	kr�tj
dd|d�n|r�d|d}t}||d<nd|d}t	}|ji|d6|d6|d6�|S(	NsPrefix %s createdRKtdiffR$s*Request failed, couldn't update prefix: %ssPrefix %s updatedsPrefix %s already existsRH(R]R>R^RRR-t
check_modeR+RR,R/tupdate(RDRt	nb_prefixtresultRKR_RHR$((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_prefix.pyRNs,
	
	
"cC`s�yt||�}Wntk
r-t|�SXt�}|sct}d|d}i|d6|d6S|jj�r�t|j|tj	�\}}t
}d|d}||d<nt}d|d}|ji|d6|d6|d6�|S(	Ns Parent prefix does not exist: %sRIR$RHsPrefix %s createdRKR_sNo available prefixes within %s(R]R>R^RR,tavailable_prefixestlistRR-R`R+Ra(RDRt
parent_prefixRcRHR$RKR_((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_prefix.pyRM�s$
	
"c	C`s�yt||�}Wntk
r-t|�SXt�}|rut|tj�\}}t}d|j}||d<nd|d}t	}|j
i|d6|d6�|S(s%
    :returns dict(msg, changed)
    sPrefix %s deletedR_sPrefix %s already absentRKR$RH(R]R>R^RR
R-R`R+RKR,Ra(	RBRDRRbRctdummyR_RHR$((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_prefix.pyR9�s
	

t__main__(,t
__future__RRRRt
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNR;t	tracebacktretansible.module_utils.basicRR	t2ansible.module_utils.net_tools.netbox.netbox_utilsR
RRR
RRtansible.module_utils.compatRtansible.module_utils._textRtNoneR0R%R+R.tImportErrort
format_excR,RGR8R6R]R^RNRMR9t__name__(((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_prefix.pyt<module>s>


uW.


	<						

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