Style fixes so "make pep8" is clean.

pull/2646/head
Michael DeHaan 12 years ago
parent 0113951580
commit 29209c4913

@ -334,12 +334,12 @@ class Inventory(object):
results = [] results = []
# allow Unix style @filename data # allow Unix style @filename data
for x in subset_pattern: for x in subset_pattern:
if x.startswith("@"): if x.startswith("@"):
fd = open(x[1:]) fd = open(x[1:])
results.extend(fd.read().split("\n")) results.extend(fd.read().split("\n"))
fd.close() fd.close()
else: else:
results.append(x) results.append(x)
self._subset = results self._subset = results
def lift_restriction(self): def lift_restriction(self):

@ -505,7 +505,7 @@ class PlayBook(object):
host_list = self._list_available_hosts(play.hosts) host_list = self._list_available_hosts(play.hosts)
if task.any_errors_fatal and len(host_list) < hosts_count: if task.any_errors_fatal and len(host_list) < hosts_count:
host_list = None host_list = None
# if no hosts remain, drop out # if no hosts remain, drop out
if not host_list: if not host_list:

@ -90,7 +90,7 @@ class Play(object):
load_vars = {} load_vars = {}
if self.playbook.inventory.basedir() is not None: if self.playbook.inventory.basedir() is not None:
load_vars['inventory_dir'] = self.playbook.inventory.basedir(); load_vars['inventory_dir'] = self.playbook.inventory.basedir()
self._tasks = self._load_tasks(self._ds.get('tasks', []), load_vars) self._tasks = self._load_tasks(self._ds.get('tasks', []), load_vars)
self._handlers = self._load_tasks(self._ds.get('handlers', []), load_vars) self._handlers = self._load_tasks(self._ds.get('handlers', []), load_vars)
@ -226,7 +226,7 @@ class Play(object):
mv[k] = utils.template(self.basedir, v, mv) mv[k] = utils.template(self.basedir, v, mv)
dirname = self.basedir dirname = self.basedir
if original_file: if original_file:
dirname = os.path.dirname(original_file) dirname = os.path.dirname(original_file)
include_file = utils.template(dirname, tokens[0], mv) include_file = utils.template(dirname, tokens[0], mv)
include_filename = utils.path_dwim(dirname, include_file) include_filename = utils.path_dwim(dirname, include_file)
data = utils.parse_yaml_from_file(include_filename) data = utils.parse_yaml_from_file(include_filename)

@ -674,33 +674,33 @@ def get_diff(diff):
return ">> the files are different, but the diff library cannot compare unicode strings" return ">> the files are different, but the diff library cannot compare unicode strings"
def is_list_of_strings(items): def is_list_of_strings(items):
for x in items: for x in items:
if not isinstance(x, basestring): if not isinstance(x, basestring):
return False return False
return True return True
def safe_eval(str): def safe_eval(str):
''' '''
this is intended for allowing things like: this is intended for allowing things like:
with_items: {{ a_list_variable }} with_items: {{ a_list_variable }}
where Jinja2 would return a string where Jinja2 would return a string
but we do not want to allow it to call functions (outside of Jinja2, where but we do not want to allow it to call functions (outside of Jinja2, where
the env is constrained) the env is constrained)
''' '''
# FIXME: is there a more native way to do this? # FIXME: is there a more native way to do this?
def is_set(var): def is_set(var):
return not var.startswith("$") and not '{{' in var return not var.startswith("$") and not '{{' in var
def is_unset(var): def is_unset(var):
return var.startswith("$") or '{{' in var return var.startswith("$") or '{{' in var
# do not allow method calls to modules # do not allow method calls to modules
if re.search(r'\w\.\w+\(', str): if re.search(r'\w\.\w+\(', str):
return str return str
# do not allow imports # do not allow imports
if re.search(r'import \w+', str): if re.search(r'import \w+', str):
return str return str
return eval(str) return eval(str)

@ -267,13 +267,11 @@ def main():
if id != None: if id != None:
filter_dict = {'client-token':id, 'instance-state-name' : 'running'} filter_dict = {'client-token':id, 'instance-state-name' : 'running'}
previous_reservations = ec2.get_all_instances(None, filter_dict ) previous_reservations = ec2.get_all_instances(None, filter_dict)
for res in previous_reservations: for res in previous_reservations:
for prev_instance in res.instances: for prev_instance in res.instances:
running_instances.append(prev_instance) running_instances.append(prev_instance)
count_remaining = count_remaining - len(running_instances) count_remaining = count_remaining - len(running_instances)
# module.fail_json(msg = "known running instances: %s" % (running_instances))
# Both min_count and max_count equal count parameter. This means the launch request is explicit (we want count, or fail) in how many instances we want. # Both min_count and max_count equal count parameter. This means the launch request is explicit (we want count, or fail) in how many instances we want.

