Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add INVENTORY_URL_BASE env variable #124

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demo-workflows/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ marshmallow-dataclass==8.5.3
jinja2==3.0.3
python_graphql_client==0.4.3
influxdb_client==1.26.0
frinx-conductor-client==1.0.5
frinx-conductor-workers==1.0.5
frinx-conductor-client==1.0.5
frinx-conductor-workers==1.0.6
5 changes: 2 additions & 3 deletions demo-workflows/workers/importDevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from sys import argv
from python_graphql_client import GraphqlClient
import os
from frinx_conductor_workers.frinx_rest import x_tenant_id
from frinx_conductor_workers.frinx_rest import x_tenant_id, inventory_url_base

# graphql client settings
inventory_url = "http://inventory:8000/graphql"
inventory_headers = {
"Accept-Encoding": "gzip, deflate, br",
"Content-Type": "application/json",
Expand All @@ -17,7 +16,7 @@
"DNT": "1"
}

client = GraphqlClient(endpoint=inventory_url, headers=inventory_headers)
client = GraphqlClient(endpoint=inventory_url_base, headers=inventory_headers)


def execute(body, variables):
Expand Down
12 changes: 6 additions & 6 deletions demo-workflows/workers/influx_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from influxdb_client import InfluxDBClient, BucketsApi
from influxdb_client.client.write_api import SYNCHRONOUS
from frinx_conductor_workers.frinx_rest import influxdb_url_base

influxdb_url="http://influxdb:8086"
# You can generate an API token from the "API Tokens Tab" in the UI
token = os.getenv("DOCKER_INFLUXDB_INIT_ADMIN_TOKEN","eyJrIjoiN09MSVpVZjlVRG1xNHlLNXpVbmZJOXFLWU1GOXFxNEIiLCJuIjoic3Nzc3MiLCJpZCI6MX0")
org = os.getenv("DOCKER_INFLUXDB_INIT_ORG","frinx-machine")
Expand All @@ -15,19 +15,19 @@ def create_bucket_if_not_exist(task):
bucket_name = task['inputData']['bucket']

if bucket_name is '':
return {'status': 'FAILED', 'output': {'url': influxdb_url, 'response_code': 500, 'response_body': "Failed"}, 'logs': []}
return {'status': 'FAILED', 'output': {'url': influxdb_url_base, 'response_code': 500, 'response_body': "Failed"}, 'logs': []}

with InfluxDBClient(url=influxdb_url, token=token, org=org) as client:
with InfluxDBClient(url=influxdb_url_base, token=token, org=org) as client:

bucket_api=client.buckets_api()
bucket = bucket_api.find_bucket_by_name(bucket_name)
if bucket != None:
print(bucket.name)
return {'status': 'COMPLETED', 'output': {'url': influxdb_url, 'response_code': 200, 'bucket_name': bucket.name, 'response_body': "Bucket with name " + bucket.name + " exist before"}, 'logs': []}
return {'status': 'COMPLETED', 'output': {'url': influxdb_url_base, 'response_code': 200, 'bucket_name': bucket.name, 'response_body': "Bucket with name " + bucket.name + " exist before"}, 'logs': []}
else:
bucket = bucket_api.create_bucket(bucket_name=bucket_name, org=org)
print(bucket.name)
return {'status': 'COMPLETED', 'output': {'url': influxdb_url, 'response_code': 200, 'bucket_name': bucket.name, 'response_body': "Created new bucket with name " + bucket.name}, 'logs': []}
return {'status': 'COMPLETED', 'output': {'url': influxdb_url_base, 'response_code': 200, 'bucket_name': bucket.name, 'response_body': "Created new bucket with name " + bucket.name}, 'logs': []}
except:
return {'status': 'FAILED', 'output': {'url': "influxdb", 'response_code': 500, 'response_body': "Creating of bucket was unsucessful"},
'logs': []}
Expand All @@ -40,7 +40,7 @@ def store_ops_data(task):
fields = task['inputData']['fields']
bucket = task['inputData']['bucket']

with InfluxDBClient(url=influxdb_url, token=token, org=org) as client:
with InfluxDBClient(url=influxdb_url_base, token=token, org=org) as client:

write_api = client.write_api(write_options=SYNCHRONOUS)

Expand Down
37 changes: 18 additions & 19 deletions demo-workflows/workers/inventory_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
import copy
import math
import json
from frinx_conductor_workers.frinx_rest import x_tenant_id
from frinx_conductor_workers.frinx_rest import x_tenant_id, inventory_url_base

# graphql client settings
inventory_url = "http://inventory:8000/graphql"
inventory_headers = {
"Accept-Encoding": "gzip, deflate, br",
"Content-Type": "application/json",
Expand All @@ -16,7 +15,7 @@
"Keep-Alive": "timeout=5"
}

