
    VhZ,                     4   d dl mZmZmZ eZdZdZdZd dl	Z	d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ  ed7i ddddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d,d-d-d.d.d/d/d0d1d2d3Zd4 Zd5 Zed6k(  r e        yy)8    )absolute_importdivisionprint_functiona0  
module: cobbler_system
short_description: Manage system objects in Cobbler
description:
  - Add, modify or remove systems in Cobbler.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: full
options:
  host:
    description:
      - The name or IP address of the Cobbler system.
    default: 127.0.0.1
    type: str
  port:
    description:
      - Port number to be used for REST connection.
      - The default value depends on parameter O(use_ssl).
    type: int
  username:
    description:
      - The username to log in to Cobbler.
    default: cobbler
    type: str
  password:
    description:
      - The password to log in to Cobbler.
    type: str
  use_ssl:
    description:
      - If V(false), an HTTP connection will be used instead of the default HTTPS connection.
    type: bool
    default: true
  validate_certs:
    description:
      - If V(false), SSL certificates will not be validated.
      - This should only set to V(false) when used on personally controlled sites using self-signed certificates.
    type: bool
    default: true
  name:
    description:
      - The system name to manage.
    type: str
  properties:
    description:
      - A dictionary with system properties.
    type: dict
  interfaces:
    description:
      - A list of dictionaries containing interface options.
    type: dict
  sync:
    description:
      - Sync on changes.
      - Concurrently syncing Cobbler is bound to fail.
    type: bool
    default: false
  state:
    description:
      - Whether the system should be present, absent or a query is made.
    choices: [absent, present, query]
    default: present
    type: str
author:
  - Dag Wieers (@dagwieers)
notes:
  - Concurrently syncing Cobbler is bound to fail with weird errors.
  - On Python 2.7.8 and older (such as RHEL7) you may need to tweak the Python behaviour to disable certificate validation.
    More information at L(Certificate verification in Python standard library HTTP clients,https://access.redhat.com/articles/2039753).
a  
- name: Ensure the system exists in Cobbler
  community.general.cobbler_system:
    host: cobbler01
    username: cobbler
    password: MySuperSecureP4sswOrd
    name: myhost
    properties:
      profile: CentOS6-x86_64
      name_servers: [2.3.4.5, 3.4.5.6]
      name_servers_search: foo.com, bar.com
    interfaces:
      eth0:
        macaddress: 00:01:02:03:04:05
        ipaddress: 1.2.3.4
  delegate_to: localhost

- name: Enable network boot in Cobbler
  community.general.cobbler_system:
    host: bdsol-aci-cobbler-01
    username: cobbler
    password: ins3965!
    name: bdsol-aci51-apic1.cisco.com
    properties:
      netboot_enabled: true
    state: present
  delegate_to: localhost

- name: Query all systems in Cobbler
  community.general.cobbler_system:
    host: cobbler01
    username: cobbler
    password: MySuperSecureP4sswOrd
    state: query
  register: cobbler_systems
  delegate_to: localhost

- name: Query a specific system in Cobbler
  community.general.cobbler_system:
    host: cobbler01
    username: cobbler
    password: MySuperSecureP4sswOrd
    name: '{{ inventory_hostname }}'
    state: query
  register: cobbler_properties
  delegate_to: localhost

- name: Ensure the system does not exist in Cobbler
  community.general.cobbler_system:
    host: cobbler01
    username: cobbler
    password: MySuperSecureP4sswOrd
    name: myhost
    state: absent
  delegate_to: localhost
z
systems:
  description: List of systems.
  returned: O(state=query) and O(name) is not provided
  type: list
system:
  description: (Resulting) information about the system we are working with.
  returned: when O(name) is provided
  type: dict
N)AnsibleModule)	iteritems)xmlrpc_client)to_text)now)LooseVersionbondingoptsbonding_opts
bridgeoptsbridge_optsconnected_modecnamesdhcptagdhcp_tagdnsnamedns_name	ifgateway
if_gatewayinterfacetypeinterface_typeinterfacemasterinterface_master	ipaddress
ip_addressipv6addressipv6_addressipv6defaultgatewayipv6_default_gatewayipv6mtuipv6_mtu
ipv6prefixipv6_prefixipv6secondariesipv6_secondariesuipv6staticroutesipv6_static_routes
macaddressmac_address
managementmtunetmaskstaticstaticroutesstatic_routes
virtbridgevirt_bridgec                 d    t               }|r#| j                  t        |      |      }|r|d   }|S )N)namer   )dictfind_system)connr5   tokensystemsystemss        t/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/cobbler_system.py	getsystemr=      s3    VF""4T?E:QZFM    c                     t        t        t        dd      t        d      t        dd      t        dd      t        d	d      t        d	d      t        d      t        d
      t        d
      t        d	d      t        ddg d            d      } | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }|rdnd| j                  d<   |s|rdnd| j                  d<   t        d      }t               }	d }
|s.	 t	        j
                         }
t        j
                  t        _         dj                  d7i | j                  }|
