diff --git a/molteniron/moltenirond.py b/molteniron/moltenirond.py index cf71c55..8a21010 100755 --- a/molteniron/moltenirond.py +++ b/molteniron/moltenirond.py @@ -29,6 +29,7 @@ This is the MoltenIron server. from __future__ import print_function +import argparse import calendar from datetime import datetime import json @@ -37,25 +38,24 @@ import sys import time import traceback import yaml -import argparse from contextlib import contextmanager from sqlalchemy import create_engine -from sqlalchemy.orm import sessionmaker -from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String, ForeignKey +from sqlalchemy.exc import OperationalError +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import sessionmaker +from sqlalchemy.schema import MetaData, Table from sqlalchemy.sql import insert, update, delete from sqlalchemy.sql import and_ from sqlalchemy.types import TIMESTAMP -from sqlalchemy.schema import MetaData, Table import sqlalchemy_utils -from sqlalchemy.exc import OperationalError import collections # noqa -if (sys.version_info >= (3, 0)): +if sys.version_info >= (3, 0): from http.server import HTTPServer, BaseHTTPRequestHandler # noqa else: from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler # noqa @@ -166,7 +166,7 @@ class Nodes(declarative_base()): # from sqlalchemy.dialects.mysql import INTEGER # CREATE TABLE `Nodes` ( - # id INTEGER NOT NULL AUTO_INCREMENT, #@TODO UNSIGNED + # id INTEGER NOT NULL AUTO_INCREMENT, #@TODO(hamzy) UNSIGNED # name VARCHAR(50), # ipmi_ip VARCHAR(50), # ipmi_user VARCHAR(50), @@ -254,8 +254,9 @@ class IPs(declarative_base()): __tablename__ = 'IPs' # CREATE TABLE `IPs` ( - # id INTEGER NOT NULL AUTO_INCREMENT, #@TODO INTEGER(unsigned=True) - # node_id INTEGER, #@TODO UNSIGNED + # id INTEGER NOT NULL AUTO_INCREMENT, #@TODO(hamzy) \ + # INTEGER(unsigned=True) + # node_id INTEGER, #@TODO(hamzy) UNSIGNED # ip VARCHAR(50), # PRIMARY KEY (id), # FOREIGN KEY(node_id) REFERENCES `Nodes` (id) @@ -293,7 +294,7 @@ TYPE_SQLITE = 3 TYPE_SQLITE_MEMORY = 4 -class DataBase(): +class DataBase(object): """This class may be used access the molten iron database. """ def __init__(self, @@ -546,10 +547,10 @@ class DataBase(): # and ("." in node_id): check = isinstance(node_id, str) - if (sys.version_info < (3, 0)): + if sys.version_info < (3, 0): check = check or isinstance(node_id, unicode) # noqa - if (check and ("." in node_id)): + if check and ("." in node_id): # If an ipmi_ip was passed query = query.filter_by(ipmi_ip=node_id) else: @@ -744,11 +745,11 @@ class DataBase(): return {'status': 200} def cull(self, maxSeconds): - """If any node has been in use for longer than maxSeconds, deallocate - that node. + """Deallocate old nodes. - Nodes that are deallocated in this way get their state set to "dirty". - They are also scheduled for cleaning. + If any node has been in use for longer than maxSeconds, deallocate + that node. Nodes that are deallocated in this way get their state set + to "dirty". They are also scheduled for cleaning. """ if DEBUG: @@ -845,7 +846,7 @@ class DataBase(): return {'status': 200} - # @TODO shouldn't it return allocation_pool rather than ipmi_ip? + # @TODO(hamzy) shouldn't it return allocation_pool rather than ipmi_ip? def get_ips(self, owner_name): """Return all IPs allocated to a given node owner @@ -953,8 +954,9 @@ class DataBase(): return {'status': 200} def setup_status(self): - """Setup the status formatting strings depending on skipped elements, - lengths, and types. + """Setup the status formatting strings. + + Which depends on the skipped elements, lengths, and types. """ self.result_separator = "+" diff --git a/molteniron/tests/testAddBMNode.py b/molteniron/tests/testAddBMNode.py index e6d4e64..c4ced62 100755 --- a/molteniron/tests/testAddBMNode.py +++ b/molteniron/tests/testAddBMNode.py @@ -23,11 +23,11 @@ Tests the addBMNode MoltenIron command. from __future__ import print_function -import sys -import os -import yaml import argparse from molteniron import moltenirond +import os +import sys +import yaml if __name__ == "__main__": parser = argparse.ArgumentParser(description="Molteniron CLI tool") diff --git a/molteniron/tests/testAllocateBM.py b/molteniron/tests/testAllocateBM.py index a924084..955496e 100755 --- a/molteniron/tests/testAllocateBM.py +++ b/molteniron/tests/testAllocateBM.py @@ -23,11 +23,11 @@ Tests the MoltenIron allocateBM command. from __future__ import print_function -import sys -import os -import yaml import argparse from molteniron import moltenirond +import os +import sys +import yaml def compare_provisioned_nodes(lhs, rhs): diff --git a/molteniron/tests/testCull.py b/molteniron/tests/testCull.py index 504989a..da410b1 100755 --- a/molteniron/tests/testCull.py +++ b/molteniron/tests/testCull.py @@ -10,7 +10,7 @@ Tests the MoltenIron cull command. # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http: //www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -23,12 +23,12 @@ Tests the MoltenIron cull command. from __future__ import print_function -import sys -import os -import yaml import argparse -import time from molteniron import moltenirond +import os +import sys +import time +import yaml def compare_culled_nodes(lhs, rhs): diff --git a/molteniron/tests/testDeallocateBM.py b/molteniron/tests/testDeallocateBM.py index 17e1728..0c11723 100755 --- a/molteniron/tests/testDeallocateBM.py +++ b/molteniron/tests/testDeallocateBM.py @@ -23,11 +23,11 @@ Tests the MoltenIron deallocateBM command. from __future__ import print_function -import sys -import os -import yaml import argparse from molteniron import moltenirond +import os +import sys +import yaml def compare_provisioned_nodes(lhs, rhs): diff --git a/molteniron/tests/testDeallocateOwner.py b/molteniron/tests/testDeallocateOwner.py index 5b423e3..af189ea 100755 --- a/molteniron/tests/testDeallocateOwner.py +++ b/molteniron/tests/testDeallocateOwner.py @@ -23,11 +23,11 @@ Tests the MoltenIron deallocateOwner command. from __future__ import print_function -import sys -import os -import yaml import argparse from molteniron import moltenirond +import os +import sys +import yaml def compare_provisioned_nodes(lhs, rhs): diff --git a/molteniron/tests/testDoClean.py b/molteniron/tests/testDoClean.py index 4335468..a4d5471 100755 --- a/molteniron/tests/testDoClean.py +++ b/molteniron/tests/testDoClean.py @@ -23,11 +23,12 @@ Tests the MoltenIron doClean command. from __future__ import print_function -import sys -import os -import yaml import argparse from molteniron import moltenirond +import os +import sys +import yaml + if __name__ == "__main__": parser = argparse.ArgumentParser(description="Molteniron CLI tool") diff --git a/molteniron/tests/testGetField.py b/molteniron/tests/testGetField.py index 841d6b1..2038a62 100755 --- a/molteniron/tests/testGetField.py +++ b/molteniron/tests/testGetField.py @@ -23,11 +23,12 @@ Tests the MoltenIron get_field command. from __future__ import print_function -import sys -import os -import yaml import argparse from molteniron import moltenirond +import os +import sys +import yaml + if __name__ == "__main__": parser = argparse.ArgumentParser(description="Molteniron CLI tool") diff --git a/molteniron/tests/testGetIps.py b/molteniron/tests/testGetIps.py index 9a38d45..2bdbf86 100755 --- a/molteniron/tests/testGetIps.py +++ b/molteniron/tests/testGetIps.py @@ -23,11 +23,12 @@ Tests the MoltenIron get_ips command. from __future__ import print_function -import sys -import os -import yaml import argparse from molteniron import moltenirond +import os +import sys +import yaml + if __name__ == "__main__": parser = argparse.ArgumentParser(description="Molteniron CLI tool") diff --git a/molteniron/tests/testRemoveBMNode.py b/molteniron/tests/testRemoveBMNode.py index 0bd0fac..d30a57c 100755 --- a/molteniron/tests/testRemoveBMNode.py +++ b/molteniron/tests/testRemoveBMNode.py @@ -23,11 +23,12 @@ Tests the MoltenIron removeBMNode command. from __future__ import print_function -import sys -import os -import yaml import argparse from molteniron import moltenirond +import os +import sys +import yaml + if __name__ == "__main__": parser = argparse.ArgumentParser(description="Molteniron CLI tool") diff --git a/tox.ini b/tox.ini index 144c229..3c8de58 100644 --- a/tox.ini +++ b/tox.ini @@ -73,7 +73,7 @@ commands = mkdir -p testenv/var/run/ stop [testenv:pep8] -#commands = flake8 {posargs} +commands = flake8 {posargs} [testenv:venv] commands = {posargs}