Commit 45fd0fa9 authored by Gustavo Hermínio de Araújo's avatar Gustavo Hermínio de Araújo
Browse files

Adding baremetal orchestration via orquesta. Fog task

parent 107048db
name: baremetal_workflow_action
description: Baremetal orquestra workflow
runner_type: orquesta
entry_point: workflows/baremetal_workflow.yaml
enabled: true
parameters:
job_id:
required: true
type: string
\ No newline at end of file
---
name: get_baremetal_tasks
entry_point: scripts/get_baremetal_tasks.py
runner_type: python-script
enabled: true
parameters:
job_id:
type: string
required: true
\ No newline at end of file
name: main_action
description: Starting point action to fire the main orquestra workflow
runner_type: orquesta
entry_point: workflows/main_workflow.yaml
enabled: true
parameters:
job_id:
required: true
type: string
name: orquesta-sequential
description: A basic sequential workflow.
runner_type: orquesta
entry_point: workflows/orquesta-sequential.yaml
enabled: true
parameters:
name:
required: true
type: string
default: Michael
---
name: persist_job_action
entry_point: scripts/persist_job.py
runner_type: python-script
enabled: true
parameters:
job_id:
type: string
required: true
\ No newline at end of file
......@@ -6,9 +6,11 @@ from st2actions.runners.pythonrunner import Action
class FogAction(Action):
"""
This class talks with the REST web api for the FOG server.
"""
def __init__(self, config=None):
self.baseURL = config['fog']['address']
self.fogKey = config['fog']['api_key']
......@@ -22,17 +24,17 @@ class FogAction(Action):
self.header = {}
self.header['fog-api-token'] = self.fogKey
self.header['fog-user-token'] = self.userKey
def getAllTasks(self):
try:
tasks = requests.get(
self.baseURL+'task/current',
headers=self.header
).json()['tasks']
self.baseURL+'task/current',
headers=self.header
).json()['tasks']
return tasks
except Exception:
return []
def getFogHost(self, host):
hostData = self.action_service.get_value(host, local=False)
......@@ -43,15 +45,18 @@ class FogAction(Action):
returns the host number of given host
"""
try:
req = requests.get(self.baseURL+"host", headers=self.header)
req = requests.get(self.baseURL + "host", headers=self.header)
print("Request: " + str(req))
hostData = req.json()
print("Json data: " + str(hostData))
if hostData is not None:
for hostDict in hostData['hosts']:
if hostname == hostDict['name']:
return hostDict['id']
return -1
except Exception:
self.logger.exception('%s', "Failed to connect to the FOG server")
except Exception as e:
print(e)
raise Exception("ERROR IN SOMETHING!!")
def delTask(self, hostNum):
"""
......@@ -65,7 +70,7 @@ class FogAction(Action):
self.logger.info("%s", "successfully deleted image task")
except Exception:
self.logger.exception("Failed to delete the imaging task!")
def request(self, url, data=None, method="get"):
if data is not None:
return self.dataRequest(url, data, method=method)
......@@ -78,9 +83,9 @@ class FogAction(Action):
def dataRequest(self, url, data, method="post"):
methods = {
"post": requests.post,
"put": requests.put
}
"post": requests.post,
"put": requests.put
}
try:
return methods[method](url, json=data, headers=self.header)
except Exception:
......
......@@ -11,10 +11,11 @@ class StartCaptureAction(FogAction):
Schedules a capture for the given host with its
assigned image
"""
host_fog_name = self.getFogHost(host)
host_fog_num = str(self.getHostNumber(host_fog_name))
url = self.baseURL+'host/'+host_fog_num+'/task'
try:
host_fog_name = self.getFogHost(host)
host_fog_num = str(self.getHostNumber(host_fog_name))
url = self.baseURL+'host/'+host_fog_num+'/task'
self.request(url, data={"taskTypeID": 2}, method="post")
except Exception:
except Exception as e:
print(e)
sys.exit(1)
import sys
import json
from st2actions.runners.pythonrunner import Action
class BaremetalManager(Action):
def __init__(self, config=None):
super(BaremetalManager, self).__init__(config=config)
def run(self, job_id=None):
"""
Return baremetal tasks
"""
try:
job = json.loads(
self.action_service.get_value(job_id, local=False))
baremetal_tasks = job['baremetal']
print(baremetal_tasks)
return baremetal_tasks
except Exception as e:
print(e)
sys.exit(1)
#!/bin/bash
# change this
export ST2_AUTH_TOKEN="a7ebbad490874cd6a4548226f76e9fe0"
export ST2_AUTH_TOKEN="9b7ad55b163041829536d469b54204fd"
HOST_NAME="$1"
IP=$(st2 key get "$HOST_NAME" -j | jq -r '.value | fromjson.ipmi_address')
......
#!/bin/bash
# change this
export ST2_AUTH_TOKEN="a7ebbad490874cd6a4548226f76e9fe0"
export ST2_AUTH_TOKEN="9b7ad55b163041829536d469b54204fd"
HOST_NAME="$1"
IP=$(st2 key get "$HOST_NAME" -j | jq -r '.value | fromjson.ipmi_address')
......
import sys
import json
from st2actions.runners.pythonrunner import Action
class PersistJob(Action):
def __init__(self, config=None):
super(PersistJob, self).__init__(config=config)
def run(self, job_id=None):
"""
Persist ongoing job on store
"""
try:
jobs = set(json.loads(
self.action_service.get_value("jobs", local=False)))
if job_id in jobs:
print("job already started!")
else:
jobs.add(job_id)
self.action_service.set_value(
"jobs", json.dumps(list(jobs)), local=False)
except Exception as e:
print(e)
sys.exit(1)
version: 1.0
description: Baremetal workflow.
input:
- job_id
tasks:
get_baremetal_tasks:
action: sdnm.get_baremetal_tasks job_id=<% ctx().job_id %>
next:
- when: <% succeeded() %>
publish: baremetal_tasks=<% task(get_baremetal_tasks).result.result %>
do:
- log
log:
with: <% ctx(baremetal_tasks) %>
action: core.echo message=<% str(item()) %>
next:
- when: <% succeeded() %>
do: fog_deploy_image
fog_deploy_image:
with: <% ctx(baremetal_tasks) %>
action: sdnm.fog_deploy_host_action host=<% item()['hostname'] %>
version: 1.0
description: A basic sequential workflow.
input:
- job_id
tasks:
persist_job:
action: sdnm.persist_job_action job_id=<% ctx().job_id %>
next:
- when: <% succeeded() %>
do: baremetal
baremetal:
action: sdnm.baremetal_workflow_action job_id=<% ctx().job_id %>
\ No newline at end of file
version: 1.0
description: A basic sequential workflow.
input:
- name
vars:
- greeting: null
output:
- greeting: <% ctx().greeting %>
tasks:
task1:
action: core.echo message=<% ctx().name %>
next:
- when: <% succeeded() %>
publish: greeting=<% result().stdout %>
do: task2
task2:
action: core.echo
input:
message: "All your base are belong to us!"
next:
- when: <% succeeded() %>
publish:
- greeting: <% ctx("greeting") %>, <% result().stdout %>
do:
- task3
task3:
action: core.echo message=<% ctx('greeting') %>
next:
- when: <% succeeded() %>
publish: greeting=<% result().stdout %>
......@@ -35,18 +35,22 @@ fog:
required: true
secret: true
portal_service:
description: "Portal server configuration"
dashboard_api:
description: "Dashbord API configuration"
type: "object"
required: true
properties:
address:
type: "string"
description: "where to reach the fog server"
description: "where to reach the Dashboard API"
required: true
portalCredential:
type: "string"
description: "api key"
required: true
api_key:
type: "string"
description: "FOG api key"
required: true
secret: true
\ No newline at end of file
secret: true
authorization:
type: "string"
description: "api key"
required: true
secret: true
name: on_job_trigger
description: "rule to start the main action"
enabled: true
trigger:
type: sdnm.start_job_trigger
action:
ref: sdnm.main_action
parameters:
job_id: "{{ trigger.job_id }}"
---
name: "notify_slack"
pack: "sdnm"
description: "Sample rule firing on action completion."
enabled: true
trigger:
type: "core.st2.generic.notifytrigger"
parameters: {}
criteria:
trigger.channel:
pattern: "slack"
type: "equals"
action:
ref: "slack.post_message"
parameters:
message: "{{trigger.message}}"
This diff is collapsed.
......@@ -6,33 +6,39 @@ from st2reactor.sensor.base import PollingSensor
class sdnm_sensor(PollingSensor):
def setup(self):
self.logger = self.sensor_service.get_logger(name=self.__class__.__name__)
self.auth_token = self.sensor_service.get_value(name="lab_auth_token", local=False)
self.logger.info("got auth token %s", self.auth_token)
self.logger = self.sensor_service.get_logger(
name=self.__class__.__name__)
self.dashboard_address = self._config['dashboard_api']['address']
self.dasboard_portalCredential = self._config['dashboard_api']['portalCredential']
self.dasboard_authorization = self._config['dashboard_api']['authorization']
self.logger.info("got dashboard address: %s", self.dashboard_address)
def poll(self):
try:
jobs = json.loads(self.sensor_service.get_value("jobs", local=False))
dashboard = self._config['dashboard']['address']
name = self._config['dashboard']['lab_name']
url = dashboard + "/reservations"
jobs = json.loads(
self.sensor_service.get_value("jobs", local=False))
url = self.dashboard_address + "/reservations"
self.logger.info("polling at url %s", url)
header = {"auth-token": self.auth_token}
header = {"Content-Type": "application/json", "PortalCredential":
self.dasboard_portalCredential, "Autorization": self.dasboard_authorization}
todo_jobs = requests.get(url, timeout=10, headers=header).json()
for job_data in todo_jobs:
if job_data['id'] in jobs:
if "job_" + str(job_data['_id']) in jobs:
continue
self.logger.info("doing job %s", str(job_data['id']))
self.logger.info("doing job %s", str(todo_jobs))
# put job into datastore for workflow
self.sensor_service.set_value(
"job_" + str(job_data['id']),
json.dumps(job_data['payload']),
"job_" + str(job_data['_id']),
json.dumps(job_data['template']['metadata']),
local=False
)
# dispatch trigger
self.sensor_service.dispatch(
trigger="laas.start_job_trigger",
payload={"job_id": job_data['id']}
trigger="sdnm.start_job_trigger",
payload={"job_id": "job_" + str(job_data['_id'])}
)
except Exception as e:
self.logger.exception("Failed to poll(): %s", str(e))
......@@ -53,4 +59,4 @@ class sdnm_sensor(PollingSensor):
def remove_trigger(self, trigger):
# called when trigger is deleted
pass
\ No newline at end of file
pass
class_name: "sdnm_sensor"
entry_point: "sdnm.py"
description: "polls the dashboard api for deployments"
description: "polls the portal service api for reservations"
poll_interval: 60
trigger_types:
-
name: "start_job_trigger"
descrition: "a simple deployment trigger"
payload_schema:
type: "object"
properties:
job_id:
type: integer
\ No newline at end of file
- name: "start_job_trigger"
descrition: "a simple job trigger"
payload_schema:
type: "object"
properties:
job_id:
type: string
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 to comment