summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-03-31 17:05:43 -0400
committerJesse Keating <jkeating@j2solutions.net>2015-05-20 11:41:24 -0700
commit6606e4f68dc9d7b6e4fb25e1bd05b02cac84a46c (patch)
tree45813e08fb6c98434a9ebf54393db6834e627b81
parentb0412c13fc51a74c2236f7dd9e66d8b4d1feed84 (diff)
downloadansible-modules-core-6606e4f68dc9d7b6e4fb25e1bd05b02cac84a46c.tar.gz
Add OpenStack Network module
Also, deprecate the old quantum network module
-rw-r--r--cloud/openstack/_quantum_network.py (renamed from cloud/openstack/quantum_network.py)1
-rw-r--r--cloud/openstack/os_network.py107
2 files changed, 108 insertions, 0 deletions
diff --git a/cloud/openstack/quantum_network.py b/cloud/openstack/_quantum_network.py
index ff8b2683..93b10880 100644
--- a/cloud/openstack/quantum_network.py
+++ b/cloud/openstack/_quantum_network.py
@@ -30,6 +30,7 @@ DOCUMENTATION = '''
---
module: quantum_network
version_added: "1.4"
+deprecated: Deprecated in 2.0. Use os_network instead
short_description: Creates/Removes networks from OpenStack
description:
- Add or Remove network from OpenStack.
diff --git a/cloud/openstack/os_network.py b/cloud/openstack/os_network.py
new file mode 100644
index 00000000..b77a7e33
--- /dev/null
+++ b/cloud/openstack/os_network.py
@@ -0,0 +1,107 @@
+#!/usr/bin/python
+
+# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
+# Copyright (c) 2013, Benno Joy <benno@ansible.com>
+#
+# This module is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This software is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this software. If not, see <http://www.gnu.org/licenses/>.
+
+try:
+ import shade
+ HAS_SHADE = True
+except ImportError:
+ HAS_SHADE = False
+
+DOCUMENTATION = '''
+---
+module: os_network
+short_description: Creates/Removes networks from OpenStack
+extends_documentation_fragment: openstack
+version_added: "2.0"
+description:
+ - Add or Remove network from OpenStack.
+options:
+ name:
+ description:
+ - Name to be assigned to the network.
+ required: true
+ shared:
+ description:
+ - Whether this network is shared or not.
+ required: false
+ default: false
+ admin_state_up:
+ description:
+ - Whether the state should be marked as up or down.
+ required: false
+ default: true
+ state:
+ description:
+ - Indicate desired state of the resource.
+ choices: ['present', 'absent']
+ required: false
+ default: present
+requirements: ["shade"]
+'''
+
+EXAMPLES = '''
+- os_network:
+ name=t1network
+ state=present
+'''
+
+
+def main():
+ argument_spec = openstack_full_argument_spec(
+ name=dict(required=True),
+ shared=dict(default=False, type='bool'),
+ admin_state_up=dict(default=True, type='bool'),
+ )
+
+ module_kwargs = openstack_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']
+ name = module.params['name']
+ shared = module.params['shared']
+ admin_state_up = module.params['admin_state_up']
+
+ try:
+ cloud = shade.openstack_cloud(**module.params)
+ net = cloud.get_network(name)
+
+ if state == 'present':
+ if not net:
+ net = cloud.create_network(name, shared, admin_state_up)
+ module.exit_json(changed=True, result="Created", id=net['id'])
+ else:
+ module.exit_json(changed=False, result="Success", id=net['id'])
+
+ elif state == 'absent':
+ if not net:
+ module.exit_json(changed=False, result="Success")
+ else:
+ cloud.delete_network(name)
+ module.exit_json(changed=True, result="Deleted")
+
+ except shade.OpenStackCloudException as e:
+ module.fail_json(msg=e.message)
+
+
+# this is magic, see lib/ansible/module_common.py
+from ansible.module_utils.basic import *
+from ansible.module_utils.openstack import *
+main()