Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update provider code to python3 #176

Merged
merged 1 commit into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions contrib/inventory/alicloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

import sys
import os
import argparse
import re
import yaml
import configparser

from time import time
from ansible.module_utils.alicloud_ecs import connect_to_acs
if sys.version_info >= (3, 0):
import configparser
else:
import ConfigParser as configparser

try:
import json
Expand Down Expand Up @@ -127,7 +123,7 @@ def parse_cli_args(self):
def read_settings(self):
''' Reads the settings from the alicloud.ini file '''

config = configparser.SafeConfigParser()
config = configparser.ConfigParser()

ecs_default_ini_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'alicloud.ini')
ecs_ini_path = os.path.expanduser(os.path.expandvars(os.environ.get('ALICLOUD_INI_PATH', ecs_default_ini_path)))
Expand Down Expand Up @@ -394,9 +390,9 @@ def add_instance(self, instance, region):

# Inventory: Group by tag keys
if self.group_by_tag_keys:
for k, v in instance.tags.items():
for k, v in list(instance.tags.items()):
if self.expand_csv_tags and v and ',' in v:
values = map(lambda x: x.strip(), v.split(','))
values = [x.strip() for x in v.split(',')]
else:
values = [v]

Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_disk_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_eip.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/cloud/alicloud/ali_eip_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down Expand Up @@ -202,7 +202,7 @@ def main():
if not filters:
filters = {}
new_filters = {}
for key, value in filters.items():
for key, value in list(filters.items()):
if str(key).lower().replace("-").replace("_") == "allocationid" and value not in eip_ids:
eip_ids.append(value)
continue
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/cloud/alicloud/ali_eni.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down Expand Up @@ -338,8 +338,8 @@ def main():
if not tags:
removed = eni.tags
else:
for key, value in eni.tags.items():
if key not in tags.keys():
for key, value in list(eni.tags.items()):
if key not in list(tags.keys()):
removed[key] = value
try:
if eni.remove_tags(removed):
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/cloud/alicloud/ali_eni_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down Expand Up @@ -203,7 +203,7 @@ def main():
eni_ids = module.params["eni_ids"]
if not eni_ids:
eni_ids = []
for key, value in filters.items():
for key, value in list(filters.items()):
if str(key).startswith("NetworkInterfaceId") or \
str(key).startswith("network_interface_id") or \
str(key).startswith("network-interface-id"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_ess_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_ess_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_ess_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_ess_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_image_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
8 changes: 4 additions & 4 deletions lib/ansible/modules/cloud/alicloud/ali_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down Expand Up @@ -630,7 +630,7 @@ def modify_instance(module, instance):
setattr(instance, "user_data", instance.describe_user_data())
user_data = instance.user_data
if state == "stopped":
user_data = module.params['user_data']
user_data = module.params['user_data'].encode()

try:
return instance.modify(name=name, description=description, host_name=host_name, password=password, user_data=user_data)
Expand Down Expand Up @@ -849,8 +849,8 @@ def main():
if not tags:
removed = inst.tags
else:
for key, value in inst.tags.items():
if key not in tags.keys():
for key, value in list(inst.tags.items()):
if key not in list(tags.keys()):
removed[key] = value
try:
if inst.remove_tags(removed):
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/cloud/alicloud/ali_instance_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down Expand Up @@ -397,7 +397,7 @@ def main():
filters = {}
if not ids:
ids = []
for key, value in filters.items():
for key, value in list(filters.items()):
if key in ["InstanceIds", "instance_ids", "instance-ids"] and isinstance(ids, list):
for id in value:
if id not in ids:
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/cloud/alicloud/ali_instance_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down Expand Up @@ -400,7 +400,7 @@ def main():
filters = {}
if not ids:
ids = []
for key, value in filters.items():
for key, value in list(filters.items()):
if key in ["InstanceIds", "instance_ids", "instance-ids"] and isinstance(ids, list):
for id in value:
if id not in ids:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_rds_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/cloud/alicloud/ali_rds_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down Expand Up @@ -367,7 +367,7 @@ def main():
description=dict(type='str', aliases=['db_instance_description']),
security_ips=dict(type='str'),
instance_charge_type=dict(type='str', choices=["Postpaid", "Prepaid"]),
period=dict(type='int', choices=range(1, 10).extend([12, 24, 36])),
period=dict(type='int', choices=list(range(1, 10)).extend([12, 24, 36])),
connection_mode=dict(type='str', choices=["Performance", "Safty"]),
vpc_id=dict(type='str'),
vswitch_id=dict(type='str'),
Expand All @@ -383,7 +383,7 @@ def main():
dest_connection_string_prefix=dict(type='str'),
dest_port=dict(type='str'),
public_port=dict(type='str'),
private_port=dict(type='int', choices=range(3001, 4000)),
private_port=dict(type='int', choices=list(range(3001, 4000))),
current_connection_string=dict(type='str'),
instance_type=dict(type='str', aliases=['db_instance_class']),
instance_storage=dict(type='int', aliases=['db_instance_storage'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_security_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down Expand Up @@ -221,7 +221,7 @@ def main():
group_ids = module.params['group_ids']
if not group_ids:
group_ids = []
for key, value in filters.items():
for key, value in list(filters.items()):
if key in ["SecurityGroupIds", "security_group_ids", "security_group_ids"] and isinstance(group_ids, list):
for id in value:
if id not in group_ids:
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_slb_lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/modules/cloud/alicloud/ali_slb_lb_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down Expand Up @@ -278,7 +278,7 @@ def main():
filters = module.params['filters']
if not filters:
filters = {}
for key, value in filters.items():
for key, value in list(filters.items()):
if key in ["LoadBalancerId", "load-balancer-id", "load_balancer_id"] and value not in lb_ids:
lb_ids.append(value)
lbs = []
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_slb_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_slb_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/cloud/alicloud/ali_slb_server_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see http://www.gnu.org/licenses/.

from __future__ import absolute_import, division, print_function

__metaclass__ = type

ANSIBLE_METADATA = {'metadata_version': '1.1',
Expand Down
Loading