Add a module_utils OpenStack Cloud constructor (#20974)

Start using this to construct shade OpenStack Cloud objects in a
consistent manner. This will let us centralize things like dealing with
password arguments and whatnot. It also allows us to introduce the
ability to pass a fully formed config dict directly to the module.

Migrate all OpenStack modules to use openstack_cloud_from_module.

Have it return the shade library since it's responsible for
importing shade and shade is needed for the exceptions.

Only pull specific OpenStack arguments for the constructor

Rather than passing **module.params to the shade constructor, pull out
only the values that make sense. This should prevent the issues with
module parameters stepping on shade parameters.

Replace module.params.pop with module.params.get

We don't need to pop these anymore since the shade constructor is now
using opt-in values.

Using real urls is ungood. Use example.com domains. Also, get rid of the
antiquated port numbers.
This commit is contained in:
Monty Taylor 2018-02-15 08:20:49 -06:00 committed by Ricardo Carrillo Cruz
parent 577ff4d949
commit 0f893027c4
47 changed files with 270 additions and 673 deletions

View file

@ -1,18 +1,10 @@
clouds: clouds:
mordred: vexxhost:
cloud: hp profile: vexxhost
auth: auth:
username: mordred@example.com project_name: 39e296b2-fc96-42bf-8091-cb742fa13da9
password: my-wonderful-password username: fb886a9b-c37b-442a-9be3-964bed961e04
project_name: mordred-tenant password: fantastic-password1
region_name: region-b.geo-1
monty:
cloud: hp
auth:
username: monty.taylor@example.com
password: another-wonderful-password
project_name: monty.taylor@example.com-default-tenant
region_name: region-b.geo-1
rax: rax:
cloud: rackspace cloud: rackspace
auth: auth:
@ -22,7 +14,7 @@ clouds:
region_name: DFW,ORD,IAD region_name: DFW,ORD,IAD
devstack: devstack:
auth: auth:
auth_url: http://127.0.0.1:35357/v2.0/ auth_url: https://devstack.example.com
username: stack username: stack
password: stack password: stack
project_name: stack project_name: stack

View file

@ -76,7 +76,7 @@ def openstack_find_nova_addresses(addresses, ext_tag, key_name=None):
def openstack_full_argument_spec(**kwargs): def openstack_full_argument_spec(**kwargs):
spec = dict( spec = dict(
cloud=dict(default=None), cloud=dict(default=None, type='raw'),
auth_type=dict(default=None), auth_type=dict(default=None),
auth=dict(default=None, type='dict', no_log=True), auth=dict(default=None, type='dict', no_log=True),
region_name=dict(default=None), region_name=dict(default=None),
@ -88,12 +88,9 @@ def openstack_full_argument_spec(**kwargs):
wait=dict(default=True, type='bool'), wait=dict(default=True, type='bool'),
timeout=dict(default=180, type='int'), timeout=dict(default=180, type='int'),
api_timeout=dict(default=None, type='int'), api_timeout=dict(default=None, type='int'),
endpoint_type=dict( interface=dict(
default='public', choices=['public', 'internal', 'admin'] default='public', choices=['public', 'internal', 'admin'],
), aliases=['endpoint_type']),
identity_api_version=dict(
default=None, choices=['2.0', '3']
)
) )
spec.update(kwargs) spec.update(kwargs)
return spec return spec
@ -109,3 +106,46 @@ def openstack_module_kwargs(**kwargs):
ret[key] = kwargs[key] ret[key] = kwargs[key]
return ret return ret
def openstack_cloud_from_module(module, min_version=None):
from distutils.version import StrictVersion
try:
import shade
except ImportError:
module.fail_json(msg='shade is required for this module')
if min_version:
if StrictVersion(shade.__version__) < StrictVersion(min_version):
module.fail_json(
msg="To utilize this module, the installed version of"
"the shade library MUST be >={min_version}".format(
min_version=min_version))
cloud_config = module.params.pop('cloud', None)
if isinstance(cloud_config, dict):
fail_message = (
"A cloud config dict was provided to the cloud parameter"
" but also a value was provided for {param}. If a cloud"
" config dict is provided, {param} should be"
" excluded.")
for param in (
'auth', 'region_name', 'verify',
'cacert', 'key', 'api_timeout', 'interface'):
if module.params[param] is not None:
module.fail_json(fail_message.format(param=param))
if module.params['auth_type'] != 'password':
module.fail_json(fail_message.format(param='auth_type'))
return shade, shade.operator_cloud(**cloud_config)
else:
return shade, shade.operator_cloud(
cloud=cloud_config,
auth_type=module.params['auth_type'],
auth=module.params['auth'],
region_name=module.params['region_name'],
verify=module.params['verify'],
cacert=module.params['cacert'],
key=module.params['key'],
api_timeout=module.params['api_timeout'],
interface=module.params['interface'],
)

View file

@ -43,15 +43,8 @@ EXAMPLES = '''
import traceback import traceback
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
# this is magic, see lib/ansible/module_common.py
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def main(): def main():
@ -60,11 +53,8 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE: shade, cloud = openstack_cloud_from_module(module)
module.fail_json(msg='shade is required for this module')
try: try:
cloud = shade.openstack_cloud(**module.params)
module.exit_json( module.exit_json(
changed=False, changed=False,
ansible_facts=dict( ansible_facts=dict(

View file

@ -11,7 +11,6 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'community'} 'supported_by': 'community'}
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: os_flavor_facts module: os_flavor_facts
@ -171,16 +170,9 @@ openstack_flavors:
sample: true sample: true
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def main(): def main():
@ -200,22 +192,12 @@ def main():
) )
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
name = module.params['name'] name = module.params['name']
vcpus = module.params['vcpus'] vcpus = module.params['vcpus']
ram = module.params['ram'] ram = module.params['ram']
ephemeral = module.params['ephemeral'] ephemeral = module.params['ephemeral']
limit = module.params['limit'] limit = module.params['limit']
try:
cloud = shade.openstack_cloud(**module.params)
if name:
flavors = cloud.search_flavors(filters={'name': name})
else:
flavors = cloud.list_flavors()
filters = {} filters = {}
if vcpus: if vcpus:
filters['vcpus'] = vcpus filters['vcpus'] = vcpus
@ -223,10 +205,21 @@ def main():
filters['ram'] = ram filters['ram'] = ram
if ephemeral: if ephemeral:
filters['ephemeral'] = ephemeral filters['ephemeral'] = ephemeral
if filters: if filters:
# Range search added in 1.5.0 # Range search added in 1.5.0
if StrictVersion(shade.__version__) < StrictVersion('1.5.0'): min_version = '1.5.0'
module.fail_json(msg="Shade >= 1.5.0 needed for this functionality") else:
min_version = None
shade, cloud = openstack_cloud_from_module(module, min_version=min_version)
try:
if name:
flavors = cloud.search_flavors(filters={'name': name})
else:
flavors = cloud.list_flavors()
if filters:
flavors = cloud.range_search(flavors, filters) flavors = cloud.range_search(flavors, filters)
if limit is not None: if limit is not None:

View file

@ -128,16 +128,8 @@ EXAMPLES = '''
server: cattle001 server: cattle001
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule, remove_values from ansible.module_utils.basic import AnsibleModule, remove_values
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _get_floating_ip(cloud, floating_ip_address): def _get_floating_ip(cloud, floating_ip_address):
@ -167,13 +159,10 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE: if module.params['nat_destination']:
module.fail_json(msg='shade is required for this module') min_version = '1.8.0'
else:
if (module.params['nat_destination'] and min_version = None
StrictVersion(shade.__version__) < StrictVersion('1.8.0')):
module.fail_json(msg="To utilize nat_destination, the installed version of"
"the shade library MUST be >= 1.8.0")
server_name_or_id = module.params['server'] server_name_or_id = module.params['server']
state = module.params['state'] state = module.params['state']
@ -186,7 +175,7 @@ def main():
timeout = module.params['timeout'] timeout = module.params['timeout']
purge = module.params['purge'] purge = module.params['purge']
cloud = shade.openstack_cloud(**module.params) shade, cloud = openstack_cloud_from_module(module, min_version=min_version)
try: try:
server = cloud.get_server(server_name_or_id) server = cloud.get_server(server_name_or_id)

View file

@ -99,14 +99,8 @@ group:
sample: "default" sample: "default"
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _system_state_change(state, description, group): def _system_state_change(state, description, group):
@ -132,16 +126,14 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE: name = module.params.get('name')
module.fail_json(msg='shade is required for this module') description = module.params.get('description')
state = module.params.get('state')
name = module.params.pop('name')
description = module.params.pop('description')
domain_id = module.params.pop('domain_id') domain_id = module.params.pop('domain_id')
state = module.params.pop('state')
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.operator_cloud(**module.params)
if domain_id: if domain_id:
group = cloud.get_group(name, filters={'domain_id': domain_id}) group = cloud.get_group(name, filters={'domain_id': domain_id})
else: else:

View file

@ -108,7 +108,7 @@ EXAMPLES = '''
# Upload an image from a local file named cirros-0.3.0-x86_64-disk.img # Upload an image from a local file named cirros-0.3.0-x86_64-disk.img
- os_image: - os_image:
auth: auth:
auth_url: http://localhost/auth/v2.0 auth_url: https://identity.example.com
username: admin username: admin
password: passme password: passme
project_name: admin project_name: admin
@ -124,14 +124,8 @@ EXAMPLES = '''
distro: ubuntu distro: ubuntu
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def main(): def main():
@ -155,11 +149,8 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE: shade, cloud = openstack_cloud_from_module(module)
module.fail_json(msg='shade is required for this module')
try: try:
cloud = shade.openstack_cloud(**module.params)
changed = False changed = False
if module.params['checksum']: if module.params['checksum']:

View file

@ -40,7 +40,7 @@ EXAMPLES = '''
- name: Gather facts about a previously created image named image1 - name: Gather facts about a previously created image named image1
os_image_facts: os_image_facts:
auth: auth:
auth_url: https://your_api_url.com:9000/v2.0 auth_url: https://identity.example.com
username: user username: user
password: password password: password
project_name: someproject project_name: someproject
@ -127,14 +127,8 @@ openstack_image:
type: int type: int
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def main(): def main():
@ -145,11 +139,8 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE: shade, cloud = openstack_cloud_from_module(module)
module.fail_json(msg='shade is required for this module')
try: try:
cloud = shade.openstack_cloud(**module.params)
image = cloud.get_image(module.params['image']) image = cloud.get_image(module.params['image'])
module.exit_json(changed=False, ansible_facts=dict( module.exit_json(changed=False, ansible_facts=dict(
openstack_image=image)) openstack_image=image))

View file

@ -148,14 +148,8 @@ try:
except ImportError: except ImportError:
HAS_JSONPATCH = False HAS_JSONPATCH = False
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _parse_properties(module): def _parse_properties(module):
@ -169,7 +163,7 @@ def _parse_properties(module):
return props return props
def _parse_driver_info(module): def _parse_driver_info(shade, module):
p = module.params['driver_info'] p = module.params['driver_info']
info = p.get('power') info = p.get('power')
if not info: if not info:
@ -226,8 +220,6 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
if not HAS_JSONPATCH: if not HAS_JSONPATCH:
module.fail_json(msg='jsonpatch is required for this module') module.fail_json(msg='jsonpatch is required for this module')
if (module.params['auth_type'] in [None, 'None'] and if (module.params['auth_type'] in [None, 'None'] and
@ -243,8 +235,8 @@ def main():
node_id = _choose_id_value(module) node_id = _choose_id_value(module)
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.operator_cloud(**module.params)
server = cloud.get_machine(node_id) server = cloud.get_machine(node_id)
if module.params['state'] == 'present': if module.params['state'] == 'present':
if module.params['driver'] is None: if module.params['driver'] is None:
@ -252,7 +244,7 @@ def main():
"to set a node to present.") "to set a node to present.")
properties = _parse_properties(module) properties = _parse_properties(module)
driver_info = _parse_driver_info(module) driver_info = _parse_driver_info(shade, module)
kwargs = dict( kwargs = dict(
driver=module.params['driver'], driver=module.params['driver'],
properties=properties, properties=properties,

View file

@ -89,16 +89,8 @@ EXAMPLES = '''
name: "testnode1" name: "testnode1"
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _choose_id_value(module): def _choose_id_value(module):
@ -121,12 +113,6 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
if StrictVersion(shade.__version__) < StrictVersion('1.0.0'):
module.fail_json(msg="To utilize this module, the installed version of"
"the shade library MUST be >=1.0.0")
if (module.params['auth_type'] in [None, 'None'] and if (module.params['auth_type'] in [None, 'None'] and
module.params['ironic_url'] is None): module.params['ironic_url'] is None):
module.fail_json(msg="Authentication appears to be disabled, " module.fail_json(msg="Authentication appears to be disabled, "
@ -138,8 +124,9 @@ def main():
endpoint=module.params['ironic_url'] endpoint=module.params['ironic_url']
) )
shade, cloud = openstack_cloud_from_module(
module, min_version='1.0.0')
try: try:
cloud = shade.operator_cloud(**module.params)
if module.params['name'] or module.params['uuid']: if module.params['name'] or module.params['uuid']:
server = cloud.get_machine(_choose_id_value(module)) server = cloud.get_machine(_choose_id_value(module))

View file

@ -122,16 +122,8 @@ os_ironic_node:
delegate_to: localhost delegate_to: localhost
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _choose_id_value(module): def _choose_id_value(module):
@ -245,13 +237,11 @@ def main():
) )
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
if (module.params['wait'] and if module.params['wait']:
StrictVersion(shade.__version__) < StrictVersion('1.4.0')): min_version = '1.4.0'
module.fail_json(msg="To utilize wait, the installed version of" else:
"the shade library MUST be >=1.4.0") min_version = None
if (module.params['auth_type'] in [None, 'None'] and if (module.params['auth_type'] in [None, 'None'] and
module.params['ironic_url'] is None): module.params['ironic_url'] is None):
@ -269,8 +259,9 @@ def main():
if not node_id: if not node_id:
module.fail_json(msg="A uuid or name value must be defined " module.fail_json(msg="A uuid or name value must be defined "
"to use this module.") "to use this module.")
shade, cloud = openstack_cloud_from_module(
module, min_version=min_version)
try: try:
cloud = shade.operator_cloud(**module.params)
node = cloud.get_machine(node_id) node = cloud.get_machine(node_id)
if node is None: if node is None:

View file

@ -88,14 +88,8 @@ private_key:
type: string type: string
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _system_state_change(module, keypair): def _system_state_change(module, keypair):
@ -123,9 +117,6 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
state = module.params['state'] state = module.params['state']
name = module.params['name'] name = module.params['name']
public_key = module.params['public_key'] public_key = module.params['public_key']
@ -134,8 +125,8 @@ def main():
public_key = open(module.params['public_key_file']).read() public_key = open(module.params['public_key_file']).read()
public_key = public_key.rstrip() public_key = public_key.rstrip()
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.openstack_cloud(**module.params)
keypair = cloud.get_keypair(name) keypair = cloud.get_keypair(name)
if module.check_mode: if module.check_mode:

View file

@ -98,14 +98,8 @@ id:
sample: "474acfe5-be34-494c-b339-50f06aa143e4" sample: "474acfe5-be34-494c-b339-50f06aa143e4"
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _needs_update(module, domain): def _needs_update(module, domain):
@ -143,16 +137,13 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
name = module.params['name'] name = module.params['name']
description = module.params['description'] description = module.params['description']
enabled = module.params['enabled'] enabled = module.params['enabled']
state = module.params['state'] state = module.params['state']
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.operator_cloud(**module.params)
domains = cloud.search_domains(filters=dict(name=name)) domains = cloud.search_domains(filters=dict(name=name))