@ -136,7 +136,7 @@ def activate_packages(module, port_path, packages):
for package in packages: for package in packages:
if not query_package(module, port_path, package): if not query_package(module, port_path, package):
module.fail_json(msg="failed to activate %s, package(s) not present" % (package)) module.fail_json(msg="failed to activate %s, package(s) not present" % (package))
if query_package(module, port_path, package, state="active"): if query_package(module, port_path, package, state="active"):
continue continue
@ -161,7 +161,7 @@ def deactivate_packages(module, port_path, packages):
for package in packages: for package in packages:
if not query_package(module, port_path, package): if not query_package(module, port_path, package):
module.fail_json(msg="failed to activate %s, package(s) not present" % (package)) module.fail_json(msg="failed to activate %s, package(s) not present" % (package))
if not query_package(module, port_path, package, state="active"): if not query_package(module, port_path, package, state="active"):
continue continue

@ -345,7 +345,7 @@ class Nagios(object):
notif_str += ";%s" % host notif_str += ";%s" % host
if svc is not None: if svc is not None:
notif_str += ";%s" % svc notif_str += ";%s" % svc
notif_str += "\n" notif_str += "\n"

@ -77,7 +77,7 @@ def get_current_name(name, specific_version):
for line in stdout.splitlines(): for line in stdout.splitlines():
if syntax % name in line: if syntax % name in line:
current_name = line.split()[0] current_name = line.split()[0]
return current_name return current_name

@ -385,9 +385,9 @@ class LinuxService(Service):
look_for = "%s.service" % name look_for = "%s.service" % name
for line in out.splitlines(): for line in out.splitlines():
if line.startswith(look_for): if line.startswith(look_for):
self.enable_cmd = location['systemctl'] self.enable_cmd = location['systemctl']
break break
# Locate a tool for runtime service management (start, stop etc.) # Locate a tool for runtime service management (start, stop etc.)
self.svc_cmd = '' self.svc_cmd = ''

@ -853,29 +853,29 @@ class AIX(Hardware):
self.facts['firmware_version'] = data[1].strip('IBM,') self.facts['firmware_version'] = data[1].strip('IBM,')
class Darwin(Hardware): class Darwin(Hardware):
""" """
Darwin-specific subclass of Hardware. Defines memory and CPU facts: Darwin-specific subclass of Hardware. Defines memory and CPU facts:
- processor - processor
- processor_cores - processor_cores
- memtotal_mb - memtotal_mb
- memfree_mb - memfree_mb
- model - model
- osversion - osversion
- osrevision - osrevision
""" """
platform = 'Darwin' platform = 'Darwin'
def __init__(self): def __init__(self):
Hardware.__init__(self) Hardware.__init__(self)
def populate(self): def populate(self):
self.sysctl = self.get_sysctl() self.sysctl = self.get_sysctl()
self.get_mac_facts() self.get_mac_facts()
self.get_cpu_facts() self.get_cpu_facts()
self.get_memory_facts() self.get_memory_facts()
return self.facts return self.facts
def get_sysctl(self): def get_sysctl(self):
rc, out, err = module.run_command(["/usr/sbin/sysctl", "hw", "machdep", "kern"]) rc, out, err = module.run_command(["/usr/sbin/sysctl", "hw", "machdep", "kern"])
if rc != 0: if rc != 0:
return dict() return dict()
@ -886,16 +886,16 @@ class Darwin(Hardware):
sysctl[key] = value.strip() sysctl[key] = value.strip()
return sysctl return sysctl
def get_mac_facts(self): def get_mac_facts(self):
self.facts['model'] = self.sysctl['hw.model'] self.facts['model'] = self.sysctl['hw.model']
self.facts['osversion'] = self.sysctl['kern.osversion'] self.facts['osversion'] = self.sysctl['kern.osversion']
self.facts['osrevision'] = self.sysctl['kern.osrevision'] self.facts['osrevision'] = self.sysctl['kern.osrevision']
def get_cpu_facts(self): def get_cpu_facts(self):
self.facts['processor'] = self.sysctl['machdep.cpu.brand_string'] self.facts['processor'] = self.sysctl['machdep.cpu.brand_string']
self.facts['processor_cores'] = self.sysctl['machdep.cpu.core_count'] self.facts['processor_cores'] = self.sysctl['machdep.cpu.core_count']
def get_memory_facts(self): def get_memory_facts(self):
self.facts['memtotal_mb'] = long(self.sysctl['hw.memsize']) / 1024 / 1024 self.facts['memtotal_mb'] = long(self.sysctl['hw.memsize']) / 1024 / 1024
self.facts['memfree_mb'] = long(self.sysctl['hw.usermem']) / 1024 / 1024 self.facts['memfree_mb'] = long(self.sysctl['hw.usermem']) / 1024 / 1024

@ -181,7 +181,7 @@ class VagrantWrapper(object):
self._deserialize() self._deserialize()
this_instance_dict = self._get_instance(vm_name,icount) this_instance_dict = self._get_instance(vm_name,icount)
if not this_instance_dict.has_key('box_name'): if not 'box_name' in this_instance_dict:
this_instance_dict['box_name'] = box_name this_instance_dict['box_name'] = box_name
this_instance_dict['forward_ports'] = ports this_instance_dict['forward_ports'] = ports
@ -205,7 +205,8 @@ class VagrantWrapper(object):
def status(self, vm_name = None, index = -1): def status(self, vm_name = None, index = -1):
'''Return the run status of the VM instance. If no instance N is given, returns first instance.''' '''Return the run status of the VM instance. If no instance N is given, returns first instance.'''
vm_names = [] vm_names = []
if vm_name != None: vm_names = [vm_name] if vm_name != None:
vm_names = [vm_name]
else: else:
vm_names = self._instances().keys() vm_names = self._instances().keys()
@ -225,7 +226,8 @@ class VagrantWrapper(object):
def config(self, vm_name, index = -1): def config(self, vm_name, index = -1):
'''Return info on SSH for the running instance.''' '''Return info on SSH for the running instance.'''
vm_names = [] vm_names = []
if vm_name != None: vm_names = [vm_name] if vm_name != None:
vm_names = [vm_name]
else: else:
vm_names = self._instances().keys() vm_names = self._instances().keys()
@ -247,7 +249,8 @@ class VagrantWrapper(object):
changed = False changed = False
vm_names = [] vm_names = []
if vm_name != None: vm_names = [vm_name] if vm_name != None:
vm_names = [vm_name]
else: else:
vm_names = self._instances().keys() vm_names = self._instances().keys()
@ -300,6 +303,7 @@ class VagrantWrapper(object):
# #
# Helper Methods # Helper Methods
# #
def _instances(self): def _instances(self):
return self.vg_data['instances'] return self.vg_data['instances']
@ -308,7 +312,7 @@ class VagrantWrapper(object):
instances = self._instances() instances = self._instances()
inst_array = [] inst_array = []
if instances.has_key(vm_name): if vm_name in instances:
inst_array = instances[vm_name] inst_array = instances[vm_name]
if len(inst_array) > index: if len(inst_array) > index:
@ -393,18 +397,17 @@ class VagrantWrapper(object):
name = instance_dict['vagrant_name'] name = instance_dict['vagrant_name']
ip = instance_dict['internal_ip'] ip = instance_dict['internal_ip']
box_name = instance_dict['box_name'] box_name = instance_dict['box_name']
vfile.write(VAGRANT_FILE_VM_STANZA_HEAD % vfile.write(VAGRANT_FILE_VM_STANZA_HEAD % (name, name, name, ip, name, box_name))
(name, name, name, ip, name, box_name) ) if 'ram' in instance_dict:
if instance_dict.has_key('ram'): vfile.write(VAGRANT_FILE_MEMORY_LINE % (name, instance_dict['ram']))
vfile.write(VAGRANT_FILE_MEMORY_LINE % (name, instance_dict['ram']) ) vfile.write(VAGRANT_FILE_HOSTNAME_LINE % (name, name.replace('_','-')))
vfile.write(VAGRANT_FILE_HOSTNAME_LINE % (name, name.replace('_','-')) ) if 'forward_ports' in instance_dict:
if instance_dict.has_key('forward_ports'):
for port in instance_dict['forward_ports']: for port in instance_dict['forward_ports']:
port = int(port) port = int(port)
host_port = port host_port = port
if port < 1024: if port < 1024:
host_port = port + 10000 host_port = port + 10000
vfile.write(VAGRANT_FILE_PORT_FORWARD_LINE % (name, port, host_port) ) vfile.write(VAGRANT_FILE_PORT_FORWARD_LINE % (name, port, host_port))
vfile.write(VAGRANT_FILE_VM_STANZA_TAIL) vfile.write(VAGRANT_FILE_VM_STANZA_TAIL)
vfile.write(VAGRANT_FILE_TAIL) vfile.write(VAGRANT_FILE_TAIL)
@ -522,14 +525,15 @@ def main():
elif cmd == "config" or cmd == "conf": elif cmd == "config" or cmd == "conf":
if vm_name == None: if vm_name == None:
module.fail_json(msg = "Error: you must specify a vm_name when calling config." ) module.fail_json(msg = "Error: a vm_name is required when calling config.")
(changd, cnf) = vgw.config(vm_name) (changd, cnf) = vgw.config(vm_name)
module.exit_json(changed = changd, config = cnf) module.exit_json(changed = changd, config = cnf)
elif cmd == 'ssh': elif cmd == 'ssh':
# this doesn't really seem to belong here, should just manage the VM with ansible -- MPD
if vm_name == None: if vm_name == None:
module.fail_json(msg = "Error: you must specify a vm_name when calling ssh." ) module.fail_json(msg = "Error: a vm_name is required when calling ssh.")
(changd, cnf) = vgw.config(vm_name) (changd, cnf) = vgw.config(vm_name)
sshcmd = "ssh -i %s -p %s %s@%s" % (cnf["IdentityFile"], cnf["Port"], cnf["User"], cnf["HostName"]) sshcmd = "ssh -i %s -p %s %s@%s" % (cnf["IdentityFile"], cnf["Port"], cnf["User"], cnf["HostName"])

Loading…
Cancel
Save