mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
[PY3] Add unicode_literals to spm, queues, and rosters
This commit is contained in:
parent
4ff2d1ab18
commit
f78c71bd6b
20 changed files with 110 additions and 116 deletions
|
@ -40,7 +40,7 @@ Use the following Pg database schema:
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
from contextlib import contextmanager
|
||||
import sys
|
||||
|
||||
|
@ -93,7 +93,7 @@ def _conn(commit=False):
|
|||
yield cursor
|
||||
except psycopg2.DatabaseError as err:
|
||||
error = err.args
|
||||
sys.stderr.write(str(error))
|
||||
sys.stderr.write(six.text_type(error))
|
||||
cursor.execute("ROLLBACK")
|
||||
raise err
|
||||
else:
|
||||
|
@ -107,7 +107,7 @@ def _conn(commit=False):
|
|||
|
||||
def _list_tables(cur):
|
||||
cmd = "select relname from pg_class where relkind='r' and relname !~ '^(pg_|sql_)';"
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
cur.execute(cmd)
|
||||
result = cur.fetchall()
|
||||
return [x[0] for x in result]
|
||||
|
@ -116,7 +116,7 @@ def _list_tables(cur):
|
|||
def _create_table(cur, queue):
|
||||
cmd = 'CREATE TABLE {0}(id SERIAL PRIMARY KEY, '\
|
||||
'data jsonb NOT NULL)'.format(queue)
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
cur.execute(cmd)
|
||||
return True
|
||||
|
||||
|
@ -127,7 +127,7 @@ def _list_items(queue):
|
|||
'''
|
||||
with _conn() as cur:
|
||||
cmd = 'SELECT data FROM {0}'.format(queue)
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
cur.execute(cmd)
|
||||
contents = cur.fetchall()
|
||||
return contents
|
||||
|
@ -174,8 +174,7 @@ def _queue_exists(queue):
|
|||
def handle_queue_creation(queue):
|
||||
if not _queue_exists(queue):
|
||||
with _conn(commit=True) as cur:
|
||||
log.debug('Queue %s does not exist.'
|
||||
' Creating', queue)
|
||||
log.debug('Queue %s does not exist. Creating', queue)
|
||||
_create_table(cur, queue)
|
||||
else:
|
||||
log.debug('Queue %s already exists.', queue)
|
||||
|
@ -191,7 +190,7 @@ def insert(queue, items):
|
|||
if isinstance(items, dict):
|
||||
items = salt.utils.json.dumps(items)
|
||||
cmd = str('''INSERT INTO {0}(data) VALUES('{1}')''').format(queue, items) # future lint: disable=blacklisted-function
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
try:
|
||||
cur.execute(cmd)
|
||||
except psycopg2.IntegrityError as esc:
|
||||
|
@ -200,7 +199,7 @@ def insert(queue, items):
|
|||
if isinstance(items, list):
|
||||
items = [(salt.utils.json.dumps(el),) for el in items]
|
||||
cmd = str("INSERT INTO {0}(data) VALUES (%s)").format(queue) # future lint: disable=blacklisted-function
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
try:
|
||||
cur.executemany(cmd, items)
|
||||
except psycopg2.IntegrityError as esc:
|
||||
|
@ -218,13 +217,13 @@ def delete(queue, items):
|
|||
cmd = str("""DELETE FROM {0} WHERE data = '{1}'""").format( # future lint: disable=blacklisted-function
|
||||
queue,
|
||||
salt.utils.json.dumps(items))
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
cur.execute(cmd)
|
||||
return True
|
||||
if isinstance(items, list):
|
||||
items = [(salt.utils.json.dumps(el),) for el in items]
|
||||
cmd = 'DELETE FROM {0} WHERE data = %s'.format(queue)
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
cur.executemany(cmd, items)
|
||||
return True
|
||||
|
||||
|
@ -242,7 +241,7 @@ def pop(queue, quantity=1, is_runner=False):
|
|||
'Error: "{0}".'.format(exc))
|
||||
raise SaltInvocationError(error_txt)
|
||||
cmd = ''.join([cmd, ' LIMIT {0};'.format(quantity)])
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
items = []
|
||||
with _conn(commit=True) as cur:
|
||||
cur.execute(cmd)
|
||||
|
@ -254,7 +253,7 @@ def pop(queue, quantity=1, is_runner=False):
|
|||
del_cmd = '''DELETE FROM {0} WHERE id IN ('{1}');'''.format(
|
||||
queue, idlist)
|
||||
|
||||
log.debug('SQL Query: {0}'.format(del_cmd))
|
||||
log.debug('SQL Query: %s', del_cmd)
|
||||
|
||||
cur.execute(del_cmd)
|
||||
return items
|
||||
|
|
|
@ -13,7 +13,7 @@ to another location::
|
|||
sqlite_queue_dir: /home/myuser/salt/master/queues
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
|
@ -43,7 +43,7 @@ def _conn(queue):
|
|||
'''
|
||||
queue_dir = __opts__['sqlite_queue_dir']
|
||||
db = os.path.join(queue_dir, '{0}.db'.format(queue))
|
||||
log.debug('Connecting to: {0}'.format(db))
|
||||
log.debug('Connecting to: %s', db)
|
||||
|
||||
con = sqlite3.connect(db)
|
||||
tables = _list_tables(con)
|
||||
|
@ -56,7 +56,7 @@ def _list_tables(con):
|
|||
with con:
|
||||
cur = con.cursor()
|
||||
cmd = 'SELECT name FROM sqlite_master WHERE type = "table"'
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
cur.execute(cmd)
|
||||
result = cur.fetchall()
|
||||
return [x[0] for x in result]
|
||||
|
@ -67,7 +67,7 @@ def _create_table(con, queue):
|
|||
cur = con.cursor()
|
||||
cmd = 'CREATE TABLE {0}(id INTEGER PRIMARY KEY, '\
|
||||
'name TEXT UNIQUE)'.format(queue)
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
cur.execute(cmd)
|
||||
return True
|
||||
|
||||
|
@ -80,7 +80,7 @@ def _list_items(queue):
|
|||
with con:
|
||||
cur = con.cursor()
|
||||
cmd = 'SELECT name FROM {0}'.format(queue)
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
cur.execute(cmd)
|
||||
contents = cur.fetchall()
|
||||
return contents
|
||||
|
@ -144,7 +144,7 @@ def insert(queue, items):
|
|||
if isinstance(items, six.string_types):
|
||||
items = _quote_escape(items)
|
||||
cmd = '''INSERT INTO {0}(name) VALUES('{1}')'''.format(queue, items)
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
try:
|
||||
cur.execute(cmd)
|
||||
except sqlite3.IntegrityError as esc:
|
||||
|
@ -153,7 +153,7 @@ def insert(queue, items):
|
|||
if isinstance(items, list):
|
||||
items = [_quote_escape(el) for el in items]
|
||||
cmd = "INSERT INTO {0}(name) VALUES(?)".format(queue)
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
newitems = []
|
||||
for item in items:
|
||||
newitems.append((item,))
|
||||
|
@ -167,7 +167,7 @@ def insert(queue, items):
|
|||
items = salt.utils.json.dumps(items).replace('"', "'")
|
||||
items = _quote_escape(items)
|
||||
cmd = str('''INSERT INTO {0}(name) VALUES('{1}')''').format(queue, items) # future lint: disable=blacklisted-function
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
try:
|
||||
cur.execute(cmd)
|
||||
except sqlite3.IntegrityError as esc:
|
||||
|
@ -186,13 +186,13 @@ def delete(queue, items):
|
|||
if isinstance(items, six.string_types):
|
||||
items = _quote_escape(items)
|
||||
cmd = """DELETE FROM {0} WHERE name = '{1}'""".format(queue, items)
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
cur.execute(cmd)
|
||||
return True
|
||||
if isinstance(items, list):
|
||||
items = [_quote_escape(el) for el in items]
|
||||
cmd = 'DELETE FROM {0} WHERE name = ?'.format(queue)
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
newitems = []
|
||||
for item in items:
|
||||
newitems.append((item,))
|
||||
|
@ -202,7 +202,7 @@ def delete(queue, items):
|
|||
items = salt.utils.json.dumps(items).replace('"', "'")
|
||||
items = _quote_escape(items)
|
||||
cmd = ("""DELETE FROM {0} WHERE name = '{1}'""").format(queue, items) # future lint: disable=blacklisted-function
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
cur.execute(cmd)
|
||||
return True
|
||||
return True
|
||||
|
@ -221,7 +221,7 @@ def pop(queue, quantity=1, is_runner=False):
|
|||
'Error: "{0}".'.format(exc))
|
||||
raise SaltInvocationError(error_txt)
|
||||
cmd = ''.join([cmd, ' LIMIT {0}'.format(quantity)])
|
||||
log.debug('SQL Query: {0}'.format(cmd))
|
||||
log.debug('SQL Query: %s', cmd)
|
||||
con = _conn(queue)
|
||||
items = []
|
||||
with con:
|
||||
|
@ -234,7 +234,7 @@ def pop(queue, quantity=1, is_runner=False):
|
|||
del_cmd = '''DELETE FROM {0} WHERE name IN ("{1}")'''.format(
|
||||
queue, itemlist)
|
||||
|
||||
log.debug('SQL Query: {0}'.format(del_cmd))
|
||||
log.debug('SQL Query: %s', del_cmd)
|
||||
|
||||
cur.execute(del_cmd)
|
||||
con.commit()
|
||||
|
|
|
@ -5,7 +5,7 @@ hit from the master rather than acting as an independent entity. This covers
|
|||
hitting minions without zeromq in place via an ssh agent, and connecting to
|
||||
systems that cannot or should not host a minion agent.
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import salt libs
|
||||
import salt.loader
|
||||
|
@ -13,7 +13,7 @@ import salt.syspaths
|
|||
|
||||
import os
|
||||
import logging
|
||||
from salt.ext.six import string_types
|
||||
from salt.ext import six
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -68,7 +68,7 @@ class Roster(object):
|
|||
self.opts = opts
|
||||
if isinstance(backends, list):
|
||||
self.backends = backends
|
||||
elif isinstance(backends, string_types):
|
||||
elif isinstance(backends, six.string_types):
|
||||
self.backends = backends.split(',')
|
||||
else:
|
||||
self.backends = backends
|
||||
|
@ -104,9 +104,9 @@ class Roster(object):
|
|||
try:
|
||||
targets.update(self.rosters[f_str](tgt, tgt_type))
|
||||
except salt.exceptions.SaltRenderError as exc:
|
||||
log.error('Unable to render roster file: {0}'.format(exc))
|
||||
log.error('Unable to render roster file: %s', exc)
|
||||
except IOError as exc:
|
||||
pass
|
||||
|
||||
log.debug('Matched minions: {0}'.format(targets))
|
||||
log.debug('Matched minions: %s', targets)
|
||||
return targets
|
||||
|
|
|
@ -88,7 +88,7 @@ This is the format that an inventory script needs to output to work with ansible
|
|||
Any of the [groups] or direct hostnames will return. The 'all' is special, and returns everything.
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import re
|
||||
import fnmatch
|
||||
|
|
|
@ -93,7 +93,7 @@ This should be especially useful for the other roster keys:
|
|||
- ssh:auth:private_key
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Python
|
||||
import logging
|
||||
|
@ -172,9 +172,9 @@ def targets(tgt, tgt_type='glob', **kwargs): # pylint: disable=W0613
|
|||
if 'host' in minion_res:
|
||||
ret[minion_id] = minion_res
|
||||
else:
|
||||
log.warning('Could not determine host information for minion {0}'.format(minion_id))
|
||||
log.warning('Could not determine host information for minion %s', minion_id)
|
||||
|
||||
log.debug('Roster lookup result: {0}'.format(ret))
|
||||
log.debug('Roster lookup result: %s', ret)
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -183,15 +183,15 @@ def _load_minion(minion_id, cache):
|
|||
data_minion, grains, pillar = salt.utils.minions.get_minion_data(minion_id, __opts__)
|
||||
|
||||
if minion_id != data_minion:
|
||||
log.error('Asked for minion {0}, got {1}'.format(minion_id, data_minion))
|
||||
log.error('Asked for minion %s, got %s', minion_id, data_minion)
|
||||
raise LookupError
|
||||
|
||||
if not grains:
|
||||
log.warning('No grain data for minion id {0}'.format(minion_id))
|
||||
log.warning('No grain data for minion id %s', minion_id)
|
||||
grains = {}
|
||||
|
||||
if not pillar:
|
||||
log.warning('No pillar data for minion id {0}'.format(minion_id))
|
||||
log.warning('No pillar data for minion id %s', minion_id)
|
||||
pillar = {}
|
||||
|
||||
addrs = {
|
||||
|
@ -211,7 +211,7 @@ def _data_lookup(ref, lookup):
|
|||
res = []
|
||||
for data_key in lookup:
|
||||
data = salt.utils.data.traverse_dict_and_list(ref, data_key, None)
|
||||
# log.debug('Fetched {0} in {1}: {2}'.format(data_key, ref, data))
|
||||
# log.debug('Fetched %s in %s: %s', data_key, ref, data)
|
||||
if data:
|
||||
res.append(data)
|
||||
|
||||
|
@ -246,12 +246,12 @@ def _minion_lookup(minion_id, key, minion):
|
|||
try:
|
||||
net = ipaddress.ip_network(key, strict=True)
|
||||
except ValueError:
|
||||
log.error('{0} is an invalid CIDR network'.format(net))
|
||||
log.error('%s is an invalid CIDR network', net)
|
||||
return None
|
||||
|
||||
for addr in addrs[net.version]:
|
||||
if addr in net:
|
||||
return str(addr)
|
||||
return six.text_type(addr)
|
||||
else:
|
||||
# Take the addresses from the grains and filter them
|
||||
filters = {
|
||||
|
@ -270,6 +270,6 @@ def _minion_lookup(minion_id, key, minion):
|
|||
try:
|
||||
for addr in addrs[ip_ver]:
|
||||
if filters[key](addr):
|
||||
return str(addr)
|
||||
return six.text_type(addr)
|
||||
except KeyError:
|
||||
raise KeyError('Invalid filter {0} specified in roster_order'.format(key))
|
||||
|
|
|
@ -19,7 +19,7 @@ usually located at /etc/salt/cloud. For example, add the following:
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import copy
|
||||
|
||||
|
|
|
@ -13,9 +13,10 @@ When you want to use host globs for target matching, use ``--roster clustershell
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import socket
|
||||
import copy
|
||||
from salt.ext import six
|
||||
from salt.ext.six.moves import map # pylint: disable=import-error,redefined-builtin
|
||||
|
||||
REQ_ERROR = None
|
||||
|
@ -37,13 +38,13 @@ def targets(tgt, tgt_type='glob', **kwargs):
|
|||
ports = __opts__['ssh_scan_ports']
|
||||
if not isinstance(ports, list):
|
||||
# Comma-separate list of integers
|
||||
ports = list(map(int, str(ports).split(',')))
|
||||
ports = list(map(int, six.text_type(ports).split(',')))
|
||||
|
||||
hosts = list(NodeSet(tgt))
|
||||
host_addrs = dict([(h, socket.gethostbyname(h)) for h in hosts])
|
||||
|
||||
for host, addr in host_addrs.items():
|
||||
addr = str(addr)
|
||||
addr = six.text_type(addr)
|
||||
ret[addr] = copy.deepcopy(__opts__.get('roster_defaults', {}))
|
||||
for port in ports:
|
||||
try:
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
'''
|
||||
Read in the roster from a flat file using the renderer system
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import fnmatch
|
||||
|
@ -21,8 +21,8 @@ except ImportError:
|
|||
# Import Salt libs
|
||||
import salt.loader
|
||||
import salt.config
|
||||
from salt.ext import six
|
||||
from salt.template import compile_template
|
||||
from salt.ext.six import string_types
|
||||
from salt.roster import get_roster_file
|
||||
|
||||
import logging
|
||||
|
@ -45,7 +45,7 @@ def targets(tgt, tgt_type='glob', **kwargs):
|
|||
**kwargs)
|
||||
conditioned_raw = {}
|
||||
for minion in raw:
|
||||
conditioned_raw[str(minion)] = salt.config.apply_sdb(raw[minion])
|
||||
conditioned_raw[six.text_type(minion)] = salt.config.apply_sdb(raw[minion])
|
||||
rmatcher = RosterMatcher(conditioned_raw, tgt, tgt_type, 'ipv4')
|
||||
return rmatcher.targets()
|
||||
|
||||
|
@ -145,7 +145,7 @@ class RosterMatcher(object):
|
|||
Return the configured ip
|
||||
'''
|
||||
ret = copy.deepcopy(__opts__.get('roster_defaults', {}))
|
||||
if isinstance(self.raw[minion], string_types):
|
||||
if isinstance(self.raw[minion], six.string_types):
|
||||
ret.update({'host': self.raw[minion]})
|
||||
return ret
|
||||
elif isinstance(self.raw[minion], dict):
|
||||
|
@ -162,5 +162,5 @@ def _convert_range_to_list(tgt, range_server):
|
|||
try:
|
||||
return r.expand(tgt)
|
||||
except seco.range.RangeException as err:
|
||||
log.error('Range server exception: {0}'.format(err))
|
||||
log.error('Range server exception: %s', err)
|
||||
return []
|
||||
|
|
|
@ -11,7 +11,7 @@ When you want to use a range query for target matching, use ``--roster range``.
|
|||
salt-ssh --roster range '%%%example.range.cluster' test.ping
|
||||
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import fnmatch
|
||||
import copy
|
||||
|
||||
|
@ -38,16 +38,16 @@ def targets(tgt, tgt_type='range', **kwargs):
|
|||
'''
|
||||
|
||||
r = seco.range.Range(__opts__['range_server'])
|
||||
log.debug('Range connection to \'{0}\' established'.format(__opts__['range_server']))
|
||||
log.debug('Range connection to \'%s\' established', __opts__['range_server'])
|
||||
|
||||
hosts = []
|
||||
try:
|
||||
log.debug('Querying range for \'{0}\''.format(tgt))
|
||||
log.debug('Querying range for \'%s\'', tgt)
|
||||
hosts = r.expand(tgt)
|
||||
except seco.range.RangeException as err:
|
||||
log.error('Range server exception: %s', err)
|
||||
return {}
|
||||
log.debug('Range responded with: \'{0}\''.format(hosts))
|
||||
log.debug('Range responded with: \'%s\'', hosts)
|
||||
|
||||
# Currently we only support giving a raw range entry, no target filtering supported other than what range returns :S
|
||||
tgt_func = {
|
||||
|
@ -56,12 +56,12 @@ def targets(tgt, tgt_type='range', **kwargs):
|
|||
# 'glob': target_glob,
|
||||
}
|
||||
|
||||
log.debug('Filtering using tgt_type: \'{0}\''.format(tgt_type))
|
||||
log.debug('Filtering using tgt_type: \'%s\'', tgt_type)
|
||||
try:
|
||||
targeted_hosts = tgt_func[tgt_type](tgt, hosts)
|
||||
except KeyError:
|
||||
raise NotImplementedError
|
||||
log.debug('Targeting data for salt-ssh: \'{0}\''.format(targeted_hosts))
|
||||
log.debug('Targeting data for salt-ssh: \'%s\'', targeted_hosts)
|
||||
|
||||
return targeted_hosts
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ Scan a netmask or ipaddr for open ssh ports
|
|||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import socket
|
||||
import logging
|
||||
import copy
|
||||
|
@ -12,6 +12,7 @@ import copy
|
|||
# Import salt libs
|
||||
import salt.utils.network
|
||||
from salt._compat import ipaddress
|
||||
from salt.ext import six
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext.six.moves import map # pylint: disable=import-error,redefined-builtin
|
||||
|
@ -46,7 +47,7 @@ class RosterMatcher(object):
|
|||
ports = __opts__['ssh_scan_ports']
|
||||
if not isinstance(ports, list):
|
||||
# Comma-separate list of integers
|
||||
ports = list(map(int, str(ports).split(',')))
|
||||
ports = list(map(int, six.text_type(ports).split(',')))
|
||||
try:
|
||||
addrs = [ipaddress.ip_address(self.tgt)]
|
||||
except ValueError:
|
||||
|
@ -55,11 +56,11 @@ class RosterMatcher(object):
|
|||
except ValueError:
|
||||
pass
|
||||
for addr in addrs:
|
||||
addr = str(addr)
|
||||
addr = six.text_type(addr)
|
||||
ret[addr] = copy.deepcopy(__opts__.get('roster_defaults', {}))
|
||||
log.trace('Scanning host: {0}'.format(addr))
|
||||
log.trace('Scanning host: %s', addr)
|
||||
for port in ports:
|
||||
log.trace('Scanning port: {0}'.format(port))
|
||||
log.trace('Scanning port: %s', port)
|
||||
try:
|
||||
sock = salt.utils.network.get_socket(addr, socket.SOCK_STREAM)
|
||||
sock.settimeout(float(__opts__['ssh_scan_timeout']))
|
||||
|
|
|
@ -6,7 +6,7 @@ Parses roster entries out of Host directives from SSH config
|
|||
|
||||
salt-ssh --roster sshconfig '*' -r "echo hi"
|
||||
'''
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import python libs
|
||||
import os
|
||||
|
@ -16,7 +16,8 @@ import re
|
|||
|
||||
# Import Salt libs
|
||||
import salt.utils.files
|
||||
from salt.ext.six import string_types
|
||||
import salt.utils.stringutils
|
||||
from salt.ext import six
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -52,6 +53,7 @@ def parse_ssh_config(lines):
|
|||
# sublist represents a single Host definition
|
||||
hosts = []
|
||||
for line in lines:
|
||||
line = salt.utils.stringutils.to_unicode(line)
|
||||
if not line or line.startswith('#'):
|
||||
continue
|
||||
elif line.startswith('Host '):
|
||||
|
@ -139,7 +141,7 @@ class RosterMatcher(object):
|
|||
'''
|
||||
Return the configured ip
|
||||
'''
|
||||
if isinstance(self.raw[minion], string_types):
|
||||
if isinstance(self.raw[minion], six.string_types):
|
||||
return {'host': self.raw[minion]}
|
||||
if isinstance(self.raw[minion], dict):
|
||||
return self.raw[minion]
|
||||
|
|
|
@ -6,7 +6,7 @@ This module provides the point of entry to SPM, the Salt Package Manager
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import, print_function
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import yaml
|
||||
import tarfile
|
||||
|
@ -137,7 +137,7 @@ class SPMClient(object):
|
|||
else:
|
||||
raise SPMInvocationError('Invalid command \'{0}\''.format(command))
|
||||
except SPMException as exc:
|
||||
self.ui.error(str(exc))
|
||||
self.ui.error(six.text_type(exc))
|
||||
|
||||
def _pkgdb_fun(self, func, *args, **kwargs):
|
||||
try:
|
||||
|
@ -653,11 +653,11 @@ class SPMClient(object):
|
|||
raise SPMException('Auth defined, but password is not set for username: \'{0}\''
|
||||
.format(repo_info['username']))
|
||||
except SPMException as exc:
|
||||
self.ui.error(str(exc))
|
||||
self.ui.error(six.text_type(exc))
|
||||
else:
|
||||
query = http.query(dl_path, text=True)
|
||||
except SPMException as exc:
|
||||
self.ui.error(str(exc))
|
||||
self.ui.error(six.text_type(exc))
|
||||
|
||||
try:
|
||||
if query:
|
||||
|
@ -668,7 +668,7 @@ class SPMClient(object):
|
|||
else:
|
||||
raise SPMException('Response is empty, please check for Errors above.')
|
||||
except SPMException as exc:
|
||||
self.ui.error(str(exc))
|
||||
self.ui.error(six.text_type(exc))
|
||||
|
||||
return response
|
||||
|
||||
|
@ -757,35 +757,25 @@ class SPMClient(object):
|
|||
if use_formula is True:
|
||||
# Ignore/archive/delete the old version
|
||||
log.debug(
|
||||
'{0} {1}-{2} had been added, but {3}-{4} will replace it'.format(
|
||||
spm_name,
|
||||
cur_info['version'],
|
||||
cur_info['release'],
|
||||
new_info['version'],
|
||||
new_info['release'],
|
||||
)
|
||||
'%s %s-%s had been added, but %s-%s will replace it',
|
||||
spm_name, cur_info['version'], cur_info['release'],
|
||||
new_info['version'], new_info['release']
|
||||
)
|
||||
old_files.append(repo_metadata[spm_name]['filename'])
|
||||
else:
|
||||
# Ignore/archive/delete the new version
|
||||
log.debug(
|
||||
'{0} {1}-{2} has been found, but is older than {3}-{4}'.format(
|
||||
spm_name,
|
||||
new_info['version'],
|
||||
new_info['release'],
|
||||
cur_info['version'],
|
||||
cur_info['release'],
|
||||
)
|
||||
'%s %s-%s has been found, but is older than %s-%s',
|
||||
spm_name, new_info['version'], new_info['release'],
|
||||
cur_info['version'], cur_info['release']
|
||||
)
|
||||
old_files.append(spm_file)
|
||||
|
||||
if use_formula is True:
|
||||
log.debug(
|
||||
'adding {0}-{1}-{2} to the repo'.format(
|
||||
formula_conf['name'],
|
||||
formula_conf['version'],
|
||||
formula_conf['release'],
|
||||
)
|
||||
'adding %s-%s-%s to the repo',
|
||||
formula_conf['name'], formula_conf['version'],
|
||||
formula_conf['release']
|
||||
)
|
||||
repo_metadata[spm_name] = {
|
||||
'info': formula_conf.copy(),
|
||||
|
@ -803,33 +793,31 @@ class SPMClient(object):
|
|||
Dumper=SafeOrderedDumper
|
||||
)
|
||||
|
||||
log.debug('Wrote {0}'.format(metadata_filename))
|
||||
log.debug('Wrote %s', metadata_filename)
|
||||
|
||||
for file_ in old_files:
|
||||
if self.opts['spm_repo_dups'] == 'ignore':
|
||||
# ignore old packages, but still only add the latest
|
||||
log.debug('{0} will be left in the directory'.format(file_))
|
||||
log.debug('%s will be left in the directory', file_)
|
||||
elif self.opts['spm_repo_dups'] == 'archive':
|
||||
# spm_repo_archive_path is where old packages are moved
|
||||
if not os.path.exists('./archive'):
|
||||
try:
|
||||
os.makedirs('./archive')
|
||||
log.debug('{0} has been archived'.format(file_))
|
||||
log.debug('%s has been archived', file_)
|
||||
except IOError:
|
||||
log.error('Unable to create archive directory')
|
||||
try:
|
||||
shutil.move(file_, './archive')
|
||||
except (IOError, OSError):
|
||||
log.error(
|
||||
'Unable to archive {0}'.format(file_)
|
||||
)
|
||||
log.error('Unable to archive %s', file_)
|
||||
elif self.opts['spm_repo_dups'] == 'delete':
|
||||
# delete old packages from the repo
|
||||
try:
|
||||
os.remove(file_)
|
||||
log.debug('{0} has been deleted'.format(file_))
|
||||
log.debug('%s has been deleted', file_)
|
||||
except IOError:
|
||||
log.error('Unable to delete {0}'.format(file_))
|
||||
log.error('Unable to delete %s', file_)
|
||||
except OSError:
|
||||
# The file has already been deleted
|
||||
pass
|
||||
|
|
|
@ -5,11 +5,11 @@ This module allows SPM to use sqlite3 as the backend for SPM's package database.
|
|||
.. versionadded:: 2015.8.0
|
||||
'''
|
||||
|
||||
from __future__ import absolute_import
|
||||
import os.path
|
||||
import logging
|
||||
import sqlite3
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import sqlite3
|
||||
from sqlite3 import OperationalError
|
||||
from salt.ext.six.moves import zip
|
||||
|
||||
|
@ -22,11 +22,11 @@ def init():
|
|||
Get an sqlite3 connection, and initialize the package database if necessary
|
||||
'''
|
||||
if not os.path.exists(__opts__['spm_cache_dir']):
|
||||
log.debug('Creating SPM cache directory at {0}'.format(__opts__['spm_db']))
|
||||
log.debug('Creating SPM cache directory at %s', __opts__['spm_db'])
|
||||
os.makedirs(__opts__['spm_cache_dir'])
|
||||
|
||||
if not os.path.exists(__opts__['spm_db']):
|
||||
log.debug('Creating new package database at {0}'.format(__opts__['spm_db']))
|
||||
log.debug('Creating new package database at %s', __opts__['spm_db'])
|
||||
|
||||
sqlite3.enable_callback_tracebacks(True)
|
||||
conn = sqlite3.connect(__opts__['spm_db'], isolation_level=None)
|
||||
|
|
|
@ -6,7 +6,7 @@ This module allows SPM to use the local filesystem to install files for SPM.
|
|||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import os.path
|
||||
import logging
|
||||
|
@ -16,6 +16,9 @@ import salt.syspaths
|
|||
import salt.utils.files
|
||||
import salt.utils.stringutils
|
||||
|
||||
# Import 3rd-party libs
|
||||
from salt.ext import six
|
||||
|
||||
# Get logging started
|
||||
log = logging.getLogger(__name__)
|
||||
FILE_TYPES = ('c', 'd', 'g', 'l', 'r', 's', 'm')
|
||||
|
@ -52,7 +55,7 @@ def check_existing(package, pkg_files, formula_def, conn=None):
|
|||
if conn is None:
|
||||
conn = init()
|
||||
|
||||
node_type = str(__opts__.get('spm_node_type'))
|
||||
node_type = six.text_type(__opts__.get('spm_node_type'))
|
||||
|
||||
existing_files = []
|
||||
for member in pkg_files:
|
||||
|
@ -92,7 +95,7 @@ def check_existing(package, pkg_files, formula_def, conn=None):
|
|||
if os.path.exists(out_file):
|
||||
existing_files.append(out_file)
|
||||
if not __opts__['force']:
|
||||
log.error('{0} already exists, not installing'.format(out_file))
|
||||
log.error('%s already exists, not installing', out_file)
|
||||
|
||||
return existing_files
|
||||
|
||||
|
@ -107,7 +110,7 @@ def install_file(package, formula_tar, member, formula_def, conn=None):
|
|||
if conn is None:
|
||||
conn = init()
|
||||
|
||||
node_type = str(__opts__.get('spm_node_type'))
|
||||
node_type = six.text_type(__opts__.get('spm_node_type'))
|
||||
|
||||
out_path = conn['formula_path']
|
||||
|
||||
|
@ -115,7 +118,7 @@ def install_file(package, formula_tar, member, formula_def, conn=None):
|
|||
new_name = member.name.replace('{0}/'.format(package), '', 1)
|
||||
if not new_name.startswith(tld) and not new_name.startswith('_') and not \
|
||||
new_name.startswith('pillar.example') and not new_name.startswith('README'):
|
||||
log.debug('{0} not in top level directory, not installing'.format(new_name))
|
||||
log.debug('%s not in top level directory, not installing', new_name)
|
||||
return False
|
||||
|
||||
for line in formula_def.get('files', []):
|
||||
|
@ -160,7 +163,7 @@ def install_file(package, formula_tar, member, formula_def, conn=None):
|
|||
if len(comps) > 1 and comps[0] == comps[1]:
|
||||
member.path = '/'.join(comps[1:])
|
||||
|
||||
log.debug('Installing package file {0} to {1}'.format(member.name, out_path))
|
||||
log.debug('Installing package file %s to %s', member.name, out_path)
|
||||
formula_tar.extract(member, out_path)
|
||||
|
||||
return out_path
|
||||
|
@ -173,7 +176,7 @@ def remove_file(path, conn=None):
|
|||
if conn is None:
|
||||
conn = init()
|
||||
|
||||
log.debug('Removing package file {0}'.format(path))
|
||||
log.debug('Removing package file %s', path)
|
||||
os.remove(path)
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Tests for the spm build utility
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Tests for the spm files utility
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Tests for the spm info utility
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import shutil
|
||||
|
||||
# Import Salt Testing libs
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Tests for the spm install utility
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Tests for the spm remove utility
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
Tests for the spm repo
|
||||
'''
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue