Fix lint.

This commit is contained in:
C. R. Oldham 2015-03-06 10:34:13 -07:00
parent d19937eca2
commit 780c07b279

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
'''
Linode Cloud Module using Apache Libcloud ORlinode-python bindings
==================================================================
Linode Cloud Module using Apache Libcloud OR linode-python bindings
============================================-======================
The Linode cloud module is used to control access to the Linode VPS system
@ -37,7 +37,6 @@ Cloning requires a post 2015-02-01 salt-bootstrap.
from __future__ import absolute_import
# Import python libs
import copy
import pprint
import logging
import time
@ -81,9 +80,12 @@ LINODE_STATUS = {
'4': 'Saved to Disk (not in use)',
}
# Linode-python is now returning some complex types that
# are not serializable by msgpack. Kill those.
def remove_complex_types(dictionary):
'''
Linode-python is now returning some complex types that
are not serializable by msgpack. Kill those.
'''
for k, v in dictionary.iteritems():
if isinstance(v, dict):
@ -221,11 +223,11 @@ if HAS_LIBCLOUD:
loc = config.get_cloud_config_value('location', vm_, __opts__, default=2)
for location in locations:
if str(loc) in (str(location.id), str(location.name)):
return location
return location
def get_disk_size(vm_, size, swap):
'''
Return the size of of the root disk in MB
Return the size of of the root disk in MB
'''
return config.get_cloud_config_value(
'disk_size', vm_, __opts__, default=size.disk - swap
@ -244,7 +246,6 @@ if HAS_LINODEPY:
images = avail_images(conn)
return images[vm_['image']]['id']
def get_size(conn, vm_):
'''
Return available size from Linode (Linode calls them "plans")
@ -252,7 +253,6 @@ if HAS_LINODEPY:
sizes = avail_sizes(conn)
return sizes[vm_['size']]
def avail_sizes(conn=None):
'''
Return available sizes ("plans" in LinodeSpeak)
@ -272,7 +272,6 @@ if HAS_LINODEPY:
return remove_complex_types(sizes)
def avail_locations(conn=None):
'''
return available datacenter locations
@ -288,7 +287,6 @@ if HAS_LINODEPY:
return locations
def avail_images(conn=None):
'''
Return available images
@ -302,7 +300,6 @@ if HAS_LINODEPY:
images[d['LABEL']]['extra'] = d
return images
def get_ips(conn=None, LinodeID=None):
'''
Return IP addresses, both public and provate
@ -323,7 +320,6 @@ if HAS_LINODEPY:
return all_ips
def linodes(full=False, include_ips=False, conn=None):
'''
Return data on all nodes
@ -354,7 +350,6 @@ if HAS_LINODEPY:
results[n['LABEL']] = thisnode
return results
def stop(*args, **kwargs):
'''
Execute a "stop" action on a VM in Linode.
@ -380,7 +375,6 @@ if HAS_LINODEPY:
return {'action': 'stop',
'success': False}
def start(*args, **kwargs):
'''
Execute a "start" action on a VM in Linode.
@ -410,7 +404,6 @@ if HAS_LINODEPY:
return {'action': 'start',
'success': False}
def clone(*args, **kwargs):
'''
Clone an existing Linode
@ -458,21 +451,18 @@ if HAS_LINODEPY:
return node_data
def list_nodes():
'''
Return basic data on nodes
'''
return linodes(full=False, include_ips=True)
def list_nodes_full():
'''
Return all data on nodes
'''
return linodes(full=True, include_ips=True)
def get_node(LinodeID=None, name=None, full=False):
'''
Return information on a single node
@ -493,13 +483,11 @@ if HAS_LINODEPY:
return None
def destroy(vm_):
conn = get_conn()
machines = linodes(full=False, include_ips=False)
return conn.linode_delete(LinodeID=machines[vm_]['id'], skipChecks=True)
def get_location(conn, vm_):
'''
Return the node location to use.
@ -516,12 +504,12 @@ if HAS_LINODEPY:
# Was this an id that matches something in locations?
if str(loc) not in [locations[k]['id'] for k in locations]:
# No, let's try to match it against the full
# No, let's try to match it against the full
# name and the abbreviation and return the id
for key in locations:
if str(loc).lower() in (key,
str(locations[key]['id']).lower(),
str(locations[key]['abbreviation']).\
str(locations[key]['abbreviation']).
lower()):
return locations[key]['id']
else:
@ -531,8 +519,6 @@ if HAS_LINODEPY:
# use a default or throw an exception
return None
def get_disk_size(vm_, size, swap):
'''
Return the size of of the root disk in MB
@ -663,7 +649,7 @@ def get_one_kernel(conn=None, name=None):
return None
def waitfor_status(conn=None, LinodeID=None, status=None,
def waitfor_status(conn=None, LinodeID=None, status=None,
timeout=300, quiet=True):
'''
Wait for a certain status
@ -704,7 +690,7 @@ def waitfor_job(conn=None, LinodeID=None, JobID=None, timeout=300, quiet=True):
try:
result = conn.linode_job_list(LinodeID=LinodeID, JobID=JobID)
except linode.ApiError as exc:
log.info('Waiting for job {0} on host {1} returned {2}'.\
log.info('Waiting for job {0} on host {1} returned {2}'.
format(LinodeID, JobID, exc))
return False
@ -713,10 +699,10 @@ def waitfor_job(conn=None, LinodeID=None, JobID=None, timeout=300, quiet=True):
time.sleep(interval)
if not quiet:
log.info('Still waiting on Job {0} for {1}'.format(JobID,
log.info('Still waiting on Job {0} for {1}'.format(JobID,
LinodeID))
else:
log.debug('Still waiting on Job {0} for {1}'.format(JobID,
log.debug('Still waiting on Job {0} for {1}'.format(JobID,
LinodeID))
return False