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
# 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)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: sl_vm
short_description: create or cancel a virtual instance in SoftLayer
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"
options:
instance_id:
description:
- Instance Id of the virtual instance to perform action option
required: false
default: null
- Instance Id of the virtual instance to perform action option.
hostname:
description:
- Hostname to be provided to a virtual instance
required: false
default: null
- Hostname to be provided to a virtual instance.
domain:
description:
- Domain name to be provided to a virtual instance
required: false
default: null
- Domain name to be provided to a virtual instance.
datacenter:
description:
- Datacenter for the virtual instance to be deployed
required: false
default: null
- Datacenter for the virtual instance to be deployed.
tags:
description:
- Tag or list of tags to be provided to a virtual instance
required: false
default: null
- Tag or list of tags to be provided to a virtual instance.
hourly:
description:
- Flag to determine if the instance should be hourly billed
required: false
default: true
- Flag to determine if the instance should be hourly billed.
type: bool
default: 'yes'
private:
description:
- Flag to determine if the instance should be private only
required: false
default: false
- Flag to determine if the instance should be private only.
type: bool
default: 'no'
dedicated:
description:
- Flag to determine if the instance should be deployed in dedicated space
required: false
default: false
- Flag to determine if the instance should be deployed in dedicated space.
type: bool
default: 'no'
local_disk:
description:
- Flag to determine if local disk should be used for the new instance
required: false
default: true
- Flag to determine if local disk should be used for the new instance.
type: bool
default: 'yes'
cpus:
description:
- Count of cpus to be assigned to new virtual instance
- Count of cpus to be assigned to new virtual instance.
required: true
default: null
memory:
description:
- Amount of memory to be assigned to new virtual instance
- Amount of memory to be assigned to new virtual instance.
required: true
default: null
disks:
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
default: [25]
default: [ 25 ]
os_code:
description:
- OS Code to be used for new virtual instance
required: false
default: null
- OS Code to be used for new virtual instance.
image_id:
description:
- Image Template to be used for new virtual instance
required: false
default: null
- Image Template to be used for new virtual instance.
nic_speed:
description:
- NIC Speed to be assigned to new virtual instance
required: false
- NIC Speed to be assigned to new virtual instance.
default: 10
public_vlan:
description:
- VLAN by its Id to be assigned to the public NIC
required: false
default: null
- VLAN by its Id to be assigned to the public NIC.
private_vlan:
description:
- VLAN by its Id to be assigned to the private NIC
required: false
default: null
- VLAN by its Id to be assigned to the private NIC.
ssh_keys:
description:
- List of ssh keys by their Id to be assigned to a virtual instance
required: false
default: null
- List of ssh keys by their Id to be assigned to a virtual instance.
post_uri:
description:
- URL of a post provisioning script to be loaded and executed on virtual instance
required: false
default: null
- URL of a post provisioning script to be loaded and executed on virtual instance.
state:
description:
- Create, or cancel a virtual instance. Specify "present" for create, "absent" to cancel.
required: false
default: 'present'
- Create, or cancel a virtual instance.
- Specify C(present) for create, C(absent) to cancel.
choices: [ absent, present ]
default: present
wait:
description:
- Flag used to wait for active status before returning
required: false
default: true
- Flag used to wait for active status before returning.
type: bool
default: 'yes'
wait_time:
description:
- time in seconds before wait returns
required: false
- Time in seconds before wait returns.
default: 600
requirements:
- "python >= 2.6"
- "softlayer >= 4.1.1"
author: "Matt Colton (@mcltn)"
- python >= 2.6
- softlayer >= 4.1.1
author:
- Matt Colton (@mcltn)
'''
EXAMPLES = '''
- name: Build instance
hosts: localhost
gather_facts: False
gather_facts: no
tasks:
- name: Build instance request
sl_vm:
@ -147,19 +123,19 @@ EXAMPLES = '''
domain: anydomain.com
datacenter: dal09
tags: ansible-module-test
hourly: True
private: False
dedicated: False
local_disk: True
hourly: yes
private: no
dedicated: no
local_disk: yes
cpus: 1
memory: 1024
disks: [25]
os_code: UBUNTU_LATEST
wait: False
wait: no
- name: Build additional instances
hosts: localhost
gather_facts: False
gather_facts: no
tasks:
- name: Build instances request
sl_vm:
@ -184,10 +160,10 @@ EXAMPLES = '''
tags:
- ansible-module-test
- ansible-module-test-slaves
hourly: True
private: False
dedicated: False
local_disk: True
hourly: yes
private: no
dedicated: no
local_disk: yes
cpus: 1
memory: 1024
disks:
@ -202,10 +178,10 @@ EXAMPLES = '''
tags:
- ansible-module-test
- ansible-module-test-slaves
hourly: True
private: False
dedicated: False
local_disk: True
hourly: yes
private: no
dedicated: no
local_disk: yes
cpus: 1
memory: 1024
disks:
@ -213,11 +189,11 @@ EXAMPLES = '''
- 100
os_code: UBUNTU_LATEST
ssh_keys: []
wait: True
wait: yes
- name: Cancel instances
hosts: localhost
gather_facts: False
gather_facts: no
tasks:
- name: Cancel by tag
sl_vm:
@ -244,7 +220,7 @@ from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six import string_types
#TODO: get this info from API
# TODO: get this info from API
STATES = ['present', 'absent']
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']
@ -259,21 +235,20 @@ NIC_SPEEDS = [10, 100, 1000]
def create_virtual_instance(module):
instances = vsManager.list_instances(
hostname = module.params.get('hostname'),
domain = module.params.get('domain'),
datacenter = module.params.get('datacenter')
hostname=module.params.get('hostname'),
domain=module.params.get('domain'),
datacenter=module.params.get('datacenter')
)
if instances:
return False, None
# 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') != ''):
module.params['image_id'] = ''
elif (module.params.get('image_id') is not None and module.params.get('image_id') != ''):
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:
return False, None
@ -282,24 +257,25 @@ def create_virtual_instance(module):
tags = ','.join(map(str, module.params.get('tags')))
instance = vsManager.create_instance(
hostname = module.params.get('hostname'),
domain = module.params.get('domain'),
cpus = module.params.get('cpus'),
memory = module.params.get('memory'),
hourly = module.params.get('hourly'),
datacenter = module.params.get('datacenter'),
os_code = module.params.get('os_code'),
image_id = module.params.get('image_id'),
local_disk = module.params.get('local_disk'),
disks = module.params.get('disks'),
ssh_keys = module.params.get('ssh_keys'),
nic_speed = module.params.get('nic_speed'),
private = module.params.get('private'),
public_vlan = module.params.get('public_vlan'),
private_vlan = module.params.get('private_vlan'),
dedicated = module.params.get('dedicated'),
post_uri = module.params.get('post_uri'),
tags = tags)
hostname=module.params.get('hostname'),
domain=module.params.get('domain'),
cpus=module.params.get('cpus'),
memory=module.params.get('memory'),
hourly=module.params.get('hourly'),
datacenter=module.params.get('datacenter'),
os_code=module.params.get('os_code'),
image_id=module.params.get('image_id'),
local_disk=module.params.get('local_disk'),
disks=module.params.get('disks'),
ssh_keys=module.params.get('ssh_keys'),
nic_speed=module.params.get('nic_speed'),
private=module.params.get('private'),
public_vlan=module.params.get('public_vlan'),
private_vlan=module.params.get('private_vlan'),
dedicated=module.params.get('dedicated'),
post_uri=module.params.get('post_uri'),
tags=tags,
)
if instance is not None and instance['id'] > 0:
return True, instance
@ -307,7 +283,7 @@ def create_virtual_instance(module):
return False, None
def wait_for_instance(module,id):
def wait_for_instance(module, id):
instance = None
completed = False
wait_timeout = time.time() + module.params.get('wait_time')
@ -328,7 +304,7 @@ def cancel_instance(module):
tags = module.params.get('tags')
if isinstance(tags, string_types):
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:
try:
vsManager.cancel_instance(instance['id'])
@ -349,11 +325,11 @@ def main():
module = AnsibleModule(
argument_spec=dict(
instance_id=dict(),
hostname=dict(),
domain=dict(),
datacenter=dict(choices=DATACENTERS),
tags=dict(),
instance_id=dict(type='str'),
hostname=dict(type='str'),
domain=dict(type='str'),
datacenter=dict(type='str', choices=DATACENTERS),
tags=dict(type='str'),
hourly=dict(type='bool', default=True),
private=dict(type='bool', default=False),
dedicated=dict(type='bool', default=False),
@ -361,17 +337,17 @@ def main():
cpus=dict(type='int', choices=CPU_SIZES),
memory=dict(type='int', choices=MEMORY_SIZES),
disks=dict(type='list', default=[25]),
os_code=dict(),
image_id=dict(),
os_code=dict(type='str'),
image_id=dict(type='str'),
nic_speed=dict(type='int', choices=NIC_SPEEDS),
public_vlan=dict(),
private_vlan=dict(),
public_vlan=dict(type='str'),
private_vlan=dict(type='str'),
ssh_keys=dict(type='list', default=[]),
post_uri=dict(),
state=dict(default='present', choices=STATES),
post_uri=dict(type='str'),
state=dict(type='str', default='present', choices=STATES),
wait=dict(type='bool', default=True),
wait_time=dict(type='int', default=600)
)
wait_time=dict(type='int', default=600),
)
)
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_notification.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_zone.py
lib/ansible/modules/cloud/univention/udm_group.py