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

�
�Udac@`sNddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZddlm
Z
mZdd
lmZmZmZmZmZmZddlmZddlmZdZyddlZeZWn#ek
rej �Ze!ZnXd�Z"d�Z#d�Z$d�Z%e&dkrJe"�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bys�
---
module: netbox_site
short_description: Creates or removes sites from Netbox
description:
  - Creates or removes sites 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 site configuration
    suboptions:
      name:
        description:
          - Name of the site to be created
        required: true
        type: str
      status:
        description:
          - Status of the site
        choices:
          - Active
          - Planned
          - Retired
        type: str
      region:
        description:
          - The region that the site should be associated with
        type: str
      tenant:
        description:
          - The tenant the site will be assigned to
        type: str
      facility:
        description:
          - Data center provider or facility, ex. Equinix NY7
        type: str
      asn:
        description:
          - The ASN associated with the site
        type: int
      time_zone:
        description:
          - Timezone associated with the site, ex. America/Denver
        type: str
      description:
        description:
          - The description of the prefix
        type: str
      physical_address:
        description:
          - Physical address of site
        type: str
      shipping_address:
        description:
          - Shipping address of site
        type: str
      latitude:
        description:
          - Latitude in decimal format
        type: int
      longitude:
        description:
          - Longitude in decimal format
        type: int
      contact_name:
        description:
          - Name of contact for site
        type: str
      contact_phone:
        description:
          - Contact phone number for site
        type: str
      contact_email:
        description:
          - Contact email for site
        type: str
      comments:
        description:
          - Comments for the site. This can be markdown syntax
        type: str
      tags:
        description:
          - Any tags that the prefix may need to be associated with
        type: list
      custom_fields:
        description:
          - must exist in Netbox
        type: dict
    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 site module"
  connection: local
  hosts: localhost
  gather_facts: False
  tasks:
    - name: Create site within Netbox with only required information
      netbox_site:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          name: Test - Colorado
        state: present

    - name: Delete site within netbox
      netbox_site:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          name: Test - Colorado
        state: absent

    - name: Create site with all parameters
      netbox_site:
        netbox_url: http://netbox.local
        netbox_token: thisIsMyToken
        data:
          name: Test - California
          status: Planned
          region: Test Region
          tenant: Test Tenant
          facility: EquinoxCA7
          asn: 65001
          time_zone: America/Los Angeles
          description: This is a test description
          physical_address: Hollywood, CA, 90210
          shipping_address: Hollywood, CA, 90210
          latitude: 10.100000
          longitude: 12.200000
          contact_name: Jenny
          contact_phone: 867-5309
          contact_email: [email protected]
          comments: ### Placeholder
        state: present
s�
site:
  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_objecttSITE_STATUS(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	exceptiontdcimtsitesttokent
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_site_presenttensure_site_absenttRequestErrortjsontloadsterrort
ValueErrorR(
R!tapptendpointturlR(RRRtnbtnb_apptnb_endpointt	norm_datate((sP/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_site.pytmain�sP!	






cC`s�t||�}|jd�r>tj|dj��|d<nd|dkrm|djdd�j�}n?d|dkr�|djdd�j�}n|dj�}||d<|S(NRt-tnamet ttslug(R
tgetRtlowertreplace(RARt	site_slug((sP/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_site.pyR5s 
c	C`s+t|t�s't}i|d6|d6S|jd|d�}t�}|s�t||tj�\}}t}d|d}||d<n}t||tj�\}}|tkr�tj	dd|d�n|r�d|d}t}||d<nd	|d}t}|j
i|d
6|d6|d6�|S(s�
    :returns dict(interface, msg, changed): dictionary resulting of the request,
    where 'site' is the serialized interface fetched or newly created in Netbox
    R#tchangedRKsSite %s createdRHtdiffs*Request failed, couldn't update device: %ssSite %s updatedsSite %s already existstsite(t
isinstanceRR+RLRR,t
check_modeR*RR.tupdate(	RARCRRPtnb_sitetresultRRRQR#((sP/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_site.pyR7%s,	
	
"c	C`s�|jd|d�}t�}|r^t|tj�\}}t}d|d}||d<nd|d}t}|ji|d6|d6�|S(s%
    :returns dict(msg, changed)
    RKsSite %s deletedRHRQsSite %s already absentR#RP(RLRR
R,RTR*R+RU(	RARCRRVRWtdummyRQRPR#((sP/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_site.pyR8Hs	
t__main__('t
__future__RRRRt
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNR:t	tracebacktansible.module_utils.basicRR	t2ansible.module_utils.net_tools.netbox.netbox_utilsR
RRR
RRtansible.module_utils.compatRtansible.module_utils._textRtNoneR/R$R*R-tImportErrort
format_excR+RFR5R7R8t__name__(((sP/usr/lib/python2.7/site-packages/ansible/modules/net_tools/netbox/netbox_site.pyt<module>s4


z..


	9		#	

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