Skip to content

Commit

Permalink
Merge pull request #254 from stfc/refactor-to-openstack-actions
Browse files Browse the repository at this point in the history
Refactor entrypoints for openstack actions
  • Loading branch information
DavidFair authored Sep 11, 2024
2 parents b39a01c + 7e10746 commit 45466c9
Show file tree
Hide file tree
Showing 19 changed files with 209 additions and 130 deletions.
6 changes: 3 additions & 3 deletions actions/email.test.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: Sends a test email
enabled: true
entry_point: src/workflow_actions.py
entry_point: src/openstack_actions.py
name: email.test
parameters:
timeout:
default: 5400
action_name:
default: send_test_email
lib_entry_point:
default: workflows.send_test_email.send_test_email
immutable: true
type: string
email_to:
Expand Down
6 changes: 3 additions & 3 deletions actions/email.users.with.decom.flavors.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: Sends an email to inform users that they have VMs running on flavors that are to be decommissioned
enabled: true
entry_point: src/workflow_actions.py
entry_point: src/openstack_actions.py
name: email.users.with.decom.flavors
parameters:
timeout:
default: 5400
action_name:
default: send_decom_flavor_email
lib_entry_point:
default: workflows.send_decom_flavor_email.send_decom_flavor_email
immutable: true
type: string
subject:
Expand Down
6 changes: 3 additions & 3 deletions actions/email.users.with.decom.images.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: Sends an email to inform users that they have VMs running images that are to be decommissioned
enabled: true
entry_point: src/workflow_actions.py
entry_point: src/openstack_actions.py
name: email.users.with.decom.images
parameters:
timeout:
default: 5400
action_name:
default: send_decom_image_email
lib_entry_point:
default: workflows.send_decom_image_email.send_decom_image_email
immutable: true
type: string
subject:
Expand Down
6 changes: 3 additions & 3 deletions actions/email.users.with.shutoff.vms.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: Sends an email to inform users that they have VMs in Shutoff state
enabled: true
entry_point: src/workflow_actions.py
entry_point: src/openstack_actions.py
name: email.users.with.shutoff.vms
parameters:
timeout:
default: 5400
action_name:
default: send_shutoff_vm_email
lib_entry_point:
default: workflows.send_shutoff_vm_email.send_shutoff_vm_email
immutable: true
type: string
subject:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
---
description: Create external project orquesta workflow
description: Create external project
enabled: true
entry_point: workflows/project.create.external.yaml
name: workflow.project.create.external
entry_point: src/openstack_actions.py
name: project.create.external
parameters:
lib_entry_point:
default: workflows.create_external_project.create_external_project
immutable: true
type: string
requires_openstack:
default: true
immutable: true
type: string
cloud_account:
description: The clouds.yaml account to use whilst performing this action
required: true
Expand Down Expand Up @@ -71,4 +79,4 @@ parameters:
type: integer
default: 1
description: Floating Ips to allocate to the project
runner_type: orquesta
runner_type: python-script
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
---
description: Create internal project orquesta workflow
description: Create internal project
enabled: true
entry_point: workflows/project.create.internal.yaml
name: workflow.project.create.internal
entry_point: src/openstack_actions.py
name: project.create.internal
parameters:
lib_entry_point:
default: workflows.create_internal_project.create_internal_project
immutable: true
type: string
requires_openstack:
default: true
immutable: true
type: string
cloud_account:
description: The clouds.yaml account to use whilst performing this action
required: true
Expand Down Expand Up @@ -44,4 +52,4 @@ parameters:
default: []
type: array
description: List of Users (stfc domain) (IDs or Names) to give local user access
runner_type: orquesta
runner_type: python-script
10 changes: 7 additions & 3 deletions actions/project.delete.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---
description: Delete Openstack Project
enabled: true
entry_point: src/project_actions.py
entry_point: src/openstack_actions.py
name: project.delete
parameters:
submodule:
default: project_delete
lib_entry_point:
default: openstack_api.openstack_project.delete_project
immutable: true
type: string
requires_openstack:
default: true
immutable: true
type: string
cloud_account:
Expand Down
10 changes: 7 additions & 3 deletions actions/quota.set.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---
description: Set quota for project
enabled: true
entry_point: src/quota_actions.py
entry_point: src/openstack_actions.py
name: quota.set
parameters:
submodule:
default: quota_set
lib_entry_point:
default: openstack_api.openstack_quota.set_quota
immutable: true
type: string
requires_openstack:
default: true
immutable: true
type: string
cloud_account:
Expand Down
10 changes: 7 additions & 3 deletions actions/role.add.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---
description: Add User Role to Project
enabled: true
entry_point: src/role_actions.py
entry_point: src/openstack_actions.py
name: role.add
parameters:
submodule:
default: role_add
lib_entry_point:
default: openstack_api.openstack_roles.assign_role_to_user
immutable: true
type: string
requires_openstack:
default: true
immutable: true
type: string
cloud_account:
Expand Down
10 changes: 7 additions & 3 deletions actions/role.remove.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
---
description: Removes a role from a user's project permissions
enabled: true
entry_point: src/role_actions.py
entry_point: src/openstack_actions.py
name: role.remove
parameters:
submodule:
default: role_remove
lib_entry_point:
default: openstack_api.openstack_roles.remove_role_from_user
immutable: true
type: string
requires_openstack:
default: true
immutable: true
type: string
cloud_account:
Expand Down
6 changes: 3 additions & 3 deletions actions/server.list.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: List all servers
enabled: true
entry_point: src/workflow_actions.py
entry_point: src/openstack_actions.py
name: server.list
parameters:
timeout:
default: 5400
action_name:
default: list_all_openstack
lib_entry_point:
default: workflows.list_all_openstack.list_all_openstack
immutable: true
type: string
query_type:
Expand Down
6 changes: 3 additions & 3 deletions actions/server.search.by.datetime.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: Query servers based on a datetime property (e.g. created-at or last-updated)
enabled: true
entry_point: src/workflow_actions.py
entry_point: src/openstack_actions.py
name: server.search.by.datetime
parameters:
timeout:
default: 5400
action_name:
default: search_by_datetime
lib_entry_point:
default: workflows.search_by_datetime_search_by_datetime
immutable: true
type: string
query_type:
Expand Down
6 changes: 3 additions & 3 deletions actions/server.search.by.property.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: Search for servers with a selected property matching, or not matching given value(s)
enabled: true
entry_point: src/workflow_actions.py
entry_point: src/openstack_actions.py
name: server.search.by.property
parameters:
timeout:
default: 5400
action_name:
default: search_by_property
lib_entry_point:
default: workflows.search_by_property.search_by_property
immutable: true
type: string
query_type:
Expand Down
6 changes: 3 additions & 3 deletions actions/server.search.by.regex.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: Search for servers property using regex pattern, or not matching given value(s)
enabled: true
entry_point: src/workflow_actions.py
entry_point: src/openstack_actions.py
name: server.search.by.regex
parameters:
timeout:
default: 5400
action_name:
default: search_by_regex
lib_entry_point:
default: workflows.search_by_regex.search_by_regex
immutable: true
type: string
query_type:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
from importlib import import_module
from st2common.runners.base_action import Action

