mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-03 23:41:51 +00:00
move imports from functions to the top of the file (#11396)
* move imports from functions to the top of the file * add changelog frag * Apply suggestions from code review Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
defd15609c
commit
c8356981bb
7 changed files with 21 additions and 27 deletions
7
changelogs/fragments/11396-in-def-imports.yml
Normal file
7
changelogs/fragments/11396-in-def-imports.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
minor_changes:
|
||||
- jenkins_script - move ``import`` statemetns to the top of the file (https://github.com/ansible-collections/community.general/pull/11396).
|
||||
- linode - move ``import`` statemetns to the top of the file (https://github.com/ansible-collections/community.general/pull/11396).
|
||||
- one_image - move ``import`` statemetns to the top of the file (https://github.com/ansible-collections/community.general/pull/11396).
|
||||
- one_image_info - move ``import`` statemetns to the top of the file (https://github.com/ansible-collections/community.general/pull/11396).
|
||||
- one_service - move ``import`` statemetns to the top of the file (https://github.com/ansible-collections/community.general/pull/11396).
|
||||
- one_vm - move ``import`` statemetns to the top of the file (https://github.com/ansible-collections/community.general/pull/11396).
|
||||
|
|
@ -103,6 +103,7 @@ output:
|
|||
|
||||
import json
|
||||
from http import cookiejar
|
||||
from string import Template
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
|
@ -153,8 +154,6 @@ def main():
|
|||
module.params["force_basic_auth"] = True
|
||||
|
||||
if module.params["args"] is not None:
|
||||
from string import Template
|
||||
|
||||
try:
|
||||
script_contents = Template(module.params["script"]).substitute(module.params["args"])
|
||||
except KeyError as err:
|
||||
|
|
|
|||
|
|
@ -272,6 +272,8 @@ EXAMPLES = r"""
|
|||
delegate_to: localhost
|
||||
"""
|
||||
|
||||
import random
|
||||
import string
|
||||
import time
|
||||
import traceback
|
||||
|
||||
|
|
@ -295,8 +297,6 @@ def randompass():
|
|||
# It must contain at least two of these four character classes:
|
||||
# lower case letters - upper case letters - numbers - punctuation
|
||||
# we play it safe :)
|
||||
import random
|
||||
import string
|
||||
|
||||
# as of python 2.4, this reseeds the PRNG from urandom
|
||||
random.seed()
|
||||
|
|
|
|||
|
|
@ -368,6 +368,8 @@ snapshots:
|
|||
"""
|
||||
|
||||
|
||||
import time
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.opennebula import OpenNebulaModule
|
||||
|
||||
|
||||
|
|
@ -489,8 +491,6 @@ class ImageModule(OpenNebulaModule):
|
|||
return result
|
||||
|
||||
def wait_for_ready(self, image_id, wait_timeout=60):
|
||||
import time
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
while (time.time() - start_time) < wait_timeout:
|
||||
|
|
@ -507,8 +507,6 @@ class ImageModule(OpenNebulaModule):
|
|||
self.module.fail_json(msg="Wait timeout has expired!")
|
||||
|
||||
def wait_for_delete(self, image_id, wait_timeout=60):
|
||||
import time
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
while (time.time() - start_time) < wait_timeout:
|
||||
|
|
|
|||
|
|
@ -269,6 +269,7 @@ images:
|
|||
name: SampleName
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.opennebula import OpenNebulaModule
|
||||
|
||||
|
|
@ -345,8 +346,6 @@ class ImageInfoModule(OpenNebulaModule):
|
|||
pool = self.get_all_images()
|
||||
|
||||
if name_pattern.startswith("~"):
|
||||
import re
|
||||
|
||||
if name_pattern[1] == "*":
|
||||
pattern = re.compile(name_pattern[2:], re.IGNORECASE)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -231,6 +231,9 @@ roles:
|
|||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
from collections import namedtuple
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.urls import open_url
|
||||
|
||||
|
|
@ -396,8 +399,6 @@ def create_service(module, auth, template_id, service_name, custom_attrs, unique
|
|||
|
||||
|
||||
def wait_for_service_to_become_ready(module, auth, service_id, wait_timeout):
|
||||
import time
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
while (time.time() - start_time) < wait_timeout:
|
||||
|
|
@ -729,8 +730,6 @@ def get_connection_info(module):
|
|||
module.fail_json(
|
||||
msg="One or more connection parameters (api_url, api_username, api_password) were not specified"
|
||||
)
|
||||
from collections import namedtuple
|
||||
|
||||
auth_params = namedtuple("auth", ("url", "user", "password"))
|
||||
|
||||
return auth_params(url=url, user=username, password=password)
|
||||
|
|
|
|||
|
|
@ -682,8 +682,12 @@ try:
|
|||
except ImportError:
|
||||
HAS_PYONE = False
|
||||
|
||||
|
||||
import copy
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.common.dict_transformations import dict_merge
|
||||
|
|
@ -875,7 +879,6 @@ def get_vm_info(client, vm):
|
|||
"security_groups": vm.TEMPLATE["NIC"].get("SECURITY_GROUPS", ""),
|
||||
}
|
||||
)
|
||||
import time
|
||||
|
||||
current_time = time.localtime()
|
||||
vm_start_time = time.localtime(vm.STIME)
|
||||
|
|
@ -1146,8 +1149,6 @@ def get_all_vms_by_attributes(client, attributes_dict, labels_list):
|
|||
vm_list.append(vm)
|
||||
pool = vm_list
|
||||
|
||||
import copy
|
||||
|
||||
vm_list = copy.copy(pool)
|
||||
|
||||
for vm in pool:
|
||||
|
|
@ -1367,8 +1368,6 @@ LCM_STATES = [
|
|||
|
||||
|
||||
def wait_for_state(module, client, vm, wait_timeout, state_predicate):
|
||||
import time
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
while (time.time() - start_time) < wait_timeout:
|
||||
|
|
@ -1551,8 +1550,6 @@ def release_vm(module, client, vm):
|
|||
|
||||
def check_name_attribute(module, attributes):
|
||||
if attributes.get("NAME"):
|
||||
import re
|
||||
|
||||
if re.match(r"^[^#]+#*$", attributes.get("NAME")) is None:
|
||||
module.fail_json(
|
||||
msg=f"Illegal 'NAME' attribute: '{attributes.get('NAME')}"
|
||||
|
|
@ -1638,7 +1635,6 @@ def get_connection_info(module):
|
|||
module.fail_json(msg=f"Error occurs when read ONE_AUTH file at '{authfile}'")
|
||||
if not url:
|
||||
module.fail_json(msg="Opennebula API url (api_url) is not specified")
|
||||
from collections import namedtuple
|
||||
|
||||
auth_params = namedtuple("auth", ("url", "username", "password"))
|
||||
|
||||
|
|
@ -1752,8 +1748,6 @@ def main():
|
|||
if count_attributes:
|
||||
count_attributes = {key.upper(): value for key, value in count_attributes.items()}
|
||||
if not attributes:
|
||||
import copy
|
||||
|
||||
module.warn(
|
||||
"When you pass `count_attributes` without `attributes` option when deploying, `attributes` option will have same values implicitly."
|
||||
)
|
||||
|
|
@ -1820,8 +1814,6 @@ def main():
|
|||
module.fail_json(msg="`count` has to be greater than 0")
|
||||
|
||||
if permissions is not None:
|
||||
import re
|
||||
|
||||
if re.match("^[0-7]{3}$", permissions) is None:
|
||||
module.fail_json(msg="Option `mode` has to have exactly 3 digits and be in the octet format e.g. 600")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue