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_interface.pyc

�
�Udac@`sTddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZddlm
Z
mZdd
lmZmZmZmZmZmZmZddlmZddlmZdZyddlZeZWn#e k
rej!�Ze"ZnXd�Z#d�Z$d�Z%d�Z&e'dkrPe#�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys:
---
module: netbox_interface
short_description: Creates or removes interfaces from Netbox
description:
  - Creates or removes interfaces 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)
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:
      device:
        description:
          - Name of the device the interface will be associated with (case-sensitive)
        required: true
        type: str
      name:
        description:
          - Name of the interface to be created
        required: true
        type: str
      form_factor:
        description:
          - |
            Form factor of the interface:
            ex. 1000Base-T (1GE), Virtual, 10GBASE-T (10GE)
            This has to be specified exactly as what is found within UI
        type: str
      enabled:
        description:
          - Sets whether interface shows enabled or disabled
        type: bool
      lag:
        description:
          - Parent LAG interface will be a member of
        type: dict
      mtu:
        description:
          - The MTU of the interface
        type: str
      mac_address:
        description:
          - The MAC address of the interface
        type: str
      mgmt_only:
        description:
          - This interface is used only for out-of-band management
        type: bool
      description:
        description:
          - The description of the prefix
        type: str
      mode:
        description:
          - The mode of the interface
        choices:
          - Access
          - Tagged
          - Tagged All
        type: str
      untagged_vlan:
        description:
          - The untagged VLAN to be assigned to interface
        type: dict
      tagged_vlans:
        description:
          - A list of tagged VLANS to be assigned to interface. Mode must be set to either C(Tagged) or C(Tagged All)
        type: list
      tags:
        description:
          - Any tags that the prefix may need to be associated with
        type: list
    required: true
  state:
    description:
      - Use C(present) or C(absent) for adding or removing.
    choices: [ absent, present ]
    default: present
    type: str
  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
s�
- name: "Test Netbox interface module"
  connection: local
  hosts: localhost
  gather_facts: False
  tasks:
    - name: Create interface within Netbox with only required information
      netbox_interface:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          device: test100
          name: GigabitEthernet1
        state: present
    - name: Delete interface within netbox
      netbox_interface:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          device: test100
          name: GigabitEthernet1
        state: absent
    - name: Create LAG with several specified options
      netbox_interface:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          device: test100
          name: port-channel1
          form_factor: Link Aggregation Group (LAG)
          mtu: 1600
          mgmt_only: false
          mode: Access
        state: present
    - name: Create interface and assign it to parent LAG
      netbox_interface:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          device: test100
          name: GigabitEthernet1
          enabled: false
          form_factor: 1000Base-t (1GE)
          lag:
            name: port-channel1
          mtu: 1600
          mgmt_only: false
          mode: Access
        state: present
    - name: Create interface as a trunk port
      netbox_interface:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          device: test100
          name: GigabitEthernet25
          enabled: false
          form_factor: 1000Base-t (1GE)
          untagged_vlan:
            name: Wireless
            site: Test Site
          tagged_vlans:
            - name: Data
              site: Test Site
            - name: VoIP
              site: Test Site
          mtu: 1600
          mgmt_only: true
          mode: Tagged
        state: present
s�
interface:
  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_objecttINTF_FORM_FACTORt	INTF_MODE(t	ipaddress(tto_textc
C`sutdtdddt�dtdddtdt�dtdddt�d	tdtd
dddd
g�dtddd
t��}td|dt�ats�tjdtd�dt�nd}d}tj	d}tj	d}tj	d}tj	d	}tj	d}yt
j|d|d|�}Wn!tk
rMtjdd�nXyt
||�}	Wn%tk
r�tjdd|�nXt
|	|�}
t|�}yQt||�}d|kr�tjt||
|��Stjt||
|��SWnyt
jk
r&}tjdtj|j��Stk
rK}tjdt|��Stk
rp}tjdt|��SXdS(s/
    Main entry point for module execution
    t
netbox_urlttypetstrtrequiredtnetbox_tokentno_logtdatatdicttstatetdefaulttpresenttchoicestabsenttvalidate_certstboolt
argument_spectsupports_check_modetmsgtpynetboxt	exceptiontdcimt
interfacesttokent
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_interface_presenttensure_interface_absenttRequestErrortjsontloadsterrort
ValueErrorR(
R"tapptendpointturlR)RRR tnbtnb_apptnb_endpointt	norm_datate((sU/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_interface.pytmain�sP!	






cC`sqt||�}|jd�r>tj|dj��|d<n|jd�rmtj|dj��|d<n|S(Ntform_factortmode(R
tgetRtlowerR(RBR((sU/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_interface.pyR6s  c	C`s+t|t�s't}i|d6|d6S|jd|dd|d�}t�}|s�t||tj�\}}t}d|d}n}t||tj�\}}|tkr�tj	dd|d�n|r�d|d}t}||d	<nd
|d}t}|j
i|d6|d6|d6�|S(s�
    :returns dict(interface, msg, changed): dictionary resulting of the request,
    where 'interface' is the serialized interface fetched or newly created in Netbox
    R$tchangedtnamet	device_idtdevicesInterface %s createds*Request failed, couldn't update device: %ssInterface %s updatedtdiffsInterface %s already existst	interface(t
isinstanceRR,RJRR-t
check_modeR+RR/tupdate(	RBRDRRLtnb_intftresulttintfRPR$((sU/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_interface.pyR8)s* 		
"c	C`s�|jd|dd|d�}t�}|rht|tj�\}}t}d|d}||d<nd|d}t}|ji|d6|d6�|S(	s+
    :returns dict(msg, changed, diff)
    RMRNROsInterface %s deletedRPsInterface %s already absentR$RL(RJRR
R-RSR+R,RT(	RBRDRRURVtdummyRPRLR$((sU/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_interface.pyR9Ks 	
t__main__((t
__future__RRRRt
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNR;t	tracebacktansible.module_utils.basicRR	t2ansible.module_utils.net_tools.netbox.netbox_utilsR
RRR
RRRtansible.module_utils.compatRtansible.module_utils._textRtNoneR0R%R+R.tImportErrort
format_excR,RGR6R8R9t__name__(((sU/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_interface.pyt<module>s4


jH4	


	9		"	

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