Skip to content

Commit

Permalink
Remove six use from cloudbaseinit
Browse files Browse the repository at this point in the history
Change-Id: Ia4b4add954ee5192dbf437b415d8e698c0a271b8
  • Loading branch information
kulikjak committed May 31, 2024
1 parent 954753b commit afe08fd
Show file tree
Hide file tree
Showing 58 changed files with 106 additions and 181 deletions.
5 changes: 1 addition & 4 deletions cloudbaseinit/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@

import abc

import six


@six.add_metaclass(abc.ABCMeta)
class Options(object):
class Options(object, metaclass=abc.ABCMeta):

"""Contact class for all the collections of config options."""

Expand Down
6 changes: 3 additions & 3 deletions cloudbaseinit/metadata/services/azureservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# under the License.

import contextlib
import io
import os
import socket
import time
from xml.etree import ElementTree

from oslo_log import log as oslo_logging
import six
import untangle

from cloudbaseinit import conf as cloudbaseinit_conf
Expand Down Expand Up @@ -115,13 +115,13 @@ def _wire_server_request(self, path, data_xml=None, headers=None,
path, data_xml, headers=all_headers))

if parse_xml:
return untangle.parse(six.StringIO(encoding.get_as_string(data)))
return untangle.parse(io.StringIO(encoding.get_as_string(data)))
else:
return data

@staticmethod
def _encode_xml(xml_root):
bio = six.BytesIO()
bio = io.BytesIO()
ElementTree.ElementTree(xml_root).write(
bio, encoding='utf-8', xml_declaration=True)
return bio.getvalue()
Expand Down
4 changes: 1 addition & 3 deletions cloudbaseinit/metadata/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from oslo_log import log as oslo_logging
import requests
import six

from cloudbaseinit import conf as cloudbaseinit_conf
from cloudbaseinit import exception
Expand All @@ -35,8 +34,7 @@ class NotExistingMetadataException(Exception):
pass


@six.add_metaclass(abc.ABCMeta)
class BaseMetadataService(object):
class BaseMetadataService(object, metaclass=abc.ABCMeta):
_GZIP_MAGIC_NUMBER = b'\x1f\x8b'

def __init__(self):
Expand Down
10 changes: 5 additions & 5 deletions cloudbaseinit/metadata/services/cloudstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# under the License.

import contextlib
import http.client
import posixpath
import urllib

from oslo_log import log as oslo_logging
from six.moves import http_client
from six.moves import urllib