View file

@ -89,14 +89,8 @@ openstack_domains:
type: bool type: bool
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def main(): def main():
@ -112,15 +106,11 @@ def main():
) )
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE: shade, opcloud = openstack_cloud_from_module(module)
module.fail_json(msg='shade is required for this module')
try: try:
name = module.params['name'] name = module.params['name']
filters = module.params['filters'] filters = module.params['filters']
opcloud = shade.operator_cloud(**module.params)
if name: if name:
# Let's suppose user is passing domain ID # Let's suppose user is passing domain ID
try: try:

View file

@ -59,7 +59,7 @@ EXAMPLES = '''
os_keystone_endpoint: os_keystone_endpoint:
cloud: mycloud cloud: mycloud
service: glance service: glance
interface: public endpoint_interface: public
url: http://controller:9292 url: http://controller:9292
region: RegionOne region: RegionOne
state: present state: present
@ -68,7 +68,7 @@ EXAMPLES = '''
os_keystone_endpoint: os_keystone_endpoint:
cloud: mycloud cloud: mycloud
service: nova service: nova
interface: public endpoint_interface: public
region: RegionOne region: RegionOne
state: absent state: absent
''' '''
@ -107,14 +107,8 @@ endpoint:
from distutils.version import StrictVersion from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _needs_update(module, endpoint): def _needs_update(module, endpoint):
@ -141,7 +135,7 @@ def _system_state_change(module, endpoint):
def main(): def main():
argument_spec = openstack_full_argument_spec( argument_spec = openstack_full_argument_spec(
service=dict(type='str', required=True), service=dict(type='str', required=True),
interface=dict(type='str', required=True, choices=['admin', 'public', 'internal']), endpoint_interface=dict(type='str', required=True, choices=['admin', 'public', 'internal']),
url=dict(type='str', required=True), url=dict(type='str', required=True),
region=dict(type='str'), region=dict(type='str'),
enabled=dict(type='bool', default=True), enabled=dict(type='bool', default=True),
@ -153,14 +147,10 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE: shade, cloud = openstack_cloud_from_module(module, min_version='1.11.0')
module.fail_json(msg='shade is required for this module')
if StrictVersion(shade.__version__) < StrictVersion('1.11.0'):
module.fail_json(msg="To utilize this module, the installed version of"
"the shade library MUST be >=1.11.0")
service_name_or_id = module.params['service'] service_name_or_id = module.params['service']
interface = module.params['interface'] interface = module.params['endpoint_interface']
url = module.params['url'] url = module.params['url']
region = module.params['region'] region = module.params['region']
enabled = module.params['enabled'] enabled = module.params['enabled']

View file

@ -69,14 +69,8 @@ role:
sample: "demo" sample: "demo"
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _system_state_change(state, role): def _system_state_change(state, role):
@ -98,14 +92,11 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE: name = module.params.get('name')
module.fail_json(msg='shade is required for this module') state = module.params.get('state')
name = module.params.pop('name')
state = module.params.pop('state')
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.operator_cloud(**module.params)
role = cloud.get_role(name) role = cloud.get_role(name)

View file

@ -104,16 +104,8 @@ id:
sample: "3292f020780b4d5baf27ff7e1d224c44" sample: "3292f020780b4d5baf27ff7e1d224c44"
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _needs_update(module, service): def _needs_update(module, service):
@ -152,21 +144,14 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
if StrictVersion(shade.__version__) < StrictVersion('1.6.0'):
module.fail_json(msg="To utilize this module, the installed version of"
"the shade library MUST be >=1.6.0")
description = module.params['description'] description = module.params['description']
enabled = module.params['enabled'] enabled = module.params['enabled']
name = module.params['name'] name = module.params['name']
state = module.params['state'] state = module.params['state']
service_type = module.params['service_type'] service_type = module.params['service_type']
shade, cloud = openstack_cloud_from_module(module, min_version='1.6.0')
try: try:
cloud = shade.operator_cloud(**module.params)
services = cloud.search_services(name_or_id=name, services = cloud.search_services(name_or_id=name,
filters=dict(type=service_type)) filters=dict(type=service_type))

View file

@ -151,16 +151,8 @@ network:
sample: 101 sample: 101
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def main(): def main():
@ -179,14 +171,6 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
if (module.params['project'] and
StrictVersion(shade.__version__) < StrictVersion('1.6.0')):
module.fail_json(msg="To utilize project, the installed version of"
"the shade library MUST be >=1.6.0")
state = module.params['state'] state = module.params['state']
name = module.params['name'] name = module.params['name']
shared = module.params['shared'] shared = module.params['shared']
@ -195,10 +179,10 @@ def main():
provider_physical_network = module.params['provider_physical_network'] provider_physical_network = module.params['provider_physical_network']
provider_network_type = module.params['provider_network_type'] provider_network_type = module.params['provider_network_type']
provider_segmentation_id = module.params['provider_segmentation_id'] provider_segmentation_id = module.params['provider_segmentation_id']
project = module.params.pop('project') project = module.params.get('project')
shade, cloud = openstack_cloud_from_module(module, min_version='1.6.0')
try: try:
cloud = shade.openstack_cloud(**module.params)
if project is not None: if project is not None:
proj = cloud.get_project(project) proj = cloud.get_project(project)
if proj is None: if proj is None:
@ -220,9 +204,6 @@ def main():
if provider_segmentation_id: if provider_segmentation_id:
provider['segmentation_id'] = provider_segmentation_id provider['segmentation_id'] = provider_segmentation_id
if provider and StrictVersion(shade.__version__) < StrictVersion('1.5.0'):
module.fail_json(msg="Shade >= 1.5.0 required to use provider options")
if project_id is not None: if project_id is not None:
net = cloud.create_network(name, shared, admin_state_up, net = cloud.create_network(name, shared, admin_state_up,
external, provider, project_id) external, provider, project_id)

View file

@ -44,7 +44,7 @@ EXAMPLES = '''
- name: Gather facts about previously created networks - name: Gather facts about previously created networks
os_networks_facts: os_networks_facts:
auth: auth:
auth_url: https://your_api_url.com:9000/v2.0 auth_url: https://identity.example.com
username: user username: user
password: password password: password
project_name: someproject project_name: someproject
@ -56,7 +56,7 @@ EXAMPLES = '''
- name: Gather facts about a previously created network by name - name: Gather facts about a previously created network by name
os_networks_facts: os_networks_facts:
auth: auth:
auth_url: https://your_api_url.com:9000/v2.0 auth_url: https://identity.example.com
username: user username: user
password: password password: password
project_name: someproject project_name: someproject
@ -70,7 +70,7 @@ EXAMPLES = '''
# Note: name and filters parameters are Not mutually exclusive # Note: name and filters parameters are Not mutually exclusive
os_networks_facts: os_networks_facts:
auth: auth:
auth_url: https://your_api_url.com:9000/v2.0 auth_url: https://identity.example.com
username: user username: user
password: password password: password
project_name: someproject project_name: someproject
@ -117,14 +117,8 @@ openstack_networks:
type: boolean type: boolean
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_cloud_from_module
def main(): def main():
@ -135,11 +129,8 @@ def main():
) )
module = AnsibleModule(argument_spec) module = AnsibleModule(argument_spec)
if not HAS_SHADE: shade, cloud = openstack_cloud_from_module(module)
module.fail_json(msg='shade is required for this module')
try: try:
cloud = shade.openstack_cloud(**module.params)
networks = cloud.search_networks(module.params['name'], networks = cloud.search_networks(module.params['name'],
module.params['filters']) module.params['filters'])
module.exit_json(changed=False, ansible_facts=dict( module.exit_json(changed=False, ansible_facts=dict(

View file

@ -173,14 +173,8 @@ flavor:
"aggregate_instance_extra_specs:pinned": false "aggregate_instance_extra_specs:pinned": false
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _system_state_change(module, flavor): def _system_state_change(module, flavor):
@ -220,15 +214,12 @@ def main():
], ],
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
state = module.params['state'] state = module.params['state']
name = module.params['name'] name = module.params['name']
extra_specs = module.params['extra_specs'] or {} extra_specs = module.params['extra_specs'] or {}
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.operator_cloud(**module.params)
flavor = cloud.get_flavor(name) flavor = cloud.get_flavor(name)
if module.check_mode: if module.check_mode:

View file

@ -69,16 +69,8 @@ RETURN = '''
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _needs_update(module, aggregate): def _needs_update(module, aggregate):
@ -123,12 +115,6 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
if StrictVersion(shade.__version__) < StrictVersion('1.9.0'):
module.fail_json(msg="To utilize this module, the installed version of"
"the shade library MUST be >=1.9.0")
name = module.params['name'] name = module.params['name']
metadata = module.params['metadata'] metadata = module.params['metadata']
availability_zone = module.params['availability_zone'] availability_zone = module.params['availability_zone']
@ -138,8 +124,8 @@ def main():
if metadata is not None: if metadata is not None:
metadata.pop('availability_zone', None) metadata.pop('availability_zone', None)
shade, cloud = openstack_cloud_from_module(module, min_version='1.9.0')
try: try:
cloud = shade.operator_cloud(**module.params)
aggregates = cloud.search_aggregates(name_or_id=name) aggregates = cloud.search_aggregates(name_or_id=name)
if len(aggregates) == 1: if len(aggregates) == 1:

View file

@ -69,14 +69,8 @@ EXAMPLES = '''
container: config container: config
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def process_object( def process_object(
@ -118,12 +112,8 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE: shade, cloud = openstack_cloud_from_module(module)
module.fail_json(msg='shade is required for this module')
try: try:
cloud = shade.openstack_cloud(**module.params)
changed = process_object(cloud, **module.params) changed = process_object(cloud, **module.params)
module.exit_json(changed=changed) module.exit_json(changed=changed)

View file

@ -105,7 +105,7 @@ EXAMPLES = '''
- os_port: - os_port:
state: present state: present
auth: auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/ auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -116,7 +116,7 @@ EXAMPLES = '''
- os_port: - os_port:
state: present state: present
auth: auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/ auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -129,7 +129,7 @@ EXAMPLES = '''
- os_port: - os_port:
state: present state: present
auth: auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/ auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -141,7 +141,7 @@ EXAMPLES = '''
- os_port: - os_port:
state: present state: present
auth: auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/d auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -152,7 +152,7 @@ EXAMPLES = '''
- os_port: - os_port:
state: present state: present
auth: auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/d auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -201,14 +201,8 @@ admin_state_up:
type: bool type: bool
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _needs_update(module, port, cloud): def _needs_update(module, port, cloud):
@ -329,13 +323,11 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
name = module.params['name'] name = module.params['name']
state = module.params['state'] state = module.params['state']
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.openstack_cloud(**module.params)
if module.params['security_groups']: if module.params['security_groups']:
# translate security_groups to UUID's if names where provided # translate security_groups to UUID's if names where provided
module.params['security_groups'] = [ module.params['security_groups'] = [

View file

@ -189,14 +189,8 @@ openstack_ports:
sample: "51fce036d7984ba6af4f6c849f65ef00" sample: "51fce036d7984ba6af4f6c849f65ef00"
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def main(): def main():
@ -207,14 +201,11 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE: port = module.params.get('port')
module.fail_json(msg='shade is required for this module') filters = module.params.get('filters')
port = module.params.pop('port')
filters = module.params.pop('filters')
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.openstack_cloud(**module.params)
ports = cloud.search_ports(port, filters) ports = cloud.search_ports(port, filters)
module.exit_json(changed=False, ansible_facts=dict( module.exit_json(changed=False, ansible_facts=dict(
openstack_ports=ports)) openstack_ports=ports))

View file

@ -102,16 +102,8 @@ project:
sample: True sample: True
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _needs_update(module, project): def _needs_update(module, project):
@ -159,37 +151,35 @@ def main():
**module_kwargs **module_kwargs
) )
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
name = module.params['name'] name = module.params['name']
description = module.params['description'] description = module.params['description']
domain = module.params.pop('domain_id') domain = module.params.get('domain_id')
enabled = module.params['enabled'] enabled = module.params['enabled']
state = module.params['state'] state = module.params['state']
if domain and StrictVersion(shade.__version__) < StrictVersion('1.8.0'): if domain:
module.fail_json(msg="The domain argument requires shade >=1.8.0") min_version = '1.8.0'
else:
min_version = None
shade, cloud = openstack_cloud_from_module(
module, min_version=min_version)
try: try:
if domain: if domain:
opcloud = shade.operator_cloud(**module.params)
try: try:
# We assume admin is passing domain id # We assume admin is passing domain id
dom = opcloud.get_domain(domain)['id'] dom = cloud.get_domain(domain)['id']
domain = dom domain = dom
except: except:
# If we fail, maybe admin is passing a domain name. # If we fail, maybe admin is passing a domain name.
# Note that domains have unique names, just like id. # Note that domains have unique names, just like id.
try: try:
dom = opcloud.search_domains(filters={'name': domain})[0]['id'] dom = cloud.search_domains(filters={'name': domain})[0]['id']
domain = dom domain = dom
except: except:
# Ok, let's hope the user is non-admin and passing a sane id # Ok, let's hope the user is non-admin and passing a sane id
pass pass
cloud = shade.openstack_cloud(**module.params)
if domain: if domain:
project = cloud.get_project(name, domain_id=domain) project = cloud.get_project(name, domain_id=domain)
else: else:

View file

@ -107,14 +107,8 @@ openstack_projects:
type: bool type: bool
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_cloud_from_module
def main(): def main():
@ -127,16 +121,12 @@ def main():
module = AnsibleModule(argument_spec) module = AnsibleModule(argument_spec)
if not HAS_SHADE: shade, opcloud = openstack_cloud_from_module(module)
module.fail_json(msg='shade is required for this module')
try: try:
name = module.params['name'] name = module.params['name']
domain = module.params['domain'] domain = module.params['domain']
filters = module.params['filters'] filters = module.params['filters']
opcloud = shade.operator_cloud(**module.params)
if domain: if domain:
try: try:
# We assume admin is passing domain id # We assume admin is passing domain id

View file

@ -291,15 +291,8 @@ openstack_quotas:
''' '''
try:
import shade
from keystoneauth1 import exceptions
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _get_volume_quotas(cloud, project): def _get_volume_quotas(cloud, project):
@ -317,17 +310,17 @@ def _get_compute_quotas(cloud, project):
return cloud.get_compute_quotas(project) return cloud.get_compute_quotas(project)
def _get_quotas(module, cloud, project): def _get_quotas(shade, module, cloud, project):
quota = {} quota = {}
try: try:
quota['volume'] = _get_volume_quotas(cloud, project) quota['volume'] = _get_volume_quotas(cloud, project)
except exceptions.EndpointNotFound: except shade.OpenStackCloudURINotFound:
module.warn("No public endpoint for volumev2 service was found. Ignoring volume quotas.") module.warn("No public endpoint for volumev2 service was found. Ignoring volume quotas.")
try: try:
quota['network'] = _get_network_quotas(cloud, project) quota['network'] = _get_network_quotas(cloud, project)
except exceptions.EndpointNotFound: except shade.OpenStackCloudURINotFound:
module.warn("No public endpoint for network service was found. Ignoring network quotas.") module.warn("No public endpoint for network service was found. Ignoring network quotas.")
quota['compute'] = _get_compute_quotas(cloud, project) quota['compute'] = _get_compute_quotas(cloud, project)
@ -437,12 +430,9 @@ def main():
supports_check_mode=True supports_check_mode=True
) )
if not HAS_SHADE: shade, cloud = openstack_cloud_from_module(module)
module.fail_json(msg='shade is required for this module')
try: try:
cloud_params = dict(module.params) cloud_params = dict(module.params)
cloud = shade.operator_cloud(**cloud_params)
# In order to handle the different volume types we update module params after. # In order to handle the different volume types we update module params after.
dynamic_types = [ dynamic_types = [
@ -456,7 +446,8 @@ def main():
module.params[k] = int(v) module.params[k] = int(v)
# Get current quota values # Get current quota values
project_quota_output = _get_quotas(module, cloud, cloud_params['name']) project_quota_output = _get_quotas(
shade, module, cloud, cloud_params['name'])
changes_required = False changes_required = False
if module.params['state'] == "absent": if module.params['state'] == "absent":
@ -485,7 +476,8 @@ def main():
else: else:
module.fail_json(msg=str(e), extra_data=e.extra_data) module.fail_json(msg=str(e), extra_data=e.extra_data)
project_quota_output = _get_quotas(module, cloud, cloud_params['name']) project_quota_output = _get_quotas(
shade, module, cloud, cloud_params['name'])
changes_required = True changes_required = True
elif module.params['state'] == "present": elif module.params['state'] == "present":
@ -503,7 +495,8 @@ def main():
quota_call(cloud_params['name'], **quota_change_request[quota_type]) quota_call(cloud_params['name'], **quota_change_request[quota_type])
# Get quota state post changes for validation # Get quota state post changes for validation
project_quota_update = _get_quotas(module, cloud, cloud_params['name']) project_quota_update = _get_quotas(
shade, module, cloud, cloud_params['name'])
if project_quota_output == project_quota_update: if project_quota_output == project_quota_update:
module.fail_json(msg='Could not apply quota update') module.fail_json(msg='Could not apply quota update')

View file

@ -127,16 +127,8 @@ recordset:
sample: ['10.0.0.1'] sample: ['10.0.0.1']
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _system_state_change(state, records, description, ttl, zone, recordset): def _system_state_change(state, records, description, ttl, zone, recordset):
@ -173,18 +165,12 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
if StrictVersion(shade.__version__) <= StrictVersion('1.8.0'):
module.fail_json(msg="To utilize this module, the installed version of "
"the shade library MUST be >1.8.0")
zone = module.params.get('zone') zone = module.params.get('zone')
name = module.params.get('name') name = module.params.get('name')
state = module.params.get('state') state = module.params.get('state')
shade, cloud = openstack_cloud_from_module(module, min_version='1.9.0')
try: try:
cloud = shade.openstack_cloud(**module.params)
recordset_type = module.params.get('recordset_type') recordset_type = module.params.get('recordset_type')
recordset_filter = {'type': recordset_type} recordset_filter = {'type': recordset_type}

View file

@ -215,16 +215,8 @@ router:
type: list type: list
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
ROUTER_INTERFACE_OWNERS = set([ ROUTER_INTERFACE_OWNERS = set([
@ -401,13 +393,10 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE: if module.params['project']:
module.fail_json(msg='shade is required for this module') min_version = '1.10.0'
else:
if (module.params['project'] and min_version = None
StrictVersion(shade.__version__) <= StrictVersion('1.9.0')):
module.fail_json(msg="To utilize project, the installed version of"
"the shade library MUST be > 1.9.0")
state = module.params['state'] state = module.params['state']
name = module.params['name'] name = module.params['name']
@ -417,8 +406,8 @@ def main():
if module.params['external_fixed_ips'] and not network: if module.params['external_fixed_ips'] and not network:
module.fail_json(msg='network is required when supplying external_fixed_ips') module.fail_json(msg='network is required when supplying external_fixed_ips')
shade, cloud = openstack_cloud_from_module(module, min_version=min_version)
try: try:
cloud = shade.openstack_cloud(**module.params)
if project is not None: if project is not None:
proj = cloud.get_project(project) proj = cloud.get_project(project)
if proj is None: if proj is None:

View file

@ -60,14 +60,8 @@ EXAMPLES = '''
description: updated description for the foo security group description: updated description for the foo security group
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _needs_update(module, secgroup): def _needs_update(module, secgroup):
@ -103,15 +97,12 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
name = module.params['name'] name = module.params['name']
state = module.params['state'] state = module.params['state']
description = module.params['description'] description = module.params['description']
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.openstack_cloud(**module.params)
secgroup = cloud.get_security_group(name) secgroup = cloud.get_security_group(name)
if module.check_mode: if module.check_mode:

View file

@ -167,14 +167,8 @@ security_group_id:
returned: state == present returned: state == present
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _ports_match(protocol, module_min, module_max, rule_min, rule_max): def _ports_match(protocol, module_min, module_max, rule_min, rule_max):
@ -297,16 +291,13 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
state = module.params['state'] state = module.params['state']
security_group = module.params['security_group'] security_group = module.params['security_group']
remote_group = module.params['remote_group'] remote_group = module.params['remote_group']
changed = False changed = False
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.openstack_cloud(**module.params)
secgroup = cloud.get_security_group(security_group) secgroup = cloud.get_security_group(security_group)
if remote_group: if remote_group:

View file

@ -199,7 +199,7 @@ EXAMPLES = '''
os_server: os_server:
state: present state: present
auth: auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/ auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -224,7 +224,7 @@ EXAMPLES = '''
os_server: os_server:
state: present state: present
auth: auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/ auth_url: https://identity.example.com
username: username username: username
password: Equality7-2521 password: Equality7-2521
project_name: username-project1 project_name: username-project1
@ -291,7 +291,7 @@ EXAMPLES = '''
- name: launch an instance with a string - name: launch an instance with a string
os_server: os_server:
auth: auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/ auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -306,7 +306,7 @@ EXAMPLES = '''
os_server: os_server:
state: present state: present
auth: auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/ auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -324,7 +324,7 @@ EXAMPLES = '''
os_server: os_server:
state: present state: present
auth: auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/ auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -407,20 +407,14 @@ EXAMPLES = '''
''' '''
try:
import shade
from shade import meta
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import (openstack_find_nova_addresses, from ansible.module_utils.openstack import (
openstack_find_nova_addresses, openstack_cloud_from_module,
openstack_full_argument_spec, openstack_module_kwargs) openstack_full_argument_spec, openstack_module_kwargs)
def _exit_hostvars(module, cloud, server, changed=True): def _exit_hostvars(module, cloud, server, changed=True):
hostvars = meta.get_hostvars_from_server(cloud, server) hostvars = cloud.get_openstack_vars(server)
module.exit_json( module.exit_json(
changed=changed, server=server, id=server.id, openstack=hostvars) changed=changed, server=server, id=server.id, openstack=hostvars)
@ -727,9 +721,6 @@ def main():
) )
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
state = module.params['state'] state = module.params['state']
image = module.params['image'] image = module.params['image']
boot_volume = module.params['boot_volume'] boot_volume = module.params['boot_volume']
@ -748,11 +739,8 @@ def main():
"if state == 'present'" "if state == 'present'"
) )
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud_params = dict(module.params)
cloud_params.pop('userdata', None)
cloud = shade.openstack_cloud(**cloud_params)
if state == 'present': if state == 'present':
_get_server_state(module, cloud) _get_server_state(module, cloud)
_create_server(module, cloud) _create_server(module, cloud)

View file

@ -66,7 +66,7 @@ EXAMPLES = '''
- os_server_action: - os_server_action:
action: pause action: pause
auth: auth:
auth_url: https://mycloud.openstack.blueboxgrid.com:5001/v2.0 auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -74,15 +74,8 @@ EXAMPLES = '''
timeout: 200 timeout: 200
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
_action_map = {'stop': 'SHUTOFF', _action_map = {'stop': 'SHUTOFF',
'start': 'ACTIVE', 'start': 'ACTIVE',
@ -97,7 +90,7 @@ _action_map = {'stop': 'SHUTOFF',
_admin_actions = ['pause', 'unpause', 'suspend', 'resume', 'lock', 'unlock'] _admin_actions = ['pause', 'unpause', 'suspend', 'resume', 'lock', 'unlock']
def _wait(timeout, cloud, server, action, module): def _wait(timeout, cloud, server, action, module, shade):
"""Wait for the server to reach the desired state for the given action.""" """Wait for the server to reach the desired state for the given action."""
for count in shade._utils._iterate_timeout( for count in shade._utils._iterate_timeout(
@ -139,19 +132,16 @@ def main():
if module._name == 'os_server_actions': if module._name == 'os_server_actions':
module.deprecate("The 'os_server_actions' module is being renamed 'os_server_action'", version=2.8) module.deprecate("The 'os_server_actions' module is being renamed 'os_server_action'", version=2.8)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
action = module.params['action'] action = module.params['action']
wait = module.params['wait'] wait = module.params['wait']
timeout = module.params['timeout'] timeout = module.params['timeout']
image = module.params['image'] image = module.params['image']
try:
if action in _admin_actions: if action in _admin_actions:
cloud = shade.operator_cloud(**module.params) shade, cloud = openstack_cloud_from_module(module)
else: else:
cloud = shade.openstack_cloud(**module.params) shade, cloud = openstack_cloud_from_module(module)
try:
server = cloud.get_server(module.params['server']) server = cloud.get_server(module.params['server'])
if not server: if not server:
module.fail_json(msg='Could not find server %s' % server) module.fail_json(msg='Could not find server %s' % server)
@ -166,7 +156,7 @@ def main():
cloud.nova_client.servers.stop(server=server.id) cloud.nova_client.servers.stop(server=server.id)
if wait: if wait:
_wait(timeout, cloud, server, action, module) _wait(timeout, cloud, server, action, module, shade)
module.exit_json(changed=True) module.exit_json(changed=True)
if action == 'start': if action == 'start':
@ -175,7 +165,7 @@ def main():
cloud.nova_client.servers.start(server=server.id) cloud.nova_client.servers.start(server=server.id)
if wait: if wait:
_wait(timeout, cloud, server, action, module) _wait(timeout, cloud, server, action, module, shade)
module.exit_json(changed=True) module.exit_json(changed=True)
if action == 'pause': if action == 'pause':
@ -184,7 +174,7 @@ def main():
cloud.nova_client.servers.pause(server=server.id) cloud.nova_client.servers.pause(server=server.id)
if wait: if wait:
_wait(timeout, cloud, server, action, module) _wait(timeout, cloud, server, action, module, shade)
module.exit_json(changed=True) module.exit_json(changed=True)
elif action == 'unpause': elif action == 'unpause':
@ -193,7 +183,7 @@ def main():
cloud.nova_client.servers.unpause(server=server.id) cloud.nova_client.servers.unpause(server=server.id)
if wait: if wait:
_wait(timeout, cloud, server, action, module) _wait(timeout, cloud, server, action, module, shade)
module.exit_json(changed=True) module.exit_json(changed=True)
elif action == 'lock': elif action == 'lock':
@ -212,7 +202,7 @@ def main():
cloud.nova_client.servers.suspend(server=server.id) cloud.nova_client.servers.suspend(server=server.id)
if wait: if wait:
_wait(timeout, cloud, server, action, module) _wait(timeout, cloud, server, action, module, shade)
module.exit_json(changed=True) module.exit_json(changed=True)
elif action == 'resume': elif action == 'resume':
@ -221,7 +211,7 @@ def main():
cloud.nova_client.servers.resume(server=server.id) cloud.nova_client.servers.resume(server=server.id)
if wait: if wait:
_wait(timeout, cloud, server, action, module) _wait(timeout, cloud, server, action, module, shade)
module.exit_json(changed=True) module.exit_json(changed=True)
elif action == 'rebuild': elif action == 'rebuild':
@ -233,7 +223,7 @@ def main():
# rebuild doesn't set a state, just do it # rebuild doesn't set a state, just do it
cloud.nova_client.servers.rebuild(server=server.id, image=image.id) cloud.nova_client.servers.rebuild(server=server.id, image=image.id)
if wait: if wait:
_wait(timeout, cloud, server, action, module) _wait(timeout, cloud, server, action, module, shade)
module.exit_json(changed=True) module.exit_json(changed=True)
except shade.OpenStackCloudException as e: except shade.OpenStackCloudException as e:

View file

@ -57,14 +57,8 @@ EXAMPLES = '''
import fnmatch import fnmatch
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def main(): def main():
@ -76,17 +70,15 @@ def main():
module_kwargs = openstack_module_kwargs() module_kwargs = openstack_module_kwargs()
module = AnsibleModule(argument_spec, **module_kwargs) module = AnsibleModule(argument_spec, **module_kwargs)
if not HAS_SHADE: shade, cloud = openstack_cloud_from_module(module)
module.fail_json(msg='shade is required for this module')
try: try:
cloud = shade.openstack_cloud(**module.params)
openstack_servers = cloud.list_servers( openstack_servers = cloud.list_servers(
detailed=module.params['detailed']) detailed=module.params['detailed'])
if module.params['server']: if module.params['server']:
# filter servers by name # filter servers by name
pattern = module.params['server'] pattern = module.params['server']
# TODO(mordred) This is handled by shade now
openstack_servers = [server for server in openstack_servers openstack_servers = [server for server in openstack_servers
if fnmatch.fnmatch(server['name'], pattern) or fnmatch.fnmatch(server['id'], pattern)] if fnmatch.fnmatch(server['name'], pattern) or fnmatch.fnmatch(server['id'], pattern)]
module.exit_json(changed=False, ansible_facts=dict( module.exit_json(changed=False, ansible_facts=dict(

View file

@ -54,7 +54,7 @@ EXAMPLES = '''
- os_server_group: - os_server_group:
state: present state: present
auth: auth:
auth_url: https://api.cloud.catalyst.net.nz:5000/v2.0 auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -66,7 +66,7 @@ EXAMPLES = '''
- os_server_group: - os_server_group:
state: absent state: absent
auth: auth:
auth_url: https://api.cloud.catalyst.net.nz:5000/v2.0 auth_url: https://identity.example.com
username: admin username: admin
password: admin password: admin
project_name: admin project_name: admin
@ -104,14 +104,8 @@ user_id:
type: string type: string
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _system_state_change(state, server_group): def _system_state_change(state, server_group):
@ -136,15 +130,12 @@ def main():
**module_kwargs **module_kwargs
) )
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
name = module.params['name'] name = module.params['name']
policies = module.params['policies'] policies = module.params['policies']
state = module.params['state'] state = module.params['state']
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.openstack_cloud(**module.params)
server_group = cloud.get_server_group(name) server_group = cloud.get_server_group(name)
if module.check_mode: if module.check_mode:

View file

@ -65,15 +65,8 @@ EXAMPLES = '''
device: /dev/vdb device: /dev/vdb
''' '''
try:
import shade
from shade import meta
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _system_state_change(state, device): def _system_state_change(state, device):
@ -102,15 +95,12 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
state = module.params['state'] state = module.params['state']
wait = module.params['wait'] wait = module.params['wait']
timeout = module.params['timeout'] timeout = module.params['timeout']
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.openstack_cloud(**module.params)
server = cloud.get_server(module.params['server']) server = cloud.get_server(module.params['server'])
volume = cloud.get_volume(module.params['volume']) volume = cloud.get_volume(module.params['volume'])
dev = cloud.get_volume_attach_device(volume, server.id) dev = cloud.get_volume_attach_device(volume, server.id)
@ -128,7 +118,7 @@ def main():
server = cloud.get_server(module.params['server']) # refresh server = cloud.get_server(module.params['server']) # refresh
volume = cloud.get_volume(module.params['volume']) # refresh volume = cloud.get_volume(module.params['volume']) # refresh
hostvars = meta.get_hostvars_from_server(cloud, server) hostvars = cloud.get_openstack_vars(server)
module.exit_json( module.exit_json(
changed=True, changed=True,

View file

@ -158,19 +158,11 @@ stack:
'updated_time': null}" 'updated_time': null}"
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _create_stack(module, stack, cloud): def _create_stack(module, stack, cloud, shade):
try: try:
stack = cloud.create_stack(module.params['name'], stack = cloud.create_stack(module.params['name'],
tags=module.params['tag'], tags=module.params['tag'],
@ -190,7 +182,7 @@ def _create_stack(module, stack, cloud):
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))
def _update_stack(module, stack, cloud): def _update_stack(module, stack, cloud, shade):
try: try:
stack = cloud.update_stack( stack = cloud.update_stack(
module.params['name'], module.params['name'],
@ -238,15 +230,12 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
# stack API introduced in 1.8.0
min_version = '1.8.0'
tag = module.params['tag'] tag = module.params['tag']
if tag is not None: if tag is not None:
# stack tag API was introduced in 1.26.0 # stack tag API was introduced in 1.26.0
if not HAS_SHADE or (StrictVersion(shade.__version__) < StrictVersion('1.26.0')): min_version = '1.26.0'
module.fail_json(msg='shade 1.26.0 or higher is required for this module')
else:
# stack API introduced in 1.8.0
if not HAS_SHADE or (StrictVersion(shade.__version__) < StrictVersion('1.8.0')):
module.fail_json(msg='shade 1.8.0 or higher is required for this module')
state = module.params['state'] state = module.params['state']
name = module.params['name'] name = module.params['name']
@ -256,8 +245,8 @@ def main():
if not module.params[p]: if not module.params[p]:
module.fail_json(msg='%s required with present state' % p) module.fail_json(msg='%s required with present state' % p)
shade, cloud = openstack_cloud_from_module(module, min_version='1.26.0')
try: try:
cloud = shade.openstack_cloud(**module.params)
stack = cloud.get_stack(name) stack = cloud.get_stack(name)
if module.check_mode: if module.check_mode:
@ -266,9 +255,9 @@ def main():
if state == 'present': if state == 'present':
if not stack: if not stack:
stack = _create_stack(module, stack, cloud) stack = _create_stack(module, stack, cloud, shade)
else: else:
stack = _update_stack(module, stack, cloud) stack = _update_stack(module, stack, cloud, shade)
changed = True changed = True
module.exit_json(changed=changed, module.exit_json(changed=changed,
stack=stack, stack=stack,

View file

@ -157,16 +157,8 @@ EXAMPLES = '''
ipv6_address_mode: dhcpv6-stateless ipv6_address_mode: dhcpv6-stateless
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _can_update(subnet, module, cloud): def _can_update(subnet, module, cloud):
@ -270,9 +262,6 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
state = module.params['state'] state = module.params['state']
network_name = module.params['network_name'] network_name = module.params['network_name']
cidr = module.params['cidr'] cidr = module.params['cidr']
@ -290,10 +279,9 @@ def main():
use_default_subnetpool = module.params['use_default_subnetpool'] use_default_subnetpool = module.params['use_default_subnetpool']
project = module.params.pop('project') project = module.params.pop('project')
if (use_default_subnetpool and min_version = None
StrictVersion(shade.__version__) < StrictVersion('1.16.0')): if use_default_subnetpool:
module.fail_json(msg="To utilize use_default_subnetpool, the installed" min_version = '1.16.0'
" version of the shade library MUST be >=1.16.0")
# Check for required parameters when state == 'present' # Check for required parameters when state == 'present'
if state == 'present': if state == 'present':
@ -313,8 +301,8 @@ def main():
if no_gateway_ip and gateway_ip: if no_gateway_ip and gateway_ip:
module.fail_json(msg='no_gateway_ip is not allowed with gateway_ip') module.fail_json(msg='no_gateway_ip is not allowed with gateway_ip')
shade, cloud = openstack_cloud_from_module(module, min_version=min_version)
try: try:
cloud = shade.openstack_cloud(**module.params)
if project is not None: if project is not None:
proj = cloud.get_project(project) proj = cloud.get_project(project)
if proj is None: if proj is None:

View file

@ -44,7 +44,7 @@ EXAMPLES = '''
- name: Gather facts about previously created subnets - name: Gather facts about previously created subnets
os_subnets_facts: os_subnets_facts:
auth: auth:
auth_url: https://your_api_url.com:9000/v2.0 auth_url: https://identity.example.com
username: user username: user
password: password password: password
project_name: someproject project_name: someproject
@ -56,7 +56,7 @@ EXAMPLES = '''
- name: Gather facts about a previously created subnet by name - name: Gather facts about a previously created subnet by name
os_subnets_facts: os_subnets_facts:
auth: auth:
auth_url: https://your_api_url.com:9000/v2.0 auth_url: https://identity.example.com
username: user username: user
password: password password: password
project_name: someproject project_name: someproject
@ -70,7 +70,7 @@ EXAMPLES = '''
# Note: name and filters parameters are not mutually exclusive # Note: name and filters parameters are not mutually exclusive
os_subnets_facts: os_subnets_facts:
auth: auth:
auth_url: https://your_api_url.com:9000/v2.0 auth_url: https://identity.example.com
username: user username: user
password: password password: password
project_name: someproject project_name: someproject
@ -130,14 +130,8 @@ openstack_subnets:
type: list of dicts type: list of dicts
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def main(): def main():
@ -148,11 +142,8 @@ def main():
) )
module = AnsibleModule(argument_spec) module = AnsibleModule(argument_spec)
if not HAS_SHADE: shade, cloud = openstack_cloud_from_module(module)
module.fail_json(msg='shade is required for this module')
try: try:
cloud = shade.openstack_cloud(**module.params)
subnets = cloud.search_subnets(module.params['name'], subnets = cloud.search_subnets(module.params['name'],
module.params['filters']) module.params['filters'])
module.exit_json(changed=False, ansible_facts=dict( module.exit_json(changed=False, ansible_facts=dict(

View file

@ -139,14 +139,8 @@ user:
''' '''
from distutils.version import StrictVersion from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _needs_update(params_dict, user): def _needs_update(params_dict, user):
@ -205,11 +199,8 @@ def main():
argument_spec, argument_spec,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
name = module.params['name'] name = module.params['name']
password = module.params.pop('password') password = module.params.get('password')
email = module.params['email'] email = module.params['email']
default_project = module.params['default_project'] default_project = module.params['default_project']
domain = module.params['domain'] domain = module.params['domain']
@ -221,14 +212,13 @@ def main():
if description and StrictVersion(shade.__version__) < StrictVersion('1.13.0'): if description and StrictVersion(shade.__version__) < StrictVersion('1.13.0'):
module.fail_json(msg="To utilize description, the installed version of the shade library MUST be >=1.13.0") module.fail_json(msg="To utilize description, the installed version of the shade library MUST be >=1.13.0")
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.openstack_cloud(**module.params)
user = cloud.get_user(name) user = cloud.get_user(name)
domain_id = None domain_id = None
if domain: if domain:
opcloud = shade.operator_cloud(**module.params) domain_id = _get_domain_id(cloud, domain)
domain_id = _get_domain_id(opcloud, domain)
if state == 'present': if state == 'present':
if update_password in ('always', 'on_create'): if update_password in ('always', 'on_create'):

View file

@ -115,14 +115,8 @@ openstack_users:
type: string type: string
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def main(): def main():
@ -135,16 +129,12 @@ def main():
module = AnsibleModule(argument_spec) module = AnsibleModule(argument_spec)
if not HAS_SHADE: shade, opcloud = openstack_cloud_from_module(module)
module.fail_json(msg='shade is required for this module')
try: try:
name = module.params['name'] name = module.params['name']
domain = module.params['domain'] domain = module.params['domain']
filters = module.params['filters'] filters = module.params['filters']
opcloud = shade.operator_cloud(**module.params)
if domain: if domain:
try: try:
# We assume admin is passing domain id # We assume admin is passing domain id

View file

@ -51,14 +51,8 @@ EXAMPLES = '''
group: demo group: demo
''' '''
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _system_state_change(state, in_group): def _system_state_change(state, in_group):
@ -81,16 +75,12 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
user = module.params['user'] user = module.params['user']
group = module.params['group'] group = module.params['group']
state = module.params['state'] state = module.params['state']
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.operator_cloud(**module.params)
in_group = cloud.is_user_in_group(user, group) in_group = cloud.is_user_in_group(user, group)
if module.check_mode: if module.check_mode:

View file

@ -86,16 +86,8 @@ RETURN = '''
# #
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _system_state_change(state, assignment): def _system_state_change(state, assignment):
@ -137,20 +129,17 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
role = module.params.get('role')
user = module.params.get('user')
group = module.params.get('group')
project = module.params.get('project')
domain = module.params.get('domain')
state = module.params.get('state')
# role grant/revoke API introduced in 1.5.0 # role grant/revoke API introduced in 1.5.0
if not HAS_SHADE or (StrictVersion(shade.__version__) < StrictVersion('1.5.0')): shade, cloud = openstack_cloud_from_module(
module.fail_json(msg='shade 1.5.0 or higher is required for this module') module, min_version='1.5.0')
role = module.params.pop('role')
user = module.params.pop('user')
group = module.params.pop('group')
project = module.params.pop('project')
domain = module.params.pop('domain')
state = module.params.pop('state')
try: try:
cloud = shade.operator_cloud(**module.params)
filters = {} filters = {}
r = cloud.get_role(role) r = cloud.get_role(role)

View file

@ -95,14 +95,9 @@ EXAMPLES = '''
''' '''
from distutils.version import StrictVersion from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _present_volume(module, cloud): def _present_volume(module, cloud):
@ -137,7 +132,7 @@ def _present_volume(module, cloud):
module.exit_json(changed=True, id=volume['id'], volume=volume) module.exit_json(changed=True, id=volume['id'], volume=volume)
def _absent_volume(module, cloud): def _absent_volume(module, cloud, shade):
changed = False changed = False
if cloud.volume_exists(module.params['display_name']): if cloud.volume_exists(module.params['display_name']):
try: try:
@ -169,9 +164,6 @@ def main():
) )
module = AnsibleModule(argument_spec=argument_spec, **module_kwargs) module = AnsibleModule(argument_spec=argument_spec, **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
if (module.params['scheduler_hints'] and if (module.params['scheduler_hints'] and
StrictVersion(shade.__version__) < StrictVersion('1.22')): StrictVersion(shade.__version__) < StrictVersion('1.22')):
module.fail_json(msg="To utilize scheduler_hints, the installed version of" module.fail_json(msg="To utilize scheduler_hints, the installed version of"
@ -182,12 +174,12 @@ def main():
if state == 'present' and not module.params['size']: if state == 'present' and not module.params['size']:
module.fail_json(msg="Size is required when state is 'present'") module.fail_json(msg="Size is required when state is 'present'")
shade, cloud = openstack_cloud_from_module(module)
try: try:
cloud = shade.openstack_cloud(**module.params)
if state == 'present': if state == 'present':
_present_volume(module, cloud) _present_volume(module, cloud)
if state == 'absent': if state == 'absent':
_absent_volume(module, cloud) _absent_volume(module, cloud, shade)
except shade.OpenStackCloudException as e: except shade.OpenStackCloudException as e:
module.fail_json(msg=str(e)) module.fail_json(msg=str(e))

View file

@ -126,16 +126,8 @@ zone:
sample: [] sample: []
''' '''
from distutils.version import StrictVersion
try:
import shade
HAS_SHADE = True
except ImportError:
HAS_SHADE = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs from ansible.module_utils.openstack import openstack_full_argument_spec, openstack_module_kwargs, openstack_cloud_from_module
def _system_state_change(state, email, description, ttl, masters, zone): def _system_state_change(state, email, description, ttl, masters, zone):
@ -171,17 +163,11 @@ def main():
supports_check_mode=True, supports_check_mode=True,
**module_kwargs) **module_kwargs)
if not HAS_SHADE:
module.fail_json(msg='shade is required for this module')
if StrictVersion(shade.__version__) < StrictVersion('1.8.0'):
module.fail_json(msg="To utilize this module, the installed version of"
"the shade library MUST be >=1.8.0")
name = module.params.get('name') name = module.params.get('name')
state = module.params.get('state') state = module.params.get('state')
shade, cloud = openstack_cloud_from_module(module, min_version='1.8.0')
try: try:
cloud = shade.openstack_cloud(**module.params)
zone = cloud.get_zone(name) zone = cloud.get_zone(name)
if state == 'present': if state == 'present':

View file

@ -23,9 +23,13 @@ class ModuleDocFragment(object):
options: options:
cloud: cloud:
description: description:
- Named cloud to operate against. Provides default values for I(auth) and - Named cloud or cloud config to operate against.
I(auth_type). This parameter is not needed if I(auth) is provided or if If I(cloud) is a string, it references a named cloud config as defined
OpenStack OS_* environment variables are present. in an OpenStack clouds.yaml file. Provides default values for I(auth)
and I(auth_type). This parameter is not needed if I(auth) is provided
or if OpenStack OS_* environment variables are present.
If I(cloud) is a dict, it contains a complete cloud configuration like
would be in a section of clouds.yaml.
required: false required: false
auth: auth:
description: description:
@ -87,18 +91,14 @@ options:
- A path to a client key to use as part of the SSL transaction. - A path to a client key to use as part of the SSL transaction.
required: false required: false
default: None default: None
endpoint_type: interface:
description: description:
- Endpoint URL type to fetch from the service catalog. - Endpoint URL type to fetch from the service catalog.
choices: [public, internal, admin] choices: [public, internal, admin]
required: false required: false
default: public default: public
identity_api_version: aliases: ['endpoint_type']
description: version_added: "2.3"
- The identity API version
choices: [2.0, 3]
required: false
default: None
requirements: requirements:
- python >= 2.7 - python >= 2.7
- shade - shade

View file

@ -81,6 +81,9 @@ class FakeCloud (object):
def get_network(self, name): def get_network(self, name):
return self._find(self.networks, name) return self._find(self.networks, name)
def get_openstack_vars(self, server):
return server
create_server = mock.MagicMock() create_server = mock.MagicMock()