Removing name2int module
Module not widely used. Module usage should be replaced with string_2_int filter. Change-Id: I1b71275af47db50380965bbb8c899ae4d5aa439f Closes-Bug: #1826243
This commit is contained in:
parent
12c118f1e2
commit
5af0b9bcc3
|
@ -1,13 +0,0 @@
|
||||||
name2int
|
|
||||||
~~~~~~~~
|
|
||||||
|
|
||||||
Synopsis
|
|
||||||
--------
|
|
||||||
Hash a host name and return an integer.
|
|
||||||
|
|
||||||
Examples
|
|
||||||
--------
|
|
||||||
.. literalinclude:: ../../../library/name2int
|
|
||||||
:language: yaml
|
|
||||||
:start-after: EXAMPLES = """
|
|
||||||
:end-before: """
|
|
|
@ -1,79 +0,0 @@
|
||||||
#!/usr/bin/python
|
|
||||||
# (c) 2014, Kevin Carter <kevin.carter@rackspace.com>
|
|
||||||
#
|
|
||||||
# Copyright 2014, Rackspace US, Inc.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
|
|
||||||
import hashlib
|
|
||||||
import platform
|
|
||||||
|
|
||||||
# import module snippets
|
|
||||||
from ansible.module_utils.basic import *
|
|
||||||
|
|
||||||
DOCUMENTATION = """
|
|
||||||
---
|
|
||||||
module: name2int
|
|
||||||
version_added: "1.6.6"
|
|
||||||
short_description:
|
|
||||||
- hash a host name and return an integer
|
|
||||||
description:
|
|
||||||
- hash a host name and return an integer
|
|
||||||
options:
|
|
||||||
name:
|
|
||||||
description:
|
|
||||||
- login username
|
|
||||||
required: true
|
|
||||||
author: Kevin Carter
|
|
||||||
"""
|
|
||||||
|
|
||||||
EXAMPLES = """
|
|
||||||
# Create a new container
|
|
||||||
- name2int:
|
|
||||||
name: "Some-hostname.com"
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class HashHostname(object):
|
|
||||||
def __init__(self, module):
|
|
||||||
"""Generate an integer from a name."""
|
|
||||||
self.module = module
|
|
||||||
|
|
||||||
def return_hashed_host(self, name):
|
|
||||||
hashed_name = hashlib.md5(name).hexdigest()
|
|
||||||
hash_int = int(hashed_name, 32)
|
|
||||||
real_int = int(hash_int % 300)
|
|
||||||
return real_int
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
module = AnsibleModule(
|
|
||||||
argument_spec=dict(
|
|
||||||
name=dict(
|
|
||||||
required=True
|
|
||||||
)
|
|
||||||
),
|
|
||||||
supports_check_mode=False
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
sm = HashHostname(module=module)
|
|
||||||
int_value = sm.return_hashed_host(platform.node())
|
|
||||||
resp = {'int_value': int_value}
|
|
||||||
module.exit_json(changed=True, **resp)
|
|
||||||
except Exception as exp:
|
|
||||||
resp = {'stderr': exp}
|
|
||||||
module.fail_json(msg='Failed Process', **resp)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
Loading…
Reference in New Issue