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_device.pyo

�
�Udac@`s4ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZddlm
Z
mZdd
lmZmZmZmZmZmZmZdZyddlZeZWn#ek
r�ej�ZeZnXd�Zd�Z d�Z!d�Z"e#dkr0e�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys�

---
module: netbox_device
short_description: Create, update or delete devices within Netbox
description:
  - Creates, updates or removes devices 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)
  - David Gomez (@amb1s1)
requirements:
  - pynetbox
version_added: '2.8'
options:
  netbox_url:
    description:
      - URL of the Netbox instance resolvable by Ansible control host
    required: true
  netbox_token:
    description:
      - The token created within Netbox to authorize API access
    required: true
  data:
    description:
      - Defines the device configuration
    suboptions:
      name:
        description:
          - The name of the device
        required: true
      device_type:
        description:
          - Required if I(state=present) and the device does not exist yet
      device_role:
        description:
          - Required if I(state=present) and the device does not exist yet
      tenant:
        description:
          - The tenant that the device will be assigned to
      platform:
        description:
          - The platform of the device
      serial:
        description:
          - Serial number of the device
      asset_tag:
        description:
          - Asset tag that is associated to the device
      site:
        description:
          - Required if I(state=present) and the device does not exist yet
      rack:
        description:
          - The name of the rack to assign the device to
      position:
        description:
          - The position of the device in the rack defined above
      face:
        description:
          - Required if I(rack) is defined
      status:
        description:
          - The status of the device
        choices:
          - Active
          - Offline
          - Planned
          - Staged
          - Failed
          - Inventory
      cluster:
        description:
          - Cluster that the device will be assigned to
      comments:
        description:
          - Comments that may include additional information in regards to the device
      tags:
        description:
          - Any tags that the device may need to be associated with
      custom_fields:
        description:
          - must exist in Netbox
    required: true
  state:
    description:
      - Use C(present) or C(absent) for adding or removing.
    choices: [ absent, present ]
    default: present
  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 modules"
  connection: local
  hosts: localhost
  gather_facts: False

  tasks:
    - name: Create device within Netbox with only required information
      netbox_device:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          name: Test Device
          device_type: C9410R
          device_role: Core Switch
          site: Main
        state: present

    - name: Delete device within netbox
      netbox_device:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          name: Test Device
        state: absent

    - name: Create device with tags
      netbox_device:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          name: Another Test Device
          device_type: C9410R
          device_role: Core Switch
          site: Main
          tags:
            - Schnozzberry
        state: present

    - name: Update the rack and position of an existing device
      netbox_device:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          name: Test Device
          rack: Test Rack
          position: 10
          face: Front
        state: present
s
device:
  description: Serialized object as created or already existent within Netbox
  returned: success (when I(state=present))
  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
DEVICE_STATUStFACE_IDcC`sitdtdddt�dtdddtdt�dtdddt�d	tdtd
dddd
g�dtddd
t��}td|dt�ats�tjdtd�dt�ntj	dj
d�s�tjdd�nd}d}tj	d}tj	d}tj	d}tj	d	}tj	d}ytj|d|d|�}Wn!t
k
rvtjdd�nXyt||�}	Wn%tk
r�tjdd|�nXt|	|�}
t|�}yAd|kr�t||
|�}nt|
|�}tj|�SWnTtjk
r?}
tjdtj|
j��Stk
rd}
tjdt|
��SXdS(s/
    Main entry point for module execution
    t
netbox_urlttypetstrtrequiredtnetbox_tokentno_logtdatatdicttstatetdefaulttpresenttchoicestabsenttvalidate_certstboolt
argument_spectsupports_check_modetmsgtpynetboxt	exceptiontnamesmissing device nametdcimtdevicesttokent
ssl_verifys,Failed to establish connection to Netbox APIs#Incorrect application specified: %sN(RtTruetFalseRtmoduletHAS_PYNETBOXt	fail_jsonR	tPYNETBOX_IMP_ERRtparamstgetR#tapit	ExceptiontgetattrtAttributeErrorRtensure_device_presenttensure_device_absentt	exit_jsontRequestErrortjsontloadsterrort
ValueErrorR(R tapptendpointturlR(RRRtnbtnb_apptnb_endpointt	norm_datatresultte((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_device.pytmain�sL!	






cC`sk|jd�r/tj|dj��|d<n|jd�r^tj|dj��|d<nt||�S(NRtface(R1RtlowerRR
(RAR((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_device.pyt	_find_ids�s
  c
C`st||�}|jd|d�}i}|smt||tj�\}}d|d}t}	||d<n}t||tj�\}}|tkr�tjdd|d�n|r�d|d}t}	||d<nd|d}t}	|j	i|d6|	d	6|d6�|S(
s�
    :returns dict(device, msg, changed, diff): dictionary resulting of the request,
        where `device` is the serialized device fetched or newly created in
        Netbox
    R%sDevice %s createdtdiffR"s*Request failed, couldn't update device: %ssDevice %s updatedsDevice %s already existstdevicetchanged(
RJR1RR,t
check_modeR*RR+R.tupdate(
RARCtnormalized_dataRt	nb_deviceRERLRKR"RM((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_device.pyR6s(
	
"cC`s�|jd|d�}i}|r[t|tj�\}}d|d}t}||d<nd|d}t}|ji|d6|d6�|S(s+
    :returns dict(msg, changed, diff)
    R%sDevice %s deletedRKsDevice %s already absentRMR"(R1R
R,RNR*R+RO(RCRRQREtdummyRKR"RM((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_device.pyR7$s
t__main__($t
__future__RRRRt
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNR:t	tracebacktansible.module_utils.basicRR	t2ansible.module_utils.net_tools.netbox.netbox_utilsR
RRR
RRRtNoneR/R#R*R-tImportErrort
format_excR+RGRJR6R7t__name__(((sR/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_device.pyt<module>s0


a34



	9			

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