Skip to content

Commit

Permalink
Fix for resource-manager 2.X.X (#82)
Browse files Browse the repository at this point in the history
Update resource-manager to support 6.X.X

fix python syntax warnings
fix import error messages cased by __init__.py
  • Loading branch information
mirohudec authored May 29, 2024
1 parent 27873fc commit 011b0fc
Show file tree
Hide file tree
Showing 18 changed files with 115 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import os
from pathlib import Path

import requests
from frinx_conductor_workers.frinx_rest import conductor_headers
Expand All @@ -10,11 +11,12 @@

workflow_import_url = conductor_url_base + "/metadata/workflow"

DIR_PATH = Path(os.path.dirname(os.path.realpath(__file__))).parent
FRINX_CONDUCTOR_WORKFLOWS: Path = Path(f"{DIR_PATH}/frinx_conductor_workflows")

def import_base_workflows():
import frinx_conductor_workflows

import_workflows(os.path.dirname(frinx_conductor_workflows.__file__))
def import_base_workflows():
import_workflows(FRINX_CONDUCTOR_WORKFLOWS)


def import_workflows(path):
Expand All @@ -36,7 +38,7 @@ def import_workflows(path):
headers=conductor_headers,
)
local_logs.info("Response status code - %s", r.status_code)
if r.status_code != 204:
if r.status_code != requests.codes.ok:
local_logs.warning(
"Import of workflow %s failed. "
"Ignoring the workflow. Response content: %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ def execute_mount_netconf(task):
if (
"reconcile" in task["inputData"]
and task["inputData"]["reconcile"] is not None
and task["inputData"]["reconcile"] is not ""
and task["inputData"]["reconcile"] != ""
):
mount_body["input"]["netconf"]["node-extension:reconcile"] = task["inputData"]["reconcile"]

if (
"schema-cache-directory" in task["inputData"]
and task["inputData"]["schema-cache-directory"] is not None
and task["inputData"]["schema-cache-directory"] is not ""
and task["inputData"]["schema-cache-directory"] != ""
):
mount_body["input"]["netconf"]["netconf-node-topology:schema-cache-directory"] = task[
"inputData"
Expand All @@ -91,7 +91,7 @@ def execute_mount_netconf(task):
if (
"sleep-factor" in task["inputData"]
and task["inputData"]["sleep-factor"] is not None
and task["inputData"]["sleep-factor"] is not ""
and task["inputData"]["sleep-factor"] != ""
):
mount_body["input"]["netconf"]["netconf-node-topology:sleep-factor"] = task["inputData"][
"sleep-factor"
Expand All @@ -100,7 +100,7 @@ def execute_mount_netconf(task):
if (
"between-attempts-timeout-millis" in task["inputData"]
and task["inputData"]["between-attempts-timeout-millis"] is not None
and task["inputData"]["between-attempts-timeout-millis"] is not ""
and task["inputData"]["between-attempts-timeout-millis"] != ""
):
mount_body["input"]["netconf"]["netconf-node-topology:between-attempts-timeout-millis"] = (
task["inputData"]["between-attempts-timeout-millis"]
Expand All @@ -109,7 +109,7 @@ def execute_mount_netconf(task):
if (
"connection-timeout-millis" in task["inputData"]
and task["inputData"]["connection-timeout-millis"] is not None
and task["inputData"]["connection-timeout-millis"] is not ""
and task["inputData"]["connection-timeout-millis"] != ""
):
mount_body["input"]["netconf"]["netconf-node-topology:connection-timeout-millis"] = task[
"inputData"
Expand All @@ -118,7 +118,7 @@ def execute_mount_netconf(task):
if (
"uniconfig-native" in task["inputData"]
and task["inputData"]["uniconfig-native"] is not None
and task["inputData"]["uniconfig-native"] is not ""
and task["inputData"]["uniconfig-native"] != ""
):
mount_body["input"]["netconf"]["uniconfig-config:uniconfig-native-enabled"] = task[
"inputData"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@
},
resourceTypeId: $resource_type_id)
{
id
edges {
node {
id
}
}
}
}"""
)
Expand All @@ -81,10 +85,14 @@
"""
query SearchPools($poolTag: String!) {
SearchPoolsByTags(tags: { matchesAny: [{matchesAll: [$poolTag]}]}) {
id
AllocationStrategy {Name}
Name
PoolProperties
edges {
node {
id
AllocationStrategy {Name}
Name
PoolProperties
}
}
}
} """
)
Expand All @@ -97,9 +105,7 @@
{{ input }})
{
edges {
cursor {
ID
}
cursor
node {
id
Properties
Expand Down Expand Up @@ -162,12 +168,10 @@

query_resource_by_alt_id_template = Template(
"""
query QueryResourcesByAltId($poolId: ID, $input: Map!, $first: Int, $last: Int, $after: String, $before: String) {
query QueryResourcesByAltId($poolId: ID, $input: Map!, $first: Int, $last: Int, $after: Cursor, $before: Cursor) {
QueryResourcesByAltId(input: $input, poolId: $poolId, first: $first, last: $last, after: $after, before: $before) {
edges {
cursor {
ID
}
cursor
node {
id
Properties
Expand Down Expand Up @@ -216,14 +220,18 @@
"""
query getEmptyPools($resourceTypeId: ID) {
QueryEmptyResourcePools(resourceTypeId: $resourceTypeId) {
id
Name
Tags {
Tag
edges {
node {
id
Name
Tags {
Tag
}
AllocationStrategy {
Name
}
}
}
AllocationStrategy {
Name
}
}
}"""
)
Expand All @@ -246,9 +254,7 @@
Name
}
}
cursor{
ID
}
cursor
}
}
}
Expand Down Expand Up @@ -344,9 +350,7 @@ def query_claimed_resources(task, logs):
"data": {
"<query_type>": {
edges [
cursor {
<ID>
}
cursor: "<ID>"
node {
"id": "<id>",
"Properties": {
Expand Down Expand Up @@ -715,14 +719,18 @@ def query_pool(task, logs):
Returns:
Response from uniresource. Worker output format::
"result":{
"data": {
"QueryResourcePools": [
{
"id": "<id>"
}
]
}
"result": {
"data": {
"QueryResourcePools": {
"edges": [
{
"node": {
"id": "<id>"
}
}
]
}
}
}
"""
Expand Down Expand Up @@ -800,14 +808,18 @@ def query_pool_by_tag(task, logs):
Response from uniresource. Worker output format::
"result": {
"data": {
"SearchPoolsByTags": [
{
"SearchPoolsByTags": {
"edges": [
{
"node": {
"id": "<id>",
"AllocationStrategy": <Name>
"Name": "<name>"
"PoolProperties": <PoolProperties>
}
]
}
}
]
}
}
}
Expand Down Expand Up @@ -1395,14 +1407,18 @@ def query_search_empty_pools(task, logs):
Response from uniresource. Worker output format::
"result": {
"data": {
"QueryEmptyResourcePools": [
{
"id": "<id>",
"AllocationStrategy": <Name>
"Name": "<name>"
"Tags": <tag>
}
]
"QueryEmptyResourcePools": {
"edges": [
{
"node": {
"id": "<id>",
"AllocationStrategy": <Name>
"Name": "<name>"
"Tags": <tag>
}
}
]
}
}
}
Expand Down Expand Up @@ -1444,9 +1460,7 @@ def query_recently_active_resources(task, logs):
Name
}
}
cursor{
ID
}
cursor: "<ID>"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,9 @@ def parse_devices(task, fail_on_empty=True):
if "name" in dev:
extracted_devices.append(dev.get("name"))
else:
extracted_devices = (
[x.strip() for x in devices.split(",") if x is not ""] if devices else []
)
extracted_devices = [x.strip() for x in devices.split(",") if x != ""] if devices else []

if fail_on_empty and len(extracted_devices) is 0:
if fail_on_empty and len(extracted_devices) == 0:
raise Exception(
"For Uniconfig RPCs, a list of devices needs to be specified. "
"Global RPCs (involving all devices in topology) are not allowed for your own safety."
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"name": "decisionTask",
"taskReferenceName": "pool_exists",
"inputParameters": {
"pool_exists": "${query_pool_by_tag.output.result.data.SearchPoolsByTags}"
"pool_exists": "${query_pool_by_tag.output.result.data.SearchPoolsByTags.edges}"
},
"type": "DECISION",
"caseExpression": "$.pool_exists.length > 0 ? 'True' : 'False'",
Expand Down Expand Up @@ -48,8 +48,8 @@
"name": "LAMBDA_TASK",
"taskReferenceName": "lambda_print_alt_id",
"inputParameters": {
"address": "${query_pool_by_tag.output.result.data.SearchPoolsByTags[0].PoolProperties.address}",
"prefix": "${query_pool_by_tag.output.result.data.SearchPoolsByTags[0].PoolProperties.prefix}",
"address": "${query_pool_by_tag.output.result.data.SearchPoolsByTags.edges[0].node.PoolProperties.address}",
"prefix": "${query_pool_by_tag.output.result.data.SearchPoolsByTags.edges[0].node.PoolProperties.prefix}",
"scriptExpression": "return {'subnetAddress': $.address, 'subnetPrefix': $.prefix}"
},
"type": "LAMBDA",
Expand All @@ -67,7 +67,7 @@
"name": "RESOURCE_MANAGER_calculate_desired_size_from_prefix",
"taskReferenceName": "calculate_desired_size_from_prefix",
"inputParameters": {
"subnet": "${query_pool_by_tag.output.result.data.SearchPoolsByTags[0].PoolProperties.subnet}",
"subnet": "${query_pool_by_tag.output.result.data.SearchPoolsByTags.edges[0].node.PoolProperties.subnet}",
"prefix": "${workflow.input.prefix}",
"resourceType": "ipv4_prefix"
},
Expand All @@ -92,7 +92,7 @@
"taskReferenceName": "claim_resource_with_desired_value",
"type": "SIMPLE",
"inputParameters": {
"poolId": "${query_pool_by_tag.output.result.data.SearchPoolsByTags[0].id}",
"poolId": "${query_pool_by_tag.output.result.data.SearchPoolsByTags.edges[0].node.id}",
"userInput": {"desiredValue": "${workflow.input.desired_value}", "desiredSize": "${calculate_desired_size_from_prefix.output.result.data}"},
"description": "${workflow.input.description}",
"alternativeId": "${lambda_print_alt_id.output.result}"
Expand All @@ -105,7 +105,7 @@
"taskReferenceName": "claim_resource_without_desired_value",
"type": "SIMPLE",
"inputParameters": {
"poolId": "${query_pool_by_tag.output.result.data.SearchPoolsByTags[0].id}",
"poolId": "${query_pool_by_tag.output.result.data.SearchPoolsByTags.edges[0].node.id}",
"userInput": {"desiredSize": "${calculate_desired_size_from_prefix.output.result.data}"},
"description": "${workflow.input.description}",
"alternativeId": "${lambda_print_alt_id.output.result}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"name": "decisionTask",
"taskReferenceName": "pool_exists",
"inputParameters": {
"pool_exists": "${query_pool_by_tag.output.result.data.SearchPoolsByTags}"
"pool_exists": "${query_pool_by_tag.output.result.data.SearchPoolsByTags.edges}"
},
"type": "DECISION",
"caseExpression": "$.pool_exists.length > 0 ? 'True' : 'False'",
Expand Down Expand Up @@ -48,8 +48,8 @@
"name": "LAMBDA_TASK",
"taskReferenceName": "lambda_print_alt_id",
"inputParameters": {
"address": "${query_pool_by_tag.output.result.data.SearchPoolsByTags[0].PoolProperties.address}",
"prefix": "${query_pool_by_tag.output.result.data.SearchPoolsByTags[0].PoolProperties.prefix}",
"address": "${query_pool_by_tag.output.result.data.SearchPoolsByTags.edges[0].node.PoolProperties.address}",
"prefix": "${query_pool_by_tag.output.result.data.SearchPoolsByTags.edges[0].node.PoolProperties.prefix}",
"scriptExpression": "return {'subnetAddress': $.address, 'subnetPrefix': $.prefix}"
},
"type": "LAMBDA",
Expand Down Expand Up @@ -79,7 +79,7 @@
"taskReferenceName": "claim_resource_with_desired_value",
"type": "SIMPLE",
"inputParameters": {
"poolId": "${query_pool_by_tag.output.result.data.SearchPoolsByTags[0].id}",
"poolId": "${query_pool_by_tag.output.result.data.SearchPoolsByTags.edges[0].node.id}",
"userInput": {"desiredValue": "${workflow.input.desired_value}"},
"description": "${workflow.input.description}",
"alternativeId": "${lambda_print_alt_id.output.result}"
Expand All @@ -92,7 +92,7 @@
"taskReferenceName": "claim_resource_without_desired_value",
"type": "SIMPLE",
"inputParameters": {
"poolId": "${query_pool_by_tag.output.result.data.SearchPoolsByTags[0].id}",
"poolId": "${query_pool_by_tag.output.result.data.SearchPoolsByTags.edges[0].node.id}",
"description": "${workflow.input.description}",
"alternativeId": "${lambda_print_alt_id.output.result}"
}
Expand Down
Loading

0 comments on commit 011b0fc

Please sign in to comment.