Fix pep8 failures
Update to fix style errors to pass pep8 checks. Change-Id: If27182ad18e52aa9e7fe5ac8d48db52dacbbf0f3 Closes-bug: #1631536
This commit is contained in:
		@@ -11,12 +11,11 @@
 | 
			
		||||
#    limitations under the License.
 | 
			
		||||
 | 
			
		||||
from oslo_config import cfg
 | 
			
		||||
from oslo_middleware import request_id
 | 
			
		||||
from oslo_service import service
 | 
			
		||||
from pecan import configuration
 | 
			
		||||
from pecan import make_app
 | 
			
		||||
from valence.api import hooks
 | 
			
		||||
from valence.common import exceptions as p_excp
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def setup_app(*args, **kwargs):
 | 
			
		||||
    config = {
 | 
			
		||||
 
 | 
			
		||||
@@ -12,8 +12,8 @@
 | 
			
		||||
 | 
			
		||||
from oslo_config import cfg
 | 
			
		||||
from oslo_log import log as logging
 | 
			
		||||
from valence.common import rpc
 | 
			
		||||
import sys
 | 
			
		||||
from valence.common import rpc
 | 
			
		||||
 | 
			
		||||
LOG = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,8 +11,8 @@
 | 
			
		||||
#    under the License.
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
import six
 | 
			
		||||
from oslo_utils import strutils
 | 
			
		||||
import six
 | 
			
		||||
from valence.common import exceptions as exception
 | 
			
		||||
 | 
			
		||||
LOG = logging.getLogger(__name__)
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,6 @@ from oslo_log import log as logging
 | 
			
		||||
import pecan
 | 
			
		||||
from pecan import expose
 | 
			
		||||
from pecan import request
 | 
			
		||||
from pecan import response
 | 
			
		||||
from pecan.rest import RestController
 | 
			
		||||
from valence.controller import api as controller_api
 | 
			
		||||
 | 
			
		||||
@@ -25,7 +24,6 @@ CONF = cfg.CONF
 | 
			
		||||
LOG = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#class NodeDetailController(object):
 | 
			
		||||
class NodeDetailController(RestController):
 | 
			
		||||
    def __init__(self, nodeid):
 | 
			
		||||
        self.nodeid = nodeid
 | 
			
		||||
@@ -58,7 +56,6 @@ class NodesController(RestController):
 | 
			
		||||
        return res
 | 
			
		||||
 | 
			
		||||
    # HTTP GET /nodes/
 | 
			
		||||
#    @index.when(method='POST', template='json')
 | 
			
		||||
    @expose(template='json')
 | 
			
		||||
    def post(self, **kwargs):
 | 
			
		||||
        LOG.debug("POST /nodes")
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,3 @@
 | 
			
		||||
from oslo_config import cfg
 | 
			
		||||
from pecan.hooks import PecanHook
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -6,8 +5,10 @@ class CORSHook(PecanHook):
 | 
			
		||||
 | 
			
		||||
    def after(self, state):
 | 
			
		||||
        state.response.headers['Access-Control-Allow-Origin'] = '*'
 | 
			
		||||
        state.response.headers['Access-Control-Allow-Methods'] = 'GET, POST, DELETE, PUT, LIST, OPTIONS'
 | 
			
		||||
        state.response.headers['Access-Control-Allow-Headers'] = 'origin, authorization, content-type, accept'
 | 
			
		||||
        state.response.headers['Access-Control-Allow-Methods'] = (
 | 
			
		||||
            'GET, POST, DELETE, PUT, LIST, OPTIONS')
 | 
			
		||||
        state.response.headers['Access-Control-Allow-Headers'] = (
 | 
			
		||||
            'origin, authorization, content-type, accept')
 | 
			
		||||
        if not state.response.headers['Content-Length']:
 | 
			
		||||
            state.response.headers['Content-Length'] = str(len(state.response.body))
 | 
			
		||||
 | 
			
		||||
            state.response.headers['Content-Length'] = (
 | 
			
		||||
                str(len(state.response.body)))
 | 
			
		||||
 
 | 
			
		||||
@@ -20,13 +20,12 @@ import os
 | 
			
		||||
from oslo_config import cfg
 | 
			
		||||
from oslo_log import log as logging
 | 
			
		||||
from oslo_service import service
 | 
			
		||||
import sys
 | 
			
		||||
import uuid
 | 
			
		||||
from valence.common import rpc_service
 | 
			
		||||
from valence.controller import config as controller_config
 | 
			
		||||
from valence.controller.handlers import flavor_controller
 | 
			
		||||
from valence.controller.handlers import node_controller
 | 
			
		||||
# from valence import version
 | 
			
		||||
import sys
 | 
			
		||||
import uuid
 | 
			
		||||
 | 
			
		||||
LOG = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
@@ -36,10 +35,6 @@ def main():
 | 
			
		||||
    controller_config.setup_logging()
 | 
			
		||||
    LOG.info(('Starting valence-controller in PID %s'), os.getpid())
 | 
			
		||||
    LOG.debug("Configuration:")
 | 
			
		||||
#   cfg.CONF.import_opt('topic',
 | 
			
		||||
#                       'valence.controller.config',
 | 
			
		||||
#                        group='controller')
 | 
			
		||||
 | 
			
		||||
    controller_id = uuid.uuid4()
 | 
			
		||||
    endpoints = [
 | 
			
		||||
        flavor_controller.Handler(),
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,9 @@ def send_request(resource, method="GET",**kwargs):
 | 
			
		||||
    httppwd = cfg.CONF.podm.password
 | 
			
		||||
    resp = None
 | 
			
		||||
    try:
 | 
			
		||||
        resp = requests.request(method, url, verify=False, auth=HTTPBasicAuth(httpuser, httppwd), **kwargs)    
 | 
			
		||||
        resp = requests.request(method, url, verify=False,
 | 
			
		||||
                                auth=HTTPBasicAuth(httpuser, httppwd),
 | 
			
		||||
                                **kwargs)
 | 
			
		||||
    except requests.exceptions.RequestException as e:
 | 
			
		||||
        LOG.error(e)
 | 
			
		||||
    return resp
 | 
			
		||||
@@ -52,7 +54,6 @@ def filter_chassis(jsonContent, filterCondition):
 | 
			
		||||
    returnMembers = []
 | 
			
		||||
    parsed = json.loads(jsonContent)
 | 
			
		||||
    members = parsed['Members']
 | 
			
		||||
    # count = parsed['Members@odata.count']
 | 
			
		||||
    for member in members:
 | 
			
		||||
        resource = member['@odata.id']
 | 
			
		||||
        resp = send_request(resource)
 | 
			
		||||
@@ -67,7 +68,6 @@ def filter_chassis(jsonContent, filterCondition):
 | 
			
		||||
 | 
			
		||||
def generic_filter(jsonContent, filterConditions):
 | 
			
		||||
    # returns boolean based on filters..its generic filter
 | 
			
		||||
    # returnMembers = []
 | 
			
		||||
    is_filter_passed = False
 | 
			
		||||
    for fc in filterConditions:
 | 
			
		||||
        if fc in jsonContent:
 | 
			
		||||
@@ -93,7 +93,6 @@ def generic_filter(jsonContent, filterConditions):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def get_details(source):
 | 
			
		||||
    # count = source['Members@odata.count']
 | 
			
		||||
    returnJSONObj = []
 | 
			
		||||
    members = source['Members']
 | 
			
		||||
    for member in members:
 | 
			
		||||
@@ -192,7 +191,6 @@ def node_ram_details(nodeurl):
 | 
			
		||||
    resp = send_request(nodeurl)
 | 
			
		||||
    respjson = resp.json()
 | 
			
		||||
    ram = extract_val(respjson, "MemorySummary/TotalSystemMemoryGiB")
 | 
			
		||||
    #LOG.debug(" Total Ram for node %s : %d " % (nodeurl, ram))
 | 
			
		||||
    return str(ram) if ram else "0"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -229,7 +227,6 @@ def systems_list(count=None, filters={}):
 | 
			
		||||
    lst_systems = []
 | 
			
		||||
    systemurllist = urls2list("Systems")
 | 
			
		||||
    podmtree = build_hierarchy_tree()
 | 
			
		||||
    #podmtree.writeHTML("0","/tmp/a.html")
 | 
			
		||||
 | 
			
		||||
    for lnk in systemurllist[:count]:
 | 
			
		||||
        filterPassed = True
 | 
			
		||||
@@ -337,10 +334,9 @@ def build_hierarchy_tree():
 | 
			
		||||
            podmtree.add_node(system, {"name": sysname}, d["ChassisID"])
 | 
			
		||||
    return podmtree
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def compose_node(criteria={}):
 | 
			
		||||
    #node comosition
 | 
			
		||||
    composeurl = "Nodes/Actions/Allocate"
 | 
			
		||||
    reqbody = None if not criteria else criteria
 | 
			
		||||
    headers = {'Content-type': 'application/json'}
 | 
			
		||||
    if not criteria:
 | 
			
		||||
        resp = send_request(composeurl, "POST", headers=headers)
 | 
			
		||||
@@ -355,11 +351,11 @@ def compose_node(criteria={}):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def delete_composednode(nodeid):
 | 
			
		||||
    #delete composed node
 | 
			
		||||
    deleteurl = "Nodes/" + str(nodeid)
 | 
			
		||||
    resp = send_request(deleteurl, "DELETE")
 | 
			
		||||
    return resp
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def nodes_list(count=None, filters={}):
 | 
			
		||||
    # comment the count value which is set to 2 now..
 | 
			
		||||
    # list of nodes with hardware details needed for flavor creation
 | 
			
		||||
@@ -373,7 +369,7 @@ def nodes_list(count=None, filters={}):
 | 
			
		||||
        filterPassed = True
 | 
			
		||||
        resp = send_request(lnk)
 | 
			
		||||
        if resp.status_code != 200:
 | 
			
		||||
            Log.info("Error in fetching Node details " + lnk)
 | 
			
		||||
            LOG.info("Error in fetching Node details " + lnk)
 | 
			
		||||
        else:
 | 
			
		||||
            node = resp.json()
 | 
			
		||||
 | 
			
		||||
@@ -387,8 +383,8 @@ def nodes_list(count=None, filters={}):
 | 
			
		||||
            nodeid = lnk.split("/")[-1]
 | 
			
		||||
            nodeuuid = node['UUID']
 | 
			
		||||
            nodelocation = node['AssetTag']
 | 
			
		||||
            #podmtree.getPath(lnk) commented as location should be computed using
 | 
			
		||||
            #other logic.consult Chester
 | 
			
		||||
            # podmtree.getPath(lnk) commented as location should be
 | 
			
		||||
            # computed using other logic.consult Chester
 | 
			
		||||
            nodesystemurl = node["Links"]["ComputerSystem"]["@odata.id"]
 | 
			
		||||
            cpu = {}
 | 
			
		||||
            ram = 0
 | 
			
		||||
@@ -404,7 +400,6 @@ def nodes_list(count=None, filters={}):
 | 
			
		||||
            if "EthernetInterfaces" in node["Links"]:
 | 
			
		||||
                nw = len(node["Links"]["EthernetInterfaces"])
 | 
			
		||||
 | 
			
		||||
            storage = 0
 | 
			
		||||
            bmcip = "127.0.0.1"  # system['Oem']['Dell_G5MC']['BmcIp']
 | 
			
		||||
            bmcmac = "00:00:00:00:00"  # system['Oem']['Dell_G5MC']['BmcMac']
 | 
			
		||||
            node = {"nodeid": nodeid, "cpu": cpu,
 | 
			
		||||
 
 | 
			
		||||
@@ -105,7 +105,6 @@ class RequestContextSerializer(messaging.Serializer):
 | 
			
		||||
            return context.to_dict()
 | 
			
		||||
 | 
			
		||||
    def deserialize_context(self, context):
 | 
			
		||||
#        return valence.common.context.Context.from_dict(context)
 | 
			
		||||
        return valence_ctx.Context.from_dict(context)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,11 +12,8 @@
 | 
			
		||||
#    License for the specific language governing permissions and limitations
 | 
			
		||||
#    under the License.
 | 
			
		||||
 | 
			
		||||
import json
 | 
			
		||||
from oslo_log import log as logging
 | 
			
		||||
from valence.common import osinterface as osapi
 | 
			
		||||
from valence.common.redfish import api as rfsapi
 | 
			
		||||
import requests
 | 
			
		||||
 | 
			
		||||
LOG = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
@@ -47,11 +44,7 @@ class Handler(object):
 | 
			
		||||
 | 
			
		||||
    def compose_nodes(self, context, criteria):
 | 
			
		||||
        """Chassis details could also be fetched and inserted"""
 | 
			
		||||
 | 
			
		||||
        # no of nodes to compose
 | 
			
		||||
        nodes_to_compose = int(criteria["nodes"]) if "nodes" in criteria else 1
 | 
			
		||||
        node_criteria = criteria["filter"] if "filter" in criteria else {}
 | 
			
		||||
        #no of node is not currently implemented
 | 
			
		||||
        return rfsapi.compose_node(node_criteria)
 | 
			
		||||
 | 
			
		||||
    def list_node_storages(self, context, data):
 | 
			
		||||
 
 | 
			
		||||
@@ -12,13 +12,13 @@
 | 
			
		||||
#    License for the specific language governing permissions and limitations
 | 
			
		||||
#    under the License.
 | 
			
		||||
 | 
			
		||||
import json
 | 
			
		||||
import re
 | 
			
		||||
from oslo_log import log as logging
 | 
			
		||||
import re
 | 
			
		||||
from valence.flavor.generatorbase import generatorbase
 | 
			
		||||
 | 
			
		||||
LOG = logging.getLogger()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class assettagGenerator(generatorbase):
 | 
			
		||||
    def __init__(self, nodes):
 | 
			
		||||
        generatorbase.__init__(self, nodes)
 | 
			
		||||
@@ -32,15 +32,24 @@ class assettagGenerator(generatorbase):
 | 
			
		||||
            LOG.info("Node ID " + node['nodeid'])
 | 
			
		||||
            location = node['location']
 | 
			
		||||
            location = location.split('Sled')[0]
 | 
			
		||||
        #Systems:Rack1-Block1-Sled2-Node1_Sled:Rack1-Block1-Sled2_Enclosure:Rack1-Block1_Rack:Rack1_
 | 
			
		||||
            location_lst = re.split("(\d+)", location)
 | 
			
		||||
            LOG.info(str(location_lst))
 | 
			
		||||
            location_lst = list(filter(None, location_lst))
 | 
			
		||||
            LOG.info(str(location_lst))
 | 
			
		||||
        extraspecs = {location_lst[i]: location_lst[i+1] for i in range(0,len(location_lst),2)}
 | 
			
		||||
            extraspecs = {location_lst[i]: location_lst[i + 1]
 | 
			
		||||
                          for i in range(0, len(location_lst), 2)}
 | 
			
		||||
            name = self.prepend_name + location
 | 
			
		||||
        return {
 | 
			
		||||
        self._flavor_template("L_" + name, node['ram'] , node['cpu']["count"], node['storage'], extraspecs),
 | 
			
		||||
        self._flavor_template("M_" + name, int(node['ram'])/2 , int(node['cpu']["count"])/2 , int(node['storage'])/2, extraspecs),
 | 
			
		||||
        self._flavor_template("S_" + name, int(node['ram'])/4 , int(node['cpu']["count"])/4 , int(node['storage'])/4, extraspecs)
 | 
			
		||||
            self._flavor_template("L_" + name,
 | 
			
		||||
                                  node['ram'],
 | 
			
		||||
                                  node['cpu']["count"],
 | 
			
		||||
                                  node['storage'], extraspecs),
 | 
			
		||||
            self._flavor_template("M_" + name,
 | 
			
		||||
                                  int(node['ram']) / 2,
 | 
			
		||||
                                  int(node['cpu']["count"]) / 2,
 | 
			
		||||
                                  int(node['storage']) / 2, extraspecs),
 | 
			
		||||
            self._flavor_template("S_" + name,
 | 
			
		||||
                                  int(node['ram']) / 4,
 | 
			
		||||
                                  int(node['cpu']["count"]) / 4,
 | 
			
		||||
                                  int(node['storage']) / 4, extraspecs)
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -12,32 +12,44 @@
 | 
			
		||||
#    License for the specific language governing permissions and limitations
 | 
			
		||||
#    under the License.
 | 
			
		||||
 | 
			
		||||
import json
 | 
			
		||||
import re
 | 
			
		||||
from oslo_log import log as logging
 | 
			
		||||
from valence.flavor.generatorbase import generatorbase
 | 
			
		||||
 | 
			
		||||
LOG = logging.getLogger()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class defaultGenerator(generatorbase):
 | 
			
		||||
    def __init__(self, nodes):
 | 
			
		||||
        generatorbase.__init__(self, nodes)
 | 
			
		||||
 | 
			
		||||
    def description(self):
 | 
			
		||||
      return "Generates 3 flavors(Tiny, Medium, Large) for each node considering all cpu cores, ram and storage"
 | 
			
		||||
        return ("Generates 3 flavors(Tiny, Medium, Large) for "
 | 
			
		||||
                "each node considering all cpu cores, ram and storage")
 | 
			
		||||
 | 
			
		||||
    def generate(self):
 | 
			
		||||
        LOG.info("Default Generator")
 | 
			
		||||
        for node in self.nodes:
 | 
			
		||||
            LOG.info("Node ID " + node['nodeid'])
 | 
			
		||||
            location = node['location']
 | 
			
		||||
        #Systems:Rack1-Block1-Sled2-Node1_Sled:Rack1-Block1-Sled2_Enclosure:Rack1-Block1_Rack:Rack1_
 | 
			
		||||
        location_lst = location.split("_");
 | 
			
		||||
            location_lst = location.split("_")
 | 
			
		||||
            location_lst = list(filter(None, location_lst))
 | 
			
		||||
        extraspecs = { l[0] : l[1] for l in (l.split(":") for l in location_lst) }
 | 
			
		||||
            extraspecs = (
 | 
			
		||||
                {l[0]: l[1] for l in (l.split(":") for l in location_lst)})
 | 
			
		||||
            name = self.prepend_name + location
 | 
			
		||||
        return {
 | 
			
		||||
        self._flavor_template("L_" + name, node['ram'] , node['cpu']["count"], node['storage'], extraspecs),
 | 
			
		||||
        self._flavor_template("M_" + name, int(node['ram'])/2 , int(node['cpu']["count"])/2 , int(node['storage'])/2, extraspecs),
 | 
			
		||||
        self._flavor_template("S_" + name, int(node['ram'])/4 , int(node['cpu']["count"])/4 , int(node['storage'])/4, extraspecs)
 | 
			
		||||
            self._flavor_template("L_" + name,
 | 
			
		||||
                                  node['ram'],
 | 
			
		||||
                                  node['cpu']["count"],
 | 
			
		||||
                                  node['storage'],
 | 
			
		||||
                                  extraspecs),
 | 
			
		||||
            self._flavor_template("M_" + name,
 | 
			
		||||
                                  int(node['ram']) / 2,
 | 
			
		||||
                                  int(node['cpu']["count"]) / 2,
 | 
			
		||||
                                  int(node['storage']) / 2,
 | 
			
		||||
                                  extraspecs),
 | 
			
		||||
            self._flavor_template("S_" + name,
 | 
			
		||||
                                  int(node['ram']) / 4,
 | 
			
		||||
                                  int(node['cpu']["count"]) / 4,
 | 
			
		||||
                                  int(node['storage']) / 4,
 | 
			
		||||
                                  extraspecs)
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user