rt        j                  ||
      }nt        j                  |      }	 |j                  ||      }t#        ||      }|d$k(  r|r||d%<   n[|j%                         |d&<   nF|dk(  r|rd'}t'        t)        |j+                                     t'        d(      k\  r|j-                  |      }n|j-                  ||      }t/        | j                  d)         D ]L  \  }}||vr | j1                  d*j                  |             ||   |k7  s3	 |j3                  ||||       d|d+<   N nn|j5                  |      }|j3                  |d||       d|d+<   | j                  d)   r5t/        | j                  d)         D ]  \  }}	 |j3                  ||||        t               }| j                  d-   rt/        | j                  d-         D ]w  \  }}t/        |      D ]d  \  }}|dk(  r|t6        vr | j1                  d*j                  |             |r|d-   |   t6        |      |k7  rd|d+<   ||d.j                  ||      <   f y |d+   du r|j3                  |d/||       | j8                  sB|d+   r=|j;                  ||       n*|d0k(  r%|r#| j8                  s|j=                  ||       d|d+<   | j8                  s&| j                  d1   r|d+   r	 |j?                  |       |d3v r/t#        |||      |d%<   | j@                  rt        ||d%   4      |d5<   t               |	z
  } | jB                  d7d6|jD                  i| y # t        $ r Y qw xY w# t        j                  $ rC}| j                   d j                  d7|t        |      d!| j                  "       Y d }~hd }~wt         $ rC}| j                   d#j                  d7|t        |      d!| j                  "       Y d }~d }~ww xY w# t         $ r.}| j                  d,j                  |||      "       Y d }~Hd }~ww xY w# t         $ r.}| j                  d,j                  |||      "       Y d }~d }~ww xY w# t         $ r5}| j                  d2j                  t        |            "       Y d }~d }~ww xY w)8Nstrz	127.0.0.1)typedefaultint)rA   cobblerT)rA   no_logboolr6   Fpresent)absentrG   query)rA   rB   choices)hostportusernamepassworduse_sslvalidate_certsr5   
interfaces
propertiessyncstate)argument_specsupports_check_moderM   rN   rL   rO   rP   r5   rT   httpshttpproto44380)changedz#{proto}://{host}:{port}/cobbler_api)contextz<Failed to log in to Cobbler '{url}' as '{username}'. {error})urlerror)msgz%Connection to '{url}' failed. {error}rI   r:   r;    z3.4rR   z.Property '{0}' is not a valid system property.r\   z$Unable to change '{0}' to '{1}'. {2}rQ   z{0}-{1}modify_interfacerH   rS   zFailed to sync Cobbler. {0})rH   rG   )beforeafterdiffelapsed )#r   r6   paramsr
   ssl_create_unverified_context_create_default_https_contextAttributeErrorformatr   ServerProxyServerloginFault	fail_jsonr	   	Exceptionr=   get_systemsr   r@   versionget_system_handler   warnmodify_system
new_systemIFPROPS_MAPPING
check_modesave_systemremove_systemrS   _diff	exit_jsonseconds)modulerM   rN   rL   rO   rP   r5   rT   resultstartssl_contextr^   r8   r9   er:   	system_idkeyvalueinterface_propertiesdevicevaluesrf   s                          r<   mainr      sW   5+65!ui8uT2fd3VT:5!((651E9>\]
 !F" }}Z(H}}Z(H== DmmI&G]]#34N== DMM'"E(/WVFMM')0dfF EEK	O88:K 140N0NC-
6
/
6
6
G
GC((kB##C(y

8X. tT5)F %F8 !% 0 0 2F9	)	IC/0L4GG 2248	 224?	'l(CD k
Uf$KK P W WX[ \]#;%'k**9c5%H,0y)k .Iy&$> $F9}}\*"+FMM,,G"H kJCk**9c5%Hk  $v==&"+FMM,,G"H P"+F"3 PJCf} /1$T$[$[\_$`a!VL%9&%A/RUBV%W[`%`,0y)JO()9)9#v)FGPP i D(""9.@BVX]^   VI%6Y.	(	$$""4/ $F9v!66);L	SIIe %%$T47x<<!vh7GHF6NeemGF7W__77W  		  Pb[bb  Ogjryz{r|  O  AG  AN  AN  O  	P  	P yKDKKwPS[bcd[ewioivivwxxyD % k((-S-Z-Z[^`egh-i(jjk % k((-S-Z-Z[^`egh-i(jjkB  	S!>!E!Egaj!QRR	Ss~   S ?S( )VW(W? 	S%$S%(V;8T99V8VV	W#V==W	W<#W77W<?	X=*X88X=__main__rg   )
__future__r   r   r   rA   __metaclass__DOCUMENTATIONEXAMPLESRETURNri   ansible.module_utils.basicr   ansible.module_utils.sixr   ansible.module_utils.six.movesr   +ansible.module_utils.common.text.convertersr	   Cansible_collections.community.general.plugins.module_utils.datetimer
   Bansible_collections.community.general.plugins.module_utils.versionr   r6   rz   r=   r   __name__rg   r>   r<   <module>r      sS   A @IV7r	
  4 . 8 ? \  $ 	
    # '   .   (  *!" #$ %& 	'( )* +, !-. /6T8n zF r>   