Fix pep8 failures
Update to fix style errors to pass pep8 checks. Change-Id: If27182ad18e52aa9e7fe5ac8d48db52dacbbf0f3 Closes-bug: #1631536
This commit is contained in:
parent
0ac90c5522
commit
fa3395fb29
@ -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 = {
|
||||
@ -40,7 +39,7 @@ def setup_app(*args, **kwargs):
|
||||
app = make_app(
|
||||
pecan_config.app.root,
|
||||
hooks=app_hooks,
|
||||
force_canonical = False,
|
||||
force_canonical=False,
|
||||
logging=getattr(config, 'logging', {})
|
||||
)
|
||||
return app
|
||||
|
@ -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
|
||||
@ -37,7 +35,7 @@ class NodeDetailController(RestController):
|
||||
rpcapi = controller_api.API(context=request.context)
|
||||
res = rpcapi.delete_composednode(nodeid=self.nodeid)
|
||||
LOG.info(str(res))
|
||||
return res
|
||||
return res
|
||||
|
||||
@expose()
|
||||
def storages(self):
|
||||
@ -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(),
|
||||
|
@ -26,7 +26,7 @@ cfg.CONF.import_group('podm', 'valence.common.redfish.config')
|
||||
|
||||
def get_rfs_url(serviceext):
|
||||
REDFISH_BASE_EXT = "/redfish/v1/"
|
||||
INDEX = ''
|
||||
INDEX = ''
|
||||
# '/index.json'
|
||||
if REDFISH_BASE_EXT in serviceext:
|
||||
return cfg.CONF.podm.url + serviceext + INDEX
|
||||
@ -34,14 +34,16 @@ def get_rfs_url(serviceext):
|
||||
return cfg.CONF.podm.url + REDFISH_BASE_EXT + serviceext + INDEX
|
||||
|
||||
|
||||
def send_request(resource, method="GET",**kwargs):
|
||||
def send_request(resource, method="GET", **kwargs):
|
||||
# The verify=false param in the request should be removed eventually
|
||||
url = get_rfs_url(resource)
|
||||
httpuser = cfg.CONF.podm.user
|
||||
httppwd = cfg.CONF.podm.password
|
||||
resp = None
|
||||
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,43 +334,42 @@ 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
|
||||
composeurl = "Nodes/Actions/Allocate"
|
||||
headers = {'Content-type': 'application/json'}
|
||||
if not criteria:
|
||||
resp = send_request(composeurl, "POST", headers = headers)
|
||||
resp = send_request(composeurl, "POST", headers=headers)
|
||||
else:
|
||||
resp = send_request(composeurl, "POST", json=criteria, headers = headers)
|
||||
resp = send_request(composeurl, "POST", json=criteria, headers=headers)
|
||||
LOG.info(resp.headers)
|
||||
LOG.info(resp.text)
|
||||
LOG.info(resp.status_code)
|
||||
composednode = resp.headers['Location']
|
||||
|
||||
return { "node" : composednode }
|
||||
return {"node": composednode}
|
||||
|
||||
|
||||
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
|
||||
# count = 2
|
||||
lst_nodes = []
|
||||
nodeurllist = urls2list("Nodes")
|
||||
#podmtree = build_hierarchy_tree()
|
||||
#podmtree.writeHTML("0","/tmp/a.html")
|
||||
# podmtree = build_hierarchy_tree()
|
||||
# podmtree.writeHTML("0","/tmp/a.html")
|
||||
|
||||
for lnk in nodeurllist:
|
||||
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,16 +383,16 @@ 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
|
||||
nw = 0
|
||||
localstorage = node_storage_details(nodesystemurl)
|
||||
if "Processors" in node:
|
||||
cpu = { "count" : node["Processors"]["Count"],
|
||||
"model" : node["Processors"]["Model"]}
|
||||
cpu = {"count": node["Processors"]["Count"],
|
||||
"model": node["Processors"]["Model"]}
|
||||
|
||||
if "Memory" in node:
|
||||
ram = node["Memory"]["TotalSystemMemoryGiB"]
|
||||
@ -404,14 +400,13 @@ 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']
|
||||
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,
|
||||
"ram": ram, "storage": localstorage,
|
||||
"nw": nw, "location": nodelocation,
|
||||
"uuid": nodeuuid, "bmcip": bmcip, "bmcmac": bmcmac}
|
||||
if filterPassed:
|
||||
lst_nodes.append(node)
|
||||
# LOG.info(str(node))
|
||||
lst_nodes.append(node)
|
||||
# LOG.info(str(node))
|
||||
return lst_nodes
|
||||
|
@ -12,9 +12,9 @@ class Tree(object):
|
||||
|
||||
def add_node(self, identifier, data={}, parent=None):
|
||||
if identifier in self.nodes:
|
||||
node = self[identifier]
|
||||
node = self[identifier]
|
||||
else:
|
||||
node = TreeNode(identifier,data)
|
||||
node = TreeNode(identifier, data)
|
||||
self[identifier] = node
|
||||
|
||||
if parent is not None:
|
||||
@ -53,7 +53,7 @@ class Tree(object):
|
||||
self.processHTML(fileref, child, depth) # recursive call
|
||||
fileref.write("</ul>")
|
||||
|
||||
def writeHTML(self, rootnodeid, filename="chassisTree.html"):
|
||||
def writeHTML(self, rootnodeid, filename="chassisTree.html"):
|
||||
htmlfile = open(filename, 'w+')
|
||||
htmlfile.write("<html><body><h1>Tree</h1>")
|
||||
self.processHTML(htmlfile, rootnodeid)
|
||||
|
@ -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,35 +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
|
||||
import re
|
||||
from valence.flavor.generatorbase import generatorbase
|
||||
|
||||
LOG = logging.getLogger()
|
||||
|
||||
|
||||
class assettagGenerator(generatorbase):
|
||||
def __init__(self, nodes):
|
||||
generatorbase.__init__(self, nodes)
|
||||
generatorbase.__init__(self, nodes)
|
||||
|
||||
def description(self):
|
||||
return "Demo only: Generates location based on assettag"
|
||||
return "Demo only: Generates location based on assettag"
|
||||
|
||||
def generate(self):
|
||||
LOG.info("Default Generator")
|
||||
for node in self.nodes:
|
||||
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)}
|
||||
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)
|
||||
}
|
||||
LOG.info("Default Generator")
|
||||
for node in self.nodes:
|
||||
LOG.info("Node ID " + node['nodeid'])
|
||||
location = node['location']
|
||||
location = location.split('Sled')[0]
|
||||
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)}
|
||||
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)
|
||||
}
|
||||
|
@ -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)
|
||||
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 = list(filter(None, 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)
|
||||
}
|
||||
LOG.info("Default Generator")
|
||||
for node in self.nodes:
|
||||
LOG.info("Node ID " + node['nodeid'])
|
||||
location = node['location']
|
||||
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)})
|
||||
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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user