mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 12:33:59 -07:00
[PR #10063/6a40d459 backport][stable-10] Add connection_timeout option to cobbler inventory (#10095)
Some checks failed
EOL CI / EOL Sanity (Ⓐ2.15) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py2.7) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py3.10) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py3.5) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/3/) (push) Has been cancelled
nox / Run extra sanity tests (push) Has been cancelled
Some checks failed
EOL CI / EOL Sanity (Ⓐ2.15) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py2.7) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py3.10) (push) Has been cancelled
EOL CI / EOL Units (Ⓐ2.15+py3.5) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+alpine3+py:azp/posix/3/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/1/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/2/) (push) Has been cancelled
EOL CI / EOL I (Ⓐ2.15+fedora37+py:azp/posix/3/) (push) Has been cancelled
nox / Run extra sanity tests (push) Has been cancelled
Add connection_timeout option to cobbler inventory (#10063)
Signed-off-by: Orion Poplawski <orion@nwra.com>
(cherry picked from commit 6a40d459b5
)
Co-authored-by: Orion Poplawski <orion@nwra.com>
This commit is contained in:
parent
3e5d58129d
commit
14e2dd4cea
2 changed files with 25 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- cobbler inventory plugin - add ``connection_timeout`` option to specify the connection timeout to the cobbler server (https://github.com/ansible-collections/community.general/pull/11063).
|
|
@ -45,6 +45,11 @@ DOCUMENTATION = '''
|
||||||
description: Fallback to cached results if connection to cobbler fails.
|
description: Fallback to cached results if connection to cobbler fails.
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
connection_timeout:
|
||||||
|
description: Timeout to connect to cobbler server.
|
||||||
|
type: int
|
||||||
|
required: false
|
||||||
|
version_added: 10.7.0
|
||||||
exclude_mgmt_classes:
|
exclude_mgmt_classes:
|
||||||
description: Management classes to exclude from inventory.
|
description: Management classes to exclude from inventory.
|
||||||
type: list
|
type: list
|
||||||
|
@ -142,6 +147,18 @@ except ImportError:
|
||||||
HAS_XMLRPC_CLIENT = False
|
HAS_XMLRPC_CLIENT = False
|
||||||
|
|
||||||
|
|
||||||
|
class TimeoutTransport (xmlrpc_client.SafeTransport):
|
||||||
|
def __init__(self, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
|
||||||
|
super(TimeoutTransport, self).__init__()
|
||||||
|
self._timeout = timeout
|
||||||
|
self.context = None
|
||||||
|
|
||||||
|
def make_connection(self, host):
|
||||||
|
conn = xmlrpc_client.SafeTransport.make_connection(self, host)
|
||||||
|
conn.timeout = self._timeout
|
||||||
|
return conn
|
||||||
|
|
||||||
|
|
||||||
class InventoryModule(BaseInventoryPlugin, Cacheable):
|
class InventoryModule(BaseInventoryPlugin, Cacheable):
|
||||||
''' Host inventory parser for ansible using cobbler as source. '''
|
''' Host inventory parser for ansible using cobbler as source. '''
|
||||||
|
|
||||||
|
@ -235,7 +252,12 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
|
||||||
# get connection host
|
# get connection host
|
||||||
self.cobbler_url = self.get_option('url')
|
self.cobbler_url = self.get_option('url')
|
||||||
self.display.vvvv(f'Connecting to {self.cobbler_url}\n')
|
self.display.vvvv(f'Connecting to {self.cobbler_url}\n')
|
||||||
self.cobbler = xmlrpc_client.Server(self.cobbler_url, allow_none=True)
|
|
||||||
|
if 'connection_timeout' in self._options:
|
||||||
|
self.cobbler = xmlrpc_client.Server(self.cobbler_url, allow_none=True,
|
||||||
|
transport=TimeoutTransport(timeout=self.get_option('connection_timeout')))
|
||||||
|
else:
|
||||||
|
self.cobbler = xmlrpc_client.Server(self.cobbler_url, allow_none=True)
|
||||||
self.token = None
|
self.token = None
|
||||||
if self.get_option('user') is not None:
|
if self.get_option('user') is not None:
|
||||||
self.token = self.cobbler.login(text_type(self.get_option('user')), text_type(self.get_option('password')))
|
self.token = self.cobbler.login(text_type(self.get_option('user')), text_type(self.get_option('password')))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue