Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • osm/nbi
1 result
Show changes
Commits on Source (3)
......@@ -411,7 +411,9 @@ class BaseTopic:
return None
@staticmethod
def format_on_operation(content, operation_type, operation_params):
def format_on_operation(
content, operation_type, operation_params=None, launch_workflow=True
):
if content["current_operation"] is None:
op_id = str(uuid4())
content["current_operation"] = op_id
......@@ -423,14 +425,16 @@ class BaseTopic:
operation = {}
operation["operationType"] = operation_type
operation["git_operation_info"] = None
operation["op_id"] = op_id
operation["result"] = None
operation["workflowState"] = "PROCESSING"
operation["resourceState"] = "NOT_READY"
operation["creationDate"] = now
operation["endDate"] = None
operation["operationParams"] = operation_params
if launch_workflow:
operation["workflowState"] = "PROCESSING"
operation["resourceState"] = "NOT_READY"
operation["operationState"] = "IN_PROGRESS"
operation["gitOperationInfo"] = None
operation["operationParams"] = operation_params
content["operationHistory"].append(operation)
return op_id
......
......@@ -344,12 +344,19 @@ class Engine(object):
with self.write_lock:
return self.map_topic[topic].move_ksu(session, _id, indata, kwargs)
def get_cluster_info(self, session, topic, _id, item):
def get_cluster_creds_file(self, session, topic, _id, item, op_id):
if topic not in self.map_topic:
raise EngineException(
"Unknown topic {}!!!".format(topic), HTTPStatus.INTERNAL_SERVER_ERROR
)
return self.map_topic[topic].get_cluster_info(session, _id, item)
return self.map_topic[topic].get_cluster_creds_file(session, _id, item, op_id)
def get_cluster_creds(self, session, topic, _id, item):
if topic not in self.map_topic:
raise EngineException(
"Unknown topic {}!!!".format(topic), HTTPStatus.INTERNAL_SERVER_ERROR
)
return self.map_topic[topic].get_cluster_creds(session, _id, item)
def update_cluster(self, session, topic, _id, item, indata):
if topic not in self.map_topic:
......
......@@ -458,16 +458,67 @@ class K8sTopic(BaseTopic):
f"{item} {profile_id} does'nt exists", HTTPStatus.UNPROCESSABLE_ENTITY
)
def get_cluster_info(self, session, _id, item):
def get_cluster_creds(self, session, _id, item):
if not self.multiproject:
filter_db = {}
else:
filter_db = self._get_project_filter(session)
filter_db[BaseTopic.id_field(self.topic, _id)] = _id
op_id = str(uuid4())
operation_params = {}
data = self.db.get_one(self.topic, filter_db)
data["current_operation"] = op_id
self.format_on_operation(data, item, operation_params, launch_workflow=False)
self.db.set_one(self.topic, {"_id": data["_id"]}, data)
self._send_msg("get_creds", {"cluster_id": _id, "operation_id": op_id})
return op_id
def get_cluster_creds_file(self, session, _id, item, op_id):
if not self.multiproject:
filter_db = {}
else:
filter_db = self._get_project_filter(session)
# To allow project&user addressing by name AS WELL AS _id
filter_db[BaseTopic.id_field(self.topic, _id)] = _id
data = self.db.get_one(self.topic, filter_db)
self._send_msg(item, {"_id": _id})
return data
creds_flag = None
for operations in data["operationHistory"]:
if operations["op_id"] == op_id:
creds_flag = operations["result"]
self.logger.info("Creds Flag: {}".format(creds_flag))
if creds_flag is True:
credentials = data["credentials"]
file_pkg = None
current_path = _id
self.fs.file_delete(current_path, ignore_non_exist=True)
self.fs.mkdir(current_path)
filename = "credentials.yaml"
file_path = (current_path, filename)
self.logger.info("File path: {}".format(file_path))
file_pkg = self.fs.file_open(file_path, "a+b")
credentials_yaml = yaml.safe_dump(
credentials, indent=4, default_flow_style=False
)
file_pkg.write(credentials_yaml.encode(encoding="utf-8"))
if file_pkg:
file_pkg.close()
file_pkg = None
self.fs.sync(from_path=current_path)
return (
self.fs.file_open((current_path, filename), "rb"),
"text/plain",
)
else:
raise EngineException(
"Not possible to get the credentials of the cluster",
HTTPStatus.UNPROCESSABLE_ENTITY,
)
def update_cluster(self, session, _id, item, indata):
if not self.multiproject:
......@@ -476,7 +527,10 @@ class K8sTopic(BaseTopic):
filter_db = self._get_project_filter(session)
# To allow project&user addressing by name AS WELL AS _id
filter_db[BaseTopic.id_field(self.topic, _id)] = _id
op_id = str(uuid4())
operation_params = {}
data = self.db.get_one(self.topic, filter_db)
data["current_operation"] = op_id
data["operatingState"] = "PROCESSING"
data["resourceState"] = "IN_PROGRESS"
operation_params = indata
......@@ -486,7 +540,6 @@ class K8sTopic(BaseTopic):
operation_params,
)
self.db.set_one(self.topic, {"_id": _id}, data)
op_id = data["current_operation"]
data = {"cluster_id": _id, "operation_id": op_id}
self._send_msg(item, data)
return op_id
......@@ -671,6 +724,7 @@ class KsusTopic(BaseTopic):
oka_flag = ""
if oka["_id"]:
oka_flag = "_id"
oka["sw_catalog_path"] = ""
elif oka["sw_catalog_path"]:
oka_flag = "sw_catalog_path"
......@@ -924,7 +978,10 @@ class KsusTopic(BaseTopic):
for ksus in data:
if ksus["_id"] != _id:
for okas in ksus["oka"]:
if okas["_id"] not in existing_oka:
self.logger.info("OKA: {}".format(okas))
if okas.get("sw_catalog_path", ""):
continue
elif okas["_id"] not in existing_oka:
existing_oka.append(okas["_id"])
if used_oka:
......
......@@ -711,6 +711,14 @@ valid_url_methods = {
"METHODS": ("GET",),
"ROLE_PERMISSION": "k8scluster:id:get_creds:",
},
"get_creds_file": {
"METHODS": ("GET",),
"ROLE_PERMISSION": "k8scluster:id:get_creds_file:",
"<ID>": {
"METHODS": ("GET",),
"ROLE_PERMISSION": "k8scluster:id:get_creds_file:id",
},
},
"scale": {
"METHODS": ("POST",),
"ROLE_PERMISSION": "k8scluster:id:scale:",
......@@ -1779,10 +1787,22 @@ class Server(object):
filter_q,
api_req=True,
)
elif topic == "clusters" and item == "get_creds":
outdata = self.engine.get_cluster_info(
engine_session, engine_topic, _id, item
)
elif (
topic == "clusters"
and item == "get_creds_file"
or item == "get_creds"
):
if item == "get_creds_file":
op_id = args[0]
file, _format = self.engine.get_cluster_creds_file(
engine_session, engine_topic, _id, item, op_id
)
outdata = file
if item == "get_creds":
op_id = self.engine.get_cluster_creds(
engine_session, engine_topic, _id, item
)
outdata = {"op_id": op_id}
else:
if item == "reports":
# TODO check that project_id (_id in this context) has permissions
......@@ -1852,7 +1872,7 @@ class Server(object):
self._set_location_header(main_topic, version, topic, _id)
else:
cherrypy.response.headers["Transaction-Id"] = _id
outdata = {"_id": _id}
outdata = {"_id": _id, "id": _id}
elif topic == "ns_instances_content":
# creates NSR
_id, _ = self.engine.new_item(
......@@ -1872,9 +1892,11 @@ class Server(object):
nslcmop_desc = {
"lcmOperationType": "terminate",
"nsInstanceId": ns_id,
"autoremove": indata.get("autoremove")
if "autoremove" in indata
else True,
"autoremove": (
indata.get("autoremove")
if "autoremove" in indata
else True
),
}
op_id, _, _ = self.engine.new_item(
rollback,
......@@ -1972,7 +1994,7 @@ class Server(object):
rollback, engine_session, engine_topic, indata, kwargs
)
self._set_location_header(main_topic, version, topic, _id)
outdata = {"id": _id}
outdata = {"_id": _id, "id": _id}
elif (
topic
in (
......@@ -1989,7 +2011,7 @@ class Server(object):
rollback, engine_session, engine_topic, indata, kwargs
)
self._set_location_header(main_topic, version, topic, _id)
outdata = {"_id": _id}
outdata = {"_id": _id, "id": _id}
elif topic == "ksus" and item:
if item == "clone":
_id = self.engine.clone(
......@@ -2002,7 +2024,7 @@ class Server(object):
cherrypy.request.headers,
)
self._set_location_header(main_topic, version, topic, _id)
outdata = {"id": _id}
outdata = {"_id": _id, "id": _id}
if item == "move":
op_id = self.engine.move_ksu(
engine_session, engine_topic, _id, indata, kwargs
......@@ -2033,7 +2055,7 @@ class Server(object):
cherrypy.request.headers,
)
self._set_location_header(main_topic, version, topic, _id)
outdata = {"id": _id}
outdata = {"_id": _id, "id": _id}
if op_id:
outdata["op_id"] = op_id
cherrypy.response.status = HTTPStatus.ACCEPTED.value
......