Commit b31d4cf3 by Rahul Dutta

To merge with github

parent 369a31cc
......@@ -30,7 +30,7 @@ class Nodes(Resource):
http_client.OK,
nodes.Node.list_composed_nodes(filter_args.to_dict()))
@validator.check_input('compose_node_schema')
#@validator.check_input('compose_node_schema')
def post(self):
# TODO(): podm_id should be passed in request body, if not passed
# scheduler will decide on podm_id
......
......@@ -46,6 +46,7 @@ class Node(object):
@staticmethod
def _show_node_brief_info(node_info):
return {key: node_info[key] for key in node_info.keys()
if key in ["uuid", "name", "podm_id", "index", "resource_uri"]}
......@@ -55,7 +56,9 @@ class Node(object):
param request_body: parameter for node composition
return: brief info of this new composed node
"""
LOG.error("Compose Node triggered")
assemble_node={}
"""
if "flavor_id" in request_body:
flavor = flavors.get_flavor(request_body["flavor_id"])
requirements = flavor["properties"]
......@@ -66,28 +69,66 @@ class Node(object):
"memory": {},
"processor": {}
}
"""
name = request_body["name"]
# "description" is optional
description = request_body.get("description", "")
requirements = request_body["properties"]
#changes done as part of M2DC Project for allocating and assembling node
if "allocate" in request_body:
allocated_node=self.connection.allocate_node(name, description, requirements)
return allocated_node
if "assemble" in request_body:
assembled_node=self.connection.assemble_node(name, description, requirements)
assemble_node["uuid"] = utils.generate_uuid()
# Only store the minimum set of composed node info into backend db,
# since other fields like power status may be changed and valence is
# not aware.
node_db = {"uuid": assemble_node["uuid"],
"podm_id": self.podm_id,
"name": assemble_node["name"],
"index": assemble_node["index"],
"resource_uri": assemble_node["resource_uri"]}
db_api.Connection.create_composed_node(node_db)
return self._show_node_brief_info(assembled_node)
#name = request_body["name"]
# "description" is optional
#description = request_body.get("description", "")
# Moving _create_compose_request to drivers as this can be
# vendor specific request
composed_node = self.connection.compose_node(name, description,
requirements)
composed_node["uuid"] = utils.generate_uuid()
#composed_node = self.connection.compose_node(name, description,
#requirements)
#composed_node["uuid"] = utils.generate_uuid()
# Only store the minimum set of composed node info into backend db,
# since other fields like power status may be changed and valence is
# not aware.
node_db = {"uuid": composed_node["uuid"],
"podm_id": self.podm_id,
"name": composed_node["name"],
"index": composed_node["index"],
"resource_uri": composed_node["resource_uri"]}
db_api.Connection.create_composed_node(node_db)
return self._show_node_brief_info(composed_node)
#node_db = {"uuid": composed_node["uuid"],
#"podm_id": self.podm_id,
#"name": composed_node["name"],
#"index": composed_node["index"],
#"resource_uri": composed_node["resource_uri"]}
#db_api.Connection.create_composed_node(node_db)
#return self._show_node_brief_info(composed_node)
def manage_node(self, request_body):
"""Manage existing RSD node.
......
......@@ -15,7 +15,8 @@
import logging
import os
import json
import ast
import flask
import requests
from requests import auth
......@@ -33,6 +34,13 @@ CONF = valence.conf.CONF
LOG = logging.getLogger(__name__)
SERVICE_ROOT = None
#Added for sending request to RECSMaster
headers = {'Content-Type': 'application/json'}
username=admin
password=admin
RECS_serviceext="localhost:8080/redfish/v1/"
def update_service_root():
global SERVICE_ROOT
......@@ -92,7 +100,6 @@ def filter_chassis(jsonContent, filterCondition):
returnMembers.append(member_detail)
return returnMembers
def list_racks(filters={}, show_detail=False):
chassis_url = get_base_resource_url("Chassis")
resp = send_request(chassis_url)
......@@ -514,6 +521,193 @@ def _create_compose_request(name, description, requirements):
return request
#Listing down all available systems
def available_Systems():
listed_systems = []
available_systems=[]
r = requests.get("http://admin:admin@localhost:8080/redfish/v1/Systems", headers=headers)
json_data = json.loads(r.text)
j = ast.literal_eval(str(json_data['Members']))
for item in j:
sys_res = requests.get("http://admin:admin@localhost:8080/redfish/v1/Systems" + str(
str(str(str(item).replace("'", "")).split('u@odata.id: u'))[26:])[:-3], headers=headers)
listed_systems.append(str(str(str(str(item).replace("'", "")).split('u@odata.id: u'))[27:])[:-3])
for system in listed_systems:
response = requests.get('http://localhost:8080/redfish/v1/Systems/'+system, headers=headers,
auth=('admin', 'admin'))
json_data = json.loads(response.text)
if json_data[u'Oem'][u'EID_47597'][u'ComposedIn'] is None:
available_systems.append(system)
return available_systems
def checkFPGA(system_id):
response = requests.get('http://localhost:8080/redfish/v1/Systems/' + system_id + '/Processors', headers=headers,
auth=('admin', 'admin'))
json_data = json.loads(response.text)
if json_data["ProcessorType"] == "FPGA":
return True
return False
def available_PCIE():
listed_PCIE = []
r = requests.get("http://admin:admin@localhost:8080/redfish/v1/Systems", headers=headers)
json_data = json.loads(r.text)
j = ast.literal_eval(str(json_data['Members']))
for item in j:
sys_res = requests.get("http://admin:admin@localhost:8080/redfish/v1/Systems" + str(
str(str(str(item).replace("'", "")).split('u@odata.id: u'))[26:])[:-3], headers=headers)
listed_PCIE.append(str(str(str(str(item).replace("'", "")).split('u@odata.id: u'))[27:])[:-3])
return listed_PCIE
def available_Switches():
listed_Switches = []
r = requests.get("http://admin:admin@localhost:8080/redfish/v1/Switches", headers=headers)
json_data = json.loads(r.text)
j = ast.literal_eval(str(json_data['Members']))
for item in j:
sys_res = requests.get("http://admin:admin@localhost:8080/redfish/v1/Systems" + str(
str(str(str(item).replace("'", "")).split('u@odata.id: u'))[26:])[:-3], headers=headers)
listed_Switches.append(str(str(str(str(item).replace("'", "")).split('u@odata.id: u'))[28:])[:-3])
return listed_Switches
def get_system_details(system):
response = requests.get('http://localhost:8080/redfish/v1/Systems/' + system + '/Processors', headers=headers,
auth=('admin', 'admin'))
data = json.loads(response.text)
return data["@odata.id"]
def get_switch_details(switch):
response = requests.get('http://localhost:8080/redfish/v1/Switches/' + switch + '/Processors', headers=headers,
auth=('admin', 'admin'))
data = json.loads(response.text)
return data["@odata.id"]
def node_details(node_index, show_detail=True):
"""Get composed node details of specific index.
:param node_index: numeric index of new composed node.
:param show_detail: show more node detail when set to True.
:returns: node detail info.
"""
headers = {
'Content-Type': 'application/json',
}
response = requests.get('http://localhost:8080/redfish/v1/ComposedNodes/'+node_index, headers=headers,
auth=('admin', 'admin'))
json_data = json.loads(response.text)
node_detail = {
"name": json_data['Name'],
"index": json_data['Id'],
"resource_uri": json_data['@odata.id']
}
if show_detail:
LOG.error( "Show details Triggered")
#need to add more details of node components
node_detail.update({
"connectionSets":json_data['ConnectionSets'][0],
"components":json_data['ContainedResources'][0:],
"description": json_data['Description']})
return node_detail
#Added for M2DC project for allocate request, This method will return
# details of allocated systems
def allocate_node(name, description, requirements):
LOG.error('Allocate query triggered ')
allocated_details={}
allocate_json=""
if "system" in requirements:
if "number" in requirements["system"]:
no_of_system=requirements["system"]["number"]
l_available_Systems=available_Systems()
allocated_systems=l_available_Systems[:no_of_system]
allocated_details["Systems"]=allocated_systems
for item in allocated_systems:
allocated_details[item]=get_system_details(item)
if "FPGA" in requirements["system"]:
for item in allocated_systems:
fpga_present=checkFPGA(item)
if fpga_present is True:
allocated_details["FPGA"] = item
if "PCIE" in requirements:
no_of_PCIE=requirements["PCIE"]
available_pcie=available_PCIE()
allocated_pcie = available_pcie[:no_of_PCIE]
if "Switches" in requirements:
no_of_switches = requirements["switches"]
available_Switches=available_Switches()
allocated_switches = available_Switches[:no_of_switches]
for item in allocated_systems:
allocate_json += "{ \"Resource\": {\n\"@odata.id\": \"/redfish/v1/Systems/" + item + "\"\n} }"
allocate_json += ","
payload = '{"Name": "' + name + '",\n"Description": "' + description + '",\n"Systems": [' + allocate_json[:-1] + ']}'
return_value = requests.post('http://192.168.1.103:8080/redfish/v1/ComposedNodes/Actions/ComposedNodeCollection.Allocate',
headers=headers, data=payload, auth=('admin', 'admin'))
return allocated_details
#Method added for M2DC project. This method will return
#Deatils of assembled node
def assemble_node(name, description, requirements):
LOG.error('Assembled query Triggered')
endpoint_no = 65
list_systems=[]
s_json=""
name = name
desc = description
if "system" in requirements:
list_systems = requirements["system"]["list"]
width=requirements["system"]["width"]
connSet=requirements["system"]["connection"]
for item in list_systems:
s_json += "\n\"Endpoint" + chr(
endpoint_no) + "\": {\n\"@odata.id\": \"/redfish/v1/Systems/" + item + "/HSLLInterface\"\n}"
endpoint_no = endpoint_no + 1
s_json += ","
assemble_load = '{\n"ConnectionSets": [{\n"Connections": [{' + s_json + '\n"Width": ' + str(
width) + '\n}],\n"Description": "' + desc + '",\n"Name": "' + name + '"\n}],\n"ActiveConnectionSet": "' + connSet + '",\n"ResetNetworkSettings": "true"\n} '
response = requests.post('http://localhost:8080/redfish/v1/ComposedNodes/CN_0/Actions/ComposedNode.Assemble',
headers=headers, data=assemble_load, auth=('admin', 'admin'))
node_index='CN_0'
return node_details(node_index)
def compose_node(name, description, requirements):
"""Compose new node through podm api.
......
......@@ -143,11 +143,98 @@ compose_node_with_properties = {
'required': ['name'],
'additionalProperties': False,
}
#Changes in Schema for M2Dc project
allocate_node = {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'description': {'type': 'string'},
'podm_id': {'type': 'string'},
'properties': {
'type': 'object',
'properties': {
'system': {
'type': 'object',
'properties': {
'number': {'type': 'string'},
'fpga': {'type': 'string'}
},
'additionalProperties': False,
},
'switch': {
'type': 'object',
'properties': {
'number': {'type': 'string'},
},
'additionalProperties': False,
},
'pci_device': {
'type': 'object',
'properties': {
'type': {'type': 'array'}
},
'additionalProperties': False,
},
},
'additionalProperties': False,
},
},
'required': ['name'],
'additionalProperties': False,
}
assemble_node = {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'description': {'type': 'string'},
'podm_id': {'type': 'string'},
'properties': {
'type': 'object',
'properties': {
'system': {
'type': 'object',
'properties': {
'list': {'type': 'string'},
'width': {'type': 'string'},
'connection': {'type': 'string'}
},
'additionalProperties': False,
},
'switch': {
'type': 'object',
'properties': {
'list': {'type': 'string'},
'width': {'type': 'string'},
},
'additionalProperties': False,
},
'pci_device': {
'type': 'object',
'properties': {
'list': {'type': 'string'},
'width': {'type': 'string'},
},
'additionalProperties': False,
},
},
'additionalProperties': False,
},
},
'required': ['name'],
'additionalProperties': False,
}
compose_node_schema = {
'anyOf': [
compose_node_with_flavor,
compose_node_with_properties
compose_node_with_properties,
assemble_node,
allocate_node
]
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment