summaryrefslogtreecommitdiff
path: root/cloudinit/config
diff options
context:
space:
mode:
authorDaniel Watkins <oddbloke@ubuntu.com>2020-01-21 18:02:42 -0500
committerChad Smith <chad.smith@canonical.com>2020-01-21 16:02:42 -0700
commitbb71a9d08d25193836eda91c328760305285574e (patch)
tree50a1f2f4a61e04255c5a8129e7a2a26d9d4cecd4 /cloudinit/config
parent8c4fd886931abcf2cc8627a47463907d655b35c3 (diff)
downloadvyos-cloud-init-bb71a9d08d25193836eda91c328760305285574e.tar.gz
vyos-cloud-init-bb71a9d08d25193836eda91c328760305285574e.zip
Drop most of the remaining use of six (#179)
Diffstat (limited to 'cloudinit/config')
-rw-r--r--cloudinit/config/cc_chef.py4
-rw-r--r--cloudinit/config/cc_mcollective.py10
-rw-r--r--cloudinit/config/cc_ntp.py20
-rw-r--r--cloudinit/config/cc_power_state_change.py9
-rw-r--r--cloudinit/config/cc_rsyslog.py7
-rw-r--r--cloudinit/config/cc_ubuntu_advantage.py4
-rw-r--r--cloudinit/config/cc_write_files.py3
-rw-r--r--cloudinit/config/cc_yum_add_repo.py12
8 files changed, 27 insertions, 42 deletions
diff --git a/cloudinit/config/cc_chef.py b/cloudinit/config/cc_chef.py
index 0ad6b7f1..01d61fa1 100644
--- a/cloudinit/config/cc_chef.py
+++ b/cloudinit/config/cc_chef.py
@@ -79,8 +79,6 @@ from cloudinit import templater
from cloudinit import url_helper
from cloudinit import util
-import six
-
RUBY_VERSION_DEFAULT = "1.8"
CHEF_DIRS = tuple([
@@ -273,7 +271,7 @@ def run_chef(chef_cfg, log):
cmd_args = chef_cfg['exec_arguments']
if isinstance(cmd_args, (list, tuple)):
cmd.extend(cmd_args)
- elif isinstance(cmd_args, six.string_types):
+ elif isinstance(cmd_args, str):
cmd.append(cmd_args)
else:
log.warning("Unknown type %s provided for chef"
diff --git a/cloudinit/config/cc_mcollective.py b/cloudinit/config/cc_mcollective.py
index d5f63f5f..351183f1 100644
--- a/cloudinit/config/cc_mcollective.py
+++ b/cloudinit/config/cc_mcollective.py
@@ -49,9 +49,7 @@ private certificates for mcollective. Their values will be written to
"""
import errno
-
-import six
-from six import BytesIO
+import io
# Used since this can maintain comments
# and doesn't need a top level section
@@ -73,7 +71,7 @@ def configure(config, server_cfg=SERVER_CFG,
# original file in order to be able to mix the rest up.
try:
old_contents = util.load_file(server_cfg, quiet=False, decode=False)
- mcollective_config = ConfigObj(BytesIO(old_contents))
+ mcollective_config = ConfigObj(io.BytesIO(old_contents))
except IOError as e:
if e.errno != errno.ENOENT:
raise
@@ -93,7 +91,7 @@ def configure(config, server_cfg=SERVER_CFG,
'plugin.ssl_server_private'] = pricert_file
mcollective_config['securityprovider'] = 'ssl'
else:
- if isinstance(cfg, six.string_types):
+ if isinstance(cfg, str):
# Just set it in the 'main' section
mcollective_config[cfg_name] = cfg
elif isinstance(cfg, (dict)):
@@ -119,7 +117,7 @@ def configure(config, server_cfg=SERVER_CFG,
raise
# Now we got the whole (new) file, write to disk...
- contents = BytesIO()
+ contents = io.BytesIO()
mcollective_config.write(contents)
util.write_file(server_cfg, contents.getvalue(), mode=0o644)
diff --git a/cloudinit/config/cc_ntp.py b/cloudinit/config/cc_ntp.py
index 9e074bda..5498bbaa 100644
--- a/cloudinit/config/cc_ntp.py
+++ b/cloudinit/config/cc_ntp.py
@@ -6,19 +6,17 @@
"""NTP: enable and configure ntp"""
-from cloudinit.config.schema import (
- get_schema_doc, validate_cloudconfig_schema)
+import copy
+import os
+from textwrap import dedent
+
from cloudinit import log as logging
-from cloudinit.settings import PER_INSTANCE
from cloudinit import temp_utils
from cloudinit import templater
from cloudinit import type_utils
from cloudinit import util
-
-import copy
-import os
-import six
-from textwrap import dedent
+from cloudinit.config.schema import get_schema_doc, validate_cloudconfig_schema
+from cloudinit.settings import PER_INSTANCE
LOG = logging.getLogger(__name__)
@@ -460,7 +458,7 @@ def supplemental_schema_validation(ntp_config):
for key, value in sorted(ntp_config.items()):
keypath = 'ntp:config:' + key
if key == 'confpath':
- if not all([value, isinstance(value, six.string_types)]):
+ if not all([value, isinstance(value, str)]):
errors.append(
'Expected a config file path {keypath}.'
' Found ({value})'.format(keypath=keypath, value=value))
@@ -472,11 +470,11 @@ def supplemental_schema_validation(ntp_config):
elif key in ('template', 'template_name'):
if value is None: # Either template or template_name can be none
continue
- if not isinstance(value, six.string_types):
+ if not isinstance(value, str):
errors.append(
'Expected a string type for {keypath}.'
' Found ({value})'.format(keypath=keypath, value=value))
- elif not isinstance(value, six.string_types):
+ elif not isinstance(value, str):
errors.append(
'Expected a string type for {keypath}.'
' Found ({value})'.format(keypath=keypath, value=value))
diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py
index 43a479cf..3e81a3c7 100644
--- a/cloudinit/config/cc_power_state_change.py
+++ b/cloudinit/config/cc_power_state_change.py
@@ -49,16 +49,15 @@ key returns 0.
condition: <true/false/command>
"""
-from cloudinit.settings import PER_INSTANCE
-from cloudinit import util
-
import errno
import os
import re
-import six
import subprocess
import time
+from cloudinit.settings import PER_INSTANCE
+from cloudinit import util
+
frequency = PER_INSTANCE
EXIT_FAIL = 254
@@ -183,7 +182,7 @@ def load_power_state(cfg):
pstate['timeout'])
condition = pstate.get("condition", True)
- if not isinstance(condition, six.string_types + (list, bool)):
+ if not isinstance(condition, (str, list, bool)):
raise TypeError("condition type %s invalid. must be list, bool, str")
return (args, timeout, condition)
diff --git a/cloudinit/config/cc_rsyslog.py b/cloudinit/config/cc_rsyslog.py
index ff211f65..5df0137d 100644
--- a/cloudinit/config/cc_rsyslog.py
+++ b/cloudinit/config/cc_rsyslog.py
@@ -180,7 +180,6 @@ config entries. Legacy to new mappings are as follows:
import os
import re
-import six
from cloudinit import log as logging
from cloudinit import util
@@ -233,9 +232,9 @@ def load_config(cfg):
fillup = (
(KEYNAME_CONFIGS, [], list),
- (KEYNAME_DIR, DEF_DIR, six.string_types),
- (KEYNAME_FILENAME, DEF_FILENAME, six.string_types),
- (KEYNAME_RELOAD, DEF_RELOAD, six.string_types + (list,)),
+ (KEYNAME_DIR, DEF_DIR, str),
+ (KEYNAME_FILENAME, DEF_FILENAME, str),
+ (KEYNAME_RELOAD, DEF_RELOAD, (str, list)),
(KEYNAME_REMOTES, DEF_REMOTES, dict))
for key, default, vtypes in fillup:
diff --git a/cloudinit/config/cc_ubuntu_advantage.py b/cloudinit/config/cc_ubuntu_advantage.py
index f846e9a5..8b6d2a1a 100644
--- a/cloudinit/config/cc_ubuntu_advantage.py
+++ b/cloudinit/config/cc_ubuntu_advantage.py
@@ -4,8 +4,6 @@
from textwrap import dedent
-import six
-
from cloudinit.config.schema import (
get_schema_doc, validate_cloudconfig_schema)
from cloudinit import log as logging
@@ -98,7 +96,7 @@ def configure_ua(token=None, enable=None):
if enable is None:
enable = []
- elif isinstance(enable, six.string_types):
+ elif isinstance(enable, str):
LOG.warning('ubuntu_advantage: enable should be a list, not'
' a string; treating as a single enable')
enable = [enable]
diff --git a/cloudinit/config/cc_write_files.py b/cloudinit/config/cc_write_files.py
index 0b6546e2..bd87e9e5 100644
--- a/cloudinit/config/cc_write_files.py
+++ b/cloudinit/config/cc_write_files.py
@@ -57,7 +57,6 @@ binary gzip data can be specified and will be decoded before being written.
import base64
import os
-import six
from cloudinit import log as logging
from cloudinit.settings import PER_INSTANCE
@@ -126,7 +125,7 @@ def decode_perms(perm, default):
if perm is None:
return default
try:
- if isinstance(perm, six.integer_types + (float,)):
+ if isinstance(perm, (int, float)):
# Just 'downcast' it (if a float)
return int(perm)
else:
diff --git a/cloudinit/config/cc_yum_add_repo.py b/cloudinit/config/cc_yum_add_repo.py
index 3b354a7d..3673166a 100644
--- a/cloudinit/config/cc_yum_add_repo.py
+++ b/cloudinit/config/cc_yum_add_repo.py
@@ -30,13 +30,9 @@ entry, the config entry will be skipped.
# any repository configuration options (see man yum.conf)
"""
+import io
import os
-
-try:
- from configparser import ConfigParser
-except ImportError:
- from ConfigParser import ConfigParser
-import six
+from configparser import ConfigParser
from cloudinit import util
@@ -57,7 +53,7 @@ def _format_repo_value(val):
# Can handle 'lists' in certain cases
# See: https://linux.die.net/man/5/yum.conf
return "\n".join([_format_repo_value(v) for v in val])
- if not isinstance(val, six.string_types):
+ if not isinstance(val, str):
return str(val)
return val
@@ -72,7 +68,7 @@ def _format_repository_config(repo_id, repo_config):
# For now assume that people using this know
# the format of yum and don't verify keys/values further
to_be.set(repo_id, k, _format_repo_value(v))
- to_be_stream = six.StringIO()
+ to_be_stream = io.StringIO()
to_be.write(to_be_stream)
to_be_stream.seek(0)
lines = to_be_stream.readlines()