Finish up cleanups to modules:
* Add python>= 2.6 to documented requirements when a module's deps need python>= 2.6 so we know when a module can use python2.6+ syntax * Remove BabyJSON usage * Change modules to use if __name__ == '__main__' so that they can potentially be unittested The BabJSON changes Fixes #1211
This commit is contained in:
parent
60a66a544d
commit
1f99382dfb
17 changed files with 157 additions and 49 deletions
|
@ -19,15 +19,16 @@
|
|||
|
||||
import operator
|
||||
import os
|
||||
import time
|
||||
|
||||
try:
|
||||
from novaclient.v1_1 import client as nova_client
|
||||
from novaclient.v1_1 import floating_ips
|
||||
from novaclient import exceptions
|
||||
from novaclient import utils
|
||||
import time
|
||||
HAS_NOVACLIENT = True
|
||||
except ImportError:
|
||||
print("failed=True msg='novaclient is required for this module'")
|
||||
HAS_NOVACLIENT = False
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
|
@ -175,7 +176,9 @@ options:
|
|||
required: false
|
||||
default: None
|
||||
version_added: "1.9"
|
||||
requirements: ["novaclient"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "python-novaclient"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -563,6 +566,9 @@ def main():
|
|||
],
|
||||
)
|
||||
|
||||
if not HAS_NOVACLIENT:
|
||||
module.fail_json(msg='python-novaclient is required for this module')
|
||||
|
||||
nova = nova_client.Client(module.params['login_username'],
|
||||
module.params['login_password'],
|
||||
module.params['login_tenant_name'],
|
||||
|
@ -589,4 +595,5 @@ def main():
|
|||
# this is magic, see lib/ansible/module_common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -22,8 +22,9 @@ try:
|
|||
except ImportError:
|
||||
from quantumclient.quantum import client
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
HAVE_DEPS = True
|
||||
except ImportError:
|
||||
print("failed=True msg='quantumclient (or neutronclient) and keystoneclient are required'")
|
||||
HAVE_DEPS = False
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
|
@ -115,7 +116,10 @@ options:
|
|||
- From the subnet pool the last IP that should be assigned to the virtual machines
|
||||
required: false
|
||||
default: None
|
||||
requirements: ["quantumclient", "neutronclient", "keystoneclient"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "python-neutronclient or python-quantumclient"
|
||||
- "python-keystoneclient"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -268,6 +272,9 @@ def main():
|
|||
allocation_pool_end = dict(default=None),
|
||||
))
|
||||
module = AnsibleModule(argument_spec=argument_spec)
|
||||
if not HAVE_DEPS:
|
||||
module.fail_json(msg='python-keystoneclient and either python-neutronclient or python-quantumclient are required')
|
||||
|
||||
neutron = _get_neutron_client(module, module.params)
|
||||
_set_tenant_id(module)
|
||||
if module.params['state'] == 'present':
|
||||
|
@ -288,5 +295,6 @@ def main():
|
|||
# this is magic, see lib/ansible/module.params['common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -111,7 +111,10 @@ options:
|
|||
required: false
|
||||
default: publicURL
|
||||
version_added: "1.7"
|
||||
requirements: ["glanceclient", "keystoneclient"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "python-glanceclient"
|
||||
- "python-keystoneclient"
|
||||
|
||||
'''
|
||||
|
||||
|
@ -130,9 +133,14 @@ EXAMPLES = '''
|
|||
import time
|
||||
try:
|
||||
import glanceclient
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
HAS_GLANCECLIENT = True
|
||||
except ImportError:
|
||||
print("failed=True msg='glanceclient and keystone client are required'")
|
||||
HAS_GLANCECLIENT = False
|
||||
try:
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
HAS_KEYSTONECLIENT = True
|
||||
except ImportError:
|
||||
HAS_KEYSTONECLIENT= False
|
||||
|
||||
|
||||
def _get_ksclient(module, kwargs):
|
||||
|
@ -237,6 +245,12 @@ def main():
|
|||
argument_spec=argument_spec,
|
||||
mutually_exclusive = [['file','copy_from']],
|
||||
)
|
||||
|
||||
if not HAVE_GLANCECLIENT:
|
||||
module.fail_json(msg='python-glanceclient is required for this module')
|
||||
if not HAVE_KEYSTONECLIENT:
|
||||
module.fail_json(msg='python-keystoneclient is required for this module')
|
||||
|
||||
if module.params['state'] == 'present':
|
||||
if not module.params['file'] and not module.params['copy_from']:
|
||||
module.fail_json(msg="Either file or copy_from variable should be set to create the image")
|
||||
|
@ -257,4 +271,5 @@ def main():
|
|||
# this is magic, see lib/ansible/module_common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -72,7 +72,9 @@ options:
|
|||
- Indicate desired state of the resource
|
||||
choices: ['present', 'absent']
|
||||
default: present
|
||||
requirements: [ python-keystoneclient ]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- python-keystoneclient
|
||||
author: Lorin Hochstein
|
||||
'''
|
||||
|
||||
|
|
|
@ -17,12 +17,13 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import time
|
||||
try:
|
||||
from novaclient.v1_1 import client as nova_client
|
||||
from novaclient import exceptions as exc
|
||||
import time
|
||||
HAS_NOVACLIENT = True
|
||||
except ImportError:
|
||||
print("failed=True msg='novaclient is required for this module to work'")
|
||||
HAS_NOVACLIENT = False
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
|
@ -73,7 +74,9 @@ options:
|
|||
required: false
|
||||
default: None
|
||||
|
||||
requirements: ["novaclient"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "python-novaclient"
|
||||
'''
|
||||
EXAMPLES = '''
|
||||
# Creates a key pair with the running users public key
|
||||
|
@ -94,6 +97,8 @@ def main():
|
|||
state = dict(default='present', choices=['absent', 'present'])
|
||||
))
|
||||
module = AnsibleModule(argument_spec=argument_spec)
|
||||
if not HAVE_NOVACLIENT:
|
||||
module.fail_json(msg='python-novaclient is required for this module to work')
|
||||
|
||||
nova = nova_client.Client(module.params['login_username'],
|
||||
module.params['login_password'],
|
||||
|
@ -135,5 +140,6 @@ def main():
|
|||
# this is magic, see lib/ansible/module.params['common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -28,7 +28,10 @@ module: os_auth
|
|||
short_description: Retrieve an auth token
|
||||
version_added: "2.0"
|
||||
description:
|
||||
- Retrieve an auth token from an OpenStack Cloud
|
||||
- Retrieve an auth token from an OpenStack Cloud
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "shade"
|
||||
extends_documentation_fragment: openstack
|
||||
'''
|
||||
|
||||
|
@ -61,4 +64,5 @@ def main():
|
|||
# this is magic, see lib/ansible/module_common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -140,7 +140,9 @@ options:
|
|||
- Should the resource be present or absent.
|
||||
choices: [present, absent]
|
||||
default: present
|
||||
requirements: ["shade"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "shade"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -443,4 +445,5 @@ def main():
|
|||
# this is magic, see lib/ansible/module_common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -28,9 +28,12 @@ module: os_server_facts
|
|||
short_description: Retrieve facts about a compute instance
|
||||
version_added: "2.0"
|
||||
description:
|
||||
- Retrieve facts about a server instance from OpenStack.
|
||||
- Retrieve facts about a server instance from OpenStack.
|
||||
notes:
|
||||
- Facts are placed in the C(openstack) variable.
|
||||
- Facts are placed in the C(openstack) variable.
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "shade"
|
||||
options:
|
||||
server:
|
||||
description:
|
||||
|
@ -71,5 +74,6 @@ def main():
|
|||
# this is magic, see lib/ansible/module_common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -53,7 +53,9 @@ options:
|
|||
- Device you want to attach. Defaults to auto finding a device name.
|
||||
required: false
|
||||
default: None
|
||||
requirements: ["shade"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "shade"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -148,4 +150,5 @@ def main():
|
|||
# this is magic, see lib/ansible/module_utils/common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -91,7 +91,9 @@ options:
|
|||
- A list of host route dictionaries for the subnet.
|
||||
required: false
|
||||
default: None
|
||||
requirements: ["shade"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "shade"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -251,4 +253,5 @@ def main():
|
|||
# this is magic, see lib/ansible/module_common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ '__main__':
|
||||
main()
|
||||
|
|
|
@ -66,7 +66,9 @@ options:
|
|||
- Should the resource be present or absent.
|
||||
choices: [present, absent]
|
||||
default: present
|
||||
requirements: ["shade"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "shade"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -155,4 +157,5 @@ def main():
|
|||
# this is magic, see lib/ansible/module_common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import time
|
||||
|
||||
try:
|
||||
from novaclient.v1_1 import client as nova_client
|
||||
try:
|
||||
|
@ -23,9 +25,9 @@ try:
|
|||
except ImportError:
|
||||
from quantumclient.quantum import client
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
import time
|
||||
HAVE_DEPS = True
|
||||
except ImportError:
|
||||
print("failed=True msg='novaclient,keystoneclient and quantumclient (or neutronclient) are required'")
|
||||
HAVE_DEPS = False
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
|
@ -81,7 +83,11 @@ options:
|
|||
required: false
|
||||
default: None
|
||||
version_added: "1.5"
|
||||
requirements: ["novaclient", "quantumclient", "neutronclient", "keystoneclient"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "python-novaclient"
|
||||
- "python-neutronclient or python-quantumclient"
|
||||
- "python-keystoneclient"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -239,6 +245,9 @@ def main():
|
|||
))
|
||||
module = AnsibleModule(argument_spec=argument_spec)
|
||||
|
||||
if not HAVE_DEPS:
|
||||
module.fail_json(msg='python-novaclient, python-keystoneclient, and either python-neutronclient or python-quantumclient are required')
|
||||
|
||||
try:
|
||||
nova = nova_client.Client(module.params['login_username'], module.params['login_password'],
|
||||
module.params['login_tenant_name'], module.params['auth_url'], region_name=module.params['region_name'], service_type='compute')
|
||||
|
@ -272,5 +281,6 @@ def main():
|
|||
# this is magic, see lib/ansible/module.params['common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this software. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import time
|
||||
try:
|
||||
from novaclient.v1_1 import client as nova_client
|
||||
try:
|
||||
|
@ -23,9 +24,9 @@ try:
|
|||
except ImportError:
|
||||
from quantumclient.quantum import client
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
import time
|
||||
HAVE_DEPS = True
|
||||
except ImportError:
|
||||
print "failed=True msg='novaclient, keystone, and quantumclient (or neutronclient) client are required'"
|
||||
HAVE_DEPS = False
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
|
@ -75,7 +76,11 @@ options:
|
|||
- floating ip that should be assigned to the instance
|
||||
required: true
|
||||
default: None
|
||||
requirements: ["quantumclient", "neutronclient", "keystoneclient"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "python-novaclient"
|
||||
- "python-neutronclient or python-quantumclient"
|
||||
- "python-keystoneclient"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -186,6 +191,9 @@ def main():
|
|||
))
|
||||
module = AnsibleModule(argument_spec=argument_spec)
|
||||
|
||||
if not HAVE_DEPS:
|
||||
module.fail_json(msg='python-novaclient, python-keystoneclient, and either python-neutronclient or python-quantumclient are required')
|
||||
|
||||
try:
|
||||
nova = nova_client.Client(module.params['login_username'], module.params['login_password'],
|
||||
module.params['login_tenant_name'], module.params['auth_url'], service_type='compute')
|
||||
|
@ -214,5 +222,6 @@ def main():
|
|||
# this is magic, see lib/ansible/module.params['common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -22,8 +22,9 @@ try:
|
|||
except ImportError:
|
||||
from quantumclient.quantum import client
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
HAVE_DEPS = True
|
||||
except ImportError:
|
||||
print("failed=True msg='quantumclient (or neutronclient) and keystone client are required'")
|
||||
HAVE_DEPS = False
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
|
@ -103,7 +104,10 @@ options:
|
|||
- Whether the state should be marked as up or down
|
||||
required: false
|
||||
default: true
|
||||
requirements: ["quantumclient", "neutronclient", "keystoneclient"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "python-neutronclient or python-quantumclient"
|
||||
- "python-keystoneclient"
|
||||
|
||||
'''
|
||||
|
||||
|
@ -244,6 +248,9 @@ def main():
|
|||
))
|
||||
module = AnsibleModule(argument_spec=argument_spec)
|
||||
|
||||
if not HAVE_DEPS:
|
||||
module.fail_json(msg='python-keystoneclient and either python-neutronclient or python-quantumclient are required')
|
||||
|
||||
if module.params['provider_network_type'] in ['vlan' , 'flat']:
|
||||
if not module.params['provider_physical_network']:
|
||||
module.fail_json(msg = " for vlan and flat networks, variable provider_physical_network should be set.")
|
||||
|
@ -275,5 +282,6 @@ def main():
|
|||
# this is magic, see lib/ansible/module.params['common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -22,8 +22,9 @@ try:
|
|||
except ImportError:
|
||||
from quantumclient.quantum import client
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
HAVE_DEPS = True
|
||||
except ImportError:
|
||||
print("failed=True msg='quantumclient (or neutronclient) and keystone client are required'")
|
||||
HAVE_DEPS = False
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
|
@ -78,7 +79,10 @@ options:
|
|||
- desired admin state of the created router .
|
||||
required: false
|
||||
default: true
|
||||
requirements: ["quantumclient", "neutronclient", "keystoneclient"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "python-neutronclient or python-quantumclient"
|
||||
- "python-keystoneclient"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -183,6 +187,8 @@ def main():
|
|||
admin_state_up = dict(type='bool', default=True),
|
||||
))
|
||||
module = AnsibleModule(argument_spec=argument_spec)
|
||||
if not HAVE_DEPS:
|
||||
module.fail_json(msg='python-keystoneclient and either python-neutronclient or python-quantumclient are required')
|
||||
|
||||
neutron = _get_neutron_client(module, module.params)
|
||||
_set_tenant_id(module)
|
||||
|
@ -206,5 +212,6 @@ def main():
|
|||
# this is magic, see lib/ansible/module.params['common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -22,8 +22,10 @@ try:
|
|||
except ImportError:
|
||||
from quantumclient.quantum import client
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
HAVE_DEPS = True
|
||||
except ImportError:
|
||||
print("failed=True msg='quantumclient (or neutronclient) and keystone client are required'")
|
||||
HAVE_DEPS = False
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: quantum_router_gateway
|
||||
|
@ -72,7 +74,10 @@ options:
|
|||
- Name of the external network which should be attached to the router.
|
||||
required: true
|
||||
default: None
|
||||
requirements: ["quantumclient", "neutronclient", "keystoneclient"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "python-neutronclient or python-quantumclient"
|
||||
- "python-keystoneclient"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -181,6 +186,8 @@ def main():
|
|||
state = dict(default='present', choices=['absent', 'present']),
|
||||
))
|
||||
module = AnsibleModule(argument_spec=argument_spec)
|
||||
if not HAVE_DEPS:
|
||||
module.fail_json(msg='python-keystoneclient and either python-neutronclient or python-quantumclient are required')
|
||||
|
||||
neutron = _get_neutron_client(module, module.params)
|
||||
router_id = _get_router_id(module, neutron)
|
||||
|
@ -209,5 +216,6 @@ def main():
|
|||
# this is magic, see lib/ansible/module.params['common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
|
@ -22,8 +22,10 @@ try:
|
|||
except ImportError:
|
||||
from quantumclient.quantum import client
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
HAVE_DEPS = True
|
||||
except ImportError:
|
||||
print("failed=True msg='quantumclient (or neutronclient) and keystone client are required'")
|
||||
HAVE_DEPS = False
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: quantum_router_interface
|
||||
|
@ -77,7 +79,10 @@ options:
|
|||
- Name of the tenant whose subnet has to be attached.
|
||||
required: false
|
||||
default: None
|
||||
requirements: ["quantumclient", "keystoneclient"]
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "python-neutronclient or python-quantumclient"
|
||||
- "python-keystoneclient"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
|
@ -216,6 +221,8 @@ def main():
|
|||
state = dict(default='present', choices=['absent', 'present']),
|
||||
))
|
||||
module = AnsibleModule(argument_spec=argument_spec)
|
||||
if not HAVE_DEPS:
|
||||
module.fail_json(msg='python-keystoneclient and either python-neutronclient or python-quantumclient are required')
|
||||
|
||||
neutron = _get_neutron_client(module, module.params)
|
||||
_set_tenant_id(module)
|
||||
|
@ -245,5 +252,6 @@ def main():
|
|||
# this is magic, see lib/ansible/module.params['common.py
|
||||
from ansible.module_utils.basic import *
|
||||
from ansible.module_utils.openstack import *
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
|
Loading…
Reference in a new issue