from openstack_api.openstack_connection import OpenstackConnection
from structs.email.smtp_account import SMTPAccount


class WorkflowActions(Action):
def run(self, action_name: str, **kwargs):
class OpenstackActions(Action):
def run(self, lib_entry_point: str, requires_openstack: bool = False, **kwargs):
"""
Dynamically dispatches to the function wanted
:param action_name: name of file/function which corresponds to function that will handle the action
:param lib_entry_point: path to function that handles action in lib layer
:param requires_openstack: if action requires connection to openstack
:param kwargs: all user-defined kwargs to pass to the function
"""
action_module = import_module(f"workflows.{action_name}")
action_func = getattr(action_module, action_name)
module, fn_name = lib_entry_point.rsplit(".", 1)
action_module = import_module(module)
action_func = getattr(action_module, fn_name)

self.logger.info("Workflow Action Received - %s", action_name)
self.logger.info("Action Received - %s", lib_entry_point)
self.logger.debug(
"with Parameters: %s",
"\n".join([f"{key}: {val}" for key, val in kwargs.items()]),
)

kwargs = self.parse_configs(**kwargs)
return action_func(**kwargs)
if not requires_openstack:
return action_func(**kwargs)

# setup openstack connection
with OpenstackConnection(kwargs["cloud_account"]) as conn:
kwargs["conn"] = conn
del kwargs["cloud_account"]
return action_func(**kwargs)

def parse_configs(self, **kwargs):
"""
Expand Down
6 changes: 3 additions & 3 deletions actions/user.search.by.property.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: Search for user with a selected property matching, or not matching given value(s)
enabled: true
entry_point: src/workflow_actions.py
entry_point: src/openstack_actions.py
name: user.search.by.property
parameters:
timeout:
default: 5400
action_name:
default: list_by_property
lib_entry_point:
default: workflows.search_by_property.search_by_property
immutable: true
type: string
query_type:
Expand Down
6 changes: 3 additions & 3 deletions actions/user.search.by.regex.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
description: Search for users property using regex pattern, or not matching given value(s)
enabled: true
entry_point: src/workflow_actions.py
entry_point: src/openstack_actions.py
name: user.search.by.regex
parameters:
timeout:
default: 5400
action_name:
default: search_by_regex
lib_entry_point:
default: workflows.search_by_regex.search_by_regex
immutable: true
type: string
query_type:
Expand Down
Loading

0 comments on commit 45466c9

Please sign in to comment.