client = GraphqlClient(endpoint=inventory_url, headers=inventory_headers)
client = GraphqlClient(endpoint=inventory_url_base, headers=inventory_headers)


def execute(body, variables):
Expand Down Expand Up @@ -233,16 +232,16 @@ def installed_device(task):

if response.get('errors'):
body['message'] = response['errors'][0]['message']
return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body},
return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body},
'logs': []}

if response.get('data'):
body['name'] = response['data']['devices']['edges']

return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200, 'response_body': body},
return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200, 'response_body': body},
'logs': []}

return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': {'Workflow failed'}},
return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': {'Workflow failed'}},
'logs': []}


Expand All @@ -254,7 +253,7 @@ def install_uninstall_device(task):

if device_id is None:
body = {"message": device_status}
return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body},
return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body},
'logs': []}

variables = {
Expand Down Expand Up @@ -284,13 +283,13 @@ def install_uninstall_device(task):
body['message'] = response['errors'][0]['message']

if 'already been installed' not in body['message']:
return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body},
return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body},
'logs': []}

if response.get('data'):
body['name'] = response['data'][task_type]['device']['name']

return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200, 'response_body': body},
return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200, 'response_body': body},
'logs': []}


Expand All @@ -308,7 +307,7 @@ def install_uninstall_in_batch(task):
body = {}
if response.get('errors'):
body['message'] = response['errors'][0]['message']
return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body},
return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body},
'logs': []}

if str(task['taskType']).find('uninstall') == -1:
Expand Down Expand Up @@ -349,7 +348,7 @@ def install_uninstall_in_batch(task):

device_status.update({device_id['node']['name']: per_device_params})

return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200, 'response_body': device_status},
return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200, 'response_body': device_status},
'logs': []}


Expand All @@ -369,7 +368,7 @@ def get_device_pages_ids(task):
print(response)
if response.get('errors'):
body = {'message': response['errors'][0]['message']}
return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body},
return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body},
'logs': []}

if response.get('data'):
Expand Down Expand Up @@ -397,7 +396,7 @@ def get_device_pages_ids(task):
print(e)
break

return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200,
return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200,
'page_ids': page_loop,
'page_size': len(page_loop),
"page_ids_count": len(page_ids)},
Expand Down Expand Up @@ -429,7 +428,7 @@ def page_device_dynamic_fork_tasks(task):
taskReferenceName_id += 1

return {'status': 'COMPLETED',
'output': {'url': inventory_url, 'dynamic_tasks_i': dynamic_tasks_i, 'dynamic_tasks': dynamic_tasks},
'output': {'url': inventory_url_base, 'dynamic_tasks_i': dynamic_tasks_i, 'dynamic_tasks': dynamic_tasks},
'logs': []}

def all_devices_fork_tasks(task):
Expand Down Expand Up @@ -459,7 +458,7 @@ def all_devices_fork_tasks(task):
dynamic_tasks_i.update({device_id: per_device_params})

return {'status': 'COMPLETED',
'output': {'url': inventory_url, 'dynamic_tasks_i': dynamic_tasks_i, 'dynamic_tasks': dynamic_tasks},
'output': {'url': inventory_url_base, 'dynamic_tasks_i': dynamic_tasks_i, 'dynamic_tasks': dynamic_tasks},
'logs': []}


Expand Down Expand Up @@ -487,7 +486,7 @@ def add_cli_device(task):

if response.get('errors'):
body['message'] = response['errors'][0]['message']
return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body},
return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body},
'logs': []}

body = {
Expand All @@ -496,7 +495,7 @@ def add_cli_device(task):
"isInstalled": response['data']['addDevice']['device']['isInstalled']
}

return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200, 'response_body': body},
return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200, 'response_body': body},
'logs': []}


Expand Down Expand Up @@ -531,7 +530,7 @@ def add_netconf_device(task):

if response.get('errors'):
body['message'] = response['errors'][0]['message']
return {'status': 'FAILED', 'output': {'url': inventory_url, 'response_code': 404, 'response_body': body},
return {'status': 'FAILED', 'output': {'url': inventory_url_base, 'response_code': 404, 'response_body': body},
'logs': []}

body = {
Expand All @@ -540,7 +539,7 @@ def add_netconf_device(task):
"isInstalled": response['data']['addDevice']['device']['isInstalled']
}

return {'status': 'COMPLETED', 'output': {'url': inventory_url, 'response_code': 200, 'response_body': body},
return {'status': 'COMPLETED', 'output': {'url': inventory_url_base, 'response_code': 200, 'response_body': body},
'logs': []}


Expand Down