1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

sl_vm: PEP8 compliancy and documentation changes (#32657)

This PR includes:
- PEP8 compliancy changes
- Documentation changes
This commit is contained in:
Dag Wieers 2017-11-15 21:22:32 +01:00 committed by ansibot
parent 53c5e5bf5a
commit 3089892e59
2 changed files with 101 additions and 126 deletions

View file

@ -1,145 +1,121 @@
#!/usr/bin/python #!/usr/bin/python
# Copyright: Ansible Project # -*- coding: utf-8 -*-
# Copyright: (c) 2017, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'], 'status': ['preview'],
'supported_by': 'community'} 'supported_by': 'community'}
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: sl_vm module: sl_vm
short_description: create or cancel a virtual instance in SoftLayer short_description: create or cancel a virtual instance in SoftLayer
description: description:
- Creates or cancels SoftLayer instances. When created, optionally waits for it to be 'running'. - Creates or cancels SoftLayer instances.
- When created, optionally waits for it to be 'running'.
version_added: "2.1" version_added: "2.1"
options: options:
instance_id: instance_id:
description: description:
- Instance Id of the virtual instance to perform action option - Instance Id of the virtual instance to perform action option.
required: false
default: null
hostname: hostname:
description: description:
- Hostname to be provided to a virtual instance - Hostname to be provided to a virtual instance.
required: false
default: null
domain: domain:
description: description:
- Domain name to be provided to a virtual instance - Domain name to be provided to a virtual instance.
required: false
default: null
datacenter: datacenter:
description: description:
- Datacenter for the virtual instance to be deployed - Datacenter for the virtual instance to be deployed.
required: false
default: null
tags: tags:
description: description:
- Tag or list of tags to be provided to a virtual instance - Tag or list of tags to be provided to a virtual instance.
required: false
default: null
hourly: hourly:
description: description:
- Flag to determine if the instance should be hourly billed - Flag to determine if the instance should be hourly billed.
required: false type: bool
default: true default: 'yes'
private: private:
description: description:
- Flag to determine if the instance should be private only - Flag to determine if the instance should be private only.
required: false type: bool
default: false default: 'no'
dedicated: dedicated:
description: description:
- Flag to determine if the instance should be deployed in dedicated space - Flag to determine if the instance should be deployed in dedicated space.
required: false type: bool
default: false default: 'no'
local_disk: local_disk:
description: description:
- Flag to determine if local disk should be used for the new instance - Flag to determine if local disk should be used for the new instance.
required: false type: bool
default: true default: 'yes'
cpus: cpus:
description: description:
- Count of cpus to be assigned to new virtual instance - Count of cpus to be assigned to new virtual instance.
required: true required: true
default: null
memory: memory:
description: description:
- Amount of memory to be assigned to new virtual instance - Amount of memory to be assigned to new virtual instance.
required: true required: true
default: null
disks: disks:
description: description:
- List of disk sizes to be assigned to new virtual instance - List of disk sizes to be assigned to new virtual instance.
required: true required: true
default: [25] default: [ 25 ]
os_code: os_code:
description: description:
- OS Code to be used for new virtual instance - OS Code to be used for new virtual instance.
required: false
default: null
image_id: image_id:
description: description:
- Image Template to be used for new virtual instance - Image Template to be used for new virtual instance.
required: false
default: null
nic_speed: nic_speed:
description: description:
- NIC Speed to be assigned to new virtual instance - NIC Speed to be assigned to new virtual instance.
required: false
default: 10 default: 10
public_vlan: public_vlan:
description: description:
- VLAN by its Id to be assigned to the public NIC - VLAN by its Id to be assigned to the public NIC.
required: false
default: null
private_vlan: private_vlan:
description: description:
- VLAN by its Id to be assigned to the private NIC - VLAN by its Id to be assigned to the private NIC.
required: false
default: null
ssh_keys: ssh_keys:
description: description:
- List of ssh keys by their Id to be assigned to a virtual instance - List of ssh keys by their Id to be assigned to a virtual instance.
required: false
default: null
post_uri: post_uri:
description: description:
- URL of a post provisioning script to be loaded and executed on virtual instance - URL of a post provisioning script to be loaded and executed on virtual instance.
required: false
default: null
state: state:
description: description:
- Create, or cancel a virtual instance. Specify "present" for create, "absent" to cancel. - Create, or cancel a virtual instance.
required: false - Specify C(present) for create, C(absent) to cancel.
default: 'present' choices: [ absent, present ]
default: present
wait: wait:
description: description:
- Flag used to wait for active status before returning - Flag used to wait for active status before returning.
required: false type: bool
default: true default: 'yes'
wait_time: wait_time:
description: description:
- time in seconds before wait returns - Time in seconds before wait returns.
required: false
default: 600 default: 600
requirements: requirements:
- "python >= 2.6" - python >= 2.6
- "softlayer >= 4.1.1" - softlayer >= 4.1.1
author: "Matt Colton (@mcltn)" author:
- Matt Colton (@mcltn)
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: Build instance - name: Build instance
hosts: localhost hosts: localhost
gather_facts: False gather_facts: no
tasks: tasks:
- name: Build instance request - name: Build instance request
sl_vm: sl_vm:
@ -147,19 +123,19 @@ EXAMPLES = '''
domain: anydomain.com domain: anydomain.com
datacenter: dal09 datacenter: dal09
tags: ansible-module-test tags: ansible-module-test
hourly: True hourly: yes
private: False private: no
dedicated: False dedicated: no
local_disk: True local_disk: yes
cpus: 1 cpus: 1
memory: 1024 memory: 1024
disks: [25] disks: [25]
os_code: UBUNTU_LATEST os_code: UBUNTU_LATEST
wait: False wait: no
- name: Build additional instances - name: Build additional instances
hosts: localhost hosts: localhost
gather_facts: False gather_facts: no
tasks: tasks:
- name: Build instances request - name: Build instances request
sl_vm: sl_vm:
@ -184,10 +160,10 @@ EXAMPLES = '''
tags: tags:
- ansible-module-test - ansible-module-test
- ansible-module-test-slaves - ansible-module-test-slaves
hourly: True hourly: yes
private: False private: no
dedicated: False dedicated: no
local_disk: True local_disk: yes
cpus: 1 cpus: 1
memory: 1024 memory: 1024
disks: disks:
@ -202,10 +178,10 @@ EXAMPLES = '''
tags: tags:
- ansible-module-test - ansible-module-test
- ansible-module-test-slaves - ansible-module-test-slaves
hourly: True hourly: yes
private: False private: no
dedicated: False dedicated: no
local_disk: True local_disk: yes
cpus: 1 cpus: 1
memory: 1024 memory: 1024
disks: disks:
@ -213,11 +189,11 @@ EXAMPLES = '''
- 100 - 100
os_code: UBUNTU_LATEST os_code: UBUNTU_LATEST
ssh_keys: [] ssh_keys: []
wait: True wait: yes
- name: Cancel instances - name: Cancel instances
hosts: localhost hosts: localhost
gather_facts: False gather_facts: no
tasks: tasks:
- name: Cancel by tag - name: Cancel by tag
sl_vm: sl_vm:
@ -244,7 +220,7 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import string_types from ansible.module_utils.six import string_types
#TODO: get this info from API # TODO: get this info from API
STATES = ['present', 'absent'] STATES = ['present', 'absent']
DATACENTERS = ['ams01', 'ams03', 'che01', 'dal01', 'dal05', 'dal06', 'dal09', 'dal10', 'fra02', 'hkg02', 'hou02', 'lon02', 'mel01', 'mex01', 'mil01', 'mon01', DATACENTERS = ['ams01', 'ams03', 'che01', 'dal01', 'dal05', 'dal06', 'dal09', 'dal10', 'fra02', 'hkg02', 'hou02', 'lon02', 'mel01', 'mex01', 'mil01', 'mon01',
'osl01', 'par01', 'sjc01', 'sjc03', 'sao01', 'sea01', 'sng01', 'syd01', 'tok02', 'tor01', 'wdc01', 'wdc04'] 'osl01', 'par01', 'sjc01', 'sjc03', 'sao01', 'sea01', 'sng01', 'syd01', 'tok02', 'tor01', 'wdc01', 'wdc04']
@ -259,21 +235,20 @@ NIC_SPEEDS = [10, 100, 1000]
def create_virtual_instance(module): def create_virtual_instance(module):
instances = vsManager.list_instances( instances = vsManager.list_instances(
hostname = module.params.get('hostname'), hostname=module.params.get('hostname'),
domain = module.params.get('domain'), domain=module.params.get('domain'),
datacenter = module.params.get('datacenter') datacenter=module.params.get('datacenter')
) )
if instances: if instances:
return False, None return False, None
# Check if OS or Image Template is provided (Can't be both, defaults to OS) # Check if OS or Image Template is provided (Can't be both, defaults to OS)
if (module.params.get('os_code') is not None and module.params.get('os_code') != ''): if (module.params.get('os_code') is not None and module.params.get('os_code') != ''):
module.params['image_id'] = '' module.params['image_id'] = ''
elif (module.params.get('image_id') is not None and module.params.get('image_id') != ''): elif (module.params.get('image_id') is not None and module.params.get('image_id') != ''):
module.params['os_code'] = '' module.params['os_code'] = ''
module.params['disks'] = [] # Blank out disks since it will use the template module.params['disks'] = [] # Blank out disks since it will use the template
else: else:
return False, None return False, None
@ -282,24 +257,25 @@ def create_virtual_instance(module):
tags = ','.join(map(str, module.params.get('tags'))) tags = ','.join(map(str, module.params.get('tags')))
instance = vsManager.create_instance( instance = vsManager.create_instance(
hostname = module.params.get('hostname'), hostname=module.params.get('hostname'),
domain = module.params.get('domain'), domain=module.params.get('domain'),
cpus = module.params.get('cpus'), cpus=module.params.get('cpus'),
memory = module.params.get('memory'), memory=module.params.get('memory'),
hourly = module.params.get('hourly'), hourly=module.params.get('hourly'),
datacenter = module.params.get('datacenter'), datacenter=module.params.get('datacenter'),
os_code = module.params.get('os_code'), os_code=module.params.get('os_code'),
image_id = module.params.get('image_id'), image_id=module.params.get('image_id'),
local_disk = module.params.get('local_disk'), local_disk=module.params.get('local_disk'),
disks = module.params.get('disks'), disks=module.params.get('disks'),
ssh_keys = module.params.get('ssh_keys'), ssh_keys=module.params.get('ssh_keys'),
nic_speed = module.params.get('nic_speed'), nic_speed=module.params.get('nic_speed'),
private = module.params.get('private'), private=module.params.get('private'),
public_vlan = module.params.get('public_vlan'), public_vlan=module.params.get('public_vlan'),
private_vlan = module.params.get('private_vlan'), private_vlan=module.params.get('private_vlan'),
dedicated = module.params.get('dedicated'), dedicated=module.params.get('dedicated'),
post_uri = module.params.get('post_uri'), post_uri=module.params.get('post_uri'),
tags = tags) tags=tags,
)
if instance is not None and instance['id'] > 0: if instance is not None and instance['id'] > 0:
return True, instance return True, instance
@ -307,7 +283,7 @@ def create_virtual_instance(module):
return False, None return False, None
def wait_for_instance(module,id): def wait_for_instance(module, id):
instance = None instance = None
completed = False completed = False
wait_timeout = time.time() + module.params.get('wait_time') wait_timeout = time.time() + module.params.get('wait_time')
@ -328,7 +304,7 @@ def cancel_instance(module):
tags = module.params.get('tags') tags = module.params.get('tags')
if isinstance(tags, string_types): if isinstance(tags, string_types):
tags = [module.params.get('tags')] tags = [module.params.get('tags')]
instances = vsManager.list_instances(tags = tags, hostname = module.params.get('hostname'), domain = module.params.get('domain')) instances = vsManager.list_instances(tags=tags, hostname=module.params.get('hostname'), domain=module.params.get('domain'))
for instance in instances: for instance in instances:
try: try:
vsManager.cancel_instance(instance['id']) vsManager.cancel_instance(instance['id'])
@ -349,11 +325,11 @@ def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
instance_id=dict(), instance_id=dict(type='str'),
hostname=dict(), hostname=dict(type='str'),
domain=dict(), domain=dict(type='str'),
datacenter=dict(choices=DATACENTERS), datacenter=dict(type='str', choices=DATACENTERS),
tags=dict(), tags=dict(type='str'),
hourly=dict(type='bool', default=True), hourly=dict(type='bool', default=True),
private=dict(type='bool', default=False), private=dict(type='bool', default=False),
dedicated=dict(type='bool', default=False), dedicated=dict(type='bool', default=False),
@ -361,17 +337,17 @@ def main():
cpus=dict(type='int', choices=CPU_SIZES), cpus=dict(type='int', choices=CPU_SIZES),
memory=dict(type='int', choices=MEMORY_SIZES), memory=dict(type='int', choices=MEMORY_SIZES),
disks=dict(type='list', default=[25]), disks=dict(type='list', default=[25]),
os_code=dict(), os_code=dict(type='str'),
image_id=dict(), image_id=dict(type='str'),
nic_speed=dict(type='int', choices=NIC_SPEEDS), nic_speed=dict(type='int', choices=NIC_SPEEDS),
public_vlan=dict(), public_vlan=dict(type='str'),
private_vlan=dict(), private_vlan=dict(type='str'),
ssh_keys=dict(type='list', default=[]), ssh_keys=dict(type='list', default=[]),
post_uri=dict(), post_uri=dict(type='str'),
state=dict(default='present', choices=STATES), state=dict(type='str', default='present', choices=STATES),
wait=dict(type='bool', default=True), wait=dict(type='bool', default=True),
wait_time=dict(type='int', default=600) wait_time=dict(type='int', default=600),
) )
) )
if not HAS_SL: if not HAS_SL:

View file

@ -99,7 +99,6 @@ lib/ansible/modules/cloud/rackspace/rax_mon_check.py
lib/ansible/modules/cloud/rackspace/rax_mon_entity.py lib/ansible/modules/cloud/rackspace/rax_mon_entity.py
lib/ansible/modules/cloud/rackspace/rax_mon_notification.py lib/ansible/modules/cloud/rackspace/rax_mon_notification.py
lib/ansible/modules/cloud/rackspace/rax_mon_notification_plan.py lib/ansible/modules/cloud/rackspace/rax_mon_notification_plan.py
lib/ansible/modules/cloud/softlayer/sl_vm.py
lib/ansible/modules/cloud/univention/udm_dns_record.py lib/ansible/modules/cloud/univention/udm_dns_record.py
lib/ansible/modules/cloud/univention/udm_dns_zone.py lib/ansible/modules/cloud/univention/udm_dns_zone.py
lib/ansible/modules/cloud/univention/udm_group.py lib/ansible/modules/cloud/univention/udm_group.py