from cloudbaseinit import conf as cloudbaseinit_conf
from cloudbaseinit.metadata.services import base
Expand Down Expand Up @@ -131,12 +131,12 @@ def get_public_keys(self):
def _password_client(self, body=None, headers=None, decode=True):
"""Client for the Password Server."""
port = CONF.cloudstack.password_server_port
with contextlib.closing(http_client.HTTPConnection(
with contextlib.closing(http.client.HTTPConnection(
self._metadata_host, port, timeout=TIMEOUT)) as connection:
try:
connection.request("GET", "/", body=body, headers=headers)
response = connection.getresponse()
except http_client.HTTPException as exc:
except http.client.HTTPException as exc:
LOG.error("Request failed: %s", exc)
raise

Expand All @@ -145,7 +145,7 @@ def _password_client(self, body=None, headers=None, decode=True):
content = encoding.get_as_string(content)

if response.status != 200:
raise http_client.HTTPException(
raise http.client.HTTPException(
"%(status)s %(reason)s - %(message)r",
{"status": response.status, "reason": response.reason,
"message": content})
Expand Down
3 changes: 2 additions & 1 deletion cloudbaseinit/metadata/services/httpservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# License for the specific language governing permissions and limitations
# under the License.

from urllib import error

from oslo_log import log as oslo_logging
from six.moves.urllib import error

from cloudbaseinit import conf as cloudbaseinit_conf
from cloudbaseinit.metadata.services import base
Expand Down
4 changes: 1 addition & 3 deletions cloudbaseinit/metadata/services/opennebulaservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import struct

from oslo_log import log as oslo_logging
import six

from cloudbaseinit.metadata.services import base
from cloudbaseinit.models import network as network_model
Expand Down Expand Up @@ -108,8 +107,7 @@ def _calculate_netmask(address, gateway):
address_chunks = address.split(".")
gateway_chunks = gateway.split(".")
netmask_chunks = []
for achunk, gchunk in six.moves.zip(
address_chunks, gateway_chunks):
for achunk, gchunk in zip(address_chunks, gateway_chunks):
if achunk == gchunk:
nchunk = "255"
else:
Expand Down
5 changes: 1 addition & 4 deletions cloudbaseinit/metadata/services/osconfigdrive/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
import abc
import tempfile

import six


@six.add_metaclass(abc.ABCMeta)
class BaseConfigDriveManager(object):
class BaseConfigDriveManager(object, metaclass=abc.ABCMeta):

def __init__(self):
self.target_path = tempfile.mkdtemp()
Expand Down
2 changes: 1 addition & 1 deletion cloudbaseinit/metadata/services/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

import json
import requests
from urllib import error

from cloudbaseinit import conf as cloudbaseinit_conf
from cloudbaseinit import exception
from cloudbaseinit.metadata.services import base
from oslo_log import log as oslo_logging
from six.moves.urllib import error

CONF = cloudbaseinit_conf.CONF
LOG = oslo_logging.getLogger(__name__)
Expand Down
25 changes: 11 additions & 14 deletions cloudbaseinit/osutils/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
import struct
import subprocess
import time
import winreg

import netaddr
from oslo_log import log as oslo_logging
import pywintypes
import six
from six.moves import winreg
from tzlocal import windows_tz
import win32api
from win32com import client
Expand Down Expand Up @@ -602,7 +601,7 @@ def _get_user_sid_and_domain(self, username):
sidNameUse = wintypes.DWORD()

ret_val = advapi32.LookupAccountNameW(
0, six.text_type(username), sid, ctypes.byref(cbSid), domainName,
0, str(username), sid, ctypes.byref(cbSid), domainName,
ctypes.byref(cchReferencedDomainName), ctypes.byref(sidNameUse))
if not ret_val:
raise exception.WindowsCloudbaseInitException(
Expand All @@ -613,9 +612,9 @@ def _get_user_sid_and_domain(self, username):
def add_user_to_local_group(self, username, groupname):

lmi = Win32_LOCALGROUP_MEMBERS_INFO_3()
lmi.lgrmi3_domainandname = six.text_type(username)
lmi.lgrmi3_domainandname = str(username)

ret_val = netapi32.NetLocalGroupAddMembers(0, six.text_type(groupname),
ret_val = netapi32.NetLocalGroupAddMembers(0, str(groupname),
3, ctypes.pointer(lmi), 1)

if ret_val == self.NERR_GroupNotFound:
Expand Down Expand Up @@ -652,9 +651,9 @@ def create_user_logon_session(self, username, password, domain='.',
{"username": username, "domain": domain})

token = wintypes.HANDLE()
ret_val = advapi32.LogonUserW(six.text_type(username),
six.text_type(domain),
six.text_type(password),
ret_val = advapi32.LogonUserW(str(username),
str(domain),
str(password),
logon_type,
self.LOGON32_PROVIDER_DEFAULT,
ctypes.byref(token))
Expand All @@ -665,7 +664,7 @@ def create_user_logon_session(self, username, password, domain='.',
if load_profile:
pi = Win32_PROFILEINFO()
pi.dwSize = ctypes.sizeof(Win32_PROFILEINFO)
pi.lpUserName = six.text_type(username)
pi.lpUserName = str(username)
ret_val = userenv.LoadUserProfileW(token, ctypes.byref(pi))
if not ret_val:
kernel32.CloseHandle(token)
Expand Down Expand Up @@ -756,8 +755,7 @@ def sanitize_shell_input(self, value):

def set_host_name(self, new_host_name):
ret_val = kernel32.SetComputerNameExW(
self.ComputerNamePhysicalDnsHostname,
six.text_type(new_host_name))
self.ComputerNamePhysicalDnsHostname, str(new_host_name))
if not ret_val:
raise exception.WindowsCloudbaseInitException(
"Cannot set host name: %r")
Expand Down Expand Up @@ -1401,7 +1399,7 @@ def check_os_version(self, major, minor, build=0):
def get_volume_label(self, drive):
max_label_size = 261
label = ctypes.create_unicode_buffer(max_label_size)
ret_val = kernel32.GetVolumeInformationW(six.text_type(drive), label,
ret_val = kernel32.GetVolumeInformationW(str(drive), label,
max_label_size, 0, 0, 0, 0, 0)
if ret_val:
return label.value
Expand All @@ -1411,8 +1409,7 @@ def get_volume_path_names_by_mount_point(self, mount_point):
volume_name = ctypes.create_unicode_buffer(max_volume_name_len)

if not kernel32.GetVolumeNameForVolumeMountPointW(
six.text_type(mount_point), volume_name,
max_volume_name_len):
str(mount_point), volume_name, max_volume_name_len):
if kernel32.GetLastError() in [self.ERROR_INVALID_NAME,
self.ERROR_PATH_NOT_FOUND]:
raise exception.ItemNotFoundException(
Expand Down
4 changes: 1 addition & 3 deletions cloudbaseinit/plugins/common/createuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import abc

from oslo_log import log as oslo_logging
import six

from cloudbaseinit import conf as cloudbaseinit_conf
from cloudbaseinit.osutils import factory as osutils_factory
Expand All @@ -26,8 +25,7 @@
LOG = oslo_logging.getLogger(__name__)


@six.add_metaclass(abc.ABCMeta)
class BaseCreateUserPlugin(base.BasePlugin):
class BaseCreateUserPlugin(base.BasePlugin, metaclass=abc.ABCMeta):
"""This is a base class for creating or modifying an user."""

@abc.abstractmethod
Expand Down
5 changes: 1 addition & 4 deletions cloudbaseinit/plugins/common/userdataplugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@

import abc

import six


@six.add_metaclass(abc.ABCMeta)
class BaseUserDataPlugin(object):
class BaseUserDataPlugin(object, metaclass=abc.ABCMeta):

def __init__(self, mime_type):
self._mime_type = mime_type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@

import abc

import six


@six.add_metaclass(abc.ABCMeta)
class BaseCloudConfigPlugin(object):
class BaseCloudConfigPlugin(object, metaclass=abc.ABCMeta):
"""Base plugin class for cloud-config plugins."""

@abc.abstractmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import six

from oslo_log import log as oslo_logging

from cloudbaseinit import conf as cloudbaseinit_conf
Expand Down Expand Up @@ -45,7 +43,7 @@ def process(self, data):
group_name = None
group_users = []

if isinstance(item, six.string_types):
if isinstance(item, str):
group_name = item
elif isinstance(item, dict):
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# under the License.

import os
import six

from oslo_log import log as oslo_logging

Expand Down Expand Up @@ -49,7 +48,7 @@ def _unify_scripts(commands, env_header):

entries = 0
for command in commands:
if isinstance(command, six.string_types):
if isinstance(command, str):
script_content += command
elif isinstance(command, (list, tuple)):
subcommand_content = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import datetime
import os
import pytz
import six

from oslo_log import log as oslo_logging

Expand All @@ -41,11 +40,11 @@ def _get_groups(self, data):
groups = data.get('groups', None)
primary_group = data.get('primary_group', None)
user_groups = []
if isinstance(groups, six.string_types):
if isinstance(groups, str):
user_groups.extend(groups.split(', '))
elif isinstance(groups, (list, tuple)):
user_groups.extend(groups)
if isinstance(primary_group, six.string_types):
if isinstance(primary_group, str):
user_groups.extend(primary_group.split(', '))
elif isinstance(primary_group, (list, tuple)):
user_groups.extend(primary_group)
Expand All @@ -68,7 +67,7 @@ def _get_expire_interval(self, data):
expiredate = data.get('expiredate', None)
expire_interval = None

if isinstance(expiredate, six.string_types):
if isinstance(expiredate, str):
year, month, day = map(int, expiredate.split('-'))
expiredate = datetime.datetime(year=year, month=month, day=day,
tzinfo=pytz.utc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import os

from oslo_log import log as oslo_logging
import six

from cloudbaseinit import exception
from cloudbaseinit.plugins.common.userdataplugins.cloudconfigplugins import (
Expand Down Expand Up @@ -59,7 +58,7 @@ def _convert_permissions(permissions):
def _process_content(content, encoding):
"""Decode the content taking into consideration the encoding."""
result = content
if six.PY3 and not isinstance(result, six.binary_type):
if not isinstance(result, bytes):
# At this point, content will be string, which is wrong for Python 3.
result = result.encode()

Expand Down
4 changes: 1 addition & 3 deletions cloudbaseinit/plugins/common/userdataplugins/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

import os

import six

from cloudbaseinit import conf as cloudbaseinit_conf
from cloudbaseinit.plugins.common.userdataplugins import base
from cloudbaseinit.plugins.common import userdatautils
Expand Down Expand Up @@ -47,6 +45,6 @@ def process(self, part):
# Normalize the payload to bytes, since `execute_user_data_script`
# operates on bytes and `get_payload` returns a string on
# Python 3.
if isinstance(payload, six.text_type):
if isinstance(payload, str):
payload = payload.encode()
return userdatautils.execute_user_data_script(payload)
2 changes: 1 addition & 1 deletion cloudbaseinit/plugins/windows/azureguestagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
import datetime
import os
import shutil
import winreg
import zipfile

from oslo_log import log as oslo_logging
from six.moves import winreg

from cloudbaseinit import conf as cloudbaseinit_conf
from cloudbaseinit import exception
Expand Down
Loading

0 comments on commit afe08fd

Please sign in to comment.